Reputation: 15
I'm creating a Telegram bot using Python (using the requests package to make API calls) which sends a message with two inline buttons to a user; pressing a button sends a callback query back to the bot, which performs a different function based on which button has been pressed.
I've read on the API docs that the client will show up an animation until the bot calls the '/answerCallbackQuery' endpoint to receive the callback call from the button.
To do so I need to know the callback query's id, but the only way I know of obtaining it is by calling the '/getUpdates' endpoint to get all the updates, somehow find the correct field and then use the 'id' field as the callback_query_id
parameter in the answerCallbackQuery
call.
So to receive to get notified about a button being pressed I need to do 2 API calls, am I getting it right or is there a simpler method?
Since I'm already getting the info I need by the getUpdates
endpoint, why should I bother making another call to the answerCallbackQuery
one?
Upvotes: 0
Views: 342
Reputation: 43904
pressing a button sends a callback query back to the bot, which performs a different function based on which button has been pressed.
This is only valid if you have Webhooks enabled. Otherwise you'll still have to call getUpdates
to check if the user pressed a button.
but the only way I know of obtaining it is by calling the '/getUpdates' endpoint to get all the updates
You've already called getUpdates
since thats the only way of retrieving the actual button press update.
I need to do 2 API calls, am I getting it right or is there a simpler method?
Yep, getUpdate
to retrieve the press, answerCallbackQuery
to let Telegram know you've progressed the press.
why should I bother making another call to the answerCallbackQuery one
Well, Telegram can't assume you're processing those button presses, you'll need to tell Telegram that you've processed it. Just as the documentation states, mostly a simple notification on the top of the screen, or in most cases, removing the keyboard since the user has used it.
Upvotes: 0