Browse SDKs · WASM
SDKsWASM

Receive custom business messages

Listen for custom business notifications delivered by the server through the WASM SDK.

Copy

SdkEvent.OnRecvCustomBusinessMessage delivers business notifications from the server. Its event data is not a MessageItem. Ordinary custom chat messages still arrive through the new-message events.

import { SdkEvent } from '@openim/wasm-client-sdk';

function handleCustomBusinessMessage({ data }) {
  const payload = parseAndValidateBusinessPayload(data);
  applyBusinessPayload(payload);
}

openimsdk.on(
  SdkEvent.OnRecvCustomBusinessMessage,
  handleCustomBusinessMessage,
);

function removeCustomBusinessMessageListener() {
  openimsdk.off(
    SdkEvent.OnRecvCustomBusinessMessage,
    handleCustomBusinessMessage,
  );
}

Keep a stable reference to the handler function. The business data should contain an ID that uniquely identifies the notification. Use that ID to update state and ignore duplicates; do not rely on arrival order or array position.