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

# Automations

> Create event-driven workflows that react to Polymarket activity in real time.

Automations let you build workflows that trigger when specific Polymarket events happen (like whale trades, price spikes, or new markets) and deliver results to Discord, Telegram, a webhook, or your Struct chat.

Each automation connects a [webhook event](/webhooks/getting-started#available-events) to either an AI agent that analyzes the data or a template that formats it, then routes the output to a destination of your choice.

## Creating an Automation

<Steps>
  <Step title="Open Automations">
    Navigate to **Automations** in your dashboard sidebar.
  </Step>

  <Step title="Choose a starting point">
    Click **New Automation**. You can start from a pre-built template or build from scratch.
  </Step>

  <Step title="Select a trigger event">
    Pick the webhook event that will fire your automation (e.g. `trader_whale_trade`, `price_spike`). See [Available Events](/webhooks/getting-started#available-events) for the full list.
  </Step>

  <Step title="Configure processing">
    Choose between **AI** mode (an AI agent analyzes the event data) or **Direct** mode (a Handlebars template formats the data). See [Processing Modes](#processing-modes) below.
  </Step>

  <Step title="Set your output destination">
    Choose where results are delivered: Chat, Discord, Telegram, or a custom webhook. See [Output Destinations](#output-destinations) below.
  </Step>

  <Step title="Enable and save">
    Set a rate limit, toggle the automation on, and save. A webhook subscription is automatically created for you.
  </Step>
</Steps>

## Processing Modes

Every automation uses one of two processing modes to handle incoming event data.

### AI Mode

The event data is sent to an AI agent along with your system prompt and user prompt template. The agent can analyze the data, use Struct API tools to look up additional context, and produce a natural-language response.

* Uses an AI model with access to Struct API tools
* Supports up to 20 tool-call steps per run
* Best for analysis, recommendations, and investigations

```
System prompt:
"You are a prediction market analyst. Assess new markets for trading opportunities."

User prompt template:
"A new market was just created. Analyze it: {{event}}"
```

### Direct Mode

The event data is interpolated into your Handlebars template with zero AI processing. The rendered template output is your result.

* No AI calls, instant delivery
* Uses [Handlebars template syntax](/dashboard/automations-templates) with custom formatters
* Best for structured alerts, data forwarding, and notifications

```
Whale Trade Detected
Market: {{event.market_name}}
Side: {{uppercase event.side}}
Size: {{formatCurrency event.size_usd}}
```

## Output Destinations

Each automation delivers its result to one of four destinations.

### Chat

Results are saved as conversations in your Struct dashboard. AI-mode runs store both the prompt and response as a chat history you can review later.

### Discord

Send results to a Discord channel via webhook. You can configure rich embeds with:

* Custom title, color, and footer text
* Thumbnail and image URLs
* Structured fields (inline or full-width)
* Optional message content outside the embed

All text fields support Handlebars template syntax, so embed values can be dynamically populated from event data.

<Note>Discord embeds have a 4,096-character limit for the description field. Longer outputs are automatically truncated.</Note>

### Telegram

Send results to a Telegram chat via bot. Configuration options include:

* Bot token and chat ID
* Photo/caption mode for image-based alerts
* Inline keyboard buttons with dynamic URLs
* Link preview and notification toggles

<Note>Telegram captions are limited to 1,024 characters. Standard messages support up to 4,096 characters.</Note>

### Webhook

POST results to any HTTP endpoint. The system auto-detects Discord webhook URLs and formats the payload as a Discord embed. For all other URLs, the payload is:

```json theme={null}
{
  "automationId": "uuid",
  "automationName": "My Automation",
  "result": "The formatted or AI-generated output",
  "eventPayload": { ... },
  "timestamp": "2026-03-11T12:00:00.000Z"
}
```

## Filters

Automations inherit the same filtering capabilities as webhooks. You can narrow which events trigger your automation using:

* **Wallet address**: track specific traders
* **Market / condition ID**: target specific markets
* **Event slug**: filter by event
* **USD thresholds**: minimum/maximum value bounds
* **Probability range**: 0.0 to 1.0

Only events matching all configured filters will trigger the automation.

## Rate Limiting

Each automation has a configurable **max runs per hour** (default: 10). When the limit is reached, incoming events are logged with a `rate_limited` status and skipped until the window resets.

Adjust the rate limit when creating or editing an automation to balance between coverage and cost.

## Monitoring Runs

Every automation execution is logged as a **run** with the following details:

| Field         | Description                                                    |
| ------------- | -------------------------------------------------------------- |
| Status        | `pending`, `running`, `completed`, `failed`, or `rate_limited` |
| Result        | The AI-generated or template-rendered output text              |
| Event payload | The raw webhook event that triggered the run                   |
| Duration      | Execution time in milliseconds                                 |
| Token usage   | Input and output tokens consumed (AI mode only)                |

View run history from the automation detail page in your dashboard. Failed runs include an error message for debugging.

## Managing Automations

From the Automations page you can:

* **Enable / disable** an automation without deleting it
* **Edit** the trigger event, prompts, output config, or rate limit
* **Delete** an automation and its associated webhook subscription
* **View logs** to see the full chat history for AI-mode runs
