sendGame
发送游戏卡片到指定聊天。用户可点击卡片上的按钮打开游戏。
请求
POST /:token/sendGame
参数
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| chat_id | Integer/String | 是 | 目标聊天的唯一标识符或用户名 |
| game_short_name | String | 是 | 游戏的短名,作为游戏的唯一标识,通过 @BotFather 的 /newgame 创建 |
| reply_markup | Object | 否 | 内联键盘标记(InlineKeyboardMarkup)。缺省时自动添加一个「播放 + 游戏标题」按钮;若自定义,第一行第一个按钮必须为 callback_game 按钮 |
响应
返回发送成功的 Message 对象,其 game 字段为游戏对象。
json
{
"ok": true,
"result": {
"message_id": 100,
"from": {
"id": 123456789,
"is_bot": true,
"first_name": "MyBot",
"username": "my_bot"
},
"chat": {
"id": 987654321,
"type": "private"
},
"date": 1700000000,
"game": {
"title": "Tower Blocks",
"description": "堆叠方块,挑战最高分!",
"photo": [
{ "file_id": "AgACAgIAAx...", "width": 640, "height": 360 }
]
},
"reply_markup": {
"inline_keyboard": [
[{ "text": "▶️ Play Tower Blocks", "callback_game": {} }]
]
}
}
}错误码
| 错误码 | 描述 |
|---|---|
| 400 | 请求参数错误,如 game_short_name 不存在或未注册 |
| 401 | Token 无效或已过期 |
| 403 | Bot 无权向该聊天发送消息 |
| 404 | 聊天不存在 |
| 500 | 服务器内部错误 |
示例
cURL
bash
curl -X POST "https://api.safew.bot/<token>/sendGame" \
-H "Content-Type: application/json" \
-d '{
"chat_id": 987654321,
"game_short_name": "tower_blocks"
}'自定义按钮
bash
curl -X POST "https://api.safew.bot/<token>/sendGame" \
-H "Content-Type: application/json" \
-d '{
"chat_id": 987654321,
"game_short_name": "tower_blocks",
"reply_markup": {
"inline_keyboard": [
[{ "text": "▶️ 开始游戏", "callback_game": {} }],
[{ "text": "玩法说明", "url": "https://example.com/how-to-play" }]
]
}
}'