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 by commenting on the Reply Content Type XIP Proposal.
Configure content type
In some SDK's the ReplyCodec
is already included in the SDK. If not, you can install the package using the following command:
- JavaScript
- React
- Swift
- Kotlin
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());
The React SDK supports all current standards-track content types, but only text messages are enabled out of the box. Adding support for other standards-track content types requires a bit of configuration.
import {
XMTPProvider,
replyContentTypeConfig,
} from "@xmtp/react-sdk";
const contentTypeConfigs = [
replyContentTypeConfig,
];
createRoot(document.getElementById("root") as HTMLElement).render(
<StrictMode>
<XMTPProvider contentTypeConfigs={contentTypeConfigs}>
<App />
</XMTPProvider>
</StrictMode>,
);
Client.register(ReplyCodec());
import org.xmtp.android.library.codecs.ReplyCodec
Client.register(codec = ReplyCodec())
Sending a Reply
Once you've created a reply, you can send it:
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",
};
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
The presentation of replies are decisions to be made by client applications. It does seem worth it to call out some reply experiences that we use today that might map well to the above proposal. They are:
- Discord Individual messages can get replied to, where the replies retain a link back to the originally referenced message
- Telegram
Note that iMessage and Slack are omitted, as they follow more of a “threaded” pattern, where messages are collected into a logical grouping. There may be a separate content type proposal to explore this as a pattern, so for now, we’ll hold off.