回调查询电报游戏
Callback Query Telegram games
我使用 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.
我的问题是如何使用请求模块提供正确的 URL。
提前致谢。
最后,我成功地使用纯 Telegram API 发送并打开了游戏,没有任何库。
这里解释一下:
使用 BotFather 机器人创建游戏。
要将游戏发送到聊天室,请使用:
TOKEN = ".........."
url = "https://api.telegram.org/bot" + TOKEN
requests.get(url + '/sendGame?chat_id=' + id + '&game_short_name=' + text)
这将向选定的聊天 ID 发送一条消息和一个显示 "Play Game_Short_Name" 的按钮。
当用户按下该按钮时,您可以使用 API 的简单 "getUpdates" 方法检测获取回调查询 ID:
所以这里你只需要使用"answerCallbackQuery"方法,游戏就会在应用内浏览器中自动打开:
page_url = "you url to open here"
requests.get(url + '/answerCallbackQuery?callback_query_id=' + query_id + '&url=' + page_url)
其中 query_id 是之前得到的(本例中为 1796013210303243039)。
我使用 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.
我的问题是如何使用请求模块提供正确的 URL。
提前致谢。
最后,我成功地使用纯 Telegram API 发送并打开了游戏,没有任何库。
这里解释一下:
使用 BotFather 机器人创建游戏。
要将游戏发送到聊天室,请使用:
TOKEN = ".........."
url = "https://api.telegram.org/bot" + TOKEN
requests.get(url + '/sendGame?chat_id=' + id + '&game_short_name=' + text)
这将向选定的聊天 ID 发送一条消息和一个显示 "Play Game_Short_Name" 的按钮。
当用户按下该按钮时,您可以使用 API 的简单 "getUpdates" 方法检测获取回调查询 ID:
所以这里你只需要使用"answerCallbackQuery"方法,游戏就会在应用内浏览器中自动打开:
page_url = "you url to open here"
requests.get(url + '/answerCallbackQuery?callback_query_id=' + query_id + '&url=' + page_url)
其中 query_id 是之前得到的(本例中为 1796013210303243039)。