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
| Code | Error | Cause |
|---|---|---|
| 429 | Too Many Requests: retry after N | Called within the first 10 minutes of bot launch — wait until the cooldown expires before calling close |
| 401 | Unauthorized | Invalid 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
deleteWebhookbeforeclose. - 10-minute cooldown after launch. Calling
closewithin the first 10 minutes of the bot being launched returns a429error. Plan your migration window accordingly. - Only relevant for Local Bot API Server. The
closemethod is designed for self-hosted Local Bot API Server deployments. Standard bots using Telegram's cloud servers do not need to call this. - Use
logOutinstead for cloud-to-local migration. If you are migrating from Telegram's cloud servers to a local server, calllogOutfirst, notclose.
See Also
logOut— log out from Telegram's cloud servers before switching to a local serverdeleteWebhook— must be called beforecloseto stop incoming updatessetWebhook— register a new webhook after migration