Skip to content

Support replies in your app built with XMTP

Use the reply content type to support quote replies in your app. A reply is a method to directly respond to a specific message in a conversation. Users can select and reply to a particular message instead of sending a new one.

Use a local database for performance

Use a local database to store replies. This will enable your app to performantly display a reply with its referenced message when rendering message lists.

Configure the content type

For Browser SDK (v6.0.0+) and Node SDK (v5.0.0+), replies are built-in and do not require codec registration. Skip this step for these SDKs.

For other SDKs, register the codec:

React Native
const client = await Client.create(signer, {
  env: 'production',
  codecs: [new ReplyCodec()],
});

Send a reply

Once you've created a reply, you can send it. Replies are represented as objects with two keys:

  • reference: ID of the message being replied to

  • content: String representation of the reply

Browser
import { encodeText } from '@xmtp/browser-sdk';
 
const reply = {
  reference: someMessageID,
  referenceInboxId: senderInboxId, // Inbox ID of the original message sender
  content: await encodeText('I concur'),
};
 
await conversation.sendReply(reply);

Receive the content type

Browser
import { contentTypesAreEqual } from '@xmtp/content-type-primitives';
import { contentTypeReply } from '@xmtp/browser-sdk';
 
if (contentTypesAreEqual(message.contentType, await contentTypeReply())) {
  const reply = message.content;
 
  // Access the reply text
  console.log('Reply:', reply.content);
}

To handle unsupported content types, refer to the fallback section.

Display the reply

How you choose to display replies in your app is up to you. It might be useful to look at the user experience for replies in popular apps such as Telegram and Discord. For example, in Discord, users can reply to individual messages, and the reply provides a link to the original message.

Note that the user experience of replies in iMessage and Slack follows more of a threaded pattern, where messages display in logical groupings, or threads. This reply content type doesn't support the threaded pattern. If you'd like to request support for a threaded reply pattern, post an XIP idea.