createCustomMessage
Feature Introduction
Note
Create a custom message, where the fields are all defined by the developer. The SDK is only responsible for transparent transmission.
- iOS
- Android
- Flutter
- uni-app
- Browser/Electron/MiniProgram
- React-Native
- Unity
Function Prototype
Future<Message> createCustomMessage({
required String data,
required String extension,
required String description,
String? operationID,
})
Input Parameters
Parameter Name | Parameter Type | Mandatory | Description |
---|---|---|---|
data | String | Yes | Text content |
extension | String | No | Extension content |
description | String | No | Description |
Return Result
Name | Type | Description |
---|---|---|
~ | Message | Success |
Code Example
Message msg = await OpenIM.iMManager.messageManager.createCustomMessage(
data: jsonEncode({'key1':'value1'}),
extension: '',
description: ''
);
//todo
Function Prototype
+ (OIMMessageInfo *)createCustomMessage:(NSString *)data
extension:(NSString * _Nullable)extension
description:(NSString * _Nullable)description;
Input Parameters
Parameter Name | Parameter Type | Mandatory | Description |
---|---|---|---|
data | NSString | Yes | Text content |
extension | NSString | No | Extension content |
description | NSString | No | Description |
Return Result
Name | Type | Description |
---|---|---|
message | OIMMessageInfo | Success |
Code Example
OIMMessageInfo *message = [OIMMessageInfo createCustomMessage:@""
extension:@""
description:@""];
Function Prototype
public Message createCustomMessage(String data, String extension, String description)
Input Parameters
Parameter Name | Parameter Type | Mandatory | Description |
---|---|---|---|
data | String | Yes | Text content |
extension | String | No | Extension content |
description | String | No | Description |
Return Result
Name | Type | Description |
---|---|---|
~ | Message | Success |
Code Example
Message Message= OpenIMClient.getInstance().messageManager.createCustomMessage(data, extension, description);
Function Prototype
IMSDK.createCustomMessage({
data: string;
extension: string;
description: string;
}, operationID?: string): Promise<WsResponse<MessageItem>>
Input Parameters
Parameter Name | Parameter Type | Mandatory | Description |
---|---|---|---|
data | String | Yes | Text content |
extension | String | No | Extension content |
description | String | No | Description |
Return Result
Parameter Name | Parameter Type | Description |
---|---|---|
Promise.then() | Promise<WsResponse<MessageItem>> | Successful call |
Promise.catch() | Promise<WsResponse> | Failed call |
Code Example
import { getSDK } from '@openim/wasm-client-sdk';
const IMSDK = getSDK();
// use in electron with ffi
// import { getWithRenderProcess } from '@openim/electron-client-sdk/lib/render';
// const { instance: IMSDK } = getWithRenderProcess();
// use in mini program
// import { OpenIMSDK } from 'open-im-sdk';
// const IMSDK = new OpenIMSDK();
IMSDK.createCustomMessage({
data: '',
extension: '',
description: '',
})
.then(({ data }) => {
// Successful call
})
.catch(({ errCode, errMsg }) => {
// Failed call
});
Function Prototype
IMSDK.asyncApi('createCustomMessage', operationID: string, {
data: string;
extension: string;
description: string;
}): Promise<MessageItem>
Input Parameters
Parameter Name | Parameter Type | Mandatory | Description |
---|---|---|---|
operationID | string | Yes | Operation ID, for locating issues. Suggested to use current time and a random number. |
data | String | Yes | Text content |
extension | String | No | Extension content |
description | String | No | Description |
Return Result
Through the
openim-uniapp-polyfill
package, the function is Promise-ified. When calling, usethen
andcatch
to judge and handle successful and failed callbacks.
Parameter Name | Parameter Type | Description |
---|---|---|
Promise.then() | Promise<MessageItem> | Successful call |
Promise.catch() | Promise<CatchResponse> | Failed call |
Code Example
import IMSDK from 'openim-uniapp-polyfill';
IMSDK.asyncApi('createCustomMessage', IMSDK.uuid(), {
data: '',
extension: '',
description: '',
})
.then((data) => {
// Successful call
})
.catch(({ errCode, errMsg }) => {
// Failed call
});
### Function Prototype
OpenIMSDKRN.createCustomMessage({
data: string,
extension: string,
description: string
}, operationID: string): Promise<MessageItem>
Input Parameters
Parameter Name | Parameter Type | Mandatory | Description |
---|---|---|---|
data | String | Yes | Text content |
extension | String | Yes | Extension content |
description | String | Yes | Description |
operationID | string | Yes | Operation ID, used for problem location, keep unique, suggest using current time and random number |
Return Result
Parameter Name | Parameter Type | Description |
---|---|---|
Promise.then() | Promise<MessageItem> | Callback on successful call |
Promise.catch() | Promise<CatchResponse> | Callback on failed call |
Code Example
import OpenIMSDKRN from "open-im-sdk-rn";
OpenIMSDKRN.createCustomMessage({
data: '',
extension: '',
description: '',
}, 'operationID')
.then((data) => {
// Successful call
})
.catch(({ errCode, errMsg }) => {
// Failed call
});
Function Prototype
public static Message CreateCustomMessage(string data, string extension, string description)
Input Parameter
Parameter Name | Parameter Type | Mandatory | Description |
---|---|---|---|
data | string | Yes | Text content |
extension | string | No | Extension content |
description | string | No | Description |
Return Result
Parameter Name | Type | Description |
---|---|---|
~ | Message | Message Struct |
Code Example
var msg = IMSDK.CreateCustomMessage(data,extension,description);