|
| 1 | +import { |
| 2 | + BoltIcon, |
| 3 | + ChatBubbleLeftRightIcon, |
| 4 | + CheckIcon, |
| 5 | + ClockIcon, |
| 6 | + CodeBracketIcon, |
| 7 | + PauseCircleIcon, |
| 8 | + ShieldCheckIcon, |
| 9 | +} from "@heroicons/react/20/solid"; |
| 10 | +import { useFetcher } from "@remix-run/react"; |
| 11 | +import { type ComponentType, type ReactNode } from "react"; |
| 12 | +import { WebhookIcon } from "~/assets/icons/WebhookIcon"; |
| 13 | +import { CodeBlock } from "~/components/code/CodeBlock"; |
| 14 | +import { BetaBadge } from "~/components/FeatureBadges"; |
| 15 | +import { PageBody } from "~/components/layout/AppLayout"; |
| 16 | +import { Button } from "~/components/primitives/Buttons"; |
| 17 | +import { Header3 } from "~/components/primitives/Headers"; |
| 18 | +import { NavBar, PageTitle } from "~/components/primitives/PageHeader"; |
| 19 | +import { Paragraph } from "~/components/primitives/Paragraph"; |
| 20 | +import { type EndpointsListRow } from "~/components/webhookEndpoints/v1/EndpointsListTable"; |
| 21 | +import { WebhooksBetaPreview } from "~/components/webhookEndpoints/WebhooksBetaPreview"; |
| 22 | +import type { EndpointActivity } from "~/presenters/v3/WebhookEndpointsListPresenter.server"; |
| 23 | + |
| 24 | +const taskExample = `import { webhook, webhooks } from "@trigger.dev/sdk"; |
| 25 | +
|
| 26 | +export const stripe = webhooks.endpoint.define({ |
| 27 | + id: "stripe", |
| 28 | + source: webhooks.stripe(), |
| 29 | +}); |
| 30 | +
|
| 31 | +export const fulfillOrder = webhook({ |
| 32 | + id: "fulfill-order", |
| 33 | + endpoint: stripe, |
| 34 | + filter: "event.type == 'checkout.session.completed'", |
| 35 | + onEvent: async ({ event }) => { |
| 36 | + await fulfill(event.data.object.id); |
| 37 | + }, |
| 38 | +});`; |
| 39 | + |
| 40 | +const agentExample = `import { webhooks } from "@trigger.dev/sdk"; |
| 41 | +import { chat } from "@trigger.dev/sdk/ai"; |
| 42 | +import { slack, webhookSource } from "@trigger.dev/slack"; |
| 43 | +
|
| 44 | +const slackEvents = webhooks.endpoint.define({ |
| 45 | + id: "slack", |
| 46 | + source: webhookSource(), |
| 47 | +}); |
| 48 | +
|
| 49 | +export const support = chat.agent({ |
| 50 | + id: "support", |
| 51 | + channels: [ |
| 52 | + slack({ |
| 53 | + id: "slack", |
| 54 | + endpoint: slackEvents, |
| 55 | + token: process.env.SLACK_BOT_TOKEN!, |
| 56 | + }), |
| 57 | + ], |
| 58 | + run: async ({ messages, signal, streamText }) => |
| 59 | + streamText({ model, messages, abortSignal: signal }), |
| 60 | +});`; |
| 61 | + |
| 62 | +export function WebhooksBetaAccess({ |
| 63 | + requested, |
| 64 | + previewEndpoints, |
| 65 | + previewActivity, |
| 66 | +}: { |
| 67 | + requested: boolean; |
| 68 | + previewEndpoints: EndpointsListRow[]; |
| 69 | + previewActivity: Promise<EndpointActivity>; |
| 70 | +}) { |
| 71 | + const fetcher = useFetcher<{ requested: boolean }>(); |
| 72 | + const isRequested = requested || fetcher.data?.requested === true; |
| 73 | + |
| 74 | + return ( |
| 75 | + <> |
| 76 | + <NavBar> |
| 77 | + <PageTitle title="Webhooks" accessory={<BetaBadge />} /> |
| 78 | + </NavBar> |
| 79 | + <PageBody> |
| 80 | + <div className="mx-auto flex max-w-6xl flex-col gap-5 px-2 py-5"> |
| 81 | + <div className="flex flex-wrap items-center justify-between gap-3 rounded-md border border-grid-bright bg-background-bright py-3 pl-4 pr-3"> |
| 82 | + <Paragraph variant="base/bright"> |
| 83 | + {isRequested |
| 84 | + ? "Webhooks are in private beta. You're on the wait list for this organization." |
| 85 | + : "Webhooks are in private beta. Request access and we'll turn them on for your organization."} |
| 86 | + </Paragraph> |
| 87 | + <fetcher.Form method="post"> |
| 88 | + {isRequested ? ( |
| 89 | + <Button |
| 90 | + type="button" |
| 91 | + variant="secondary/medium" |
| 92 | + LeadingIcon={CheckIcon} |
| 93 | + leadingIconClassName="text-success" |
| 94 | + disabled |
| 95 | + > |
| 96 | + Access requested |
| 97 | + </Button> |
| 98 | + ) : ( |
| 99 | + <Button type="submit" variant="primary/medium" disabled={fetcher.state !== "idle"}> |
| 100 | + Request beta access |
| 101 | + </Button> |
| 102 | + )} |
| 103 | + </fetcher.Form> |
| 104 | + </div> |
| 105 | + |
| 106 | + <WebhooksBetaPreview endpoints={previewEndpoints} activity={previewActivity} /> |
| 107 | + |
| 108 | + <div className="grid grid-cols-1 gap-5 xl:grid-cols-[minmax(0,1fr)_minmax(0,1.1fr)]"> |
| 109 | + <FeatureGrid> |
| 110 | + <Feature icon={ShieldCheckIcon} title="Signature verification"> |
| 111 | + Built-in sources for Stripe, GitHub, Slack, Linear and dozens more, or any HMAC |
| 112 | + scheme. Bad signatures are rejected before a run starts. |
| 113 | + </Feature> |
| 114 | + <Feature icon={ClockIcon} title="Delivery history and replay"> |
| 115 | + Every delivery is stored with its headers and body. Replay any of them from the |
| 116 | + dashboard or the API. |
| 117 | + </Feature> |
| 118 | + <Feature icon={CodeBracketIcon} title="Typesafe filters"> |
| 119 | + Filters are type checked against the provider's events, and only matching deliveries |
| 120 | + start a run. |
| 121 | + </Feature> |
| 122 | + <Feature icon={WebhookIcon} title="No server to run"> |
| 123 | + Each endpoint gets its own URL hosted by Trigger.dev, so there's nothing for you to |
| 124 | + deploy or keep running. |
| 125 | + </Feature> |
| 126 | + </FeatureGrid> |
| 127 | + <CodeBlock code={taskExample} language="typescript" fileName="trigger/orders.ts" /> |
| 128 | + </div> |
| 129 | + |
| 130 | + <div className="grid grid-cols-1 gap-5 xl:grid-cols-[minmax(0,1.1fr)_minmax(0,1fr)]"> |
| 131 | + <CodeBlock code={agentExample} language="typescript" fileName="trigger/support.ts" /> |
| 132 | + <FeatureGrid> |
| 133 | + <Feature icon={ChatBubbleLeftRightIcon} title="Events become messages"> |
| 134 | + Route webhook events into a <code>chat.agent</code> conversation, so the agent |
| 135 | + replies with full context. |
| 136 | + </Feature> |
| 137 | + <Feature icon={PauseCircleIcon} title="Wait for a webhook"> |
| 138 | + Pause a task until a matching webhook arrives, like a payment succeeding, then carry |
| 139 | + on from where it left off. |
| 140 | + </Feature> |
| 141 | + <Feature icon={BoltIcon} title="Fast acknowledgement"> |
| 142 | + The endpoint responds right away, inside Slack's 3 second limit. The agent runs |
| 143 | + after that. |
| 144 | + </Feature> |
| 145 | + <Feature icon={ShieldCheckIcon} title="Slack built in"> |
| 146 | + <code>@trigger.dev/slack</code> verifies Slack's signing secret for you, with no |
| 147 | + handler code. |
| 148 | + </Feature> |
| 149 | + </FeatureGrid> |
| 150 | + </div> |
| 151 | + </div> |
| 152 | + </PageBody> |
| 153 | + </> |
| 154 | + ); |
| 155 | +} |
| 156 | + |
| 157 | +function FeatureGrid({ children }: { children: ReactNode }) { |
| 158 | + return ( |
| 159 | + <section className="grid grid-cols-1 overflow-hidden rounded-md border border-grid-bright bg-background-bright sm:grid-cols-2 [&>*]:border-grid-bright max-sm:[&>*:not(:last-child)]:border-b sm:[&>*:nth-child(-n+2)]:border-b sm:[&>*:nth-child(odd)]:border-r"> |
| 160 | + {children} |
| 161 | + </section> |
| 162 | + ); |
| 163 | +} |
| 164 | + |
| 165 | +function Feature({ |
| 166 | + icon: Icon, |
| 167 | + title, |
| 168 | + children, |
| 169 | +}: { |
| 170 | + icon: ComponentType<{ className?: string }>; |
| 171 | + title: string; |
| 172 | + children: ReactNode; |
| 173 | +}) { |
| 174 | + return ( |
| 175 | + <div className="flex flex-col gap-2 p-4"> |
| 176 | + <div className="grid size-7 place-items-center rounded border border-grid-bright bg-background-raised"> |
| 177 | + <Icon className="size-4 text-webhooks" /> |
| 178 | + </div> |
| 179 | + <Header3 className="mt-1">{title}</Header3> |
| 180 | + <Paragraph |
| 181 | + variant="small" |
| 182 | + className="[&_code]:font-mono [&_code]:text-xs [&_code]:text-text-bright" |
| 183 | + > |
| 184 | + {children} |
| 185 | + </Paragraph> |
| 186 | + </div> |
| 187 | + ); |
| 188 | +} |
0 commit comments