Browse SDKs · WASM
Platform
SDKsWASM

Create a custom message

Create a structured custom business message with the WASM SDK.

Copy

Use createCustomMessage() for application-specific messages such as orders, tasks, invitations, or polls.

Parameters

ParameterTypeRequiredDescription
datastringYesComplete business data string, typically serialized JSON.
extensionstringYesComplete business extension string.
descriptionstringYesDescription of the message type, or fallback text for clients that do not support it.
searchText EnterprisestringNoPlain text used for local message search and list display.
const { data: message } = await openimsdk.createCustomMessage({
  data: JSON.stringify({ type: 'task', taskID: 'task_42' }),
  extension: JSON.stringify({ schemaVersion: 1 }),
  description: 'Task card',
});

data contains the business data, extension contains additional business information, and description identifies the type or provides a fallback. Each value is a complete string. The receiving client should parse the agreed version, size, and fields and provide a fallback for unknown versions.

In OpenIM Enterprise, pass searchTextEnterprise when the custom message should participate in local message search. It supplies searchable text only and does not replace the business data:

const { data: searchableMessage } = await openimsdk.createCustomMessage({
  data: JSON.stringify({ type: 'task', taskID: 'task_42' }),
  extension: JSON.stringify({ schemaVersion: 1 }),
  description: 'Task card',
  searchText: 'task task_42',
});

When the Promise resolves, it returns only a pending MessageItem. Sending a message and receiving a custom business event are separate flows.