Webhook Callbacks
Overview
Some data from WuKongIM will be sent to third-party application services through webhooks, such as user online status, messages that need to be pushed, all messages, etc. All webhooks are POST requests, and the event name is passed through query parameters. For example, if the third-party server provides a webhook address ofhttp://example.com/webhook, then the online status webhook would be:
Webhook Workflow

Event Types
1. User Online Status Notification
Each user’s online and offline status will be notified to the third-party server through this webhook. Event Name:user.onlinestatus
Request Method: POST
Request URL: {webhook_url}?event=user.onlinestatus
Request Body
The request body is a string array, each element formatted as:Data Field Description
| Position | Field Name | Type | Description |
|---|---|---|---|
| 1 | User UID | string | User unique identifier |
| 2 | Device Flag | integer | 0=APP, 1=Web |
| 3 | Online Status | integer | 0=Offline, 1=Online |
| 4 | Connection ID | integer | Connection ID established by current device on server |
| 5 | Device Online Count | integer | Online count for same user and same device type |
| 6 | User Total Online Count | integer | Total online count for all user devices |
2. Offline Message Notification
Offline message notification mainly notifies the third-party server of messages that need to be pushed offline. After receiving this webhook, the third-party server needs to call mobile vendor push interfaces to push the message content to users in the ToUIDs list. Event Name:msg.offline
Request Method: POST
Request URL: {webhook_url}?event=msg.offline
Request Body
The request body is a MessageResp message object:Message header information
Message setting identifier
Server message ID (globally unique)
String type server message ID (globally unique)
Client message unique number
Message sequence number (channel unique, ordered increment)
Sender UID
Channel ID
Channel type
Server message timestamp (10 digits, to seconds)
Base64 encoded message content
3. All Messages Notification
WuKongIM server will push all messages to the third-party server. To reduce pressure on the third-party server, messages are not pushed one by one but with delay processing. By default, batch push occurs every 500 milliseconds (webhook.msgNotifyEventPushInterval), which can be configured as needed.
Event Name: msg.notify
Request Method: POST
Request URL: {webhook_url}?event=msg.notify
Request Body
The request body is an array of MessageResp message objects, each containing the following fields:Message header information
Message setting identifier
Server message ID (globally unique)
String type server message ID (globally unique)
Client message unique number
Message sequence number (channel unique, ordered increment)
Sender UID
Channel ID
Channel type
Server message timestamp (10 digits, to seconds)
Base64 encoded message content
Configure Webhook
Set the webhook URL in the WuKongIM configuration file:Best Practices
- Response Speed: Webhook processing should be as fast as possible to avoid blocking WuKongIM service
- Idempotency: Ensure webhook processing is idempotent and can be safely retried
- Error Handling: Return appropriate HTTP status codes, 2xx indicates success
- Async Processing: For complex business logic, recommend asynchronous processing
- Monitoring & Alerting: Monitor webhook success rate and response time
- Security Verification: Verify request source to prevent malicious requests
Troubleshooting
Common Issues
- Webhook Not Received: Check URL configuration and network connectivity
- Processing Timeout: Optimize processing logic to reduce response time
- Duplicate Processing: Implement idempotent processing mechanism
- Message Loss: Ensure correct HTTP status codes are returned

