Browse SDKs · uni-app / uni-app x
Platform
SDKsuni-app / uni-app x

Create a custom message

Construct a custom message containing structured business payloads.

Copy

Invoke createCustomMessage() to encapsulate structured business payloads such as orders, tasks, invites, or polls into messages synchronized across chat participants.

Parameters

ParameterTypeRequiredDescription
datastringYesSerialized business payload string (typically JSON).
extensionstringYesSupplementary extension metadata string.
descriptionTextstringYesFallback 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) return

All 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.