Skip to main content

Enable message history for group chat with XMTP

Each app installation generates unique group chat keys. This means that group chat messages sent from one app installation can only be decrypted by that same app installation.

To enable users to access their group chat messages using all of their app installations, enable the message history feature. Enabling message history is necessary for a seamless multi-app installation experience.

To learn more about the user experience without the message history feature, see ⚠️ Important: Manage actions that make a local database inaccessible.

Run a message history server

To enable the message history feature, you must run your own xmtp-message-history-server. When you do, it will provide a message history sync URL to use in the next step.

Set message history sync URL

When your app creates a new client, specify the location where the client should sync message history.

Code sample coming soon

Request message history sync

When a new client is created, it will look for other clients registered with the same inbox ID.

If there are none, there is no message history to be synced.

If there are clients registered with the same inbox ID, it will request a message history sync with the clients.

For example, let’s say that inbox ID 1/client B requests a message history sync with inbox ID 1/client A.

The request encodes, encrypts, and sends inbox ID 1/client A’s group chat messages to the message history server indicated by inbox ID 1/client A’s historySyncUrl.

The request then downloads the encrypted messages from the message history server to inbox ID 1/client B’s local database. Inbox ID 1/client B can then decrypt, decode, and display the messages.

The request performs this sync for every client registered with inbox ID 1.

Sequence diagram illustrating the request message history sync flow between Inbox 1/Client B, Inbox 1/Client A, and a message history server

caution

Downloading message history may involve a large amount of data. To help users avoid potential mobile data charges, consider prompting users to initiate the download only when connected to Wi-Fi.

Code sample coming soon

Was the information on this page helpful?
powered by XMTP