How to Create a Telegram Bot with BotFather
Every Telegram bot, no matter how complex, starts the same way: a short conversation with another bot. That bot is called BotFather, and it’s the official tool Telegram gives you to register new bots, configure them, and manage their tokens.
This guide walks through the whole thing — from naming your bot to having it reply to a message.
Step 1: Talk to BotFather
Open Telegram and search for @BotFather. The real one has a blue verified checkmark next to its name — don’t trust any of the copycats.
Start a chat and send:
/newbot
BotFather will ask you two questions:
- A name — this is the display name, shown in chats. It can be anything, like
My Weather Bot. - A username — this must be unique and end in
bot, likemy_weather_botorMyWeatherBot.
If the username is taken, BotFather just asks again. Pick another one and move on.
Step 2: Save your token
Once the username is accepted, BotFather hands you a message with your bot’s API token. It looks like this:
123456789:AAExampleTokenStringThatYouShouldKeepSecret
This token is the only thing standing between the world and full control of your bot. Treat it like a password:
- Never commit it to git.
- Never paste it into a public chat or screenshot.
- Store it in an environment variable, not in your source code.
If it ever leaks, send /revoke to BotFather to invalidate it and generate a new one.
Step 3: Configure the basics (optional but nice)
While you’re still in the BotFather chat, a few commands make your bot feel finished:
/setdescription — text shown on the bot's profile before a user starts it
/setabouttext — short bio shown in the bot's profile
/setuserpic — upload a profile picture
/setcommands — define the command menu users see when typing "/"
For /setcommands, you send a list in this format:
start - Start the bot
help - Show available commands
weather - Get the current forecast
These show up in a tidy menu inside the chat, so users don’t have to guess what your bot can do.
Step 4: Write the bot
The token is all you need to start coding. Here’s a minimal bot in Node.js using Telegraf, one of the most popular libraries:
npm install telegraf
import { Telegraf } from 'telegraf';
const bot = new Telegraf(process.env.BOT_TOKEN);
bot.start((ctx) => ctx.reply('Hello! I am alive.'));
bot.command('help', (ctx) =>
ctx.reply('Available commands: /start, /help')
);
bot.on('text', (ctx) =>
ctx.reply(`You said: ${ctx.message.text}`)
);
bot.launch();
Run it with your token set in the environment:
BOT_TOKEN=123456789:AAExampleToken node bot.js
Now message your bot in Telegram. Send /start and it replies. Send any text and it echoes it back. That’s a working bot.
If you prefer Python, the equivalent with python-telegram-bot is just as short:
import os
from telegram.ext import ApplicationBuilder, CommandHandler
async def start(update, context):
await update.message.reply_text("Hello! I am alive.")
app = ApplicationBuilder().token(os.environ["BOT_TOKEN"]).build()
app.add_handler(CommandHandler("start", start))
app.run_polling()
Polling vs webhooks
The examples above use long polling — your bot continuously asks Telegram “any new messages?” This is perfect for development and small bots. It works behind any firewall, needs no public URL, and requires zero setup.
For production, you’ll often switch to webhooks, where Telegram pushes updates to a public HTTPS endpoint you control. It’s more efficient at scale, but it needs a server with a valid TLS certificate. Don’t worry about it until polling actually becomes a bottleneck.
A few things that trip people up
- The bot can’t message you first. A user must start the conversation (or be in a group with the bot) before it can send them anything. This is by design, to prevent spam.
- Privacy mode is on by default. In groups, your bot only sees messages that start with
/or that reply to it. Turn it off via BotFather’s/setprivacyif your bot needs to read all group messages. - One token, one bot. If you regenerate the token, the old one immediately stops working.
That’s the whole loop
Register with BotFather, save the token, wire up a library, reply to a message. Everything else — payments, inline queries, mini apps, AI integrations — builds on top of this same foundation.
The hardest part was finding the real @BotFather. The rest is just code.