Skip to content

Telegram token

Every Telegram bot has a token from @BotFather. Your bot needs it to talk to Telegram, and BotBarn passes it to your bot as the variable TELEGRAM_BOT_TOKEN.

Add the token

On the bot's Overview, paste the token in the Telegram card. BotBarn calls Telegram's getMe with it and:

  • shows the bot's @username and marks it Verified;
  • saves the token as a secret variable TELEGRAM_BOT_TOKEN.

You can also add or change TELEGRAM_BOT_TOKEN on the Variables tab: the same check runs.

Message Meaning
This does not look like a Telegram bot token. The value is not shaped like 123456789:AA.... Copy it again from BotFather.
Telegram rejected this token. Telegram does not know this token: it was revoked or mistyped. Nothing is saved.
This Telegram bot is already connected to another BotBarn bot. One Telegram bot can run on one BotBarn bot only. Remove the token from the other bot first.
Saved, Not verified Telegram could not be reached. The token is saved; press Verify later.

Read it in your code

import os

token = os.environ["TELEGRAM_BOT_TOKEN"]
const token = process.env.TELEGRAM_BOT_TOKEN

Change or revoke the token

If the token leaks, send /revoke to BotFather, then paste the new token in BotBarn and deploy again. The running bot keeps the old token until it is deployed again, or stopped and started.

Do not log the token

BotBarn replaces the values of your variables with *** in logs, but other tools may not. Some libraries print request URLs, and Telegram request URLs contain the token: lower their log level (in Python: logging.getLogger("httpx").setLevel(logging.WARNING)).