Telegram allows sending polls and quizzes, that can be voted on by thousands, if not millions of users in chats and channels.
pollAnswer#6ca9c2e9 text:string option:bytes = PollAnswer;
poll#86e18161 id:long flags:# closed:flags.0?true public_voters:flags.1?true multiple_choice:flags.2?true quiz:flags.3?true question:string 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#e25ff8e0 flags:# silent:flags.5?true background:flags.6?true clear_draft:flags.7?true noforwards:flags.14?true update_stickersets_order:flags.15?true peer:InputPeer reply_to_msg_id:flags.0?int 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 = Updates;
To send a poll in a chat, call messages.sendMedia, providing an inputMediaPoll:
poll
is the actual poll constructor, containing:
question
- The poll title, aka the poll's titleanswers
- A vector of possible answers (2-10), each with a visible title text
, and a unique option
identifier (1-100 bytes)closed
- Whether the poll is closedpublic_voters
- Whether cast votes are publicly visible to all users (non-anonymous poll) multiple_choice
- Whether multiple options can be chosen as answerquiz
- Whether this is a quiz with correct answer IDs specified in inputMediaPoll.correct_answers
close_period
- Amount of time in seconds the poll will be active after creation, 5-600. Can't be used together with close_date
.close_date
- Point in time (Unix timestamp) when the poll will be automatically closed. Must be at least 5 and no more than 600 seconds in the future; can't be used together with close_period
. correct_answers
- For quizzes, option ID of the only correct answer
solution
- Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters with at most 2 line feeds
solution_entities
- Styled text message entities for the solution
explanation
In order to prematurely close the poll, preventing further votes, use messages.editMessage, setting the poll.closed
flag to true.
pollAnswerVoters#3b6ddad2 flags:# chosen:flags.0?true correct:flags.1?true option:bytes voters:int = PollAnswerVoters;
pollResults#dcb82ea3 flags:# min:flags.0?true results:flags.1?Vector<PollAnswerVoters> total_voters:flags.2?int recent_voters:flags.3?Vector<long> solution:flags.4?string solution_entities:flags.4?Vector<MessageEntity> = PollResults;
poll#86e18161 id:long flags:# closed:flags.0?true public_voters:flags.1?true multiple_choice:flags.2?true quiz:flags.3?true question:string 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;
When receiving a message with a messageMediaPoll, users can vote in it using messages.sendVote, specifying the chosen option
identifiers.
The method will return an updateMessagePoll, containing an updated pollResults constructor, with the chosen
flag set on the options we chose, and the correct
flag set on the correct answers.
pollAnswerVoters#3b6ddad2 flags:# chosen:flags.0?true correct:flags.1?true option:bytes voters:int = PollAnswerVoters;
pollResults#dcb82ea3 flags:# min:flags.0?true results:flags.1?Vector<PollAnswerVoters> total_voters:flags.2?int recent_voters:flags.3?Vector<long> 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;
Regularly, if new users have voted in polls available to the user, they will receive an updateMessagePoll, with updated pollResults.
The same constructor can also be fetched manually using messages.getPollResults.
messageUserVote#34d247b4 user_id:long option:bytes date:int = MessageUserVote;
messageUserVoteInputOption#3ca5b0ec user_id:long date:int = MessageUserVote;
messageUserVoteMultiple#8a65e557 user_id:long options:Vector<bytes> date:int = MessageUserVote;
messages.votesList#823f649 flags:# count:int votes:Vector<MessageUserVote> users:Vector<User> next_offset:flags.0?string = messages.VotesList;
updateMessagePollVote#106395c9 poll_id:long user_id:long 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 can be used to get poll results for non-anonymous polls, to see how each user voted for a poll option.
Bots will also receive an updateMessagePollVote every time a user their answer in a non-anonymous poll. Bots receive new votes only in polls that were sent by the bot itself.