Reply Content Type
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.
You are welcome to provide feedback on this implementation by commenting on the Proposal for Reply content type.
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:
- JavaScript
npm i @xmtp/content-type-reply
Import and register
- JavaScript
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 tocontent
: A string representation of the reply
- JavaScript
const reply: Reply = {
reference: someMessageID,
content: "I concur",
};
Sending a Reply
Once you've created a reply, you can send it:
- JavaScript
await conversation.send(reply, {
contentType: ContentTypeReply,
});
Receiving a Reply
Here's how you can receive a reply:
- JavaScript
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.