@trigger.dev/sdk 4.7.4 → 4.8.0-webhooks.20261015065339

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/dist/commonjs/v3/ai.d.ts +560 -8
  2. package/dist/commonjs/v3/ai.js +2263 -178
  3. package/dist/commonjs/v3/ai.js.map +1 -1
  4. package/dist/commonjs/v3/chat.d.ts +23 -0
  5. package/dist/commonjs/v3/chat.js.map +1 -1
  6. package/dist/commonjs/v3/index.d.ts +2 -0
  7. package/dist/commonjs/v3/index.js +23 -17
  8. package/dist/commonjs/v3/index.js.map +1 -1
  9. package/dist/commonjs/v3/modelFileDownload.d.ts +10 -0
  10. package/dist/commonjs/v3/modelFileDownload.js +164 -0
  11. package/dist/commonjs/v3/modelFileDownload.js.map +1 -0
  12. package/dist/commonjs/v3/test/index.d.ts +2 -1
  13. package/dist/commonjs/v3/test/index.js +4 -1
  14. package/dist/commonjs/v3/test/index.js.map +1 -1
  15. package/dist/commonjs/v3/test/mock-channel-connector.d.ts +172 -0
  16. package/dist/commonjs/v3/test/mock-channel-connector.js +173 -0
  17. package/dist/commonjs/v3/test/mock-channel-connector.js.map +1 -0
  18. package/dist/commonjs/v3/test/mock-chat-agent.d.ts +81 -1
  19. package/dist/commonjs/v3/test/mock-chat-agent.js +137 -10
  20. package/dist/commonjs/v3/test/mock-chat-agent.js.map +1 -1
  21. package/dist/commonjs/v3/transcriptStorage.d.ts +44 -1
  22. package/dist/commonjs/v3/transcriptStorage.js +24 -0
  23. package/dist/commonjs/v3/transcriptStorage.js.map +1 -1
  24. package/dist/commonjs/v3/webhookWaiters.d.ts +80 -0
  25. package/dist/commonjs/v3/webhookWaiters.js +156 -0
  26. package/dist/commonjs/v3/webhookWaiters.js.map +1 -0
  27. package/dist/commonjs/v3/webhooks.d.ts +178 -2
  28. package/dist/commonjs/v3/webhooks.js +322 -1
  29. package/dist/commonjs/v3/webhooks.js.map +1 -1
  30. package/dist/commonjs/version.js +1 -1
  31. package/dist/esm/v3/ai.d.ts +560 -8
  32. package/dist/esm/v3/ai.js +2257 -178
  33. package/dist/esm/v3/ai.js.map +1 -1
  34. package/dist/esm/v3/chat.d.ts +23 -0
  35. package/dist/esm/v3/chat.js.map +1 -1
  36. package/dist/esm/v3/index.d.ts +2 -0
  37. package/dist/esm/v3/index.js +1 -0
  38. package/dist/esm/v3/index.js.map +1 -1
  39. package/dist/esm/v3/modelFileDownload.d.ts +10 -0
  40. package/dist/esm/v3/modelFileDownload.js +161 -0
  41. package/dist/esm/v3/modelFileDownload.js.map +1 -0
  42. package/dist/esm/v3/test/index.d.ts +2 -1
  43. package/dist/esm/v3/test/index.js +2 -1
  44. package/dist/esm/v3/test/index.js.map +1 -1
  45. package/dist/esm/v3/test/mock-channel-connector.d.ts +172 -0
  46. package/dist/esm/v3/test/mock-channel-connector.js +170 -0
  47. package/dist/esm/v3/test/mock-channel-connector.js.map +1 -0
  48. package/dist/esm/v3/test/mock-chat-agent.d.ts +81 -1
  49. package/dist/esm/v3/test/mock-chat-agent.js +137 -11
  50. package/dist/esm/v3/test/mock-chat-agent.js.map +1 -1
  51. package/dist/esm/v3/transcriptStorage.d.ts +44 -1
  52. package/dist/esm/v3/transcriptStorage.js +24 -0
  53. package/dist/esm/v3/transcriptStorage.js.map +1 -1
  54. package/dist/esm/v3/webhookWaiters.d.ts +80 -0
  55. package/dist/esm/v3/webhookWaiters.js +149 -0
  56. package/dist/esm/v3/webhookWaiters.js.map +1 -0
  57. package/dist/esm/v3/webhooks.d.ts +178 -2
  58. package/dist/esm/v3/webhooks.js +318 -1
  59. package/dist/esm/v3/webhooks.js.map +1 -1
  60. package/dist/esm/version.js +1 -1
  61. package/docs/ai-chat/actions.mdx +6 -1
  62. package/docs/ai-chat/backend.mdx +34 -0
  63. package/docs/ai-chat/pending-messages.mdx +2 -0
  64. package/docs/ai-chat/reference.mdx +50 -2
  65. package/docs/mcp-tools.mdx +76 -0
  66. package/docs/webhooks/channels.mdx +128 -0
  67. package/docs/webhooks/connect.mdx +80 -0
  68. package/docs/webhooks/deliveries.mdx +92 -0
  69. package/docs/webhooks/filters.mdx +109 -0
  70. package/docs/webhooks/human-in-the-loop.mdx +149 -0
  71. package/docs/webhooks/linear.mdx +185 -0
  72. package/docs/webhooks/overview.mdx +99 -0
  73. package/docs/webhooks/session-routing.mdx +132 -0
  74. package/docs/webhooks/slack.mdx +360 -0
  75. package/docs/webhooks/sources.mdx +217 -0
  76. package/docs/webhooks/waiters.mdx +170 -0
  77. package/package.json +3 -2
