node-telegram-bot-api icon indicating copy to clipboard operation
node-telegram-bot-api copied to clipboard

Keyboard Button CallBack Query function to get callbacks on clicks

Open shankar96 opened this issue 10 years ago • 4 comments

i want to get callback query from keyboard buttons. can someone suggest me to get the same using node-telegram-bot-api. i know its not integrated into it can someone give me idea where the callback query is going in api modules or anykind of help

shankar96 avatar Jun 04 '16 11:06 shankar96

var TelegramBot = require('node-telegram-bot-api');
TelegramBot.prototype.__processUpdate = TelegramBot.prototype._processUpdate; 
TelegramBot.prototype._processUpdate = function _processUpdate(update) { 
    const callbackQuery = update.callback_query;
    if (callbackQuery)
        this.emit('callback_query', callbackQuery);
    else
        this.__processUpdate(update);
};

niklv avatar Jun 04 '16 14:06 niklv

Check out this package https://www.npmjs.com/package/monkey-patches-node-telegram-bot-api

mironov avatar Jun 04 '16 14:06 mironov

@mironov @Niklv Thankx a lot

shankar96 avatar Jun 04 '16 16:06 shankar96

Please avoid listening on callback_query as illustrated above. It is unnecessary as callback_query event emission is already implemented. Also, you should not rely on methods prefixed with one or more dashes (_). They are private (or internal) methods; not to be used by library consumers.

TelegramBot already emits callback_query when one is encountered. Thus,

bot.on("callback_query", function(callbackQuery) {
    // 'callbackQuery' is of type CallbackQuery
    console.log(callbackQuery);
});

See CallbackQuery for more information.

gochomugo avatar Oct 10 '16 20:10 gochomugo