Node-telegram-bot-api: inline_keyboard callback - where find callback_query_id ?

Created on 4 Oct 2017  路  4Comments  路  Source: yagop/node-telegram-bot-api

inline_keyboard,
when the callback button is pressed I get callback_query.
I want to answer with answerCallbackQuery but where find callback_query_id ?

thanks.

Most helpful comment

bot.answerCallbackQuery doesn't need an Array as parameter but just an object.
The syntax used in the documentation is a bit error-prone. In fact, [opts] usually means that the parameter opts is optional, while one of the properties, callback_query_id, is mandatory.

So, try with:

bot.on("callback_query", q => {
    bot.answerCallbackQuery({
        callback_query_id: q.id,
        text: "ok",
    });
});

All 4 comments

When you press a button of a inline_keyboard, your bot receives an Update containing an Object called "CallbackQuery" (Official Reference).
If you see, it contains a key:value pair called "id", which is what you are looking for and what you have to pass to answerCallbackQuery method.

Thanks @alexandercerutti. But not works.

In debug i receive:
node-telegram-bot-api Process Update callback_query {"id":"221087997479747530","from":....

I send
node-telegram-bot-api HTTP request: {"form":[{"callback_query_id":"221087997479747530","text":"ok"}]

I receive:
Unhandled rejection Error: ETELEGRAM: 400 Bad Request: QUERY_ID_INVALID

This is my code:

bot.on("callback_query",(msg)=>{
    var opts = {
        callback_query_id: msg.id,
        text: "ok"
    }
    bot.answerCallbackQuery([opts]);
})      

bot.answerCallbackQuery doesn't need an Array as parameter but just an object.
The syntax used in the documentation is a bit error-prone. In fact, [opts] usually means that the parameter opts is optional, while one of the properties, callback_query_id, is mandatory.

So, try with:

bot.on("callback_query", q => {
    bot.answerCallbackQuery({
        callback_query_id: q.id,
        text: "ok",
    });
});

thank you very much.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Kasra-S picture Kasra-S  路  3Comments

Hostile picture Hostile  路  3Comments

Dohoon-Kim picture Dohoon-Kim  路  3Comments

qunatumwhiskey picture qunatumwhiskey  路  4Comments

saeedhei picture saeedhei  路  4Comments