Saeed Heidarizarei
Saeed Heidarizarei

Reputation: 8956

Telegram bot inline keyboard via Node.JS

I'm using the node-telegram-bot-api module, How can I make my keyboard to inline Keyboard? This is my code:

bot.onText(/^\/start$/, function (msg) {
    const opts = {
        reply_to_message_id: msg.message_id,
        reply_markup: {
            resize_keyboard: true,
            one_time_keyboard: true,
            keyboard: [ ['Level 1'] ]
        }
    };

    bot.sendMessage(msg.chat.id, "I'm a test robot", opts);
});

Upvotes: 3

Views: 22996

Answers (5)

Kirubel Fekadu
Kirubel Fekadu

Reputation: 21

Use this and create your inline button

$ npm install --save node-telegram-keyboard-wrapper

Upvotes: 0

Dmitry Nevada
Dmitry Nevada

Reputation: 48

You just need to provide an InlineKeyboardButton object instead of plain text in your keyboard array of arrays.

bot.onText(/^\/start$/, function (msg) {
    const opts = {
        reply_to_message_id: msg.message_id,
        reply_markup: {
            resize_keyboard: true,
            one_time_keyboard: true,
            keyboard: [
              [{text: 'Level 1'}],
            ],
        }
    };

    bot.sendMessage(msg.chat.id, "I'm a test robot", opts);
});

Upvotes: 0

Juanmabs22
Juanmabs22

Reputation: 1300

You could use: https://github.com/RealPeha/telegram-keyboard

The library if focused on Telegraf, but you could use without it.

Upvotes: 0

kshubham506
kshubham506

Reputation: 511

In your case the solution would be:

const opts = {
        reply_to_message_id: msg.message_id,
        reply_markup: JSON.stringify({
        inline_keyboard: 
        [
            [{text: 'Level 1'}],
        ]
    })
  };

Upvotes: 0

Matteo Enna
Matteo Enna

Reputation: 1301

I answered a question similar to this link: How can create menu for telegram bot in bot father?

in your case you could use:

keyboard: [["uno :+1:"],["uno \ud83d\udc4d", "due"],["uno", "due","tre"],["uno", "due","tre","quattro"]]

Upvotes: 3

Related Questions