Create custom message
Create a custom message containing structured business payload data.
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
| Parameter | Type | Required | Description |
|---|---|---|---|
data | string | Yes | Custom payload data string. |
extension | string | Yes | Supplementary extension string. |
description | string | Yes | Summary or fallback description for legacy clients. |
searchText | string | Yes | Searchable text string for local message indexing. |
Return value
Returns a Promise resolving to CreateCustomMessageResp:
| Property | Type | Description |
|---|---|---|
message | IMMessage | Locally 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.
Was this page helpful?