stopPoll
Use this method to stop a poll which was sent by the bot. On success, the stopped Poll is returned.
Parameters
business_connection_idStringOptionalUnique identifier of the business connection on behalf of which the message to be edited was sent
chat_idIntegerStringRequiredUnique identifier for the target chat or username of the target channel (in the format
@channelusername)message_idIntegerRequiredIdentifier 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
| Code | Error | Cause |
|---|---|---|
| 400 | Bad Request: chat not found | Invalid or inaccessible chat_id |
| 400 | Bad Request: message not found | The message_id doesn't exist in the chat |
| 400 | Bad Request: poll has already been closed | The poll was already stopped — you can't stop it twice; catch this error if you may call stopPoll redundantly |
| 400 | Bad Request: message is not a poll | The referenced message is not a poll — verify the correct message_id |
| 403 | Forbidden: not enough rights | Bot lacks the rights to edit messages in this chat |
| 429 | Too Many Requests: retry after N | Rate 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_idcorresponds to a poll created by your bot. - The returned
Pollobject has the final results.stopPollreturns the completePollwith all vote counts — use this as the authoritative final result without needing a separategetUpdatescall. - 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_markupon 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
pollupdates. Telegram may deliver apollupdate when a poll closes naturally (byclose_date). You don't need to manually callstopPollto receive the final state in that case.
See Also
- sendPoll — send a new poll
- Poll — the Poll object with options and vote counts
- InlineKeyboardMarkup — keyboard structure for
reply_markup - Keyboards guide — building inline keyboards with GramIO