SDKsHarmonyOSEnterprise
Receive custom business notifications
Listen for server-pushed custom business notifications.
This event receives business notifications dispatched directly by the server, distinct from custom chat messages created via Create custom message; the latter are handled by Receive messages.
Code example
import sdk, { EventOnRecvCustomBusinessMessageData, OpenIMSDKEvent } from '@openimsdk/imsdk';
const handleBusinessMessage = (data: EventOnRecvCustomBusinessMessageData): void => {
const payload = parseAndValidateBusinessPayload(data.businessMessage);
applyBusinessPayload(data.clientMsgID, payload);
};
const unsubscribeBusinessMessage = sdk.on(
OpenIMSDKEvent.EventOnRecvCustomBusinessMessage,
handleBusinessMessage,
);
export function removeBusinessMessageListener(): void {
unsubscribeBusinessMessage();
}Parameters
This event listener does not take API call parameters.
Event payload
EventOnRecvCustomBusinessMessageData provides:
| Property | Type | Description |
|---|---|---|
clientMsgID | string | Unique client message identifier. |
businessMessage | string | Raw payload string delivered by the server. |
State changes after the call
Validate string formatting, business types, schema versioning, and mandatory attributes before updating application state. Deduplicate by clientMsgID, and re-query relevant business endpoints when definitive server state is required. Call unsubscribeBusinessMessage() when logging out or disposing of the state layer.
Was this page helpful?