Skip to content

Support replies with your agent built with XMTP

Use the reply content type to support quote replies with your agent. 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.

The reply content type is built into the Agent SDK. No installation is required.

Send a reply

Once you've created a reply, you can send it. Replies include the original message being replied to, allowing you to display the parent message context without an additional lookup.

Node
import { encodeText } from '@xmtp/agent-sdk';
 
// Simple helper method
await ctx.sendTextReply('I concur');
 
// Full reply object with reference
await ctx.conversation.sendReply({
  content: encodeText('I concur'),
  reference: someMessageID,
  referenceInboxId: ctx.message.senderInboxId,
});

Receive a reply

Replies now include enriched information, including the original message being replied to:

Node
import type { EnrichedReply } from '@xmtp/agent-sdk';
 
agent.on('reply', async (ctx) => {
  const reply: EnrichedReply = ctx.message.content;
  console.log(`New reply: ${reply.content}`);
  console.log(`Replying to message: ${reply.referenceId}`);
  
  // Access the original message being replied to
  if (reply.inReplyTo) {
    console.log(`Original message: ${reply.inReplyTo.content}`);
  }
});

Filter a reply

Now that you can send a reply, you need a way to receive a reply. For example:

Node
import type { EnrichedReply } from '@xmtp/agent-sdk';
 
if (ctx.isReply()) {
  // We've got a reply.
  const reply: EnrichedReply = ctx.message.content;
}