Browse SDKs · uni-app / uni-app x
Platform
SDKsuni-app / uni-app x

Receive custom business messages

Listen for custom application-level business notifications dispatched directly by the server.

Copy

The custom business message event listens for arbitrary application-level notifications pushed directly by the backend server. The callback receives a raw string payload rather than an OpenIMMessageItem structure. In contrast, custom peer-to-peer chat messages created with Create a custom message are delivered through the standard message events in Receive messages.

Listen for custom business notifications

Subscribe to backend notifications using onRecvCustomBusinessMessage. Parse and validate the payload before dispatching it to local business stores.

import {
  off,
  onRecvCustomBusinessMessage,
} from '@/uni_modules/unix-openim-sdk'

const handleCustomBusinessMessage = (payload: string) => {
  const businessMessage = parseAndValidateBusinessPayload(payload)
  applyBusinessPayload(businessMessage)
}

const businessMessageSubscription =
  onRecvCustomBusinessMessage(handleCustomBusinessMessage)

function removeBusinessMessageListener() {
  off(businessMessageSubscription)
}

State changes after the call

Validate the string format, schema version, and required business identifiers before updating state. Maintain a stable notification ID in your custom protocol to deduplicate events on the client; never rely on arrival order and avoid evaluating untrusted expressions received in payloads.

Unregister the listener using removeBusinessMessageListener() when unmounting components, logging out, or switching accounts. To establish initial application state, query authoritative business REST APIs; events serve strictly as incremental notifications.