> For the complete documentation index, see [llms.txt](https://docs.whereby.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.whereby.com/reference/assistant-sdk-reference/api-reference/trigger.md).

# Trigger

The `Trigger` API lets you run an `express` server that listens for Whereby [webhooks](/whereby-product-features/insights-suite-and-api/webhooks.md) and, based on your rules, returns a `TRIGGER_EVENT_SUCCESS` event if the conditions of your trigger are met.

## Constructor

```jsx
const trigger = new Trigger(options: TriggerOptions)
```

### TriggerOptions

<table><thead><tr><th>Parameter</th><th width="216.40106201171875">Type</th><th width="73.640625">Default</th><th>Description</th></tr></thead><tbody><tr><td><code>webhookTriggers</code></td><td><a href="/reference/assistant-sdk-reference/types/trigger-types.md#wherebywebhooktriggers-less-than-object-greater-than"><code>WherebyWebhookTriggers</code></a></td><td></td><td><p>Custom matcher functions that the assistant can use to self-trigger <code>TRIGGER_EVENT_SUCCESS</code> events.</p><p>Return <code>true</code> from a <a href="/reference/assistant-sdk-reference/types/trigger-types.md#wherebywebhooktriggers-less-than-object-greater-than"><code>WherebyWebhookTriggers</code></a> callback to fire this event or <code>false</code> to ignore the incoming webhook.</p></td></tr><tr><td><code>port</code></td><td><code>number</code></td><td><code>4999</code></td><td>Port for the HTTP server listening for Whereby <a href="/whereby-product-features/insights-suite-and-api/webhooks.md">webhooks</a>.</td></tr></tbody></table>

## Methods

| Method  | Parameters | Returns | Description                                              |
| ------- | ---------- | ------- | -------------------------------------------------------- |
| `start` |            | `void`  | Starts the Express server and begins accepting webhooks. |

## Events

The `Trigger` API extends `EventEmitter` and emits lifecycle events after your trigger predicate returns `true.`

```jsx
import { TRIGGER_EVENT_SUCCESS, Trigger } from "@whereby.com/assistant";

let hasJoined = false;
const trigger = new Trigger({
  webhookTriggers: {
    "room.client.joined": () => !hasJoined,
  },
  port: 4999,
});


trigger.on(TRIGGER_EVENT_SUCCESS, ({ roomUrl }) => {
  console.log("Trigger successful for room: ", roomUrl);
});
```

<table><thead><tr><th width="204.91015625">Event</th><th width="339.75225830078125">Payload</th><th>Emitted when</th></tr></thead><tbody><tr><td><code>TRIGGER_EVENT_SUCCESS</code></td><td><p><code>{</code></p><p><code>roomUrl:string;</code></p><p><code>triggerWebhook:</code> <a href="/reference/assistant-sdk-reference/types/trigger-types.md#wherebywebhooktriggers-less-than-object-greater-than"><code>WherebyWebhookType</code></a></p><p><code>}</code></p></td><td>Trigger has met the required custom conditions in a webhook trigger matcher function (matcher function returned <code>true</code>).</td></tr></tbody></table>
