0

I want to change my InlineKeyboard buttons when i press another button but I keep getting this error.

    TypeError: Cannot create property 'reply_markup' on number '750548132'
2019-04-13T06:42:14.374318+00:00 app[web.1]: at TelegramBot.editMessageReplyMarkup (/app/node_modules/node-telegram-bot-api/src/telegram.js:1201:23)
2019-04-13T06:42:14.374320+00:00 app[web.1]: at TelegramBot.bot.on (/app/index.js:371:11)
2019-04-13T06:42:14.374321+00:00 app[web.1]: at TelegramBot.emit (/app/node_modules/eventemitter3/index.js:181:35)
2019-04-13T06:42:14.374323+00:00 app[web.1]: at TelegramBot.processUpdate (/app/node_modules/node-telegram-bot-api/src/telegram.js:657:12)
2019-04-13T06:42:14.374324+00:00 app[web.1]: at TelegramBotWebHook._parseBody (/app/node_modules/node-telegram-bot-api/src/telegramWebHook.js:121:21)

My Code:


const messageID = callbackQuery.message.chat.id;
const callBackData = callbackQuery.data;

if (callBackData.substring(0,7) == 'intent_') {      
    keyboard = {
        reply_markup: {
            inline_keyboard: [[
            {
                text: 'Menu 1',
                callback_data: 'socialMediaConnect'
            },{
                text: 'Menu 2',
                callback_data: 'music'
            }
            ]]
        }
    }

    bot.editMessageReplyMarkup(messageID, callbackQuery.message.from.id, callbackQuery.inline_message_id, keyboard)    
}

1 Answers1

0

The problem is that you need to wrap reply_markup in a JSON.stringify() else it won't work.

Here is what the documentation says:

reply_markup from telegram API doc

Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

I updated your code...

const messageID = callbackQuery.message.chat.id;
const callBackData = callbackQuery.data;

if (callBackData.substring(0,7) == 'intent_') {      
    keyboard = {
        reply_markup: JSON.stringify({ // Added JSON.stringify()
            inline_keyboard: [[
            {
                text: 'Menu 1',
                callback_data: 'socialMediaConnect'
            },{
                text: 'Menu 2',
                callback_data: 'music'
            }
            ]]
        })
    }

    bot.editMessageReplyMarkup(messageID, callbackQuery.message.from.id, callbackQuery.inline_message_id, keyboard)    
}
rotimi-best
  • 1,852
  • 18
  • 29