Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in edit-markup.js #197

Open
xMA3x opened this issue Mar 28, 2021 · 2 comments
Open

Error in edit-markup.js #197

xMA3x opened this issue Mar 28, 2021 · 2 comments

Comments

@xMA3x
Copy link

xMA3x commented Mar 28, 2021

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)

@TeLoardBruh
Copy link

can you show the code ?

@xMA3x
Copy link
Author

xMA3x commented Mar 29, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants