Overview
Telegram integration provides:- 📞 Call started notifications with call details
- 💬 Live transcripts for both user and AI
- ✅ Call completion summaries with duration and outcome
- 🔴 Error notifications if calls fail
- 🤖 Direct Telegram Bot API (no ClawdBot dependency)
src/agenticai/telegram/direct_client.py
Setup
/newbot to create a new bot- Bot name: “Agentic AI Monitor” (or your choice)
- Bot username: Must end in “bot” (e.g.,
myagenticai_bot)
<YOUR_BOT_TOKEN>):
chat object in the JSON response:
chat.id value (e.g., 987654321)# Telegram Integration
TELEGRAM_BOT_TOKEN=123456789:ABCdefGHIjklMNOpqrsTUVwxyz1234567890
TELEGRAM_CHAT_ID=987654321
🔍 Testing Connections
Testing Twilio...
✓ Twilio OK
Testing Gateway...
✓ Gateway OK
Checking Gemini config...
✓ Gemini configured
┌─────────┬────────────┬──────────────────────┐
│ Service │ Status │ Details │
├─────────┼────────────┼──────────────────────┤
│ Twilio │ ✓ Connected│ Account: Your Name │
│ Gateway │ ✓ Connected│ ws://127.0.0.1:18789 │
│ Gemini │ ✓ Configured│ Model: gemini-2.5-* │
└─────────┴────────────┴──────────────────────┘
Message Types
The Telegram client sends different message types:Call Started
When a call begins:src/agenticai/telegram/direct_client.py:95-121
Live Transcripts
During the conversation:src/agenticai/telegram/direct_client.py:69-93
Call Ended
When the call completes:src/agenticai/telegram/direct_client.py:123-157
Error Notifications
If a call fails:Customizing Messages
Markdown Formatting
Messages support Telegram Markdown:HTML Formatting
Silent Notifications
Send messages without sound/vibration:src/agenticai/telegram/direct_client.py:24-67
Advanced Usage
Multiple Chat IDs
Send notifications to multiple users or groups:Programmatic Integration
Send custom messages from your application:Call Transcripts with Metadata
Include metadata in notifications:Incoming Call Notifications
For incoming calls, the direction is included:src/agenticai/server/app.py:130-145 (incoming call detection)
Telegram Bot Commands
Optional: Add Bot Commands
Enhance your bot with custom commands:- Open @BotFather in Telegram
- Send
/setcommands - Select your bot
- Send this command list:
Implementing command handlers requires extending the Telegram client. The current implementation only sends notifications.
Troubleshooting
No messages received
No messages received
Symptoms: Calls work but no Telegram notificationsSolutions:
-
Verify Telegram is enabled:
-
Check bot token is correct:
Expected response:
-
Verify chat ID:
Make sure you’ve messaged the bot at least once.
-
Test manually:
-
Check server logs:
src/agenticai/telegram/direct_client.py:159-173Messages sent to wrong chat
Messages sent to wrong chat
Symptoms: Messages appear in a different chatSolutions:
-
Verify chat ID in
.env: -
Get your correct chat ID:
- Message your bot
- Visit:
https://api.telegram.org/bot<TOKEN>/getUpdates - Find
chat.idin the response
-
Update
.env: -
Restart the service:
Error: 'Unauthorized'
Error: 'Unauthorized'
Error: 'Chat not found'
Error: 'Chat not found'
Symptoms: API returns
{"ok": false, "error_code": 400, "description": "Bad Request: chat not found"}Solutions:-
You haven’t messaged the bot yet:
- Open Telegram
- Search for your bot username
- Send any message (e.g., “hi”)
-
Chat ID might be wrong:
- Visit:
https://api.telegram.org/bot<YOUR_TOKEN>/getUpdates - Verify the
chat.idmatches your.env
- Visit:
-
For group chats:
- Add the bot to the group
- Chat ID for groups is negative (e.g.,
-123456789)
Markdown formatting not working
Markdown formatting not working
Symptoms: Asterisks and underscores appear literallySolutions:
-
Use correct Markdown syntax:
-
Escape special characters:
-
Try HTML mode instead:
API Reference
TelegramDirectClient
Main class for Telegram integration.send_message()
Send a text message.src/agenticai/telegram/direct_client.py:24-67
send_transcript()
Send a formatted transcript message.src/agenticai/telegram/direct_client.py:69-93
send_call_started()
Notify when a call begins.src/agenticai/telegram/direct_client.py:95-121
send_call_ended()
Notify when a call completes.src/agenticai/telegram/direct_client.py:123-157
test_connection()
Test the Telegram connection.src/agenticai/telegram/direct_client.py:159-173
Privacy and Security
Keep Your Bot Token Secret
Restrict Bot Access
- Only share your bot username with trusted users
- For groups: Make the bot an admin to control who can add it
- Monitor unauthorized access:
Disable Bot (Emergency)
If your token is compromised:- Message @BotFather
- Send
/mybots - Select your bot
- Click Revoke Token
- Generate a new token and update
.env
Next Steps
Making Calls
Initiate calls to see Telegram notifications
Receiving Calls
Monitor incoming calls
Scheduling
Track scheduled calls
Service Management
View Telegram logs