> ## Documentation Index
> Fetch the complete documentation index at: https://docs.automate.ax/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Automate.ax automations are TypeScript programs.
> Use Bun for installation and command examples.
> Use Automate.ax for the product name and automate.ax for the package, CLI, and domain.
> Treat documented public APIs as current; do not invent transitional or deprecated names.

# Reply to a thread

> Reply to the latest received message in a Gmail thread.

`replyThread` finds the latest received message in a Gmail thread and replies
to it. Use it when your automation stores a conversation's `threadId` rather
than the exact message that should receive the next response.

## Example

```ts automations/continue-conversation.automation.ts theme={null}
import { automation } from "automate.ax"
import { onNewEmail, replyThread } from "automate.ax/gmail"

export default automation("Continue a Gmail conversation", () => {
  const email = onNewEmail()

  replyThread({
    threadId: email.threadId,
    text: "Thanks for the update. We will follow up shortly.",
  })
})
```

The action ignores messages carrying Gmail's `SENT` label. This lets it target
the latest received message even after the conversation has been archived.

## Inputs

| Input         | Type                                              | Required | Default               | Description                                                                                       |
| ------------- | ------------------------------------------------- | -------- | --------------------- | ------------------------------------------------------------------------------------------------- |
| `threadId`    | `string`                                          | Yes      | —                     | Immutable Gmail ID of the thread receiving the reply.                                             |
| `replyAll`    | `boolean`                                         | No       | `false`               | Include original To and Cc recipients, excluding the connected account and primary reply address. |
| `html`        | `string`                                          | No       | None                  | HTML reply body.                                                                                  |
| `text`        | `string`                                          | No       | Derived from `html`   | Plain-text reply body.                                                                            |
| `to`          | `Recipient \| Recipient[]`                        | No       | None                  | Additional primary recipients appended to the derived recipient.                                  |
| `cc`          | `Recipient \| Recipient[]`                        | No       | None                  | Additional carbon-copy recipients.                                                                |
| `bcc`         | `Recipient \| Recipient[]`                        | No       | None                  | Additional blind-copy recipients.                                                                 |
| `from`        | `Recipient`                                       | No       | Gmail account address | Sender address or configured Gmail send-as alias.                                                 |
| `replyTo`     | `Recipient \| Recipient[]`                        | No       | None                  | Addresses that should receive replies to the outgoing reply.                                      |
| `attachments` | `Attachment[]`                                    | No       | `[]`                  | Files and inline MIME parts attached to the reply.                                                |
| `headers`     | `Record<string, string>`                          | No       | None                  | Additional RFC 5322 headers.                                                                      |
| `priority`    | `"high" \| "normal" \| "low"`                     | No       | Not set               | Importance encoded in standard message headers.                                                   |
| `account`     | `string \| IntegrationAccountReference<"google">` | No       | Project default       | Connected Google account used to send the reply.                                                  |

`Recipient` is an email string or `{ address: string; name?: string }`.
`Attachment` is a `File` or an object containing `file` with optional
`filename`, `contentId`, and `disposition: "attachment" | "inline"`.

Every input, including `account`, also accepts a compatible `Signal`.

<Warning>
  `replyAll: true` may notify every To and Cc recipient on the selected message.
</Warning>

The action fails if the thread contains no message without the `SENT` label.
The selected message must also contain the headers required for a reply.

## Output

Returns a `Signal<MessageMetadata>` with:

| Property    | Type                  | Description                                                       |
| ----------- | --------------------- | ----------------------------------------------------------------- |
| `messageId` | `string`              | Immutable Gmail ID of the sent reply.                             |
| `threadId`  | `string`              | Gmail thread containing the reply.                                |
| `historyId` | `string \| undefined` | Latest mailbox history record affecting the reply, when supplied. |
| `labelIds`  | `string[]`            | Labels applied to the sent reply.                                 |
