Skip to content

Conversations: capture replies and sync threads ​

When people reply to your emails, Conversations brings those replies into Outbound, so your application can read them, store them and answer them. This guide explains how conversations are created and how to keep your own system in sync. To show them to your team inside your own application, see Show Inbound Conversations in Your Application. For every method and field, see the Conversations reference.

What It Is ​

An email sent with captureReplies: true carries a second Reply-To address on your reply domain. It is the sender's own address name on that domain: an email from admin@yourcompany.com with the reply domain reply.yourcompany.com gets admin@yourcompany.com, admin@reply.yourcompany.com as its Reply-To. When the recipient replies, the reply reaches your own inbox as usual and also arrives in Outbound as a conversation. Outbound matches each reply to the email it answers through the reply headers that mail apps add when someone presses Reply (In-Reply-To and References).

An Outbound admin enables Conversations for your account and assigns you a reply domain. From then on, every email you send with captureReplies: true captures its replies. There is nothing to turn on yourself.

ts
await outbound.email.send({
  toEmail: 'riya@example.com',
  fromEmail: 'admissions@yourcompany.com',
  emailSubject: 'Your application',
  htmlBody: '<p>Hi Riya, reply to this email with any questions.</p>',
  captureReplies: true,
});

captureReplies works the same way on email.bulk, templates.send and templates.bulkSend.

Good to know:

  • Replies to emails sent before the change to the second address still arrive in Conversations as before.
  • A reply sent from an app that drops the reply headers is not captured. It still reaches the sender's own inbox through the first Reply-To address.
  • If you created an inbound mailbox with the same address as the plain reply address, such as admin@reply.yourcompany.com, that mailbox receives those replies instead of Conversations. See Receive Email on Your Own Addresses.

When a Conversation Is Created ​

Outbound creates one conversation per sent email, at the moment the first reply to it arrives. Nothing is created at send time unless you add createThread: true, see below.

Say you send 100 emails in one campaign with captureReplies: true, all 100 are delivered, and 50 of the recipients reply. Now 50 conversations exist, and the campaign report shows replied: 50 and replyRate: '50.00%'. The other 50 emails have no conversation, unless an automatic reply arrived for them.

A few details matter when you sync:

  • Automatic replies wait on a hidden conversation. Out-of-office replies and bounce notices are kept on a conversation that lists leave out by default. Pass includeAutomated: true to see it. If a person replies later, their reply joins that same conversation and carries the same threadId.
  • One email, one conversation. Replies from the email's CC recipients, and replies to the replies your team sends, stay in the same conversation.
  • One conversation per email, not per person. If the same person replies to two different emails, you get two conversations. A bulk send gives every recipient their own email, so each recipient's replies form their own conversation. To show one timeline per person, group conversations by lead.email on your side.

See who has not replied ​

Add createThread: true to open the conversation when the email is sent, instead of when its first reply arrives. It requires captureReplies: true.

ts
await outbound.email.send({
  toEmail: 'riya@example.com',
  fromEmail: 'admissions@yourcompany.com',
  emailSubject: 'Your application',
  htmlBody: '<p>Hi Riya, reply to this email with any questions.</p>',
  captureReplies: true,
  createThread: true,
  campaignId: 'Q3-LEADS',
});

for await (const thread of outbound.conversations.listAllThreads({ campaignId: 'Q3-LEADS', hasReplies: false })) {
  console.log(`${thread.lead.email} has not replied yet`);
}

To narrow the list to emails sent in a date range, add sentFrom and sentTo. Date-only values are read in the tz time zone. To leave out emails that bounced or were marked as spam, list only the delivery statuses you want with deliveryStatus:

ts
for await (const thread of outbound.conversations.listAllThreads({
  campaignId: 'Q3-LEADS',
  hasReplies: false,
  sentFrom: '2026-10-01',
  sentTo: '2026-10-31',
  tz: 'Asia/Kolkata',
  deliveryStatus: ['sent', 'delivered', 'opened', 'clicked'],
})) {
  console.log(`${thread.lead.email} has not replied yet`);
}

