A Telegram bot is a program that runs inside Telegram and responds to messages automatically. You send /start, it replies. You send a question, it answers.
In this tutorial you'll build a working bot from scratch in under 10 minutes.
python --version to check)Every bot needs a token from BotFather — Telegram's official bot manager.
/newbotMy Study Botbot, e.g. mystudyhelper_botBotFather gives you a token like:
123456789:AAFxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
⚠️ Keep this token secret. Anyone with it can control your bot.
pip install python-telegram-bot
Create a file bot.py:
from telegram import Update
from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes
TOKEN = "YOUR_BOT_TOKEN_HERE"
# This runs when user sends /start
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text("Hello! 👋 I am your bot. How can I help?")
# This runs when user sends /help
async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text("Send /start to begin.")
app = ApplicationBuilder().token(TOKEN).build()
app.add_handler(CommandHandler("start", start))
app.add_handler(CommandHandler("help", help_command))
print("Bot is running...")
app.run_polling()
Replace YOUR_BOT_TOKEN_HERE with the token BotFather gave you.
python bot.py
You should see: Bot is running...
@mystudyhelper_bot)/startYour bot replies: Hello! 👋 I am your bot. How can I help?
| Part | What it does |
|---|---|
TOKEN |
Identifies your bot to Telegram |
CommandHandler |
Listens for a specific command like /start |
reply_text |
Sends a message back to the user |
run_polling |
Keeps the bot running and checking for messages |
ModuleNotFoundError: telegram
→ Run pip install python-telegram-bot again
Bot not responding
→ Make sure python bot.py is still running in your terminal
Invalid token
→ Copy the token from BotFather again — no extra spaces
👉 Run this bot 24/7 on your OCI server so it works even when your PC is off.