Receive custom business messages
Listen for custom business notifications and server push signals using the OpenIM React Native SDK.
When the server dispatches non-chat administrative notifications (such as system-wide broadcasts, order status updates, or marketing alerts) through management endpoints, the SDK emits the OnRecvCustomBusinessMessage event.
Unlike standard chat messages, the event payload is raw business data (typically a JSON string), rather than a MessageItem object. For in-conversation custom chat messages exchanged between users, see Receive messages.
const handleCustomBusinessMessage = (businessData: string) => {
try {
const payload = JSON.parse(businessData);
// Process business notification (e.g., refresh global badge or display banner)
} catch (error) {
console.error('Failed to parse custom business payload:', error);
}
};
// Register listener
OpenIMSDK.on(
OpenIMEvent.OnRecvCustomBusinessMessage,
handleCustomBusinessMessage,
);
// Unregister listener
OpenIMSDK.off(
OpenIMEvent.OnRecvCustomBusinessMessage,
handleCustomBusinessMessage,
);Validate payload structures and signatures according to your application protocol before handling data. Always unregister the listener using the same function reference when unmounting components or signing out.
Was this page helpful?