Webhooks allow you to subscribe to events from APIs you use.
Webhooks are a crucial part of API development, allowing for real-time reactions to various events across different systems, such as when a Stripe Payment is made, or when a GitHub issue is created.
There are three ways to use webhooks with Trigger.dev:
Use one of our built-in Integrations, such as GitHub. We’ll take care of registering the webhook for you.
Use our HTTP endpoints and HTTP triggers to subscribe to any webhooks you want. This is useful if you want to use a service that we don’t have an Integration for.
import { Job } from "@trigger.dev/sdk";import { Github, events } from "@trigger.dev/github";//GitHub integration with API Key (it supports OAuth too)const github = new Github({ id: "github", token: process.env.GITHUB_API_KEY!,});client.defineJob({ id: "critical-issue-alert", name: "Critical Issue Alert", version: "0.1.0", //When a GitHub issue is modified on the triggerdotdev/trigger.dev repo trigger: github.triggers.repo({ event: events.onIssue, owner: "triggerdotdev", repo: "trigger.dev", }), //include any integrations you want to use integrations: { slack, }, //this function gets executed when the webhook is received run: async (payload, io, ctx) => { await io.logger.info(`Action was ${payload.action}`); },});