Skip to main content
Triggers subscribe to events and execute handlers when those events occur. They enable your agent to respond to external events from integrations or system events.

Creating a trigger

Create a trigger in src/triggers/:
import { Trigger } from "@botpress/runtime";

export default new Trigger({
  name: "conversationStarted",
  events: ["webchat:conversationStarted"],
  handler: async ({ event }) => {
    // Trigger logic
  },
});
Triggers subscribe to events using an array of event names. The above Trigger only executes when it receives the webchat:conversationStarted event.

Naming a Trigger

Trigger names can contain only alphanumeric characters and underscores.

Event structure

The handler receives an event object with:
  • event.type - The event type string (one of the subscribed events)
  • event.payload - The event payload data (varies by event type)
You can read these properties to handle the event appropriately:
import { Trigger } from "@botpress/runtime";

export default new Trigger({
  name: "reactionAdded",
  description: "Handles WhatsApp reactions",
  events: ["whatsapp:reactionAdded"],
  handler: async ({ event }) => {
    // Handle WhatsApp reaction added event
    // event.type contains "whatsapp:reactionAdded"
    // event.payload contains information about the reaction
    const reactionData = event.payload;
    if (reactionData.reaction === "U+1F44D")
      // Process the reaction
  },
});
For reference information about the payload from integration events, check out the Integrations documentation.

Multiple event subscriptions

A trigger can subscribe to multiple events and handle each of them differently:
export default new Trigger({
  name: "onLinearIssueUpdate",
  description: "Handles Linear issue events",
  events: [
    "linear:issueCreated",
    "linear:issueDeleted",
    "linear:issueUpdated",
  ],
  handler: async ({ event }) => {
    // Check event type to handle different cases
    if (event.type === "linear:issueDeleted") {
      // Handle deletion
    } else if (event.type === "linear:issueCreated") {
      // Handle creation
    } else if (event.type === "linear:issueUpdated") {
      // Handle update
    }
  },
});

Reference

Trigger props

Handler parameters

The handler function receives the matched event: