Browse SDKs · React Native
SDKsReact Native

Receive custom business messages

OpenIM React Native SDK guide for receive custom business messages.

Copy

When the server sends a custom business notification, OnRecvCustomBusinessMessage is emitted. Its callback receives business data, not a MessageItem; ordinary custom chat messages are delivered through the new-message events in Receive messages.

function handleCustomBusinessMessage(data) {
  // ...
}

// Set the listener
OpenIMSDK.on(
  OpenIMEvent.OnRecvCustomBusinessMessage,
  handleCustomBusinessMessage,
);

// Remove the listener
OpenIMSDK.off(
  OpenIMEvent.OnRecvCustomBusinessMessage,
  handleCustomBusinessMessage,
);

Validate the received data against your business protocol before processing it. Remove the listener when the component is destroyed, the account signs out, or the account changes.