Skip to content

logOut

Returns: TrueOfficial docs ↗

Use this method to log out from the cloud Bot API server before launching the bot locally. You must log out the bot before running it locally, otherwise there is no guarantee that the bot will receive updates. After a successful call, you can immediately log in on a local server, but will not be able to log in back to the cloud Bot API server for 10 minutes. Returns True on success. Requires no parameters.

Returns

On success, True is returned.

GramIO Usage

Log out before switching to a local Bot API server:

ts
// Call once before migrating to local server — required step
const 
result
= await
bot
.
api
.
logOut
();
console
.
log
("Logged out from cloud API:",
result
); // true

One-time migration script — log out then connect to local server:

ts
import { 
Bot
} from "gramio";
// Step 1: Connect to cloud API and log out const
cloudBot
= new
Bot
(
process
.
env
.
BOT_TOKEN
?? "");
await
cloudBot
.
api
.
logOut
();
console
.
log
("Successfully logged out from cloud Bot API.");
console
.
log
("You can now start your local Bot API server.");
console
.
log
("Note: cloud login won't be available for 10 minutes.");
// Step 2: In your next session, connect to local server: // const localBot = new Bot(process.env.BOT_TOKEN ?? "", { // api: { baseURL: "http://localhost:8081" } // });

Graceful shutdown with logout before going offline:

ts
process
.
on
("SIGTERM", async () => {
console
.
log
("Shutting down...");
await
bot
.
api
.
logOut
();
process
.
exit
(0);
});

Errors

CodeErrorCause
401UnauthorizedInvalid bot token — verify the token is correct before logging out
429Too Many Requests: retry after NRate limit hit — check retry_after before retrying

Tips & Gotchas

  • You must log out before running a local Bot API server. If you skip this step, Telegram may deliver updates to the cloud server instead of your local one, causing missed messages.
  • 10-minute cloud lockout after logout. Once you call logOut, you cannot reconnect to api.telegram.org for 10 minutes. Plan migrations accordingly — do not call it in a test environment unless intentional.
  • This is a one-way operation in the short term. After logOut, connect immediately to your local Bot API server. If you need to revert, wait the full 10 minutes before using the cloud API again.
  • No parameters needed. Unlike most Bot API methods, logOut takes no arguments. Just call it and handle the result.
  • close is different from logOut. The close method gracefully closes the bot instance without logging out — use that for restarts, and logOut only when migrating to local.

See Also

  • close — gracefully close the bot instance without logging out (use for restarts)
  • deleteWebhook — remove webhook before switching to local polling mode
  • getWebhookInfo — check current webhook status before migrating