How to Build a Telegram Bot Connected to an AI Agent ?
Learn how to build an AI-powered Telegram bot from scratch using Python, OpenAI, ngrok, and Render. This step-by-step guide covers bot creation, environment setup, webhook testing, deployment, and best practices for integrating your AI agent.
#AGENTS
Florent Ravenel
11/18/20252 min read
How to Build a Telegram Bot Connected to an AI Agent (Complete Step-by-Step Guide)
Introduction: The Real Problem That Started It All
After most of my meetings, I needed my AI agents to perform tasks for me:
Create tickets
Update my roadmap
Record decisions
But when a meeting ends, sometimes you don’t have time to open your laptop and write structured notes,
However, I always had time to do one thing:
👉 Open Telegram, record a quick voice message, and explain what needs to happen.
That's why I build this workflow.
This guide will walks you step-by-step through the exact system I built and it is fully open-sourced here:
🔗 GitHub Repository: https://github.com/FlorentLvr/telegram-bot
Prerequisites
Before starting, you’ll need:
A Telegram account
Git & GitHub account
VS Code or Cursor IDE
ngrok (for HTTPS tunneling locally)
Render (for deployment)
OpenAI account (for voice transcription)
Your AI agent API URL + token
1. Create Your Bot with BotFather
In Telegram, search for @BotFather and send: `/newbot`
You’ll be asked to choose:
A name for your bot
A username ending with bot (e.g., ai_support_bot)
BotFather returns a Bot Token: 1234567890:ABC-123xyz
Store this securely, it will go in your .env.
2. Clone & Configure the Repository
Clone the repo using command `git clone https://github.com/FlorentLvr/telegram-bot.git cd telegram-bot`
Copy environment template: `cp .env.example .env`
Fill in secrets:
ENV=dev
BOT_TOKEN
OPENAI_API_KEY
AGENT_API_TOKEN
AGENT_API_URL
WEBHOOK_URL
Install dependencies:
pip install -r src/requirements.txt
3. Local Webhook Testing with ngrok
Telegram requires HTTPS — ngrok gives you a quick public tunnel.
Start it and run in your terminal: `ngrok http 10000`
Copy your HTTPS URL (e.g. https://abc123.ngrok.io)
and put it into your WEBHOOK_URL_DEV en your .env.
Run the bot: `python bot.py`
Run the bot: `python telegram_set_webhook.py` to register your webhook in Telegram.
Now send a message to your bot — you should see logs in both:
Terminal
ngrok dashboard (http://127.0.0.1:4040)
4. Deploy to Render
Create a new Web Service on Render and connect your GitHub repo.
Settings:
Environment: Python 3
Branch: main
Root folder: src
Build Command: pip install -r requirements.txt
Environment variables on Render:
BOT_TOKEN = your Telegram token
WEBHOOK_URL = https://<your-render-service>.onrender.com (no trailing /webhook)
AGENT_API_TOKEN = your AI API token
AGENT_API_URL = your AI agent api endpoint
OPENAI_API_KEY = your OPENAI_API_KEY
Your bot is now live.
Conclusion
This system was created to solve a practical, daily problem:
How to trigger AI agents immediately after meetings using only your voice.
Now with this bot:
Speak your tasks
Your bot transcribes them
Your agent processes them
Tickets instantly appear in your roadmap
It's the fastest workflow I’ve found between thinking → speaking → execution.
Feel free to fork or adapt the repo to your own workflow!
© 2025. All rights reserved.
Ressources
Blog
Case Studies
