Prerequisites
Create a virtual environment and install the required dependencies:Step 1: Create a Telegram Bot
- Open Telegram and search for @BotFather
- Send
/newbotand follow the prompts to choose a name and username - Copy the Bot API Token you receive — you’ll need it in the next step
Step 2: Set Up the Webhook with ngrok
Telegram delivers messages to your bot via webhooks — it sends HTTPS requests to a public URL you provide. Your locallocalhost:8000 is not accessible from the internet, so you need a tunnel. We’ll use ngrok for this.
Create an ngrok account
Go to ngrok.com/signup and create a free account.
Install ngrok
After signing up, follow the instructions on your ngrok dashboard to install ngrok for your operating system.
Connect your account
Copy your authtoken from the ngrok dashboard and run:
Step 3: Configure Environment Variables
Create a.env file with your credentials:
Step 4: Write Your Bot
There are two operating modes — pick the one that fits your use case:- CHAT — The agent remembers conversation context per user. Best for conversational assistants.
- TASK — Each message is processed independently with no history. Best for one-off queries.
Step 5: Run
Make sure ngrok is running in one terminal, then start your bot in another:Operating Modes
| Mode | Description | Best For |
|---|---|---|
| TASK (default) | Each message is processed independently. No conversation history. | One-off queries, stateless bots |
| CHAT | Messages from the same user share a session. The agent remembers context. | Conversational assistants, support bots |
Reset Command (CHAT mode only)
In CHAT mode, users can clear their conversation by sending/reset. Configure it with reset_command; set to None to disable.
If the agent has a workspace configured, the reset command will also trigger a dynamic greeting message based on the workspace configuration.
Access Control
Restrict your bot to specific users by passing a list of Telegram user IDs:allowed_user_ids (or set None) to allow everyone.
Supported File & Message Types
Users can send any file type through Telegram — images, PDFs, Excel spreadsheets, Word documents, CSVs, and more. The bot receives and forwards all of them to your agent.- Images (PNG, JPG, etc.) – The agent can process these directly via its vision capabilities
- PDFs, Excel, Word, CSV, and other documents – The agent receives the file. If you equip your agent with the right tools (e.g. a PDF reader tool or an Excel parser), it can read and analyze the contents
- Voice / Audio – Downloaded and processed (e.g. transcription)
- Video / Video note – Downloaded and processed with caption
- Text – Processed as task or chat input
- Sticker – Converted to text (e.g. “User sent a sticker: ”)
- Location / Venue / Contact / Poll – Converted to text and processed
- Callback query – Inline keyboard button data processed as text