With createThread: true, the 100 emails in the example above open 100 conversations at send. The 50 recipients who never reply keep a conversation with hasReplies: false, and conversations.summary() counts them as noReply. The campaign report still shows replied: 50, because it counts replies, not conversations. Dropped, suppressed and failed emails never open a conversation, so every conversation in the list belongs to an email that was actually sent.

Webhooks give you new messages within seconds. This is the recommended way to keep your own system up to date.

1. Store the messageId of every recipient at send time. email.send returns messageId, and email.bulk returns one per recipient in recipients[].messageId. Reply events carry it back, which is how you link a conversation to your own lead record.

2. Subscribe a webhook to reply. It covers every message a person writes in the conversation, including your team's replies. Add auto_reply if you also want out-of-office notices, bounce notices and read receipts.

ts
await outbound.webhooks.create({
  url: 'https://yourapp.com/webhooks/outbound',
  events: ['reply', 'auto_reply'],
});

3. Handle each event:

  • Create your conversation record the first time you see a reply for a details.threadId, keyed by that threadId, and link it to your lead through messageId.
  • Upsert every message, keyed by details.replyId.
  • Never create a conversation from an auto_reply. Store those messages by threadId, and they line up if a person replies later.
ts
import express from 'express';
import { Outbound, type IncomingWebhookPayloadV2 } from '@masters-union/outbound-sdk';

const app = express();

app.post('/webhooks/outbound', express.raw({ type: 'application/json' }), async (req, res) => {
  const valid = Outbound.verifyWebhookSignature(
    req.body,
    req.header('X-Webhook-Signature') ?? '',
    process.env.OUTBOUND_WEBHOOK_SECRET!,
  );
  if (!valid) return res.status(401).send('invalid signature');

  const payload: IncomingWebhookPayloadV2 = JSON.parse(req.body.toString());

  for (const event of payload.events) {
    const { threadId, replyId } = event.details;
    if (!threadId || !replyId) continue;

    if (event.event === 'reply') {
      await db.conversations.createIfMissing({ threadId, messageId: event.messageId });
    }

    await db.conversationMessages.upsert({
      replyId,
      threadId,
      kind: event.details.replyType,
      direction: event.details.direction,
      from: event.details.from,
      text: event.details.newText,
      receivedAt: event.details.receivedAt,
      simulated: event.details.simulated,
    });
  }

  res.sendStatus(200);
});

Some things to know about deliveries:

  • They can be retried and arrive out of order. Always upsert, never insert blindly, and sort messages by details.receivedAt rather than by the order the webhooks arrived.
  • Your team's reply can come first. A reply with replyType: staff_reply can arrive before the reply it answers, or be the first message in a conversation that only had automatic replies. That is why the example creates the conversation on any reply. Outbound's own inbox likewise shows a conversation once it has a reply from a person or from your team.
  • messageId is the email that was replied to. On the first reply that is the original email, so it matches what you stored at send time. A reply to a message your team sent from Outbound carries that message's messageId instead. getThread(threadId) always returns the original email as thread.originMessageId.
  • Message text comes from outside your company. Escape newText, from and the other message fields before you render them.

See Conversation Events for every field and Verify Webhook Signature for signature checks.

Pull-Based Sync and Backfill ​

To backfill history, or as a safety net next to webhooks, pull the conversations that changed since your last run. listAllThreads pages through them for you, and getThread returns each conversation's messages.

ts
const lastSyncedAt = await db.syncState.get('outbound-conversations');
const since = lastSyncedAt
  ? new Date(Date.parse(lastSyncedAt) - 10 * 60 * 1000).toISOString()
  : undefined;
let newest = lastSyncedAt;

for await (const thread of outbound.conversations.listAllThreads({ status: 'all', includeAutomated: false, since })) {
  const { messages } = await outbound.conversations.getThread(thread.id);

  await db.conversations.upsert({
    threadId: thread.id,
    originMessageId: thread.originMessageId,
    leadEmail: thread.lead.email,
  });

  for (const m of messages) {
    await db.conversationMessages.upsert({
      replyId: m.id,
      threadId: m.threadId,
      kind: m.kind,
      direction: m.direction,
      from: m.from.email,
      text: m.newText,
      receivedAt: m.occurredAt,
    });
  }

  if (!newest || thread.lastMessageAt > newest) newest = thread.lastMessageAt;
}

