Skip to main content

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:
This endpoint:
  1. Sets the webhook URL to production endpoint
  2. Configures required bot commands
  3. Validates webhook connectivity
  4. Returns updated health status
Response:

Required Webhook Updates

The bot is configured to receive these update types:

Bot Commands

The following commands must be configured:

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:
Message Types:
Sent when user sends /start commandKey: welcomeVariables:
  • {username} - User’s Telegram username or “there”
Sent when user checks balance with /creditsKey: credits_balanceVariables:
  • {credits} - User’s current credit balance
Confirmation after successful credit purchaseKey: payment_successVariables:
  • {credits} - Credits purchased
  • {amount} - Amount paid (formatted)
Notification when payment failsKey: payment_failedVariables:
  • {reason} - Failure reason

Edit Message Content

Update a bot message:
Message editing requires acquiring a lock to prevent concurrent edits. Locks are automatically released after update.

Message Locking

Prevents simultaneous edits by multiple admins:
Lock status includes:
  • Admin user ID who locked
  • Admin email
  • Lock timestamp
  • Auto-expires after 10 minutes

Message History

View edit history for a message:
Returns up to 50 previous versions with:
  • 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:
Requirements:
  • Admin must have linked Telegram account
  • users.telegramId must be set
  • Rate limit: 10 messages per minute per admin
Example Response:
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

Response:

View Channel Members

Query Parameters:
  • page (number) - Page number (default: 1)
  • limit (number) - Results per page (default: 20, max: 100)
  • status (string) - Filter: all, member, not_member
  • search (string) - Search by email/name
Response:

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

  1. User sends /buy command
  2. Bot presents credit package options (inline keyboard)
  3. User selects package
  4. Bot creates invoice via createInvoiceLink()
  5. User completes payment in Telegram
  6. Bot receives pre_checkout_query
  7. Bot validates and answers with answerPreCheckoutQuery()
  8. Telegram processes payment
  9. Bot receives successful payment notification
  10. Credits are added to user account
  11. Bot sends payment success message

Invoice Creation

Webhook Security

Webhook requests are verified using the secret token:
All webhook endpoints reject requests with invalid secret tokens (403 Forbidden).

Rate Limiting

Telegram webhook endpoints have specific rate limits:

Best Practices

Message Management

  1. Test Before Deployment - Always test messages before making them live
  2. Use Variables - Leverage message variables for personalization
  3. Parse Mode - Use HTML for better formatting control
  4. Lock Messages - Acquire locks before editing to prevent conflicts
  5. Review History - Check message history before rollbacks

Channel Management

  1. Regular Monitoring - Check channel status and member count weekly
  2. Permission Verification - Ensure bot has necessary channel permissions
  3. Member Sync - Periodically sync member status with database
  4. Invite Validation - Verify user tier before bulk invites

Security

  1. Webhook Secret - Use strong, unique webhook secret
  2. Token Protection - Never expose bot token in client code
  3. Rate Limiting - Monitor webhook rate limits
  4. 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
Bot Commands Not Working
  • Sync commands via POST /api/admin/telegram/sync
  • Verify commands are registered: GET /api/admin/telegram/health
  • Check bot has necessary permissions
Messages Not Sending
  • Verify user has linked Telegram account
  • Check users.telegramId is populated
  • Review server logs for API errors
  • Ensure bot is not blocked by user
Payment Issues
  • Verify payment provider token is configured
  • Check invoice creation logs
  • Ensure currency and amounts are valid
  • Review pre-checkout query handling

API Reference

Get Bot Health

Sync Bot Configuration

Get Bot Messages

Get Specific Message

Update Message

Lock Message

Test Message