telebot
telebot copied to clipboard
Error in edit-markup.js
when i used the edit-markup.js in the examples it gives me : [bot.error.event] TypeError: Cannot read property 'message_id' of undefined at D:\xyz\test.js:47:47 at processTicksAndRejections (internal/process/task_queues.js:93:5) at async Promise.all (index 0)
can you show the code ?
can you show the code ?
this is the code
const TeleBot = require('telebot');
const bot = new TeleBot('TELEGRAM_BOT_TOKEN');
var lastMessage;
bot.on('/start', msg => {
const markup = updateKeyboard('apples');
return bot.sendMessage(
msg.from.id, 'This is a editMessageReplyMarkup example. So, apples or oranges?', {markup}
).then(re => {
// Start updating message
lastMessage = [msg.from.id, re.result.message_id];
});
});
// On button callback
bot.on('callbackQuery', msg => {
// Send confirm
bot.answerCallbackQuery(msg.id);
if (!lastMessage) return bot.sendMessage(msg.from.id, 'Type /start');
const data = msg.data;
const [chatId, messageId] = lastMessage;
const replyMarkup = updateKeyboard(data);
// Edit message markup
return bot.editMessageReplyMarkup({chatId, messageId}, {replyMarkup});
});
bot.start();
// Returns keyboard markup
function updateKeyboard(fruit) {
let apples = 'apples';
let oranges = 'oranges';
if (fruit == 'apples') {
apples = `==> ${ apples } <==`;
} else {
oranges = `==> ${ oranges } <==`;
}
return bot.inlineKeyboard([
[
bot.inlineButton(apples, {callback: 'apples'}),
bot.inlineButton(oranges, {callback: 'oranges'})
]
]);
}
and this is the link of the example