> 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="/pages/kFYC80qPylx4Qb3gkF7O#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="/pages/kFYC80qPylx4Qb3gkF7O#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="/pages/1mbheJqh7EnStvj4GPo0">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="/pages/kFYC80qPylx4Qb3gkF7O#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>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.whereby.com/reference/assistant-sdk-reference/api-reference/trigger.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
