Overview
The JOIP platform integrates with Telegram to provide users with bot interactions, notifications, and payment processing. The Telegram admin panel provides tools for monitoring bot health, configuring messages, and managing webhooks.Prerequisites
To use the Telegram integration, configure these environment variables:The bot must be created via @BotFather before configuration.
Bot Health Monitoring
Access the bot health dashboard at:Health Metrics
Bot Identity
- Bot username
- Bot user ID
- Is bot verified
- Can join groups
- Can read all messages
Webhook Status
- Webhook URL configured
- Pending update count
- Last error timestamp
- Last error message
Command Configuration
- Required commands configured
- Command count
- Command list
Channel Status
- Premium channel linked
- Channel member count
- Bot permissions in channel
Health Check Response
Webhook Configuration
Sync Webhook Settings
Automatically configure webhook and commands:- Sets the webhook URL to production endpoint
- Configures required bot commands
- Validates webhook connectivity
- Returns updated health status
Required Webhook Updates
The bot is configured to receive these update types:Bot Commands
The following commands must be configured:| Command | Description | Handler |
|---|---|---|
/start | Initialize bot interaction | Welcome message with app link |
/credits | Check credit balance | Display current balance |
/link | Link Telegram to JOIP account | OAuth flow initiation |
/buy | Purchase credits | Payment menu |
/help | Get help information | Command list and support |
Command Configuration
Commands are automatically synced via:Bot Message Management
Admins can customize bot messages via the Messages section.Available Messages
Access the message list:Welcome Message
Welcome Message
Sent when user sends
/start commandKey: welcomeVariables:{username}- User’s Telegram username or “there”
Credits Balance
Credits Balance
Sent when user checks balance with
/creditsKey: credits_balanceVariables:{credits}- User’s current credit balance
Link Account
Link Account
Instructions for linking Telegram to JOIP accountKey:
link_accountVariables:{link_url}- Deep link to OAuth flow
Payment Success
Payment Success
Confirmation after successful credit purchaseKey:
payment_successVariables:{credits}- Credits purchased{amount}- Amount paid (formatted)
Payment Failed
Payment Failed
Notification when payment failsKey:
payment_failedVariables:{reason}- Failure reason
Edit Message Content
Update a bot message:Message Locking
Prevents simultaneous edits by multiple admins:- Admin user ID who locked
- Admin email
- Lock timestamp
- Auto-expires after 10 minutes
Message History
View edit history for a message:- Content and parse mode
- Editor user ID
- Edit timestamp
- Change type (update, rollback, reset)
Rollback Message
Restore a previous message version:Reset to Default
Restore original message template:Test Message Delivery
Admins can test message delivery to their own Telegram account:- Admin must have linked Telegram account
users.telegramIdmust be set- Rate limit: 10 messages per minute per admin
Test messages are sent with placeholder variable values (e.g.,
{credits} = “25”).Premium Channel Management
If a premium channel is configured, admins can:View Channel Status
View Channel Members
page(number) - Page number (default: 1)limit(number) - Results per page (default: 20, max: 100)status(string) - Filter:all,member,not_membersearch(string) - Search by email/name
Bulk Invite Users
Invite multiple users to the premium channel:Payment Integration
The Telegram bot supports payment processing via Telegram Payments.Configure Payment Provider
Set up via environment variables:Payment Flow
- User sends
/buycommand - Bot presents credit package options (inline keyboard)
- User selects package
- Bot creates invoice via
createInvoiceLink() - User completes payment in Telegram
- Bot receives
pre_checkout_query - Bot validates and answers with
answerPreCheckoutQuery() - Telegram processes payment
- Bot receives successful payment notification
- Credits are added to user account
- Bot sends payment success message
Invoice Creation
Webhook Security
Webhook requests are verified using the secret token:Rate Limiting
Telegram webhook endpoints have specific rate limits:Best Practices
Message Management
- Test Before Deployment - Always test messages before making them live
- Use Variables - Leverage message variables for personalization
- Parse Mode - Use HTML for better formatting control
- Lock Messages - Acquire locks before editing to prevent conflicts
- Review History - Check message history before rollbacks
Channel Management
- Regular Monitoring - Check channel status and member count weekly
- Permission Verification - Ensure bot has necessary channel permissions
- Member Sync - Periodically sync member status with database
- Invite Validation - Verify user tier before bulk invites
Security
- Webhook Secret - Use strong, unique webhook secret
- Token Protection - Never expose bot token in client code
- Rate Limiting - Monitor webhook rate limits
- Input Validation - Validate all user inputs from Telegram
Troubleshooting
Common Issues
Webhook Not Receiving Updates- Verify webhook URL is accessible publicly
- Check webhook secret is configured correctly
- Review Telegram webhook info for errors:
GET /api/admin/telegram/health - Ensure SSL certificate is valid
- Sync commands via
POST /api/admin/telegram/sync - Verify commands are registered:
GET /api/admin/telegram/health - Check bot has necessary permissions
- Verify user has linked Telegram account
- Check
users.telegramIdis populated - Review server logs for API errors
- Ensure bot is not blocked by user
- Verify payment provider token is configured
- Check invoice creation logs
- Ensure currency and amounts are valid
- Review pre-checkout query handling