SDKsuni-app / uni-app x
Create a custom message
Construct a custom message containing structured business payloads.
Invoke createCustomMessage() to encapsulate structured business payloads such as orders, tasks, invites, or polls into messages synchronized across chat participants.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
data | string | Yes | Serialized business payload string (typically JSON). |
extension | string | Yes | Supplementary extension metadata string. |
descriptionText | string | Yes | Fallback summary text displayed when a client does not support rendering this custom message type. |
Code example
import { createCustomMessage } from '@/uni_modules/unix-openim-sdk'
const message = await createCustomMessage({
data: JSON.stringify({
type: 'task',
taskID: 'task_42',
}),
extension: JSON.stringify({ schemaVersion: 1 }),
descriptionText: 'Task Card',
})
if (message == null) returnAll three parameters must be complete strings; the SDK does not parse or merge JSON schemas internally. Receiving clients should parse the protocol version and payload fields carefully, rendering descriptionText if an unsupported schema is encountered.
Return value
The Promise resolves with an OpenIMMessageItem | null object.
State changes after the call
Pass the constructed message item to Send a message. Track the message lifecycle in your UI state using clientMsgID.
Was this page helpful?