Skip to main content

Insert Message

The SDK supports inserting messages into the local database. Messages inserted locally will not be sent to the server or the recipient.

  • Ensure that all inserted messages are storable; otherwise, an error will be thrown.
  • The insert message interface only inserts messages into the local database, so messages inserted locally will not be synced from the remote server when the app is reinstalled or the user logs in from a different device.

Insert a Single Message

  • Use this feature to insert a single message into a local conversation.
  • The inserted message must be storable; otherwise, a parameter error exception will be thrown.
  • The insert message feature only supports configuring the conversation type, conversation ID, channel ID, message direction, message timestamp, and other accessible properties unique to each message type.
  • By default, the inserted message is a sender-side message that has been successfully sent.

Method


insertMessage(
message: RCIMIWMessage,
callback: IRCIMIWInsertMessageCallback
): Promise<number>;

Parameter Description

ParameterTypeDescription
messageRCIMIWMessageThe message to be inserted
callbackIRCIMIWInsertMessageCallbackCallback for the result of the interface call.

Return Value

Return ValueDescription
numberThe status code of the current operation. 0 indicates success. The specific result needs to be handled in the callback. Non-zero values indicate that the operation failed, and the callback will not be triggered. Refer to the error codes for details.

Code Example


const callback = {
onMessageInserted: (code: number, message: RCIMIWMessage) => {
//...
},
};
let code = await engine.insertMessage(message, callback);

Insert Multiple Messages

  • Use this feature to insert multiple messages into a local conversation.
  • The inserted messages must be storable; otherwise, a parameter error exception will be thrown.
  • The insert message feature only supports configuring the conversation type, conversation ID, channel ID, message direction, message timestamp, and other accessible properties unique to each message type.
  • By default, the inserted messages are sender-side messages that have been successfully sent.
  • It is recommended to insert a maximum of 10 messages at a time. If one message fails, all messages will fail to be inserted.

Method


insertMessages(
messages: Array<RCIMIWMessage>,
callback: IRCIMIWInsertMessagesCallback
): Promise<number>;

Parameter Description

ParameterTypeDescription
messagesArray<RCIMIWMessage>The collection of messages to be inserted
callbackIRCIMIWInsertMessagesCallbackCallback for the result of the interface call.

Return Value

Return ValueDescription
numberThe status code of the current operation. 0 indicates success. The specific result needs to be handled in the callback. Non-zero values indicate that the operation failed, and the callback will not be triggered. Refer to the error codes for details.

Code Example


const callback = {
onMessagesInserted: (code: number, messages: Array<RCIMIWMessage>) => {
//...
},
};
let code = await engine.insertMessages(messages, callback);