The simplest bot

Welcome! I am Param, and in this course we are going to build a Telegram assistant that actually remembers you, uses real tools, and keeps itself running in the background. We start with the smallest possible bot, then grow it piece by piece.

The goal of this first lesson is almost insulting in its simplicity. A Telegram handler that reads a message, calls Claude, and replies with the response. No memory, no tools, no personality. Just the beating heart of every AI assistant.

The simplest possible assistant

User talks to Telegram, Telegram talks to our handler, handler talks to Claude, reply goes back.

terminal
bash
# Clone the workshop repo
git clone https://github.com/learnwithparam/persistent-ai-telegram.git
cd persistent-ai-telegram

# One command sets up uv, the virtualenv, and dependencies
make install

# Copy the env template and fill in two keys
cp .env.example .env

You will need an Anthropic API key and a Telegram bot token from BotFather. Both are free to create.

01-simplest-bot/bot.py
python
from anthropic import Anthropic
from telegram import Update
from telegram.ext import ApplicationBuilder, MessageHandler, filters, ContextTypes

client = Anthropic()
MODEL = 'claude-sonnet-4-20250514'

async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
    user_text = update.message.text

    response = client.messages.create(
        model=MODEL,
        max_tokens=1024,
        messages=[{'role': 'user', 'content': user_text}],
    )

    reply = response.content[0].text
    await update.message.reply_text(reply)

Read the user text, make one API call, reply with whatever came back. That is the entire bot.

terminal
bash
make 01-simplest-bot

Run the bot, open Telegram, find your bot by username, and send it a message. You should get a Claude reply within a couple of seconds.

No. Every message is a brand new API call with no history attached. If you say your name is Luna, the next message has no way of knowing that. That is exactly the problem session files are about to solve.

Quiz: Quiz

Loading practice…

Validation checklist: First bot running checklist

Loading practice…