Build a Telegram AI Bot in 5 Minutes
Telegram bots are useful for quick access to an AI assistant from your phone. But most Telegram bot tutorials wire up a basic GPT wrapper with no memory, no tools, and no real capabilities.
This guide sets up a Telegram bot backed by PocketPaw, a full AI agent that can search the web, manage files, generate images, remember past conversations, and run 50+ tools. All self-hosted on your machine.
What You’ll Build
A Telegram bot that:
- Responds to text messages with AI-powered answers
- Handles voice messages (speech-to-text, then responds)
- Accepts file uploads and can read/analyze them
- Remembers conversations across sessions
- Can search the web, generate images, manage your calendar, and more
- Runs on your machine with your choice of AI model
Prerequisites
- PocketPaw installed (follow the installation guide if you haven’t)
- Telegram account (you need one to create a bot)
- An AI provider: Anthropic API key or Ollama for free local models
Creating Your Bot
Get a bot token from BotFather
- Open Telegram and search for
@BotFather - Send
/newbot - Choose a name (e.g., “My AI Assistant”)
- Choose a username (e.g.,
my_ai_paw_bot) - BotFather will give you a token like
7123456789:AAF...
Copy that token. You’ll need it next.
Send /setdescription to BotFather to add a description that appears when users open your bot for the first time.
Install the Telegram extra
pip install pocketpaw[telegram]Configure the bot token
export POCKETPAW_TELEGRAM_BOT_TOKEN="7123456789:AAF..."export POCKETPAW_ANTHROPIC_API_KEY="sk-ant-..." # or use OllamaTo restrict who can use the bot (recommended):
# Your Telegram user ID (get it from @userinfobot)export POCKETPAW_ALLOWED_USER_ID="123456789"Start PocketPaw
Option A: With web dashboard (recommended)
pocketpawThis starts the dashboard at localhost:8888 AND your Telegram bot simultaneously. Manage both from the dashboard.
Option B: Telegram-only (headless)
pocketpaw --telegramTest your bot
Open Telegram, find your bot, and send a message. Try:
- “What’s the weather like?” (triggers web search)
- Send a voice message (auto-transcribed and answered)
- Send a photo (analyzed with vision)
- “Remember that my favorite color is blue” (stored in memory)
- “What’s my favorite color?” (recalled from memory)
Features That Work Out of the Box
| Feature | How it works |
|---|---|
| Text messages | Processed through the full agent pipeline with tool access |
| Voice messages | Auto-transcribed via speech-to-text, then processed as text |
| Photos & files | Analyzed with vision models or read as documents |
| Streaming | Responses appear progressively via edit-in-place |
| Topic support | Each forum topic gets its own conversation thread |
| Memory | Conversations persist. Your bot remembers across sessions |
| Inline keyboards | Confirmation prompts for sensitive actions |
Securing Your Bot
By default, anyone who finds your bot can message it. Lock it down:
# Only allow a specific Telegram user IDexport POCKETPAW_ALLOWED_USER_ID="123456789"Get your user ID by messaging @userinfobot on Telegram.
PocketPaw also has built-in security features:
- Injection scanning: blocks prompt injection attempts
- Guardian AI: secondary LLM checks for dangerous requests
- Audit logging: every tool execution is logged
Running Your Bot 24/7
Your bot only works when PocketPaw is running. For always-on access:
Option 1: systemd (Linux servers)
sudo systemctl enable pocketpawsudo systemctl start pocketpawOption 2: Docker
docker compose up -dOption 3: Keep your laptop open (works for personal use)
See the deployment guide for production setups.
Next Steps
Add Discord Too
Same agent, now on Discord. One PocketPaw instance handles both.
Telegram Channel Docs
Full reference for Telegram-specific features and configuration.
Tools Overview
Browse all 50+ tools available to your Telegram bot.