Skip to content

close

Returns: TrueOfficial docs ↗

Use this method to close the bot instance before moving it from one local server to another. You need to delete the webhook before calling this method to ensure that the bot isn't launched again after server restart. The method will return error 429 in the first 10 minutes after the bot is launched. Returns True on success. Requires no parameters.

Returns

On success, True is returned.

GramIO Usage

ts
// Gracefully shut down the bot before migrating to another local server
await 
bot
.
api
.
deleteWebhook
();
await
bot
.
api
.
close
();
ts
// Full shutdown sequence with error handling
async function 
migrateBotServer
() {
try { // Step 1: Stop receiving updates await
bot
.
api
.
deleteWebhook
({
drop_pending_updates
: true });
// Step 2: Close the bot instance on the current server await
bot
.
api
.
close
();
console
.
log
("Bot instance closed. Safe to restart on new server.");
} catch (
error
) {
console
.
error
("Shutdown failed:",
error
);
} } await
migrateBotServer
();

Errors

CodeErrorCause
429Too Many Requests: retry after NCalled within the first 10 minutes of bot launch — wait until the cooldown expires before calling close
401UnauthorizedInvalid bot token — the bot cannot authenticate with the API

Tips & Gotchas

  • Must delete the webhook first. If a webhook is still active, Telegram may re-launch the bot after the server restarts. Always call deleteWebhook before close.
  • 10-minute cooldown after launch. Calling close within the first 10 minutes of the bot being launched returns a 429 error. Plan your migration window accordingly.
  • Only relevant for Local Bot API Server. The close method is designed for self-hosted Local Bot API Server deployments. Standard bots using Telegram's cloud servers do not need to call this.
  • Use logOut instead for cloud-to-local migration. If you are migrating from Telegram's cloud servers to a local server, call logOut first, not close.

See Also

  • logOut — log out from Telegram's cloud servers before switching to a local server
  • deleteWebhook — must be called before close to stop incoming updates
  • setWebhook — register a new webhook after migration