- Telegram account (mobile or desktop)
- Git & GitHub account
- Visual Studio Code or Cursor (IDE)
- ngrok account (for local webhook testing)
- Render account (for production)
- OpenAI account (to transcribe voice messages)
- Your AI agent token / API endpoint
-
Open Telegram and search for @BotFather.
-
Start a chat and send:
/newbot -
Follow prompts:
- Choose a name (display name).
- Choose a username that ends with
bot(e.g.my_support_bot).
-
BotFather responds with your Bot Token (format like
123456:ABC...). Save it — you will store it in environment variables (never commit to Git).
-
Clone this repository:
git clone https://github.com/your-username/your-bot-repo.git cd your-bot-repo -
Copy the example environment file and update values:
cp .env.example .env
Edit
.envand fill in your:BOT_TOKENOPENAI_API_KEYAGENT_API_TOKENAGENT_API_URLWEBHOOK_URL
-
Install dependencies (ideally in a virtual environment):
pip install -r src/requirements.txt
Telegram webhooks require a public HTTPS URL — ngrok can expose your local server.
- Start ngrok:
ngrok http 10000-
Copy HTTPS URL from ngrok (e.g.
https://abc123.ngrok.io) and inbot.pyin variable:WEBHOOK_URL_DEV -
Start your bot (so it registers or uses new
WEBHOOK_URL).
python bot.py- Manually set webhook (optional — your code may set it):
curl -X POST "https://api.telegram.org/bot$BOT_TOKEN/setWebhook?url=$WEBHOOK_URL/webhook"- Verify:
curl "https://api.telegram.org/bot$BOT_TOKEN/getWebhookInfo"Look for "url": "https://abc123.ngrok.io/webhook" and no recent 404 errors.
- Send a message in Telegram and watch:
- Bot terminal logs (SSE chunks and edits)
- ngrok request inspector (http://127.0.0.1:4040) shows incoming POSTs
- 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 - Start Command:
python bot.py(ensure bot runs Flask and background PTB thread)
- Environment variables on Render:
BOT_TOKEN= your Telegram tokenWEBHOOK_URL=https://<your-render-service>.onrender.com(no trailing/webhook)AGENT_API_TOKEN= your AI API tokenAGENT_API_URL= your AI agent api endpointOPENAI_API_KEY= your OPENAI_API_KEY
- Optionally add
render.yamlto describe service. - Deploy — check Render logs:
- Look for startup logs,
Webhook URLlog,Telegram Application started, and streaming logs.
- Look for startup logs,