机器人游戏

电报机器人可以为用户提供HTML5 游戏,用户可以单人玩,也可以在群组和一对一聊天中进行比赛。

发送游戏

inputUserSelf#f7c1b13f = InputUser;inputGameID#32c3e77 id:long access_hash:long = InputGame; inputGameShortName#c331e80a bot_id:InputUser short_name:string = InputGame;inputMediaGame#d33f43f3 id:InputGame = InputMedia;game#bdf9653b flags:# id:long access_hash:long short_name:string title:string description:string photo:Photo document:flags.0?Document = Game; messageMediaGame#fdb19008 game:Game = MessageMedia;---functions---messages.sendMedia#ac55d9c1 flags:# silent:flags.5?true background:flags.6?true clear_draft:flags.7?true noforwards:flags.14?true update_stickersets_order:flags.15?true invert_media:flags.16?true allow_paid_floodskip:flags.19?true peer:InputPeer reply_to:flags.0?InputReplyTo media:InputMedia message:string random_id:long reply_markup:flags.2?ReplyMarkup entities:flags.3?Vector<MessageEntity> schedule_date:flags.10?int send_as:flags.13?InputPeer quick_reply_shortcut:flags.17?InputQuickReplyShortcut effect:flags.18?long allow_paid_stars:flags.21?long suggested_post:flags.22?SuggestedPost = Updates;

机器人可以使用messages.sendMedia直接发送游戏,提供以下功能:

发送的消息将包含一个messageMediaGame,其中包含一个游戏,然后用户可以使用 sendMedia 和inputGameID转发该游戏。

开始游戏

点击按钮即可开始游戏,这将触发一个回调查询,返回游戏 URL,更多信息请参见此处 »。
然后,游戏应在 WebView 或原生 UI(由native_ui标志指定)中打开,并公开相应的 HTML5 API,以便直接从游戏代码接收各种 JS 游戏事件,如这里所述 »。

创造高分

---functions---messages.setGameScore#8ef8ecc0 flags:# edit_message:flags.0?true force:flags.1?true peer:InputPeer id:int user_id:InputUser score:int = Updates; messages.setInlineGameScore#15ad9f64 flags:# edit_message:flags.0?true force:flags.1?true id:InputBotInlineMessageID user_id:InputUser score:int = Bool;

游戏应该在用户每次输掉游戏并刷新最高分时,向 MTProto API 报告结果。
由于游戏运行在浏览器中,它们无法直接使用必须保密的机器人令牌向 API 报告数据。
因此,它们应该将最高分发送到中间服务器,然后由该服务器根据游戏来源, 使用`messages.setGameScore`或`messages.setInlineGameScore`来报告分数。

获得高分

messageActionGameScore#92a72876 game_id:long score:int = MessageAction;messageService#7a800e0a flags:# out:flags.1?true mentioned:flags.4?true media_unread:flags.5?true reactions_are_possible:flags.9?true silent:flags.13?true post:flags.14?true legacy:flags.19?true id:int from_id:flags.8?Peer peer_id:Peer saved_peer_id:flags.28?Peer reply_to:flags.3?MessageReplyHeader date:int action:MessageAction reactions:flags.20?MessageReactions ttl_period:flags.25?int = Message;highScore#73a379eb pos:int user_id:long score:int = HighScore;messages.highScores#9a3bfd99 scores:Vector<HighScore> users:Vector<User> = messages.HighScores;---functions---messages.getGameHighScores#e822649d peer:InputPeer id:int user_id:InputUser = messages.HighScores; messages.getInlineGameHighScores#f635e1b id:InputBotInlineMessageID user_id:InputUser = messages.HighScores;

每次达到最高分,并edit_message在报告分数时设置标志位时,都会生成一个包含messageActionGameScore的消息服务,表明由于某个事件,某个游戏的最高分发生了变化。我们自己在排行榜上的当前位置也会被报告。user_id
pos

当收到此类更新时,图形客户端应使用messages.getGameHighScores或messages.getInlineGameHighScores重新获取记分板。