# Start work when something happens

> Start a teammate with an event in Troopy or a webhook from another app, and see what each event did.

A trigger is a routine that starts when something happens, and not on a clock. It starts a teammate with each event:
something in Troopy, or a webhook from another app. This page tells how to make a trigger, set up the app that sends
to it, and read what each event did.

## Before you begin

- Owners and admins make, change and delete triggers. Other people read them.
- A teammate never sees the URL or the secret of a trigger.
- A workspace has no limit of triggers.

## The two kinds of trigger

| Kind                    | What starts it                                              | Example                                                             |
| ----------------------- | ----------------------------------------------------------- | ------------------------------------------------------------------- |
| **Something in Troopy** | An event of a product of Troopy.                            | A customer asks to cancel, and the Churn watcher drafts a check-in. |
| A webhook               | A request that another app sends to the URL of the trigger. | GitHub opens an issue, and the Engineer reads it.                   |

### The events of Troopy

| Event                              | Product     |
| ---------------------------------- | ----------- |
| A user signs up                    | Customers   |
| A customer starts a trial          | Customers   |
| A customer starts to pay           | Customers   |
| A payment of a customer fails      | Customers   |
| A customer asks to cancel          | Customers   |
| A customer leaves                  | Customers   |
| A customer comes back              | Customers   |
| A customer becomes at risk         | Customers   |
| A customer says something          | Customers   |
| A customer disputes a payment      | Disputes    |
| The bank decides a dispute         | Disputes    |
| A reply to a campaign comes        | Campaigns   |
| New mail comes to a shared mailbox | Email       |
| A ticket goes live                 | Engineering |

A teammate takes an event only when it has the tool that reads the record of the event. The form offers only those
teammates. With none, it names the roles to hire.

### The apps that send webhooks

| Sender                                                         | Who makes the secret                                                 |
| -------------------------------------------------------------- | -------------------------------------------------------------------- |
| A URL alone, for Zapier, Make, n8n, forms and your own scripts | No secret. The URL is the secret, so keep it private.                |
| GitHub                                                         | Troopy makes the secret, and you put it into GitHub.                 |
| Stripe                                                         | Stripe makes the signing secret, and you give it to Troopy.          |
| Shopify                                                        | Your Shopify app has a client secret, and you give it to Troopy.     |
| Standard Webhooks                                              | The sending app makes the signing secret, and you give it to Troopy. |
| Your own code, with HMAC                                       | Troopy makes the secret. Your code signs each request with it.       |

## Make a trigger

1. **Start the form**

   On **Routines**, select **New routine**, then **When something happens**.

2. **Say what starts it**

   Under **What starts it**, pick **Something in Troopy** and the event, or a webhook and **Who sends it**.

3. **Pick the teammate**

   Pick the **Teammate that it starts**. For an event of Troopy, the list shows the teammates that can read its record.

4. **Write the instructions**

   Under **What the teammate does with each event**, write it like a brief: the goal, the steps, and where the result
   goes.

5. **Save**

   Select **Create routine**. The page of the trigger opens.

**More settings** has **Most tasks a day**: a trigger starts 20 tasks in a day at first, and 200 at most. For a webhook,
**Only these fields** keeps only some fields of each event for the teammate.

## Set up the sender of a webhook

On the page of the trigger, **Set up the sender** gives the steps for its app.

1. Select **Copy the URL**, and put the URL into the sending app.
2. For GitHub or your own code, select **Copy the secret**, and put it into the app.
3. For Stripe, Shopify or Standard Webhooks, copy the signing secret from the app. Add it under **Signing secret**.
4. Select **Test** to send a test event. It starts the teammate for real.

Until a trigger has the secret that it needs, Troopy refuses each request to it.

> [!WARNING]
> **Make a new URL** stops the old URL at once. Put the new URL into each app that sends to this trigger. **Make a new
> secret** does the same for the secret.

## What happens to an event

1. Troopy checks the signature of the request, and keeps the event one time.
2. The event goes on the task of the trigger that the teammate did not start yet. A task holds 10 events at most. More
   events start a new task.
3. The teammate starts on the task. The brief holds your instructions, and the events show as material.

The words of an event come from outside Troopy. The teammate reads them as material, never as instructions. A person
approves each call of that work: no standing rule does. See [Stay in control of your troop](/docs/control).

## Read the events of a trigger

**Recent events** on the page of the trigger lists each event, with what became of it:

| What it shows                       | What it means                                              |
| ----------------------------------- | ---------------------------------------------------------- |
| The status of its task              | The event started work. Select it to open the task.        |
| **Not run: the routine was paused** | The trigger was paused when the event came.                |
| **Not run: the limit of the day**   | The trigger already started its most tasks of the day.     |
| **Not run**                         | The event started nothing. Select **Run now** to start it. |

The page loads again every 5 seconds while an event is on its way to done.

## Limits

| Limit                                       | Value        |
| ------------------------------------------- | ------------ |
| Triggers in a workspace                     | 25           |
| Requests to one trigger                     | 60 a minute  |
| Requests to all the triggers of a workspace | 300 a minute |
| Size of a request                           | 256 KB       |
| Events that a trigger keeps in a day        | 500          |
| Days that Troopy keeps an event             | 30           |

An event of Troopy that is older than 48 hours starts nothing. An event from before the trigger was made starts nothing.

## When a teammate leaves

A trigger whose teammate left the troop pauses. It shows in the last card of Routines, **Without a teammate**. Give
the trigger to another teammate on its page, and switch it on again.

## A teammate proposes a trigger

When you ask a teammate for one, it can propose a trigger for its own work. The proposal waits on Routines. An owner or
admin approves it. The teammate never gets the URL or the secret.

## Related

- [Schedule work with routines](/docs/routines)
- [Stay in control of your troop](/docs/control)
- [Understand your customers](/docs/customers)
- [Ship code with engineering tickets](/docs/engineering)
