TG-Staff 团队 avatar TG-Staff 团队

TG-Staff Webhook Event Integration Guide: Automate Conversations, Messages, and Operational Workflows

tg-staff webhook api automation

TG-Staff Webhook Event Integration Guide: Automate Conversations, Messages, and Operations

When you run a Telegram Bot customer support team, one of the biggest headaches is data fragmentation: support conversations live in TG-Staff, customer info in CRM, tickets in another system. You end up manually copying and pasting, or writing scripts to poll TG-Staff’s API for data—inefficient and error-prone.

TG-Staff’s Webhook events are designed to solve this. It’s not a manual “export button,” but a real-time data bridge: when key events happen in the platform (e.g., a user sends a new message, an agent is assigned a conversation, a conversation closes), TG-Staff proactively pushes event data to a URL you specify. Your server receives a POST request and can automatically create tickets, update user tags, trigger satisfaction surveys—truly enabling event-driven automation.

This article details how to configure TG-Staff Webhook events, the subscribable event types, and 3 ready-to-implement integration scenarios. If you’re looking to connect Telegram support data with your own systems, this guide is worth bookmarking.


What Are TG-Staff Webhook Events?—From Passive Reception to Active Integration

Simply put, Webhooks are “reverse APIs”: normally you actively call an API to fetch data (e.g., check for new messages every 5 seconds), but with Webhooks, TG-Staff pushes data to your server when an event occurs.

Their core value is real-time action and eliminating polling. Imagine:

  • Without Webhooks: You write a scheduled task to call TG-Staff’s “get unread conversations” endpoint every 10 seconds, processing lots of duplicate data, straining your server, and introducing latency.
  • With Webhooks: When a user first messages the Bot, TG-Staff immediately sends a conversation.created event to your URL. You instantly know “a new customer has arrived” and can auto-create a lead in your CRM.

For B2B SaaS teams, cross-border e-commerce support, and Web3 project teams, this means seamlessly integrating Telegram support data into existing ticketing systems (like Zendesk, Freshdesk), analytics platforms (like Mixpanel), or even internal Slack or DingTalk notifications.


Overview of Subscribable Event Types

TG-Staff currently supports the following Webhook events (check the latest official docs). Each event has a fixed event_type string you can use for logic routing on your target server.

Event Nameevent_typeTrigger ConditionTypical Use Case
New Conversation Createdconversation.createdUser contacts Bot for the first time, or reopens a closed conversationAuto-create CRM lead, send welcome notification
New Messagemessage.receivedUser or agent sends a message (including text, images, etc.)Real-time sync messages to QA system or knowledge base
Conversation Status Changedconversation.status_changedConversation moves from “waiting” → “assigned” → “in progress” → “closed”Trigger ticket status update, send satisfaction survey on close
Agent Status Changedagent.status_changedAgent goes online/offline/switches to busyUpdate team scheduling board, trigger Slack notification

Tip: Event Push Scope

TG-Staff Webhook events only push key data generated internally on the platform, and do not involve original message content from the user’s Telegram side (e.g., media files). Ensure you understand the push field scope during integration to avoid relying on data that is not provided. For example, the message.received event includes the message text, sender ID, and conversation ID, but does not include binary files of images/videos.


How to Configure Webhook Events? — A Three-Step Integration

The configuration process is done within the TG-Staff console, no coding required — your backend only needs to receive POST requests.

Step 1: Find the Webhook Configuration Entry

Log in to the TG-Staff console and go to the project settings page. In the sidebar, locate the “Developer” or “Integrations” menu (the exact name depends on the console). You will see a “Webhook Configuration” section.

Step 2: Fill in the Target URL for Receiving Events

  • The URL must use HTTPS protocol (TG-Staff will not push data to HTTP endpoints).
  • If your server requires authentication, you can add custom headers in the “Request Headers” area (e.g., Authorization: Bearer your-secret-token).
  • After clicking “Save”, TG-Staff will send a ping test to that URL to verify connectivity. If it returns 200, the configuration takes effect.

Step 3: Select the Event Types to Subscribe To

You don’t need to subscribe to all events. Depending on your integration needs, check the corresponding events. For example:

  • Only need to create a CRM record when a user contacts for the first time → Check only conversation.created
  • Need to sync all messages to an internal system → Check message.received
  • Need complete conversation lifecycle tracking → Check conversation.created + conversation.status_changed + message.received

Verify if the Webhook Is Working

After configuration, the most straightforward verification is to send a message to your bot using another Telegram account, then check your target server’s logs.

Common troubleshooting:

  • URL unreachable: Check if your server’s firewall allows outbound IPs from TG-Staff (you can query the IP list in the console).
  • Response timeout: TG-Staff requires the target server to return 200 within 5 seconds. If the processing logic is complex, it’s recommended to return 200 first and process asynchronously (e.g., put it in a queue).
  • Signature verification failed: If TG-Staff supports a signing key (refer to official documentation), ensure you verify the HMAC signature in the X-TG-Staff-Signature header.

Security Recommendations: Signature Verification and Retry Mechanism

  • Signature verification: If TG-Staff provides a signing key, always verify the request signature on the receiving end to prevent forged callbacks. The verification method typically uses HMAC-SHA256 to compute a signature from the request body and compare it with the signature in the request header.
  • Retry strategy: If the target server returns a non-200 status code, TG-Staff retries up to 3 times with intervals of approximately 30 seconds, 2 minutes, and 5 minutes. If all attempts fail, the event is discarded (original data remains in the TG-Staff platform and is not lost). It is recommended that your server always returns 200 to confirm receipt.

