3

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);
});
Saeed Heidarizarei
  • 8,406
  • 21
  • 60
  • 103

4 Answers4

3

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"]]
Community
  • 1
  • 1
Matteo Enna
  • 1,285
  • 1
  • 15
  • 36
0

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'}],
        ]
    })
  };
kshubham506
  • 101
  • 1
  • 2
  • 1
  • Does not work. Error: `Unhandled rejection Error: ETELEGRAM: 400 Bad Request: can't parse inline keyboard button: Text buttons are unallowed in the inline keyboard` – aggregate1166877 Jan 30 '22 at 23:23
0

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

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

Juanmabs22
  • 1,194
  • 9
  • 10
0

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