npm install telegram-bot-ts
or
yarn add telegram-bot-ts
import { TelegramBot, Message, SendMessageParam } from 'telegram-bot-ts';
let bot = new TelegramBot(<Your bot token here>);
bot.onText(async function (message: Message) {
bot.sendMessage({
chatId: message.chat.id,
text: message.text,
replyToMessageId: message.messageId,
});
});
bot.startLongPoll();
bot.onCallback(async function(callback: CallbackQuery) {
bot.sendMessage({
chatId: callback.chat.id,
text: callback.data,
});
});
bot.sendMessage({
chatId: <chat id>,
text: <message text>,,
replyMarkup: new ReplyKeyboardMarkup({
keyboard: [[new KeyboardButton({ text: 'a' })]]
})
});
bot.sendMessage({
chatId: <chat id>,
text: <message text>,
replyMarkup: new ReplyKeyboardRemove({})
});
You must use exactly one of the optional fields in InlineKeyboardButton.
bot.sendMessage({
chatId: <chat id>,
text: <message text>,,
replyMarkup: new InlineKeyboardMarkup({
inlineKeyboard: [
[new InlineKeyboardButton({ text: 'google', url: 'https://google.com' })],
]
})
});
You can set animation as InputFile or String (url or file_id) https://core.telegram.org/bots/api#sendanimation
bot.sendAnimation({
chatId: <chat id>,
animation: new InputFile('name.mp4', fs.readFileSync('name.mp4')),
});
bot.sendAnimation({
chatId: <chat id>,
animation: "some URL or File ID",
});
You can set animation as InputFile or String (url or file_id) https://core.telegram.org/bots/api#sendvideo
bot.sendVideo({
chatId: <chat id>,
video: new InputFile('name.mp4', fs.readFileSync('name.mp4')),
});
bot.sendVideo({
chatId: <chat id>,
video: "some URL or File ID",
});
bot.editMessageText({
text: 'new Text',
chatId: <chat Id>,
messageId: <message id>
});
bot.editMessageReplyMarkup({
chatId: <chat Id>,
messageId: <message id>,
replyMarkup: new InlineKeyboardMarkup({
inlineKeyboard: [
[new InlineKeyboardButton({ text: 'text a', callbackData: 'callback_a' }), new InlineKeyboardButton({ text: 'text_b', callbackData: 'callback_b' })],
[new InlineKeyboardButton({ text: 'text_c', callbackData: 'callback_c' })]
],
}),
});