Native poll are a special kind of message with question & answers where users can vote. Options can be set to allow multiple answers, vote anonymously, or be a quizz with a correct choice and explanation.
This is the code to send a poll to a chat.
{{#include ../../../Examples/2/SendMessage.cs:send-poll}}
You can optionally send a keyboard with a poll, both an inline or a regular one.
You'll get the message with Poll
object inside it.
To close a poll you need to know original chat and message ids of the poll that you got from calling SendPoll
method.
Let's close the poll that we sent in the previous example:
{{#include ../../../Examples/2/SendMessage.cs:stop-poll}}
You can add an inline keyboard when you close a poll.
As a result of the request you'll get the the final poll state with property Poll.IsClosed
set to true.
If you'll try to close a forwarded poll using message and chat ids from the received message even if your bot is the author of the poll you'll get an ApiRequestException
with message Bad Request: poll can't be stopped
. Polls originated from channels is an exception since forwarded messages originated from channels contain original chat and message ids inside properties Message.ForwardFromChat.Id
and Message.ForwardFromMessageId
.
Also if you'll try to close an already closed poll you'll get ApiRequestException
with message Bad Request: poll has already been closed
.