How to Build a Telegram Bot with Python in 1 Hour

From zero to deployed Telegram bot — BotFather setup, polling, command handlers, and a free deploy on Replit.

Telegram bots are dead simple to build and have a free tier as long as Telegram exists. Here's the 1-hour build.

Step 1: Create the bot

In Telegram, message @BotFather. Send /newbot. Pick a name and username. BotFather replies with a token — copy it.

Step 2: Install python-telegram-bot

pip install python-telegram-bot==20.7

Step 3: Hello bot (20 lines)

from telegram import Update
from telegram.ext import Application, CommandHandler, MessageHandler, filters, ContextTypes

async def start(u: Update, c: ContextTypes.DEFAULT_TYPE): await u.message.reply_text("Hi! I'm alive.")

async def echo(u: Update, c: ContextTypes.DEFAULT_TYPE): await u.message.reply_text(f"You said: {u.message.text}")

def main(): app = Application.builder().token("YOUR_BOT_TOKEN").build() app.add_handler(CommandHandler("start", start)) app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, echo)) app.run_polling()

if __name__ == "__main__": main() ```

Run python bot.py → message your bot on Telegram → it replies.

Step 4: Real handlers

async def weather(u: Update, c: ContextTypes.DEFAULT_TYPE):
    city = " ".join(c.args) or "London"
    # call a weather API, format response
    await u.message.reply_text(f"Weather in {city}: ...")

app.add_handler(CommandHandler("weather", weather)) ```

User types /weather Mumbai → bot returns weather.

Step 5: Deploy (free)

Push to Replit → set BOT_TOKEN in Secrets → click Run. Replit's always-on tier is paid; for free, use a free polling-friendly service like Fly.io free tier or Railway free credit.

For zero ongoing cost: deploy on a free Oracle Cloud ARM VM (forever free tier).

Production patterns

Hire a Telegram bot developer →

Need this built for you?

Hire a vetted Nexora expert. Escrow-protected. Fixed price. From $65.

Browse automation services →