telebot icon indicating copy to clipboard operation
telebot copied to clipboard

Error in edit-markup.js

Open xMA3x opened this issue 4 years ago • 2 comments

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)

xMA3x avatar Mar 28 '21 22:03 xMA3x

can you show the code ?

TeLoardBruh avatar Mar 29 '21 03:03 TeLoardBruh

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

xMA3x avatar Mar 29 '21 06:03 xMA3x