Telegram Bot API
Install
ECMAScript (Node.js v12.x LTS or higher)
npm i --save @darkwolf/telegram-bot.mjs
CommonJS (Node.js v10.x LTS or higher)
npm i --save @darkwolf/telegram-bot.cjs
Lazy Loading CommonJS (Node.js v10.x LTS or higher)
npm i --save @darkwolf/telegram-bot.lazy.cjs
Using
import TelegramBot, {
InputFile,
InputMediaPhoto,
InlineKeyboardMarkup,
InlineKeyboardButton,
MarkdownText,
ParseMode
} from '@darkwolf/telegram-bot.mjs'
const TelegramBot = require('@darkwolf/telegram-bot.cjs')
const TelegramBot = require('@darkwolf/telegram-bot.lazy.cjs')
const {
InputFile,
InputMediaPhoto,
InlineKeyboardMarkup,
InlineKeyboardButton,
MarkdownText,
ParseMode
} = TelegramBot
const bot = new TelegramBot(token, {
agent: new Agent()
})
bot.on('request', request => {})
bot.on('response', response => {})
bot.on('error', error => {})
const text = new MarkdownText()
.addTitle(MarkdownText.escape('Ave, Darkwolf!'))
.addItem('First Name', 'Pavel')
.addItem('Last Name', 'Wolf')
const message = await bot.sendMessage(chatId, text, {
parseMode: ParseMode.MARKDOWN,
replyMarkup: new InlineKeyboardMarkup([
[new InlineKeyboardButton('Ave, Darkwolf!', {
callbackData: 'ave-darkwolf'
})]
])
})
const photoMessage = await bot.sendPhoto(chatId, new InputFile('photo.jpeg'))
const messages = await bot.sendMediaGroup(chatId, [
new InputMediaPhoto(new InputFile('first.jpeg')),
new InputMediaPhoto(new InputFile('second.jpeg')),
new InputMediaPhoto(new InputFile('third.jpeg'))
])
const files = await Promise.all(messages.map(message => message.photo[0].getFile()))
const blobs = await Promise.all(files.map(file => file.download()))
Contact Me