民意调查

Telegram 允许发送投票和测验,成千上万甚至数百万用户可以在聊天和频道中进行投票。

发送投票

pollAnswer#ff16e2ca text:TextWithEntities option:bytes = PollAnswer;poll#58747131 id:long flags:# closed:flags.0?true public_voters:flags.1?true multiple_choice:flags.2?true quiz:flags.3?true question:TextWithEntities answers:Vector<PollAnswer> close_period:flags.4?int close_date:flags.5?int = Poll;inputMediaPoll#f94e5f1 flags:# poll:Poll correct_answers:flags.0?Vector<bytes> solution:flags.1?string solution_entities:flags.1?Vector<MessageEntity> = InputMedia;---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,并提供inputMediaPoll:

为了提前结束投票,防止进一步投票,请使用messages.editMessage,并将poll.closed标志设置为 true。

投票

pollAnswerVoters#3b6ddad2 flags:# chosen:flags.0?true correct:flags.1?true option:bytes voters:int = PollAnswerVoters;pollResults#7adf2420 flags:# min:flags.0?true results:flags.1?Vector<PollAnswerVoters> total_voters:flags.2?int recent_voters:flags.3?Vector<Peer> solution:flags.4?string solution_entities:flags.4?Vector<MessageEntity> = PollResults;poll#58747131 id:long flags:# closed:flags.0?true public_voters:flags.1?true multiple_choice:flags.2?true quiz:flags.3?true question:TextWithEntities answers:Vector<PollAnswer> close_period:flags.4?int close_date:flags.5?int = Poll;messageMediaPoll#4bd6e798 poll:Poll results:PollResults = MessageMedia;updateMessagePoll#aca1657b flags:# poll_id:long poll:flags.0?Poll results:PollResults = Update;---functions---messages.sendVote#10ea6184 peer:InputPeer msg_id:int options:Vector<bytes> = Updates;

当收到包含messageMediaPoll 的消息时,用户可以使用messages.sendVote并指定所选标识符进行投票。option

该方法将返回一个updateMessagePoll,其中包含一个更新后的pollResults构造函数,其中chosen设置了我们选择的选项的标志,并correct设置了正确答案的标志。

获得民意调查选票

pollAnswerVoters#3b6ddad2 flags:# chosen:flags.0?true correct:flags.1?true option:bytes voters:int = PollAnswerVoters;pollResults#7adf2420 flags:# min:flags.0?true results:flags.1?Vector<PollAnswerVoters> total_voters:flags.2?int recent_voters:flags.3?Vector<Peer> solution:flags.4?string solution_entities:flags.4?Vector<MessageEntity> = PollResults;updateMessagePoll#aca1657b flags:# poll_id:long poll:flags.0?Poll results:PollResults = Update;---functions---messages.getPollResults#73bb643b peer:InputPeer msg_id:int = Updates;

通常情况下,如果新用户在用户可参与的投票中投了票,他们将收到一条updateMessagePoll,其中包含更新后的pollResults。

也可以使用messages.getPollResults手动获取相同的构造函数。

在非匿名民意调查中获得投票者

messagePeerVote#b6cc2d5c peer:Peer option:bytes date:int = MessagePeerVote; messagePeerVoteInputOption#74cda504 peer:Peer date:int = MessagePeerVote; messagePeerVoteMultiple#4628f6e6 peer:Peer options:Vector<bytes> date:int = MessagePeerVote;messages.votesList#4899484e flags:# count:int votes:Vector<MessagePeerVote> chats:Vector<Chat> users:Vector<User> next_offset:flags.0?string = messages.VotesList;updateMessagePollVote#24f40e77 poll_id:long peer:Peer options:Vector<bytes> qts:int = Update;---functions---messages.getPollVotes#b86e380e flags:# peer:InputPeer id:int option:flags.0?bytes offset:flags.1?string limit:int = messages.VotesList;

messages.getPollVotes可用于获取非匿名投票的结果,查看每个用户对每个投票选项的投票情况。每当用户在非匿名投票中做出选择时,
机器人都会收到updateMessagePollVote 。机器人仅接收由其自身发起的投票的新投票。