Trigger

The Trigger API lets you run an express server that listens for Whereby webhooks and, based on your rules, returns a TRIGGER_EVENT_SUCCESS event if the conditions of your trigger are met.

Constructor

const trigger = new Trigger(options: TriggerOptions)

TriggerOptions

Parameter
Type
Default
Description

webhookTriggers

Custom matcher functions that the assistant can use to self-trigger TRIGGER_EVENT_SUCCESS events.

Return true from a WherebyWebhookTriggers callback to fire this event or false to ignore the incoming webhook.

port

number

4999

Port for the HTTP server listening for Whereby webhooks.

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.

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);
});
Event
Payload
Emitted when

TRIGGER_EVENT_SUCCESS

{

roomUrl:string;

triggerWebhook: WherebyWebhookType

}

Trigger has met the required custom conditions in a webhook trigger matcher function (matcher function returned true).

Last updated

Was this helpful?