Skip to main content

Reply Content Type

Status Status

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 are welcome to provide feedback on this implementation by commenting on the Proposal for Reply content type.

Replies with React

To learn how to use the reply content type with the React SDK, see Handle content types with the React SDK.

Install the package

Use the following commands to install the package:

npm i @xmtp/content-type-reply

Import and register

import { ContentTypeReply, ReplyCodec } from "@xmtp/content-type-reply";
// Create the XMTP client
const xmtp = await Client.create(signer, { env: "dev" });
// Register the codecs, AttachmentCodec is for handling local attachments under 1MB
xmtp.registerCodec(new ReplyCodec());

Create a Reply

In XMTP, replies are represented as objects with two keys:

  • reference: The message ID for the message that is being replied to

  • content: A string representation of the reply

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

Sending a Reply

Once you've created a reply, you can send it:

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

Receiving a Reply

Here's how you can receive a reply:

if (message.contentType.sameAs(ContentTypeReply)) {
// We've got a reply.
const reply: Reply = message.content;
}

Displaying the Reply

Replies should generally be displayed alongside the original message to provide context. However, the way you choose to display replies is completely up to you.

Was the information on this page helpful?
powered by XMTP