0.0.6 • Published 4 years ago

telegram-bot-ts v0.0.6

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

Typescript, Node.js module for Telegram Bot API (https://core.telegram.org/bots/api)

David NPM npm GitHub top language CodeFactor Bot API

patreon Liberapay giving

Install

    npm install telegram-bot-ts

or

    yarn add telegram-bot-ts

Examples

Answer on text

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();

Receive callback from inline keyboard

bot.onCallback(async function(callback: CallbackQuery) {
    bot.sendMessage({
        chatId: callback.chat.id,
        text: callback.data,
    });
});

Send keyboard

bot.sendMessage({
    chatId: <chat id>,
    text: <message text>,,
    replyMarkup: new ReplyKeyboardMarkup({
        keyboard: [[new KeyboardButton({ text: 'a' })]]
    })
});

Remove keyboard

bot.sendMessage({
    chatId: <chat id>,
    text: <message text>,
    replyMarkup: new ReplyKeyboardRemove({})
});

Send inline keyboard

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' })],
        ]
    })
});

Send Animation

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",
});

Send Video

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",
});

Edit Message Text

bot.editMessageText({
    text: 'new Text',
    chatId: <chat Id>,
    messageId: <message id>
});

Edit Inline Keyboard

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' })]
        ],
    }),
});
0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago

0.0.0

4 years ago