Browse SDKs · HarmonyOS
Platform
SDKsHarmonyOSEnterprise

Create custom message

Create a custom message containing structured business payload data.

Copy

Custom messages are ideal for business content such as orders, tasks, invites, or polls that need to be synchronized with conversation members.

Code example

import sdk, { CreateCustomMessageReq, CreateCustomMessageResp } from '@openimsdk/imsdk';

const request: CreateCustomMessageReq = {
  data: JSON.stringify({ type: 'task', taskID: 'task_42' }),
  extension: JSON.stringify({ schemaVersion: 1 }),
  description: 'Task Card',
  searchText: 'Project Task',
};
const response: CreateCustomMessageResp = await sdk.createCustomMessage(request);
const message = response.message;

Parameters

ParameterTypeRequiredDescription
datastringYesCustom payload data string.
extensionstringYesSupplementary extension string.
descriptionstringYesSummary or fallback description for legacy clients.
searchTextstringYesSearchable text string for local message indexing.

Return value

Returns a Promise resolving to CreateCustomMessageResp:

PropertyTypeDescription
messageIMMessageLocally instantiated custom message object.

State changes after the call

Both data and extension are opaque strings; the SDK does not parse or merge JSON keys automatically. description serves as a fallback or concise summary, while searchText enables local keyword search. Receiving clients parse the payload according to agreed data contracts, falling back to description when encountering unknown schema versions. This method constructs the message object locally without dispatching it; call Send message to send it. To listen for server-originated business notifications, see Receive server business notifications.