Skip to main content

Support replies in your app built with XMTP

Status Status

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.

Open for feedback

You're welcome to provide feedback by commenting on the Proposal for Reply content type XIP idea.

Configure the content type

In some SDKs, the ReplyCodec is already included in the SDK. If not, you can install the package using the following command:

In the JavaScript SDK, you need to import this package first.

npm i @xmtp/content-type-reply

After importing the package, you can register the codec.

import { ContentTypeReply, ReplyCodec } from "@xmtp/content-type-reply";
// Create the XMTP client
const xmtp = await Client.create(signer, { env: "dev" });
xmtp.registerCodec(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

import { ContentTypeText } from "@xmtp/xmtp-js";
import { ContentTypeReply } from "@xmtp/content-type-reply";

const reply: Reply = {
reference: someMessageID,
contentType: ContentTypeText
content: "I concur",
};

await conversation.send(reply, {
contentType: ContentTypeReply,
});

Receive the content type

if (message.contentType.sameAs(ContentTypeReply)) {
// We've got a reply.
const reply: Reply = message.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.

Was the information on this page helpful?
powered by XMTP