Typical Integration Scenarios: From Customer Service to Automation

The following 3 scenarios demonstrate how webhook events can connect TG-Staff with your business systems.

Scenario 1: New Conversation → Auto-Create CRM Ticket

Event: conversation.created

Process: When a user sends a message to the bot for the first time, TG-Staff pushes the event to your server → Your server parses the user ID, conversation ID, and first message text from the event → Automatically create a lead or ticket in your CRM (e.g., HubSpot, Salesforce) with the title “Telegram user [username] new inquiry” and attach the conversation link.

Benefit: Customer service agents don’t need to manually enter customer information, and the sales team can see lead sources immediately.

Scenario 2: Agent Replies → Sync Message to Quality Assurance System

Event: message.received

Process: Every time an agent sends a message, the event is pushed to a quality assurance system (e.g., internal compliance platform) → The QA system performs real-time detection based on risk word rules (which can be linked with TG-Staff Pro’s content moderation) → If a sensitive word is hit, the message is automatically flagged and a QA reviewer is notified.

Benefit: Enables real-time quality monitoring of agent conversations, especially suitable for industries with high compliance requirements such as Web3 and finance.

Scenario 3: Conversation Closed → Trigger Satisfaction Survey

Event: conversation.status_changed (status changes to closed)

Process: When an agent closes a conversation, TG-Staff pushes the event → Your server checks that the status is closed → Automatically send a satisfaction survey link to the user (via TG-Staff’s bulk messaging feature or a separate bot) → Survey results are sent back to the data analysis platform.

Benefit: No manual intervention needed; automatically collect user feedback and continuously improve customer service quality.


Integration with Other TG-Staff Features

Webhook events are not isolated; they can work together with TG-Staff’s existing capabilities to create greater integration value.

  • Diversion Link + New Conversation Event: When a user enters the bot through an advertising diversion link, the conversation.created event carries the referrer field (e.g., ad source, URL parameters). You can use this to analyze conversion effectiveness from different channels.
  • Agent Status Change + Internal Notification: When an agent goes offline for more than 30 minutes, the agent.status_changed event can trigger a Slack or DingTalk bot notification to remind managers to adjust scheduling.
  • Rich User Profile Data: In the event callback, TG-Staff includes the user ID. You can call the User Profile API (requires Pro version) to retrieve user tags and historical conversation summaries, merge them with event data, and write to an external database.

Important: Avoid Data Redundancy and Loops

This is a common pitfall that is easy to overlook. If your webhook target server also sends requests to TG-Staff (e.g., via TG-Staff’s API to send messages), and that message triggers the message.received event, it creates an A → B → A infinite loop.

Solution: In the event handling logic, check the message source. For example, in the event payload, determine whether sender_type is agent or system. If the message was sent by an agent, skip the write operation to avoid duplication.

Note: Event Push Frequency Limits

TG-Staff may impose rate limits on Webhook event pushes (e.g., up to 10 per second). If a large number of events occur during peak business hours (such as multiple users consulting simultaneously), it is recommended that the target server implement queue buffering to prevent request loss due to high concurrency.


FAQ

Q: Does TG-Staff Webhook events support custom fields or filtering conditions?
A: Currently, TG-Staff event push is based on fixed event types and does not support custom fields. However, you can use the session ID or user ID in the event to call other APIs (such as the user profile API) to supplement data after receiving. It is recommended to implement filtering conditions on the target server side.

Q: What happens if a Webhook event push fails? Is there a retry mechanism?
A: Yes, TG-Staff will retry up to 3 times by default (with intervals of approximately 30 seconds, 2 minutes, and 5 minutes). If all retries fail, the event will be discarded, but no data loss will occur (since the original data remains stored on the TG-Staff platform). It is recommended that the target server ensure a 200 response.

Q: Can I configure multiple Webhook URLs to receive the same event?
A: Currently, TG-Staff only supports configuring one Webhook URL per project. If you need to distribute to multiple systems, it is recommended to forward internally on the target server (e.g., using a message queue or middleware).

Q: Do Webhook events contain user private data (e.g., phone numbers, email addresses)?
A: Webhook events mainly push metadata such as session status, message ID, and user ID, and do not include sensitive information from the user’s Telegram side (e.g., phone numbers). Custom data in user profiles (e.g., tags) may contain business data; please handle it according to your privacy policy.

Q: How can I test if the Webhook configuration is working?
A: On the console Webhook configuration page, there is usually a “Send Test Event” button. If not, you can manually create a new session (e.g., send a message using a test bot) and then check if the target server logs receive the corresponding POST request.


Start Integrating Your Telegram Customer Service Data

TG-Staff Webhook events are the “highway” connecting customer service data with your business systems. Whether you want to automatically create CRM tickets, perform real-time message quality inspection, or build full-link user behavior analysis, it saves you the hassle of polling and makes data truly flow.

  • Free Trial: Register for a 3-day trial. Webhook functionality is available with the Standard plan and above (check the official website for specific plans).
  • View Documentation: Get the latest event list, field descriptions, and signature verification examples → TG-Staff Official Documentation
  • Contact Support: Have questions about integration? Contact @tgstaff_robot directly, and the technical team will assist you with configuration.

Experience Webhook event integration now and upgrade your Telegram customer service operations from “manual handling” to an “event-driven” automated workflow.