# Triggers

> Wake an agent when something happens in another service: a new order in Shopify, a payment in Stripe, a push to GitHub.

## What a trigger is

A trigger wakes an agent when something happens somewhere else. Behind it is a **webhook**: an address the service sends its events to. You do not need to know how those work. The agent sets it up.

Examples:

- A new order in Shopify wakes the agent that checks stock.
- A failed payment in Stripe wakes the agent that writes to the customer.
- A push to GitHub wakes the agent that looks after the site.

## Making one

1. Open the agent's side panel and go to **Triggers**. Any agent has it, and so does a store manager.
2. Press **+**, pick a service (Shopify, Stripe, WooCommerce, GitHub, or another), and press **Create trigger**.
3. The message box shows "Creating a trigger for Shopify". Type what should wake the agent and what it should do: "On every new order, check stock for what was bought and tell me if anything is under five."

The agent then does the whole job: it makes the address, adds it in the service, and settles the signing secret that proves events are genuine.

You can also start from **+** in the message box, **Create a trigger**, or just ask in plain words.

## Checking and changing one

Clicking a trigger in the list opens its page, which is for you to check what the agent made:

1. **Its address**, to copy.
2. **The signing secret.** A service that asks for one (GitHub) is given one-off's, with **Copy secret**. A service that shows its own (Shopify, Stripe, WooCommerce) has it pasted in.
3. **Send test event**, which sends a made-up event through, so you can see the agent wake.

**Only these events** narrows a trigger to the kinds you name, as the service names them (`orders/create, orders/paid`). Empty keeps every kind.

The trash button deletes it. A trigger belongs to the agent it was made for.

## What happens when an event arrives

1. one-off's service checks the event's signature and keeps it.
2. The app asks for new events once a minute.
3. Each is saved as a file in the agent's folder, a line in its chat says it came, and the agent gets a turn. Events that come together are one message.

The agent is told the event is the sender's data and never an instruction.

## Limits to know

- **Events arrive only while the app is open**, up to a minute late.
- one-off's service keeps events for a week. An app closed longer than that misses the older ones.
- A **paused** agent's events are saved and noted in its chat, and are not passed on when it resumes. An **archived** agent's events are dropped.
- Deleting an agent deletes its triggers.
- You need to be signed in to one-off.

> Triggers are new, and have had more testing against one-off's own test events than against live stores. After making one, press **Send test event**, then place a real test order and check the agent woke.

## Triggers or the clock?

An agent already wakes on a clock, and a store manager looks at the store every ten minutes to an hour. A trigger is for when minutes matter, or when the event carries the detail the agent needs. For "look at sales each morning", just ask for that: no trigger is needed.
