This is a great place to start if you're new to Trigger.dev and want to learn how to build a simple workflow.
Help and guides
Get started
Run this command in your terminal to create a new project using this template.
This is a great place to start if you're new to Trigger.dev and want to learn how to build a simple workflow.
Help and guides
Get started
Run this command in your terminal to create a new project using this template.
Currently this template only has a single customEvent trigger:
import { Trigger, customEvent } from "@trigger.dev/sdk";
new Trigger({
// Give your Trigger a stable ID
id: "hello-world",
name: "Template: Hello World",
// Trigger on the custom event named "your.event", see https://docs.trigger.dev/triggers/custom-events
on: customEvent({
name: "your.event",
}),
// The run functions gets called once per "your.event" event
async run(event, ctx) {
await ctx.waitFor("waiting...", { seconds: 10 });
await ctx.logger.info("Hello world from inside trigger.dev");
},
}).listen();
Once you are happy with your workflow you can deploy it live to Render.com (or another hosting service). You can then send custom events that trigger your workflow using the sendEvent function from the @trigger.dev/sdk
, or simply by making requests to our events
API endpoint.
Here is an example of sending the custom event to trigger the workflow contained in this repo using fetch
:
const event = {
name: "your.event",
payload: {
hello: "world",
},
};
const response = await fetch("https://app.trigger.dev/api/v1/events", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.TRIGGER_API_KEY}`,
},
body: JSON.stringify({
id: randomUUID(),
event,
}),
});
You can easily adapt this workflow to a different event relevant to your app. For example, we have a workflow that runs when a user is created and it looks like this:
import { Trigger, customEvent } from "@trigger.dev/sdk";
import * as slack from "@trigger.dev/slack";
import { z } from "zod";
new Trigger({
id: "new-user",
name: "New user",
on: customEvent({
name: "user.created",
schema: z.object({ id: z.string() }),
}),
async run(event, ctx) {
const user = await prisma.user.find({
where: { id: event.id },
});
await slack.postMessage("🚨", {
channelName: "new-users",
text: `New user signed up: ${user.email}`,
});
},
}).listen();
Be sure to check out more over on our docs