Triggers

Your Connector's Triggers define the types of events that occur in your app that can start your Consumers' Automations. For example, you may want to enable your app's users to send data to their CRM (like Hubspot or Salesforce) each time a form is submitted in your app.

Directory Structure#

Triggers live in the triggers subdirectory of a given Connector. The triggers subdirectory of the example my-app Connector in the Rollout Project Template looks like this:

├── index.ts
├── my-polling-trigger
│ ├── input.ts
│ ├── payload.ts
│ ├── trigger.ts
│ └── ui.tsx
└── my-push-trigger
├── input.ts
├── payload.ts
├── trigger.ts
└── ui.tsx

Triggers are exported from the index.ts file:

import { trigger as myPollingTrigger } from "./my-polling-trigger/trigger";
import { trigger as myPushTrigger } from "./my-push-trigger/trigger";
export const triggers = {
["my-polling-trigger"]: myPollingTrigger,
["my-push-trigger"]: myPushTrigger,
};

The property names of the exported triggers object (i.e. "my-polling-trigger", "my-push-trigger") are the triggerKeys used to identify the Connector's Triggers.

For each Trigger exported by the Connector, you define:

  1. The schema for the Trigger's inputs in the input.ts file
  2. The UI displayed to users to allow them to provide trigger inputs in the ui.tsx file
  3. The schema for the Triggers outputs in the payload.ts file
  4. The logic your Trigger will use discover events (e.g. subscribing to webhooks or polling your API) in the trigger.ts file

Defining Inputs#

Trigger inputParams are defined using the defineTriggerInputParamsSchema function provided by the Rollout Framework. You can specify the type of an input, whether or not it is required, and provide helper text to the user to explain a given input's purpose.

Example Input Definition:

import { defineTriggerInputParamsSchema } from "@rollout/framework";
export const inputParamsSchema = defineTriggerInputParamsSchema((t) => ({
// Optional string input.
// Title `Task Type` will be automatically inferred by title-casing the key.
taskType: t.optional(t.string()),
// Required string input with custom title and description
taskName: t.string({ title: "Name" description: "The name of the task created" }),
}));

Creating the UI#

In the ui.tsx file, you call the defineUIComponent function. You can usually leverage one of the pre-built Rollout Input Components to enable users to provide values for Trigger Inputs.

This is simple example UI for a Trigger with a single string input called name:

import React from "react";
import { defineUIComponent, RichTextInput } from "@rollout/framework/ui";
import type { inputParamsSchema } from "./input";
export const UI = defineUIComponent<typeof inputParamsSchema>((props) => {
const { b } = props;
return (
<>
<RichTextInput bind={b.name} />
</>
);
});

Defining the Payload Schema#

A Trigger's payloadSchema is defined in the payload.ts with a call to the Rollout Framework's defineTriggerPayloadSchema function.

Example Payload Schema Definition:

import { defineTriggerPayloadSchema } from "@rollout/framework";
export const payloadSchema = defineTriggerPayloadSchema((t) => ({
id: t.string({ title: "ID" }),
name: t.string({ title: "Name" }),
}));
~

Types of Triggers#

There are three types of triggers that you can be build with Rollout:

  1. Webhook Triggers: If you've already built a webhook infrastructure for your app, you can leverage the available webhooks as Triggers in Rollout. See the defineWebhookTrigger function for details on how to subscribe and unsubscribe from webhooks in Rollout.
  2. Polling Triggers: Polling Triggers are scheduled jobs that run at a given interval (configurable by environment variable for a given Project Environment) and make requests against your API to determine whether any new events have occurred (e.g. any new items in a list). For details on implementing polling triggers see the definePollingTrigger function.
  3. Push Triggers: Push triggers are the most flexible option of all and enable you to create trigger events through HTTP requests and even from within other Triggers and Actions. See the definePushTrigger function for more details on how to create Push Triggers.