3.7 KiB
3.7 KiB
Telegram Bot Testing Guide
Why Telegram?
- ✅ Completely FREE - No costs at all
- ✅ Instant setup - 2 minutes to get started
- ✅ Real API - Test actual HTTP requests, not mocks
- ✅ Immediate testing - Use your own phone
- ✅ No verification - No business account needed
Setup Steps (5 minutes)
1. Create a Telegram Bot
- Open Telegram on your phone
- Search for
@BotFather - Send
/newbotcommand - Choose a name for your bot (e.g., "My Campaign Tester")
- Choose a username (e.g., "mycampaign_test_bot")
- Copy the bot token (looks like:
1234567890:ABCdefGHIjklMNOpqrsTUVwxyz)
2. Get Your Telegram User ID
Option A: Quick way
- Search for
@userinfoboton Telegram - Start a chat with it
- It will reply with your user ID (e.g.,
123456789)
Option B: Manual way
- Start a chat with your new bot (search for the username you created)
- Send any message to it (e.g., "hello")
- Open this URL in browser (replace
<YOUR_BOT_TOKEN>):https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates - Find your user ID in the JSON response under
"from": {"id": 123456789}
3. Configure Your App
Edit backend/.env or docker-compose.yml:
WHATSAPP_PROVIDER=telegram
TELEGRAM_BOT_TOKEN=1234567890:ABCdefGHIjklMNOpqrsTUVwxyz
4. Add Yourself as a Contact
In your app's Contacts page:
- Phone: Your Telegram user ID (e.g.,
123456789) - First Name: Your name
- Opted In: ✅ Check this box
- Click "Create"
5. Create Campaign and Send
-
Create a template (e.g., "Hello {{first_name}}!")
-
Create a list and add your contact
-
Create a campaign with that template and list
-
Click "Send"
-
Trigger the worker:
curl -X POST http://localhost:8000/api/workers/tick -
Check your Telegram - you'll receive the message! 🎉
What You'll See
In Your App
- Campaign status:
sending→done - Recipient status:
pending→sent - Real Telegram message IDs
- Actual error messages if something fails
On Your Phone
- Real message from your bot
- Variables replaced ({{first_name}} → your actual name)
- Instant delivery
Testing Different Scenarios
Test Opt-in Enforcement
- Create contact with
opted_in = false - Try sending with regular template (not WhatsApp approved)
- View campaign → See error: "Contact not opted in"
Test Multiple Contacts
- Get Telegram IDs from friends/family
- Add them as contacts (with permission!)
- Send campaign to the list
- Everyone receives the message
Test Rate Limiting
- Set
MAX_MESSAGES_PER_MINUTE=2in config - Send to 10 contacts
- Watch messages sent slowly (respects rate limit)
Troubleshooting
"Failed to send Telegram message: 400 Bad Request"
- Cause: Invalid chat ID (user ID)
- Fix: Make sure user has started a chat with your bot first
"Failed to send Telegram message: 401 Unauthorized"
- Cause: Invalid bot token
- Fix: Double-check the token from @BotFather
"Contact not opted in"
- Fix: Check the "Opted In" checkbox when creating contact
Switch Between Providers
# For mock testing (no external calls)
WHATSAPP_PROVIDER=mock
# For Telegram testing (free, real API)
WHATSAPP_PROVIDER=telegram
TELEGRAM_BOT_TOKEN=your-token
# For production WhatsApp
WHATSAPP_PROVIDER=cloud
WHATSAPP_CLOUD_ACCESS_TOKEN=your-token
WHATSAPP_CLOUD_PHONE_NUMBER_ID=your-id
Production Checklist
Once Telegram testing looks good:
- ✅ All campaigns working
- ✅ Error handling tested
- ✅ Rate limiting working
- ✅ Opt-in enforcement verified
- ✅ DND list tested
- → Ready to switch to WhatsApp Cloud API!
Happy Testing! 🚀