Browse Platform API
Platform API

Overview

Copy

Webhooks let OpenIM notify a business backend over HTTP or HTTPS before or after an operation. Before-event callbacks can validate, reject, or adjust an operation. After-event callbacks synchronize completed user, relationship, group, message, presence, and conversation changes.

Delivery model

TypeInvocationTypical useEffect on OpenIM
Before-eventSynchronousModeration, authorization, field changes, risk controlsOpenIM waits for the response and uses failedContinue, actionCode, and nextCode to continue or stop.
After-eventAsynchronousSynchronization, auditing, analytics, notificationsThe operation has completed; the response cannot change its result.

Before-event handlers are on the OpenIM request path and must remain low latency and highly available. After-event delivery can still be affected by network, process, or queue failures, so it must not be the only persistence mechanism for financial or similarly critical events.

Configure Webhooks

Configure a common URL and enable callbacks in config/webhooks.yml:

url: https://api.example.com/openim/webhooks
beforeSendSingleMsg:
  enable: true
  timeout: 5
  failedContinue: false
  deniedTypes: []
afterUserRegister:
  enable: true
  timeout: 5
SettingDescription
urlBase receiver URL. OpenIM appends the callbackCommand.
enableEnables the callback.
timeoutReceiver timeout in seconds.
failedContinueWhether a before-event operation continues after receiver failure or timeout.
attentionIdsUser or group IDs observed by an after-event callback.
allowedTypesMessage content types allowed to trigger the callback.
deniedTypesMessage content types excluded from the callback.
insecureSkipVerify EnterpriseSkips HTTPS certificate verification. Use only in controlled tests.
signature.algorithm EnterpriseHMAC-SHA1, HMAC-SHA256, HMAC-SHA512, RSA-SHA256, or ECDSA-SHA256.
signature.signatureHeader EnterpriseHeader carrying the signature.
signature.nonceHeader EnterpriseHeader carrying the signed nonce.
signature.secret EnterpriseHMAC secret or asymmetric private key.

The current Enterprise signature covers the nonce header, not the full body. Always use HTTPS and validate signature, nonce freshness, and replay state.

Request and response protocol

OpenIM sends JSON with POST to {WEBHOOK_ADDRESS}/{callbackCommand} and supplies operationID as a request header. Dispatch by callbackCommand, not arrival order, and make handlers idempotent using the event's business key, message ID, or operationID.

Before-event responses use:

{"actionCode":0,"errCode":0,"errMsg":"","errDlt":"","nextCode":0}

CallbackAction

ValueNameDescription
0ActionAllowUse nextCode to continue or stop. This is the value required by the current common response parser.
1ActionForbiddenReserved. To reject, return actionCode: 0, nextCode: 1, and a business error.

CallbackNextCode

ValueNameDescription
0ContinueContinue the OpenIM operation.
1StopStop the operation using errCode, errMsg, and errDlt.

Callback coverage

  • Users: registration and profile updates.
  • Relationships: friend requests, acceptance, deletion, remarks, blacklist changes, and imports.
  • Groups: creation, joining, leaving, dismissal, ownership, and group/member profile updates.
  • Messages: one-to-one and group sends, final message modification, read status, and revocation.
  • Push and presence: online/offline push targeting and user online, offline, or forced-logout state.
  • Conversations: creation callbacks are available in OpenIM Enterprise.

Integration guidance

  • Host receivers on a stable backend, never on a client.
  • Define strict before-event timeouts and an explicit failedContinue policy.
  • Acknowledge after-event callbacks quickly, then enqueue expensive work.
  • Restrict source addresses, rate, and body size at the gateway, and use HTTPS.