Connect a Telegram bot to chat with your agent on mobile. The Pope Bot supports text, voice messages, photos, and documents via Telegram.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/stephengpope/thepopebot/llms.txt
Use this file to discover all available pages before exploring further.
Setup Process
Use the interactive setup wizard to configure your Telegram bot:Run the setup wizard
- Creating a bot via @BotFather
- Configuring the webhook URL
- Setting up chat authorization
Create a bot with BotFather
If you don’t have a bot token yet:
- Open Telegram and search for
@BotFather - Send
/newbotand follow the prompts - Copy the bot token provided
- Enter it in the setup wizard
Configure webhook URL
The wizard will automatically configure your webhook at:The webhook is secured with a secret token that’s automatically generated.
Authorize your chat
- Start a conversation with your bot in Telegram
- Send the verification code shown by the wizard
- The bot will reply with your chat ID
- The wizard saves this to your configuration
Manual Configuration
If you prefer manual setup, add these environment variables:Message Flow
Here’s how messages flow through the system:Webhook Validation
The Telegram adapter validates every incoming webhook request:TELEGRAM_WEBHOOK_SECRETmust be set or all webhooks are rejectedTELEGRAM_CHAT_IDmust match or messages are ignored- Secret comparison uses the header
x-telegram-bot-api-secret-token
Message Normalization
The adapter converts Telegram’s message format into a channel-agnostic structure:Supported Message Types
Text Messages
Plain text messages are passed directly to the AI:Voice Messages
Voice messages are automatically transcribed via OpenAI Whisper:- Requires
OPENAI_API_KEYenvironment variable - Uses the
whisper-1model - Transcription happens before the message reaches the AI layer
Audio Messages
Audio files are handled identically to voice messages — transcribed to text:Photos
Photos are downloaded and passed as image attachments:Documents
Documents (PDFs, text files, etc.) are downloaded and attached:User Feedback
The adapter provides immediate feedback while processing:Acknowledgment
A thumbs-up reaction is added when the message is received:Typing Indicator
A typing indicator shows while the AI is processing:Sending Responses
Complete responses are sent back as regular Telegram messages:Telegram does not support real-time streaming. The
supportsStreaming getter returns false, so the AI generates the complete response before sending.Chat History
Telegram conversations are stored in the same database as web chats with a special user ID:userId of 'telegram'. This allows users to:
- View Telegram conversation history in the web UI
- Resume Telegram chats from the browser
- Star or delete Telegram conversations
API Endpoint
The webhook endpoint is defined inapi/index.js:
Troubleshooting
Bot doesn’t respond
Check webhook configuration
Check webhook configuration
Verify the webhook is registered:Should return your webhook URL and pending update count.
Verify environment variables
Verify environment variables
Check that all required variables are set:
TELEGRAM_BOT_TOKENTELEGRAM_WEBHOOK_SECRETTELEGRAM_CHAT_ID
Check server logs
Check server logs
Look for errors in the event handler logs:Common issues:
- Secret mismatch
- Chat ID mismatch
- Missing OPENAI_API_KEY for voice
Voice messages not transcribed
Verify OpenAI API key
Verify OpenAI API key
Voice transcription requires
OPENAI_API_KEY:Check Whisper availability
Check Whisper availability
The adapter checks if Whisper is enabled:
Webhook not receiving updates
Check public accessibility
Check public accessibility
Your webhook URL must be publicly accessible over HTTPS. Test with:
Verify SSL certificate
Verify SSL certificate
Telegram requires valid HTTPS. Self-signed certificates won’t work.
Check Telegram API status
Check Telegram API status
Sometimes Telegram’s API has issues. Check https://downdetector.com/status/telegram/
Related Resources
Web Interface
Learn about the built-in web chat
Adding Channels
Build custom channel adapters