import { Link } from "@remix-run/react"; import { Paragraph } from "~/components/primitives/Paragraph"; import { StepNumber } from "~/components/primitives/StepNumber"; import { useJob } from "~/hooks/useJob"; import { useOrganization } from "~/hooks/useOrganizations"; import { useProject } from "~/hooks/useProject"; import { docsPath, jobTestPath } from "~/utils/pathBuilder"; import { CodeBlock } from "../code/CodeBlock"; import { InlineCode } from "../code/InlineCode"; import { EnvironmentLabel } from "../environments/EnvironmentLabel"; import { HelpPanelProps } from "../integrations/ApiKeyHelp"; import { HelpInstall } from "../integrations/HelpInstall"; import { HelpSamples } from "../integrations/HelpSamples"; import { LinkButton } from "../primitives/Buttons"; import { Callout, variantClasses } from "../primitives/Callout"; import { Header2 } from "../primitives/Headers"; import { TextLink } from "../primitives/TextLink"; import integrationButton from "./integration-button.png"; import selectEnvironment from "./select-environment.png"; import selectExample from "./select-example.png"; import { StepContentContainer } from "../StepContentContainer"; import { TriggerDevCommand } from "../SetupCommands"; import { IntegrationIcon } from "~/assets/icons/IntegrationIcon"; import { BookOpenIcon } from "@heroicons/react/20/solid"; export function HowToRunYourJob() { const organization = useOrganization(); const project = useProject(); const job = useJob(); return ( <> There are two ways to run your Job: You can perform a Run with any payload you want, or use one of our examples, on the test page. Test Performing a real run depends on the type of Trigger your Job is using. How to run a Job Scheduled Triggers do not trigger Jobs in the DEV Environment. When developing locally you should use the{" "} Test feature {" "} to trigger any scheduled Jobs. ); } export function HowToConnectAnIntegration() { return ( <> APIs marked with a are Trigger.dev Integrations. These Integrations make connecting to the API easier by offering OAuth or API key authentication. All APIs can also be used with fetch or an SDK. Follow the instructions for your chosen connection method in the popover form. If no Integration exists yet, you can request one by clicking the "I want an Integration" button. Once you've connected your API, it will appear in the list of Integrations below. You can view details and manage your connection by selecting it from the table. View the Integration docs page for more information on connecting an API using an Integration or other method. ); } export function HowToUseThisIntegration({ integration, help, integrationClient }: HelpPanelProps) { return ( <> {help && ( <> )} ); } export function HowToDisableAJob({ id, name, version, }: { id: string; name: string; version: string; }) { return ( <> To disable a job, you need to set the enabled property to{" "} false. Set enabled to false } /> Run the @trigger.dev/cli dev command } /> If you aren't already running the dev command, run it now. ); } export function HowToUseApiKeysAndEndpoints() { return ( <> Environments and Endpoints are used to connect your server to the Trigger.dev platform. Environments Each environment has API Keys associated with it. The Server API Key is used to authenticate your Jobs with the Trigger.dev platform. The Server API Key you use for your{" "} Client {" "} is how we know which environment to run your code against: Development } /> The DEV environment should only be used for local development. It’s where you can test your Jobs before deploying them to servers. Scheduled Triggers do not trigger Jobs in the DEV Environment. When you’re working locally you should use the Test feature to trigger any scheduled Jobs. Staging } /> The STAGING environment is where your Jobs will run in a staging environment, meant to mirror your production environment. Production } /> The PROD environment is where your Jobs will run in production. It’s where you can run your Jobs against real data. Endpoints An Endpoint is a URL on your server that Trigger.dev can connect to. This URL is used to register Jobs, start them and orchestrate runs and retries. DEV has multiple endpoints associated with it – one for each team member. This allows each team member to run their own Jobs, without interfering with each other. All other environments have just a single endpoint (with a single URL) associated with them. Deployment Deployment uses Environments and Endpoints to connect your Jobs to the Trigger.dev platform. Read the deployment guide to learn more. ); } export function WhatAreHttpEndpoints() { return ( <> HTTP endpoints allow you to trigger your Jobs from any webhooks. They require a bit more work than using Integrations{" "} but allow you to connect to any API. Getting started You need to define the HTTP endpoint in your code. To do this you use{" "} client.defineHttpEndpoint(). This will create an HTTP endpoint. Then you can create a Trigger from this by calling .onRequest() on the created HTTP endpoint. Read the HTTP endpoints guide to learn more. An example: cal.com { //this helper function makes verifying most webhooks easy return await verifyRequestSignature({ request, headerName: "X-Cal-Signature-256", secret: process.env.CALDOTCOM_SECRET!, algorithm: "sha256", }); }, }); client.defineJob({ id: "http-caldotcom", name: "HTTP Cal.com", version: "1.0.0", enabled: true, //create a Trigger from the HTTP endpoint above. The filter is optional. trigger: caldotcom.onRequest({ filter: { body: { triggerEvent: ["BOOKING_CANCELLED"] } } }), run: async (request, io, ctx) => { //note that when using HTTP endpoints, the first parameter is the request //you need to get the body, usually it will be json so you do: const body = await request.json(); await io.logger.info("Body", body); }, });`} /> ); } export function HowToConnectHttpEndpoint() { return ( <> Setting up your webhook To start receiving data you need to enter the Endpoint URL and secret into the API service you want to receive webhooks from. Go to the relevant API dashboard} /> For example, if you want to receive webhooks from Cal.com then you should login to your Cal.com account and go to their Settings/Developer/Webhooks page. Copy the Webhook URL and Secret} /> A unique Webhook URL is created for each environment (Dev, Staging, and Prod). Jobs will only be triggered from the relevant environment. Copy the relevant Endpoint URL and secret from the table opposite and paste it into the correct place in the API dashboard you located in the previous step. Add the Secret to your Environment variables} /> You should also add the Secret to the Environment variables in your code and where you're deploying. Usually in Node this means adding it to the .env file. Use the secret in the verify() function of HTTP Endpoint. This ensures that someone can't just send a request to your Endpoint and trigger a Job. Different APIs do this verification in different ways – a common way is to have a header that has a hash of the payload and secret. Refer to the API's documentation for more information. Triggering runs In your code, you should use the .onRequest() function in a Job Trigger. You can filter so only data that matches your criteria triggers the Job. If you're using the Staging or Prod environment, you need to make sure your code is deployed. Deploy like you normally would –{" "} read our deployment guide . Now you need to actually perform an action on that third-party service that triggers the webhook you've subscribed to. For example, add a new meeting using Cal.com. Read the HTTP endpoints guide to learn more. ); }