Trigger.dev
Trigger.dev is an open source platform that makes it easy for developers to create event-driven background tasks directly in their code. Build, test and run workflows locally using our SDK. Subscribe to webhooks, schedule jobs, run background jobs and add long delays easily and reliably. In our web app you get full visibility of every run your workflow has ever made making it easier to monitor and debug.
Features:
- Easily subscribe to webhooks —they work locally without tunnelling.
- Fire your own custom events—a single event can trigger multiple workflows.
- Schedule workflows—easily repeat tasks or use CRON syntax for advanced cases.
- Add long delays inside workflows (up to a year) and they will pick up where they left off.
- When your server goes down it’s not a problem, workflows will reconnect and continue.
- View every step of every run, with data, previews and errors.
- Connect to and authenticate with APIs using our custom integrations.
- If you have a custom use case, we support Fetch for calling any HTTP endpoint or webhooks for subscribing to events from APIs.
- All API calls are automatically retried with exponential back off.
- TypeScript SDK, so whether you’re using JavaScript or TypeScript you will have a great experience.
Documentation:
- Getting Started with Trigger.dev
- Example workflows
- Triggers:
- Functions:
Quick start guide
1. Sign up at trigger.dev and create a new organization.
2. Install our SDK to your project:
npm install @trigger.dev/sdk @trigger.dev/slack zod
pnpm install @trigger.dev/sdk @trigger.dev/slack zod
yarn add @trigger.dev/sdk @trigger.dev/slack zod
3. Create a workflow file
Example workflows:
Post to Slack when a GitHub issue is created or modified
Integrations required: Slack, GitHub
import { Trigger } from "@trigger.dev/sdk";
import * as github from "@trigger.dev/github";
import * as slack from "@trigger.dev/slack";
new Trigger({
id: "new-github-star-to-slack",
name: "New GitHub Star: triggerdotdev/trigger.dev",
apiKey: "<my_api_key>",
on: github.events.newStarEvent({
repo: "triggerdotdev/trigger.dev",
}),
run: async (event) => {
await slack.postMessage("github-stars", {
channelName: "github-stars",
text: `New GitHub star from \n<${event.sender.html_url}|${event.sender.login}>`,
});
},
}).listen();
Welcome email drip campaign
_Integrations required: Slack, Resend_import { customEvent, Trigger, sendEvent } from "@trigger.dev/sdk";
import * as resend from "@trigger.dev/resend";
import * as slack from "@trigger.dev/slack";
import React from "react";
import { z } from "zod";
import { getUser } from "../db";
import { InactiveEmail, TipsEmail, WelcomeEmail } from "./email-templates";
new Trigger({
id: "welcome-email-campaign",
name: "Welcome email drip campaign",
apiKey: "<my_api_key>",
on: customEvent({
name: "user.created",
schema: z.object({
userId: z.string(),
}),
}),
async run(event, context) {
//get the user data from the database
const user = await getUser(event.userId);
await slack.postMessage("send-to-slack", {
channelName: "new-users",
text: `New user signed up: ${user.name} (${user.email})`,
});
//Send the first email
const welcomeResponse = await resend.sendEmail("welcome-email", {
from: "Trigger.dev <james@email.trigger.dev>",
replyTo: "James <james@trigger.dev>",
to: user.email,
subject: "Welcome to Trigger.dev",
react: <WelcomeEmail name={user.name} />,
});
await context.logger.debug(
`Sent welcome email to ${welcomeResponse.to} with id ${welcomeResponse.id}`
);
//wait 1 day, check if the user has created a workflow and send the appropriate email
await context.waitFor("wait-a-while", { days: 1 });
const updatedUser = await getUser(event.userId);
if (updatedUser.hasOnboarded) {
await resend.sendEmail("onboarding-complete", {
from: "Trigger.dev <james@email.trigger.dev>",
replyTo: "James <james@trigger.dev>",
to: updatedUser.email,
subject: "Pro tips for workflows",
react: <TipsEmail name={updatedUser.name} />,
});
} else {
await resend.sendEmail("onboarding-incomplete", {
from: "Trigger.dev <james@email.trigger.dev>",
replyTo: "James <james@trigger.dev>",
to: updatedUser.email,
subject: "Help with your first workflow",
react: <InactiveEmail name={updatedUser.name} />,
});
}
},
}).listen();
4. Sign in to your Trigger.dev dashboard and get your API keys
- Go to trigger.dev and login to your account.
- In the bottom-left corner of an Organization page you can find your API keys.
- Copy the API key for the organization you want to use and add it to your workflow file.
5. Test your workflow
Move to the "Test" page and input a valid test event, remember the workflow expects the types you have defined in the schema.
Hit the "Run test" button and it will take us to our first run 🚀!
6. The run page
All of the steps in a workflow, including the initial event, can be viewed in detail. You will need to refresh the page if it's running to see it move between steps.
7. Authenticating integrations
When a workflow step uses an API integration that you haven't already authenticated with, it will pause until you've authenticated.
Simply click the "Connect to [integration]" button and sign-in with your desired Slack workspace. As soon as you do, the workflow will pick up where it left off.
Test complete!
8. Triggering this workflow from code
As this workflow uses a custom event, we need to manually trigger it from our code. Anywhere in your code you can do this:
import { sendEvent } from "@trigger.dev/sdk";
/*
...your other code
*/
await sendEvent(uuidv4(), {
name: "user.created"
payload: {
name: "Eleven",
email: "jane@hawksmoorhigh.edu",
paidPlan: true,
},
});
Running Trigger.dev locally:
To run Trigger.dev locally, follow these steps.
Contributing:
We are open source and love contributions!
- Request a feature in our Discord community
- Open a PR
Self-hosting guide:
coming soon...
Support & contact:
- Join our Discord community
- If you have any other questions, get in touch at hello@trigger.dev
