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

# Thread Triggers

> Create automated workflows when thread admin statuses change

The Thread Trigger System allows administrators to create automated workflows that execute when thread admin statuses
change. This feature enables automated notifications, webhooks, and integrations when conversation threads are
categorized or their status updates.

## Overview

Thread triggers monitor changes to thread admin statuses and automatically perform actions like sending notifications,
executing webhooks, or triggering external integrations. This allows teams to:

* Get instant notifications when threads are marked as urgent
* Automatically notify stakeholders when thread status changes
* Integrate with external systems (custom webhooks, etc.)
* Build automated escalation workflows

## Components

### 1. Triggers

A thread trigger consists of two main parts:

* **Conditions**: Criteria based on admin status changes that must be met for the trigger to activate
* **Actions**: Tasks that the trigger performs when the conditions are met (notifications, webhooks, etc.)

### 2. Condition Types

Conditions are specifically designed for thread admin status changes:

| Condition Type               | Description                                  | Example                                  |
| ---------------------------- | -------------------------------------------- | ---------------------------------------- |
| Admin Status Changed         | Triggers on any admin status change          | Any status change occurs                 |
| Admin Status Is              | Triggers when status equals a specific value | Status is "Urgent"                       |
| Admin Status Changed From-To | Triggers on specific status transitions      | Status changed from "New" to "Escalated" |
| Combined Conditions          | Multiple conditions with thread properties   | Status is "Urgent" AND has no ticket     |

### 3. Operators

Operators define the relationship between conditions and their values:

| Operator         | Description                     | Example                              |
| ---------------- | ------------------------------- | ------------------------------------ |
| Is               | Exact match                     | Admin status is "Urgent"             |
| Is not           | Not an exact match              | Admin status is not "Closed"         |
| Contains         | Text contains the value         | Thread title contains "urgent"       |
| Does not contain | Text does not contain the value | Thread title does not contain "test" |

### 4. Actions

Actions that can be performed when conditions are met:

| Action          | Description                    | Configuration                                      |
| --------------- | ------------------------------ | -------------------------------------------------- |
| Execute Webhook | Call an external HTTP endpoint | URL, method (GET/POST/PUT), headers, body template |

## How Thread Triggers Work

1. **Status Change Detection**: When a thread's admin status is updated (via API or admin UI), the system detects the change.
2. **Condition Evaluation**: All active thread triggers are evaluated against the status change.
3. **Action Execution**: If a trigger's conditions are met, its actions are executed sequentially.
4. **Logging**: All trigger executions are logged with success/failure status and details for auditing.

## Available Placeholders

When configuring action messages (webhooks), you can use placeholders that are automatically replaced:

| Placeholder                     | Description                            |
| ------------------------------- | -------------------------------------- |
| `{​{thread.id}}`                | Thread UUID                            |
| `{​{thread.title}}`             | Thread title                           |
| `{​{thread.user.email}}`        | User's email address                   |
| `{​{thread.user.name}}`         | User's full name                       |
| `{​{thread.evaluation}}`        | Thread evaluation status               |
| `{​{old_status}}`               | Previous admin status name (or "None") |
| `{​{new_status}}`               | New admin status name (or "None")      |
| `{​{thread.creation_date}}`     | When the thread was created            |
| `{​{thread.last_message_date}}` | Last message timestamp                 |

## Example Use Cases

### 1. External Integration via Webhook

**Scenario**: Sync thread status changes to an external CRM system

**Conditions**:

* Admin Status Changed (any change)

**Actions**:

* Execute Webhook
  * URL: `https://your-crm.com/api/thread-status-update`
  * Method: `POST`
  * Body Template:
    ```json theme={null}
    {
      "thread_id": "{{thread.id}}",
      "thread_title": "{{thread.title}}",
      "user_email": "{{thread.user.email}}",
      "old_status": "{{old_status}}",
      "new_status": "{{new_status}}",
      "timestamp": "{{thread.last_message_date}}"
    }
    ```

## Trigger Execution Order

Triggers are processed in order based on their `position` field (lower values execute first). If one trigger's action
modifies the thread in a way that affects another trigger's conditions, order matters.

## Best Practices

1. **Use specific conditions**: Narrow down conditions to avoid unintended executions
2. **Monitor execution logs**: Check `/api/admin/thread-triggers/{id}/logs` regularly
3. **Avoid infinite loops**: Be careful with triggers that might cause cascading status changes

## Troubleshooting

### Webhook Failing

* Verify webhook URL is accessible
* Check authentication/headers configuration
* Test webhook URL independently
* Review HTTP status codes in execution logs

## Related Features

* [Admin Tag Management](./admin-user-management.md)
* [Thread Admin Statuses](./admin-user-management.md)
* [Ticket Trigger System](./triggers-feature.md)
