回调查询电报小游戏

2024-03-29 02:06:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我用BotFather创建了一个游戏。我可以用“sendgame”的方法发送游戏,但我不能在按下“play”按钮时启动它。我正在使用请求模块发送游戏,我不想使用任何API。你知道吗

发送我使用的游戏:

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

在那之后我不知道如何继续。我在Telegram网站上看到:

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.

我的问题是如何使用requests模块提供正确的URL。你知道吗

提前谢谢。你知道吗


Tags: 模块the方法inidgameapp游戏
1条回答
网友
1楼 · 发布于 2024-03-29 02:06:01

最后,我成功地发送并打开了游戏使用纯电报API没有任何库。你知道吗

解释如下:

使用bot创建游戏。你知道吗

要将游戏发送到聊天室,请使用:

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

这将向选定的聊天id发送一条消息,并显示一个按钮“Play Game\u Short\u Name”。你知道吗

当用户按下该按钮时,只需使用API的“getUpdates”方法即可检测并获取callbackquery id:

enter image description here

因此,您只需使用“answerCallbackQuery”方法,游戏就会在应用程序浏览器中自动打开:

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

在这个例子中,在u-got-id之前有一个。你知道吗

相关问题 更多 >