@@ -0,0 +1,360 @@
1
+ ---
2
+ title: "Slack agents"
3
+ description: "Turn a chat.agent into a Slack agent: users message it in Slack, it shows its status while it works, streams its reply with tool calls as task cards, asks for approvals, and stops on Slack's stop button."
4
+ sidebarTitle: "Slack agents"
5
+ ---
6
+
7
+ **`slack()` from `@trigger.dev/slack` turns a `chat.agent` into a native Slack agent.** Each Slack agent session (a conversation with the agent, or a thread in a channel) becomes a durable Trigger.dev [session](/ai-chat/sessions). A message runs as a turn, the session shows the agent working, the reply streams into the thread as the model writes it, and Slack's stop button stops the turn.
8
+
9
+ ```ts /trigger/support.ts
10
+ import { webhooks } from "@trigger.dev/sdk";
11
+ import { chat } from "@trigger.dev/sdk/ai";
12
+ import { slack, webhookSource } from "@trigger.dev/slack";
13
+ import { anthropic } from "@ai-sdk/anthropic";
14
+
15
+ const slackEvents = webhooks.endpoint.define({ id: "slack", source: webhookSource() });
16
+
17
+ export const support = chat.agent({
18
+ id: "support",
19
+ channels: [slack({ id: "slack", endpoint: slackEvents, token: process.env.SLACK_BOT_TOKEN! })],
20
+ tools: { searchDocs, refundOrder },
21
+ run: async ({ messages, tools, signal, streamText }) =>
22
+ streamText({ model: anthropic("claude-sonnet-4-5"), messages, tools, abortSignal: signal }),
23
+ });
24
+ ```
25
+
26
+ `run()` is the same function that answers a browser chat or a [Linear session](/webhooks/linear). Signature verification, Slack's `url_verification` handshake, retry dedup, per-thread state, status updates and streaming are handled by the connector.
27
+
28
+ ## Setup
29
+
30
+ <Steps>
31
+ <Step title="Deploy the agent">
32
+ Declare the endpoint with `webhookSource()` from `@trigger.dev/slack` and pass it to `slack({ endpoint })`. Deploying registers the hosted [endpoint](/webhooks/connect) and gives you its URL.
33
+ </Step>
34
+ <Step title="Create the Slack app from a manifest">
35
+ At [api.slack.com/apps](https://api.slack.com/apps), create an app **From a manifest** and paste this, with the endpoint's URL in both request URLs:
36
+
37
+ ```yaml manifest.yaml
38
+ display_information:
39
+ name: Support Agent
40
+ features:
41
+ bot_user:
42
+ display_name: Support Agent
43
+ always_online: true
44
+ app_home:
45
+ messages_tab_enabled: true
46
+ messages_tab_read_only_enabled: false
47
+ agent_view:
48
+ agent_description: Answers support questions and handles refunds.
49
+ oauth_config:
50
+ scopes:
51
+ bot:
52
+ - assistant:write
53
+ - chat:write
54
+ - files:read
55
+ - reactions:write
56
+ - im:history
57
+ - channels:history
58
+ - groups:history
59
+ settings:
60
+ event_subscriptions:
61
+ request_url: https://your-endpoint-url
62
+ bot_events:
63
+ - message.im
64
+ - message.channels
65
+ - message.groups
66
+ - agent_session_stopped
67
+ interactivity:
68
+ is_enabled: true
69
+ request_url: https://your-endpoint-url
70
+ ```
71
+
72
+ `agent_view` makes the app an agent, `agent_session_stopped` turns on the stop button, interactivity delivers clicks on the agent's buttons, `files:read` lets the agent read the images and PDFs users share with it, and `reactions:write` lets it mark a message it picked up mid-reply. Drop `message.channels`, `message.groups` and their `history` scopes if the agent should only answer in its own conversations.
73
+ </Step>
74
+ <Step title="Connect the endpoint">
75
+ Paste the app's **Signing Secret** (Basic Information, App Credentials) as the endpoint's signing secret. Until it is set the endpoint rejects Slack's signed requests, so Slack shows the request URL as not verified: once the secret is in, click **Verify** on the app's Event Subscriptions page (or **Click here to verify** on the App Manifest page). Install the app to your workspace and pass the bot token (`xoxb-...`) as `token`. The endpoint's setup prompt walks an AI coding agent through these settings.
76
+ </Step>
77
+ <Step title="Try it">
78
+ Open the agent in Slack and send it a message. The session shows it working within a second, and the reply streams in. In a channel, invite the bot (`/invite @Support Agent`) and message it in a thread.
79
+ </Step>
80
+ </Steps>
81
+
82
+ ## What Slack shows
83
+
84
+ | Moment | In Slack |
85
+ | --- | --- |
86
+ | A turn starts | The session's status is **processing**. On the first turn the session is titled with the prompt. |
87
+ | The model writes | The reply streams into the thread with `chat.startStream`, `chat.appendStream` and `chat.stopStream`, as markdown. |
88
+ | A tool is called | A task card in the reply, marked complete when the tool returns and failed if it throws. |
89
+ | A tool needs a decision | Approve and Deny buttons, and the status is **suspended** (see [Approvals and buttons](#approvals-and-buttons)). |
90
+ | The turn ends | The status goes back to **active**, whether it answered, stopped, failed or had nothing to say. |
91
+ | `chat.close()` | The status is **closed**. |
92
+
93
+ Set `title` to name the session yourself; return null to keep Slack's own. A title the user sets in Slack is never overwritten. Slack drops a processing status after an hour, so a longer turn re-sends it every 50 minutes. `progress: "off"` streams the reply without task cards, and `delivery: "final"` posts the whole reply once the turn ends instead of streaming it.
94
+
95
+ ```ts
96
+ slack({
97
+ id: "slack",
98
+ endpoint: slackEvents,
99
+ token,
100
+ title: (prompt) => `Support: ${prompt.slice(0, 80)}`,
101
+ });
102
+ ```
103
+
104
+ If a streaming request fails in a way that leaves its outcome unknown (a timeout or a dropped connection), the connector does not retry it, since Slack may already have shown that text. It closes the stream and posts the rest of the reply as its own message, so nothing is lost, at the cost of possibly repeating one batch. If that post fails too, the whole reply is posted again as a normal message. Rate limits wait out `Retry-After` and resend the same batch. If the worker running a turn dies mid-stream, the next worker closes that stream with a short "Interrupted" note before it picks the conversation back up.
105
+
106
+ ## Approvals and buttons
107
+
108
+ A tool with no `execute` pauses the turn until the user answers it in Slack. By default `slack()` posts Approve and Deny buttons, and a click resolves the tool to `{ approved: boolean }`, collapses the buttons to the decision and resumes the turn. See [human-in-the-loop](/webhooks/human-in-the-loop) for the tool definition.
109
+
110
+ `approval` replaces those buttons for every such tool. Build buttons with `button()`, whose `output` is what the click resolves the tool to:
111
+
112
+ ```ts
113
+ slack({
114
+ id: "slack",
115
+ endpoint: slackEvents,
116
+ token,
117
+ approval: (call, { button }) => ({
118
+ text: `Run ${call.toolName}?`,
119
+ blocks: [
120
+ { type: "section", text: { type: "mrkdwn", text: `Run \`${call.toolName}\`?` } },
121
+ {
122
+ type: "actions",
123
+ elements: [
124
+ button({ text: "Ship it", style: "primary", output: { approved: true } }),
125
+ button({ text: "Not now", output: { approved: false } }),
126
+ ],
127
+ },
128
+ ],
129
+ }),
130
+ });
131
+ ```
132
+
133
+ `interactions` gives a single tool its own UI, keyed by tool name, so a tool can ask the user to pick, rate or choose and continue with the answer:
134
+
135
+ ```ts
136
+ export const moji = chat.agent({
137
+ id: "moji",
138
+ channels: [
139
+ slack({
140
+ id: "slack",
141
+ endpoint: slackEvents,
142
+ token,
143
+ interactions: {
144
+ pickEmoji: (call, { button }) => {
145
+ const { options } = call.input as { options: { name: string }[] };
146
+ return {
147
+ text: "Pick one",
148
+ blocks: [
149
+ { type: "section", text: { type: "mrkdwn", text: "Which one should I add?" } },
150
+ {
151
+ type: "actions",
152
+ elements: options.map((o) => button({ text: `:${o.name}:`, output: { picked: o.name } })),
153
+ },
154
+ ],
155
+ };
156
+ },
157
+ },
158
+ }),
159
+ ],
160
+ tools: {
161
+ pickEmoji: tool({
162
+ description: "Ask the user to pick one of the generated emoji",
163
+ inputSchema: z.object({ options: z.array(z.object({ name: z.string() })) }),
164
+ outputSchema: z.object({ picked: z.string() }),
165
+ }),
166
+ addEmoji,
167
+ },
168
+ run: async ({ messages, tools, signal, streamText }) =>
169
+ streamText({ model, messages, tools, abortSignal: signal, stopWhen: stepCountIs(10) }),
170
+ });
171
+ ```
172
+
173
+ The click resolves `pickEmoji` to `{ picked: "wizard" }`, the buttons collapse to the choice, and the turn continues.
174
+
175
+ ### Buttons that send the agent an action
176
+
177
+ Buttons that aren't answering a tool, such as follow-up questions, are built with `slackButton()` and posted with the surface's `post()`. A click reaches `onAction`, validated against `actionSchema` like a browser action, and returning `chat.turn(message)` answers it in the thread:
178
+
179
+ ```ts
180
+ import { slackButton, type SlackSurface } from "@trigger.dev/slack";
181
+
182
+ export const support = chat.agent({
183
+ id: "support",
184
+ channels: [slack({ id: "slack", endpoint: slackEvents, token })],
185
+ actionSchema: z.object({ type: z.literal("ask"), question: z.string() }),
186
+ tools: {
187
+ offerFollowUps: tool({
188
+ description: "Offer the user up to three follow-up questions as buttons",
189
+ inputSchema: z.object({ questions: z.array(z.string()).max(3) }),
190
+ execute: async ({ questions }) => {
191
+ await chat.surface<SlackSurface>()?.post({
192
+ text: "Follow-up questions",
193
+ blocks: [
194
+ {
195
+ type: "actions",
196
+ elements: questions.map((question) =>
197
+ slackButton({ text: question, action: { type: "ask", question } })
198
+ ),
199
+ },
200
+ ],
201
+ });
202
+ return "offered";
203
+ },
204
+ }),
205
+ },
206
+ onAction: async ({ action }) => chat.turn(action.question),
207
+ run: async ({ messages, tools, signal, streamText }) =>
208
+ streamText({ model, messages, tools, abortSignal: signal, stopWhen: stepCountIs(10) }),
209
+ });
210
+ ```
211
+
212
+ `onAction` also gets the click itself as `channel.event`, typed with `SlackBlockActions`: who clicked, and the message the button was on. An action doesn't have to answer; return nothing to only do work:
213
+
214
+ ```ts
215
+ import type { SlackBlockActions } from "@trigger.dev/slack";
216
+
217
+ onAction: async ({ action, channel }) => {
218
+ const click = channel?.event as SlackBlockActions | undefined;
219
+ if (action.type === "pick") {
220
+ await addEmoji.trigger({ name: action.name, pickedBy: click?.user?.id });
221
+ return; // no turn
222
+ }
223
+ return chat.turn(action.question);
224
+ },
225
+ ```
226
+
227
+ Only buttons built with `button()` or `slackButton()` reach the agent. Buttons your own code builds by hand go to a [`webhook()`](/webhooks/overview) subscribed to the same endpoint, and never start a turn.
228
+
229
+ ## Stopping
230
+
231
+ Slack shows a stop button while the agent is working. It aborts the running turn through the run's `signal`, exactly like a browser chat's stop: the model call and any tool that honours the signal stop, the partial reply stays in the thread, and the status goes back to active. The next message continues the conversation.
232
+
233
+ - A stop pressed while nothing is running does nothing, and a repeated or delayed stop never stops a later turn.
234
+ - A stop that reaches a session waiting on an approval cancels it: the buttons are replaced with "Stopped", the pending tool call is recorded as stopped so the model sees that on the next turn, and a later click resumes nothing.
235
+ - Stopping cannot undo what already happened. A tool that finished before the stop has had its effect.
236
+
237
+ ## Channel threads
238
+
239
+ In a channel the agent answers every thread it can see. To have it answer only when it is @mentioned, pass `startOn` with the `mentions` helper and your bot's user id. A mention in a channel starts a session and the agent answers in a thread under it, then follows the rest of that thread without being mentioned again. `startOn` only applies to channels: a message in the agent's own conversation always starts a session.
240
+
241
+ ```ts
242
+ import { slack, mentions } from "@trigger.dev/slack";
243
+
244
+ slack({ id: "slack", endpoint: slackEvents, token, startOn: mentions("U012BOT") });
245
+ ```
246
+
247
+ When someone mentions the agent partway through a thread, `seedFromThread: true` loads the thread's earlier replies into the new session first, so the agent answers with the context a reader of the thread has. It reads `conversations.replies` once, on the session's first turn, and keeps the newest 50 replies (`{ limit }` changes that). New non-Marketplace apps are limited by Slack to 15 replies per call and one call a minute; a rate limit keeps what was fetched rather than failing the turn.
248
+
249
+ ## Messages sent while the agent is working
250
+
251
+ A message sent while the agent is still answering gets 👀 as soon as it arrives, so the user knows it was seen (`receivedReaction` changes the emoji, null turns it off). It then waits and runs as the next turn, in the order messages arrived. With [`pendingMessages`](/ai-chat/pending-messages) on the agent, it can be folded into the reply the agent is already writing instead: `shouldInject` decides at each step, and the message reaches the model before its next step. A message `shouldInject` declines still runs as its own turn.
252
+
253
+ ```ts
254
+ export const support = chat.agent({
255
+ id: "support",
256
+ channels: [slack({ id: "slack", endpoint: slackEvents, token })],
257
+ pendingMessages: { shouldInject: () => true },
258
+ run: async ({ messages, signal, streamText }) =>
259
+ streamText({ model, messages, abortSignal: signal, stopWhen: stepCountIs(10) }),
260
+ });
261
+ ```
262
+
263
+ A message is only folded in at a step boundary, so a reply that is one long model step with no tool calls finishes first and the message runs next. The stop button and button clicks are never folded in.
264
+
265
+ ## Files
266
+
267
+ Images (PNG, JPEG, GIF, WebP) and PDFs that a user shares in the conversation reach the model with their message, including a file sent with no text. The transcript keeps each file's Slack URL, and the `streamText` given to `run()` downloads it with the bot token when the model reads it, once per run. An image over 5 MB is sent as its largest Slack thumbnail.
268
+
269
+ Other file types, files over 20 MB, and files the app can't read (deleted, or shared from another workspace) reach the model as a one-line note naming the file, so it can say it can't open them. A file that is deleted after it was shared becomes the same note on later turns, and the conversation carries on.
270
+
271
+ A custom `inbound` keeps file support by adding `slackFileParts()` to its message:
272
+
273
+ ```ts
274
+ import { slackFileParts } from "@trigger.dev/slack";
275
+
276
+ inbound: (event) => ({
277
+ message: {
278
+ id: event.event?.ts ?? "",
279
+ role: "user",
280
+ parts: [{ type: "text", text: event.event?.text ?? "" }, ...slackFileParts(event.event?.files)],
281
+ },
282
+ }),
283
+ ```
284
+
285
+ The download happens in the `streamText` passed to `run()`. A `streamText` imported from `ai` sends the Slack URL to the model as is, which the model can't open.
286
+
287
+ ## Answering into the session from elsewhere
288
+
289
+ The first Slack message binds the session to its thread and to the user it is answering. A [`chat.event`](/webhooks/session-routing#answering-into-a-channel) action that returns `chat.turn()`, or a browser client on the same session, answers into that Slack thread with the same status, streaming and approval buttons.
290
+
291
+ ## Slash commands
292
+
293
+ Slack posts a slash command as a form, which reaches subscribers as an object of its fields, and the endpoint acknowledges it with an empty `200` so Slack shows the user nothing until you reply. Give slash commands their own endpoint, typed with `SlackSlashCommand`, and set its URL as the command's Request URL under Slash Commands in the Slack app's settings. Use the same Signing Secret as the agent's endpoint. Reply through the command's `response_url`:
294
+
295
+ ```ts /trigger/commands.ts
296
+ import { webhook, webhooks } from "@trigger.dev/sdk";
297
+ import { webhookSource, type SlackSlashCommand } from "@trigger.dev/slack";
298
+
299
+ const slackCommands = webhooks.endpoint.define({
300
+ id: "slack-commands",
301
+ source: webhookSource<SlackSlashCommand>(),
302
+ });
303
+
304
+ export const deployCommand = webhook({
305
+ id: "deploy-command",
306
+ endpoint: slackCommands,
307
+ filter: "event.command == '/deploy'",
308
+ onEvent: async ({ event }) => {
309
+ await fetch(event.response_url, {
310
+ method: "POST",
311
+ headers: { "content-type": "application/json" },
312
+ body: JSON.stringify({ response_type: "ephemeral", text: `Deploying ${event.text}` }),
313
+ });
314
+ },
315
+ });
316
+ ```
317
+
318
+ Any subscriber works here: a [`chat.event`](/webhooks/session-routing) keyed on `{event.channel_id}:{event.user_id}` routes a user's commands to one session, and a [waiter](/webhooks/waiters) can match on `event.command`.
319
+
320
+ ## Block Kit replies
321
+
322
+ Replies are sent as markdown. For a reply that is posted rather than streamed (`delivery: "final"`), return `blocks` from `outbound` to post Block Kit. `toSlackBlocks()` splits markdown into `section` blocks under Slack's 3000-character limit, never inside a code fence:
323
+
324
+ ```ts
325
+ import { slack, toSlackBlocks } from "@trigger.dev/slack";
326
+
327
+ slack({
328
+ id: "slack",
329
+ endpoint: slackEvents,
330
+ token,
331
+ delivery: "final",
332
+ outbound: (reply) =>
333
+ reply.text
334
+ ? {
335
+ text: reply.text.slice(0, 3000), // notification fallback
336
+ blocks: [{ type: "header", text: { type: "plain_text", text: "Support" } }, ...toSlackBlocks(reply.text)],
337
+ }
338
+ : null,
339
+ });
340
+ ```
341
+
342
+ ## Options
343
+
344
+ | Option | Type | Description |
345
+ | --- | --- | --- |
346
+ | `id` | `string` | Connector id, unique per agent. |
347
+ | `endpoint` | endpoint | The Slack endpoint, declared with `webhooks.endpoint.define({ id, source: webhookSource() })`. `webhook()` tasks can subscribe to the same endpoint. |
348
+ | `token` | `string` or resolver | Bot token (`xoxb-...`), or a function of the event (its `team_id`) for multi-workspace apps. |
349
+ | `delivery` | `"stream"` or `"final"` | `"stream"` (default) streams the reply natively. `"final"` posts it once when the turn ends. |
350
+ | `title` | `(prompt, event) => string \| null` | The session title, set on its first turn. Defaults to the first line of the prompt. |
351
+ | `progress` | `"tasks"` or `"off"` | Tool calls as task cards in the streamed reply. Default `"tasks"`. |
352
+ | `startOn` | `string` | Only start a session in a channel when the event matches (see `mentions`). Existing sessions always resume, and the agent's own conversation always starts one. |
353
+ | `filter` | `string` | Extra [filter](/webhooks/filters) for message events, composed with the built-in guard that drops the bot's own messages. |
354
+ | `key` | `string` | Session [key](/webhooks/session-routing) template. Defaults to one session per thread. |
355
+ | `seedFromThread` | `boolean` or `{ limit }` | Load a thread's earlier replies into a new session. Off by default. |
356
+ | `approval` | `(call, { button }) => message` | The UI for a tool with no `execute`. Defaults to Approve and Deny resolving to `{ approved }`. |
357
+ | `interactions` | `{ [toolName]: (call, { button }) => message }` | A tool's own UI; a click resolves the tool with the button's `output`. |
358
+ | `receivedReaction` | `string \| null` | Emoji added, on arrival, to a message sent while the agent is answering. Default `"eyes"`, null for none. |
359
+ | `inbound` / `outbound` | functions | Map a Slack event to the turn, and a posted reply to a Slack message. |
360
+ | `apiBaseUrl` | `string` | Override the Slack Web API base, for testing against a mock. |
@@ -0,0 +1,217 @@
1
+ ---
2
+ title: "Sources and verification"
3
+ description: "Choose an endpoint's source, configure verification, and type the event its subscribers receive."
4
+ sidebarTitle: "Sources & verification"
5
+ ---
6
+
7
+ An endpoint's `source` defines how Trigger.dev verifies requests and types the event every subscriber receives. Choose a named provider source or supply a verification configuration with `webhooks.custom()`.
8
+
9
+ ## Presets
10
+
11
+ Presets supply the verification configuration, and most also carry the provider's part of the endpoint's [setup prompt](/webhooks/connect#set-it-up-with-an-ai-agent). Set the endpoint's signing secret or public key as described in [Connect a provider](/webhooks/connect).
12
+
13
+ <CodeGroup>
14
+
15
+ ```ts /trigger/stripe.ts
16
+ import { webhook, webhooks } from "@trigger.dev/sdk";
17
+
18
+ export const stripe = webhooks.endpoint.define({ id: "stripe", source: webhooks.stripe() });
19
+
20
+ export const stripeEvents = webhook({
21
+ id: "stripe-events",
22
+ endpoint: stripe,
23
+ onEvent: async ({ event }) => {
24
+ if (event.type === "payment_intent.succeeded") {
25
+ console.log(event.id);
26
+ }
27
+ },
28
+ });
29
+ ```
30
+
31
+ ```ts /trigger/github.ts
32
+ import { webhook, webhooks } from "@trigger.dev/sdk";
33
+
34
+ export const github = webhooks.endpoint.define({ id: "github", source: webhooks.github() });
35
+
36
+ export const githubEvents = webhook({
37
+ id: "github-events",
38
+ endpoint: github,
39
+ onEvent: async ({ headers }) => {
40
+ // GitHub puts the event type in a header
41
+ console.log(headers.get("x-github-event"));
42
+ },
43
+ });
44
+ ```
45
+
46
+ ```ts /trigger/svix.ts
47
+ import { webhook, webhooks } from "@trigger.dev/sdk";
48
+
49
+ export const svix = webhooks.endpoint.define({ id: "svix", source: webhooks.svix() });
50
+
51
+ export const svixEvents = webhook({
52
+ id: "svix-events",
53
+ endpoint: svix,
54
+ onEvent: async ({ event }) => {
55
+ console.log(event);
56
+ },
57
+ });
58
+ ```
59
+
60
+ ```ts /trigger/composio.ts
61
+ import { webhook, webhooks } from "@trigger.dev/sdk";
62
+
63
+ export const composio = webhooks.endpoint.define({ id: "composio", source: webhooks.standardWebhooks() });
64
+
65
+ export const composioEvents = webhook({
66
+ id: "composio-events",
67
+ endpoint: composio,
68
+ onEvent: async ({ event }) => {
69
+ console.log(event);
70
+ },
71
+ });
72
+ ```
73
+
74
+ </CodeGroup>
75
+
76
+ The available presets are `stripe()`, `github()`, `svix()`, `standardWebhooks()`, `square()`, and `discord()`.
77
+
78
+ ### Svix and Standard Webhooks
79
+
80
+ `svix()` and `standardWebhooks()` use HMAC-SHA256 over `id.timestamp.body` with a base64-encoded `whsec_` secret. Their header names differ:
81
+
82
+ | Source | Headers |
83
+ | --- | --- |
84
+ | `svix()` | `svix-id`, `svix-timestamp`, `svix-signature` |
85
+ | `standardWebhooks()` | `webhook-id`, `webhook-timestamp`, `webhook-signature` |
86
+
87
+ Named sources such as `webhooks.clerk()` and `webhooks.composio()` select the corresponding configuration.
88
+
89
+ ## Named providers
90
+
91
+ Each function below returns a source with its provider's verification configuration. Call it through `webhooks`, for example `webhooks.calCom()`.
92
+
93
+ | Verification | Source functions |
94
+ | --- | --- |
95
+ | Svix | `clerk()`, `resend()`, `brex()` |
96
+ | Standard Webhooks | `openai()`, `replicate()`, `recallai()`, `composio()` |
97
+ | HMAC-SHA256 with `X-Hub-Signature-256` | `whatsapp()` |
98
+ | Shared secret in `X-Gitlab-Token` | `gitlab()` |
99
+ | Provider-specific HMAC | `calendly()`, `calCom()`, `sentry()`, `pagerduty()`, `vercel()`, `linear()`, `notion()`, `typeform()`, `docusign()`, `jira()`, `intercom()`, `zendesk()`, `attio()`, `workos()`, `elevenlabs()`, `vapi()`, `retell()`, `shopify()` |
100
+
101
+ Provider IDs containing a hyphen use a camel case function name: the `cal-com` provider is `webhooks.calCom()`.
102
+
103
+ Slack also ships as a chat channel in `@trigger.dev/slack`.
104
+
105
+ ## Endpoint validation
106
+
107
+ Some sources also define a response for the provider's endpoint-validation request. These requests don't create deliveries or task runs.
108
+
109
+ `discord()` answers a verified `{ type: 0 }` PING with HTTP `204` and no body. It also returns `204` for accepted events and `401` for invalid signatures. Set the Discord application's public key as the endpoint's verification credential.
110
+
111
+ Slack's `url_verification` challenge is handled the same way by `@trigger.dev/slack`.
112
+
113
+ `whatsapp()` answers Meta's GET verification request when `hub.mode` is `subscribe` and `hub.verify_token` matches the endpoint's verify token. It returns `hub.challenge` as text. The verify token is separate from the App Secret used to verify event signatures; see [Verify a WhatsApp endpoint URL](/webhooks/connect#verify-a-whatsapp-endpoint-url). Endpoints without GET verification return `405` to GET requests.
114
+
115
+ ## Custom providers
116
+
117
+ `webhooks.custom()` accepts a verification configuration. This source verifies an HMAC-SHA256 signature over the raw body in `x-webhook-signature` and uses the event's `id` for deduplication:
118
+
119
+ ```ts /trigger/internal.ts
120
+ import { webhook, webhooks } from "@trigger.dev/sdk";
121
+
122
+ export const internal = webhooks.endpoint.define({
123
+ id: "internal",
124
+ source: webhooks.custom<{ id: string; message: string }>(
125
+ {
126
+ scheme: "hmac",
127
+ algorithm: "sha256",
128
+ encoding: "hex",
129
+ signatureHeader: "x-webhook-signature",
130
+ signingString: "raw",
131
+ idempotencyField: { from: "body", name: "id" },
132
+ },
133
+ { setupPrompt: "Add the URL under Settings > Webhooks in the admin app and paste the secret there." }
134
+ ),
135
+ });
136
+
137
+ export const internalEvents = webhook({
138
+ id: "internal-events",
139
+ endpoint: internal,
140
+ onEvent: async ({ event }) => {
141
+ console.log(event.message);
142
+ },
143
+ });
144
+ ```
145
+
146
+ The optional `setupPrompt` is the provider-specific part of the endpoint's [setup prompt](/webhooks/connect#set-it-up-with-an-ai-agent): where the provider's webhook settings are and how to register a URL there. Trigger.dev adds the URL, the subscribers' filters and the signing secret steps around it.
147
+
148
+ ### Form-encoded bodies
149
+
150
+ A verified body sent as `application/x-www-form-urlencoded` reaches subscribers as an object of its fields, so filters, `chat.event` keys and waiter `match` paths read form fields the way they read JSON fields. A repeated field becomes an array of its values. Slack slash commands and other providers that post forms work this way.
151
+
152
+ By default an accepted request gets a `200` with a small JSON receipt. Some providers show the response body to the user who triggered the request, so pass `response: { acceptedBody: "empty" }` to answer with an empty `200` instead:
153
+
154
+ ```ts /trigger/forms.ts
155
+ import { webhook, webhooks } from "@trigger.dev/sdk";
156
+
157
+ export const forms = webhooks.endpoint.define({
158
+ id: "forms",
159
+ source: webhooks.custom<{ command: string; text: string; user_id: string }>(
160
+ { scheme: "url-secret", placement: "query", paramName: "token" },
161
+ { response: { acceptedBody: "empty" } }
162
+ ),
163
+ });
164
+
165
+ export const commands = webhook({
166
+ id: "commands",
167
+ endpoint: forms,
168
+ filter: "event.command == '/deploy'",
169
+ onEvent: async ({ event }) => {
170
+ console.log(event.user_id, event.text);
171
+ },
172
+ });
173
+ ```
174
+
175
+ ## Typing the event
176
+
177
+ Stripe and GitHub sources provide default event shapes; other sources default to `unknown`. Pass an event type to the source function for typed handler parameters and autocomplete. This example uses `Stripe.Event` from the `stripe` package, which must be installed in your project:
178
+
179
+ ```ts /trigger/stripe.ts
180
+ import type Stripe from "stripe";
181
+ import { webhook, webhooks } from "@trigger.dev/sdk";
182
+
183
+ export const stripe = webhooks.endpoint.define({ id: "stripe", source: webhooks.stripe<Stripe.Event>() });
184
+
185
+ export const stripeEvents = webhook({
186
+ id: "stripe-events",
187
+ endpoint: stripe,
188
+ onEvent: async ({ event }) => {
189
+ console.log(event.type, event.id);
190
+ },
191
+ });
192
+ ```
193
+
194
+ For `webhooks.custom<T>()`, pass your own event type as `T`. The endpoint's event type flows to every subscriber: `webhook()` handlers, `chat.event` keys and filters, and [waiter](/webhooks/waiters) `match` paths are all checked against it.
195
+
196
+ <Note>
197
+ Event types are compile-time annotations. Signature verification doesn't validate the body against
198
+ a TypeScript type. Validate `event` inside `onEvent` if your handler needs runtime schema checks.
199
+ </Note>
200
+
201
+ ## Verification schemes
202
+
203
+ Requests must pass verification before they reach any subscriber. Sources can check a signature or credential, enforce a timestamp tolerance, and derive an idempotency key for [deduplication](/webhooks/deliveries#deduplication). Verification failures return the source's rejected HTTP status (`400` by default).
204
+
205
+ Custom sources support these schemes:
206
+
207
+ | Scheme | Verification |
208
+ | --- | --- |
209
+ | `hmac` | Computes an HMAC over the raw body or a signing template and compares it with a request header. |
210
+ | `shared-secret` | Compares a static token supplied in a header, bearer token, basic authentication, or request body. |
211
+ | `url-secret` | Compares a token in a URL query parameter. Hosted endpoints don't support path placement. |
212
+ | `asymmetric` | Verifies an Ed25519, ECDSA, or RSA signature using the provider's public key. |
213
+
214
+ <Warning>
215
+ Query parameters can appear in access logs, proxies, and traces. Prefer a header-based scheme when
216
+ the provider supports one.
217
+ </Warning>