> ## 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.

# Has label

> Check whether a Gmail message has a specific label.

`hasLabel` resolves an existing Gmail label and reports whether it is currently applied to one message. Use it to route mail based on a user label or a Gmail system label.

## Example

Archive new messages that already carry the `Handled` label:

```ts theme={null}
import { automation, branch } from "automate.ax"
import { archive, hasLabel, onNewEmail } from "automate.ax/gmail"

export default automation("Archive handled Gmail messages", () => {
  const email = onNewEmail()
  const handled = hasLabel({
    label: "Handled",
    messageId: email.messageId,
  })

  branch(handled, () => {
    archive({ messageIds: email.messageId })
  })
})
```

## Inputs

| Name        | Type                                 | Required | Description                                                                      |
| ----------- | ------------------------------------ | -------- | -------------------------------------------------------------------------------- |
| `label`     | `string`                             | Yes      | Existing label display name or immutable Gmail label ID.                         |
| `messageId` | `string`                             | Yes      | Immutable Gmail message ID to inspect.                                           |
| `account`   | `string \| Google account reference` | No       | Google account binding to use. Defaults to the project's default Google account. |

Every input field also accepts a compatible `Signal`; the example passes the new-message signal into `messageId`.

Label IDs must match exactly. Display names are matched after trimming surrounding whitespace and ignoring capitalization.

## Output

The action returns a `Signal<boolean>`: `true` when the resolved label is applied to the message, and `false` when the label exists but is absent.

<Warning>
  A missing label is an error, not a `false` result. Labels belong to a specific
  Gmail account, so make sure `label`, `messageId`, and `account` refer to the
  same mailbox.
</Warning>