if (newest) await db.syncState.set('outbound-conversations', newest);
  • Leave since out on the first run to backfill everything.
  • Store the newest lastMessageAt you saw as the starting point for the next run.
  • Start each run a few minutes before that time, as the example does. A reply that was still being processed during the last run is then picked up on the next one, and upserting makes the overlap harmless.
  • status: 'all' includes closed conversations, which the default 'open' would skip.
  • details.replyId in webhooks and messages[].id from getThread() are the same ID, so webhooks and pull sync can write to the same table.

Replying From Your System ​

Send a reply from your own application with conversations.reply(). Pass an idempotencyKey so that a retried request never sends twice.

ts
const sent = await outbound.conversations.reply(threadId, {
  text: 'Hi Riya, the fee schedule is on our admissions page.',
  idempotencyKey: `reply:${draft.id}`,
});

await db.conversationMessages.upsert({
  replyId: sent.replyId,
  threadId,
  kind: 'staff_reply',
  direction: 'outbound',
  text: draft.text,
});

What the recipient sees:

  • An email from the same sender name and address as your original email, with the subject Re: <original subject>.
  • It sits in the same thread as their reply in their mail app, with their message quoted underneath. Pass includeQuote: false to leave the quote out.
  • When they reply again, the answer reaches your mailbox and joins the same conversation.

Your mailbox also gets a copy by BCC, so your team's inbox keeps the whole exchange. The reply fires a reply webhook (with replyType: staff_reply) carrying the same replyId, so the upsert in your webhook handler simply finds the record you already wrote.

Opt-Out Replies ​

Every human reply is checked for a request to stop, such as "please remove me from this list". Automatic replies and bounce notices are not checked. When a request is found, details.optOutDetected is true and details.optOutAction says what happened.

Turn on automatic suppression to act on these requests for you:

ts
await outbound.conversations.updateSettings({ autoSuppressOptOuts: true });

With it on, Outbound adds the sender to your suppression list when the request is unambiguous ("unsubscribe", "stop emailing me", "remove me from your list", a reply of just "STOP", or the Hindi equivalents), comes from the recipient themselves, and their address is verified. Looser phrases such as "remove my email" are only flagged, because they often mean something else. The conversation then no longer needs a reply. If the address was not already suppressed, an unsubscribe webhook also fires with unsubscribeSource: 'reply'.

Every other request is flagged. Show it to your team, and if it really is a request to stop, suppress the address yourself:

ts
await outbound.suppressions.add({ email: 'riya@example.com', reason: 'unsubscribe' });

Retention and Erasure ​

By default, conversations are kept until you delete them. To delete them automatically a set number of days after their last message, set retentionDays to a whole number from 30 to 3650:

ts
await outbound.conversations.updateSettings({ retentionDays: 365 });

To honor a data deletion request, erase everything Conversations stores about one person. This is permanent and cannot be undone:

ts
const { erasure } = await outbound.conversations.erase({ email: 'riya@example.com' });

Erasure only covers what Outbound stores. Delete the person from your own synced copy as well.

Testing With the Sandbox ​

You can try the whole flow without a real recipient. Send with captureReplies: true to success@simulator.amazonses.com, then create a reply with sandbox.simulateReply():

ts
const sent = await outbound.email.send({
  toEmail: 'success@simulator.amazonses.com',
  fromEmail: 'admissions@yourcompany.com',
  emailSubject: 'Your application',
  htmlBody: '<p>Hi, reply to this email with any questions.</p>',
  captureReplies: true,
});

await outbound.sandbox.simulateReply({
  messageId: sent.messageId!,
  text: 'Yes! What are the fees?',
});

The email must have been sent before you simulate a reply to it. If you call simulateReply() right after the send, it may not have gone out yet, and the call returns 422 with "This message has not been sent yet. Try again in a few seconds".

The simulated reply creates a conversation and fires the same reply webhook as a real one, with details.simulated: true. Skip simulated events in production, or list only real conversations with listThreads({ simulated: false }). Simulated conversations are deleted 30 days after their last message. See the Sandbox reference for out-of-office and opt-out test cases.

Released under the MIT License.