logo
In-app Chat
SDK Error Codes
Powered Byspreading
On this page

Insert local messages


Overview

The ZIM SDK supports inserting local messages into one-on-one and group conversations, and starting from version 2.13, it also supports inserting local messages into room conversations. The inserted messages will only exist locally on the device and will not be sent to other users or synchronized to other devices. Additionally, these messages will not be retained after uninstalling the client application.

You can use this feature to insert a message into the local database for displaying system notifications. For example, it can be used for local notifications such as joining or leaving a group, which do not need to be sent to other users across devices.

Implementation process

To insert a message into the local database, you need to call the insertMessageToLocalDB API and introduce the created ZIMMessage message, conversationID, conversationType, senderUserID, and other parameters.

Sample code
// Insert a message into the local database.
// Inserting a text message is used as an example here. You can also insert other types of messages. However, signaling messages are not supported.
const message = { type: 1, message: 'string' };
const conversationType = 0;
zim.insertMessageToLocalDB(
    message,
    'conversationID',
    conversationType,
    'senderUserID'
).then((res) => {
    // You can listen for whether the insertion is successful.
});
1
Copied!

Previous

Delete messages

Next

Forward messages