Andermutu
Andermutu

Reputation: 134

Callback Query Telegram games

I have created a game using BotFather. I can send the game using "sendgame" method, but I am not able to launch it when pressing "play" button. I am using requests module to send the game and I don't want to use any API.

To send the game I use:

requests.get(url + '/sendGame?chat_id=' + id + '&game_short_name=' + text)

After that I don't know how to continue. In the Telegram website I have read that:

When this button is pressed, your bot gets a callback query that indicates the requested game. You provide the correct URL for this particular user and the app automatically opens the game in the in-app browser.

My question is how can I provide the correct URL using requests module.

Thanks in advance.

Upvotes: 1

Views: 2003

Answers (1)

Andermutu
Andermutu

Reputation: 134

Finally, I managed to send and open the game using pure Telegram API without any libraries.

Here the explanation:

Create a game using BotFather bot.

To send the game to a chat use:

TOKEN = ".........."
url = "https://api.telegram.org/bot" + TOKEN
requests.get(url + '/sendGame?chat_id=' + id + '&game_short_name=' + text)

That will send a message to the selected chat id and a button that says "Play Game_Short_Name".

When the user presses that button you can detect get the callbackquery id using simply "getUpdates" method of the API:

enter image description here

So here you just need to use "answerCallbackQuery" method and the game will open automatically in the in-app browser:

page_url = "you url to open here"
requests.get(url + '/answerCallbackQuery?callback_query_id=' + query_id + '&url=' + page_url)

where the query_id is the one got before (1796013210303243039 in this example).

Upvotes: 2

Related Questions