Setting Up Webhook Integrations for Telegram
You've decided to use Telegram as your primary support channel, and you're wondering how to make those incoming messages actually turn into trackable tickets instead of getting lost in the chat noise. The answer lies in webhook integrations—the bridge between Telegram's event stream and your CRM's ticket engine.
Webhooks are essentially automated messages sent from Telegram to your CRM whenever something happens: a new message arrives, a topic is created, or a user joins a group. Unlike polling (which checks for updates every few seconds), webhooks deliver events instantly and efficiently. For a support team handling dozens or hundreds of conversations daily, that real-time delivery is the difference between a customer waiting five seconds or five minutes for an agent to notice their issue.
What You're Actually Building
Before we dive into configuration steps, let's clarify what a webhook integration does in a Telegram CRM context. You're not just forwarding messages—you're creating a structured intake pipeline:
- A customer posts in a Telegram Topic Group
- Telegram sends a webhook payload to your CRM endpoint
- Your CRM parses the payload, identifies the topic/thread, and creates a ticket
- The ticket enters your queue, gets assigned based on your routing rules, and appears in an agent's workspace
Prerequisites: What You Need Before Starting
You can't configure webhooks without a few pieces already in place. Treat this as your pre-flight checklist:
- A Telegram Bot: Create one via @BotFather. You'll need the bot token (looks like `123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11`).
- A CRM with Webhook Support: Your chosen CRM must accept incoming webhooks and map them to ticket creation. Most modern support CRMs offer this, but check their documentation for Telegram-specific endpoints.
- A Public HTTPS Endpoint: Telegram only sends webhooks to HTTPS URLs. If you're testing locally, use a tunneling service like ngrok or Cloudflare Tunnel.
- Admin Rights in the Telegram Group: Your bot needs to be a group admin with "Post Messages" and "Read Messages" permissions to receive topic events.
Step 1: Set Up Your Telegram Bot as a Group Admin
This is the most common stumbling block. A bot that's just a member of a group can't see topic messages or receive update events. It needs admin privileges.
The setup process:
- Add your bot to the Telegram Topic Group via the group's "Add Members" option
- Immediately promote the bot to admin—don't skip this step
- Grant these permissions: "Post Messages," "Read Messages," "Manage Topics" (if you want the bot to create topics automatically)
- Test by sending a message in a topic and checking your bot's update stream
Step 2: Configure the Webhook URL in Telegram
Now you need to tell Telegram where to send events. You'll do this via the `setWebhook` method of the Telegram Bot API.
The command structure:
``` https://api.telegram.org/bot<YOUR_BOT_TOKEN>/setWebhook?url=<YOUR_CRM_ENDPOINT>/telegram-webhook ```
Replace `<YOUR_BOT_TOKEN>` with your actual bot token and `<YOUR_CRM_ENDPOINT>` with your CRM's webhook URL. For example:
``` https://api.telegram.org/bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11/setWebhook?url=https://yourcrm.example.com/webhooks/telegram ```
What happens after you run this command:
- Telegram sends a test payload to your endpoint to verify connectivity
- Your CRM should respond with a `200 OK` status (any other response means Telegram will retry several times, then stop)
- All subsequent group events—new messages, topic changes, member joins—will be forwarded to your CRM
``` https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getWebhookInfo ```
The response should show `"ok": true` and the URL you configured. If it shows `"has_custom_certificate": false` and `"pending_update_count": 0`, you're in good shape.
Step 3: Map Telegram Events to Ticket Fields
This is where the real configuration happens inside your CRM. Every CRM handles webhook payloads differently, but the mapping logic follows a consistent pattern.
| Telegram Payload Field | CRM Ticket Field | Notes |
|---|---|---|
| `message.chat.id` | Source Channel ID | Used to identify the Telegram group |
| `message.message_thread_id` | Thread/Conversation ID | Links replies to the correct topic |
| `message.from.username` | Customer Identifier | Primary key for customer lookup |
| `message.text` | Ticket Description | Main body of the support request |
| `message.date` | Created Timestamp | Useful for First Response Time calculations |
| `chat.title` | Ticket Subject | Falls back to topic title if available |
A practical mapping example:
When a customer posts in a topic titled "Payment Failed," your webhook receives:
```json { "update_id": 123456789, "message": { "message_id": 42, "from": {"id": 987654321, "is_bot": false, "first_name": "Alex", "username": "alex_customer"}, "chat": {"id": -1001234567890, "title": "Support Group", "type": "supergroup"}, "message_thread_id": 567, "date": 1700000000, "text": "My payment didn't go through. Card was charged but nothing happened." } } ```
Your CRM should parse this and create a ticket with:
- Customer: `alex_customer` (or create a new contact record)
- Subject: `Payment Failed` (from the topic title, which you'd need to fetch separately)
- Description: `My payment didn't go through. Card was charged but nothing happened.`
- Channel: `Telegram - Support Group`
- Thread ID: `567` (used to send replies back to the correct topic)
Step 4: Handle Topic Creation and Thread Management
Telegram Topic Groups are powerful for support because each issue gets its own thread. But you need to decide: do you let customers create topics freely, or do you restrict topic creation to agents or bots?
Option A: Customers create topics (self-service)
- Pros: Reduces agent workload, customers can describe their issue immediately
- Cons: Topic titles can be unhelpful ("Help!" or "URGENT!!!"), and customers might create duplicate topics
- Webhook handling: Your CRM should check for existing open tickets with the same customer and topic title before creating a new one
- Pros: Structured data, consistent topic titles, prevents duplicates
- Cons: Requires a separate bot command or inline form
- Webhook handling: The bot sends a `/new` command that triggers a form, then creates the topic with the form data
- Pros: Full quality control, proper categorization
- Cons: Delays ticket creation, requires more agent time
- Webhook handling: Only agent messages trigger topic creation; customer messages are held in a general queue
Step 5: Test Your Integration End-to-End
Don't assume it works just because the webhook URL returned `200 OK`. Run through these test scenarios:
- New customer message in an existing topic: Does a ticket appear in your CRM with the correct thread ID?
- New topic created by customer: Does the CRM create a new ticket and link it to the topic?
- Media attachments: Can your CRM handle images, documents, and voice messages?
- Agent reply back to Telegram: Does the reply appear in the correct topic thread?
- Multiple concurrent conversations: Can the CRM distinguish between different topics and customers?
Step 6: Monitor and Troubleshoot Webhook Health
Webhooks fail silently. If Telegram can't reach your endpoint (server down, SSL certificate expired, rate limiting), it will retry for up to 24 hours, but eventually drops the events. You won't notice until a customer complains that their message from yesterday was never answered.
Set up monitoring for:
- Webhook response time: If your CRM takes more than 2 seconds to respond, Telegram may time out
- Error rate: Track non-200 responses from your webhook endpoint
- Pending update count: Use `getWebhookInfo` periodically; a growing `pending_update_count` means webhooks aren't being processed fast enough
- Missed events: Compare Telegram group activity against CRM ticket creation counts
| Symptom | Likely Cause | Fix |
|---|---|---|
| No tickets created | Webhook URL wrong or SSL issue | Re-run `setWebhook` with correct URL, check certificate |
| Duplicate tickets | Missing deduplication logic | Add thread ID check before ticket creation |
| Wrong customer linked | Username field not mapped | Check `from.username` vs `from.id` mapping |
| Replies go to wrong topic | Thread ID not preserved in response | Include `message_thread_id` in bot replies |
| Webhook works intermittently | Rate limiting or server timeout | Increase server timeout, add retry logic |
What a Working Integration Looks Like
After you've completed these steps, your support workflow should look like this:
- Customer opens Telegram, finds your support group, and creates a new topic titled "Order #1234 missing"
- Telegram sends a webhook to your CRM with the topic creation event and the first message
- Your CRM creates a ticket with status "New," assigns it to the appropriate queue based on keywords ("order," "missing")
- An agent sees the ticket in their dashboard, opens it, and sends a reply
- Your CRM sends the reply back to Telegram via the bot, using the correct `message_thread_id`
- The customer sees the response in their topic thread—no context switching, no "please email us separately"
Next steps once your webhooks are stable:
- Configure tags and custom fields to categorize incoming tickets automatically
- Set up workload balancing and queue management to distribute tickets evenly across your team
- Review your ticket system setup to ensure your status workflows align with your Telegram integration

Reader Comments (0)