Skip to content

stopPoll

Use this method to stop a poll which was sent by the bot. On success, the stopped Poll is returned.

Parameters

business_connection_idStringOptional
Unique identifier of the business connection on behalf of which the message to be edited was sent
chat_idIntegerStringRequired
Unique identifier for the target chat or username of the target channel (in the format @channelusername)
message_idIntegerRequired
Identifier of the original message with the poll
A JSON-serialized object for a new message inline keyboard.

Returns

On success, the Poll object is returned.

GramIO Usage

ts
// Stop a poll and read the final results
const 
closedPoll
= await
bot
.
api
.
stopPoll
({
chat_id
: 123456789,
message_id
: 55,
});
console
.
log
(`Poll closed. Total voters: ${
closedPoll
.
total_voter_count
}`);
for (const
option
of
closedPoll
.
options
) {
console
.
log
(` "${
option
.
text
}": ${
option
.
voter_count
} votes`);
}
ts
// Stop a poll and replace its inline keyboard in one call
const 
poll
= await
bot
.
api
.
stopPoll
({
chat_id
: 123456789,
message_id
: 55,
reply_markup
: new
InlineKeyboard
().
text
("See results", "poll_results_55"),
});
console
.
log
(`Winner: ${
poll
.
options
.
sort
((
a
,
b
) =>
b
.
voter_count
-
a
.
voter_count
)[0]?.
text
}`);
ts
// Stop a poll in a command handler
bot
.
command
("endpoll", async (
ctx
) => {
// Assumes the poll message ID is stored somewhere const
pollMessageId
= 55;
const
poll
= await
bot
.
api
.
stopPoll
({
chat_id
:
ctx
.
chat
.
id
,
message_id
:
pollMessageId
,
}); await
ctx
.
send
(`Poll closed with ${
poll
.
total_voter_count
} total votes.`);
});

Errors

CodeErrorCause
400Bad Request: chat not foundInvalid or inaccessible chat_id
400Bad Request: message not foundThe message_id doesn't exist in the chat
400Bad Request: poll has already been closedThe poll was already stopped — you can't stop it twice; catch this error if you may call stopPoll redundantly
400Bad Request: message is not a pollThe referenced message is not a poll — verify the correct message_id
403Forbidden: not enough rightsBot lacks the rights to edit messages in this chat
429Too Many Requests: retry after NRate limit hit — check retry_after, use auto-retry plugin

TIP

Use GramIO's auto-retry plugin to handle 429 errors automatically.

Tips & Gotchas

  • Only the bot that sent the poll can stop it. You cannot stop polls sent by other bots or users. Ensure the message_id corresponds to a poll created by your bot.
  • The returned Poll object has the final results. stopPoll returns the complete Poll with all vote counts — use this as the authoritative final result without needing a separate getUpdates call.
  • Stopping a quiz reveals the correct answer. For quiz-type polls, once closed the correct option becomes visible to all participants. Plan when to close quizzes carefully.
  • You can update reply_markup on close. Passing a new keyboard atomically replaces the poll's inline buttons at the same time as closing — useful for adding a "See results" or "Play again" button.
  • Closed polls still receive poll updates. Telegram may deliver a poll update when a poll closes naturally (by close_date). You don't need to manually call stopPoll to receive the final state in that case.

See Also