feat(webhook): add WebhookTrigger class for Workflow Builder triggers#2615
feat(webhook): add WebhookTrigger class for Workflow Builder triggers#2615zimeg wants to merge 17 commits into
Conversation
Add a new WebhookTrigger class that mirrors IncomingWebhook but handles
Workflow Builder webhook triggers which return JSON responses with
arbitrary payloads (vs plain text "ok" from incoming webhooks).
- Constructor takes URL + defaults (timeout, agent) — same pattern
- send() accepts arbitrary key-value payload, returns { ok, body }
- Reuses existing error infrastructure and User-Agent instrumentation
- Enables consumers like slack-github-action to use the SDK instead
of raw fetch for WFB triggers
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
🦋 Changeset detectedLatest commit: 7968168 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2615 +/- ##
==========================================
+ Coverage 88.90% 88.96% +0.05%
==========================================
Files 63 64 +1
Lines 10256 10375 +119
Branches 452 464 +12
==========================================
+ Hits 9118 9230 +112
- Misses 1117 1123 +6
- Partials 21 22 +1
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Workflow Builder webhook trigger inputs are always string values. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
WilliamBergamin
left a comment
There was a problem hiding this comment.
Gave this a quick look and it looks good 💯
if we need to dry this up in the future we can look into it at that time
# Conflicts: # packages/webhook/package.json # packages/webhook/src/index.ts
Allow send() to be called with no arguments, POSTing an empty body.
send({}) continues to work unchanged.
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Use a falsy check so an empty-string URL is rejected up front rather than failing later at request time. Adds a guard test. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
…s test
Add a test that a 401 with { ok: false, error: 'invalid_auth' } rejects
with an HTTPError exposing the response status and body. Remove the
success test asserting workflow_run_id so success cases only assert
result.ok === true.
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
WebhookTrigger throws the same coded errors as IncomingWebhook but had no correspondingly named types. Add WebhookTriggerSendError / WebhookTriggerHTTPError / WebhookTriggerRequestError aliases and export them so consumers have properly-named errors to catch. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
…source Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Coerce result.ok from body.ok instead of defaulting a missing field to true, so only an explicit ok:true reports success. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
zimeg
left a comment
There was a problem hiding this comment.
🗣️ Words I think for the readers and reviewers!
| } | ||
|
|
||
| export type IncomingWebhookSendError = IncomingWebhookRequestError | IncomingWebhookHTTPError; | ||
| export type WebhookTriggerSendError = WebhookTriggerRequestError | WebhookTriggerHTTPError; |
There was a problem hiding this comment.
| * Processes an HTTP response into a WebhookTriggerResult. | ||
| */ | ||
| private buildResult(response: AxiosResponse): WebhookTriggerResult { | ||
| const body = typeof response.data === 'string' ? JSON.parse(response.data) : response.data; |
There was a problem hiding this comment.
🔬 note: This feels defensive to me and might be removed as response is unpacked to match standard "fetch"!
| code: ErrorCode.RequestError; | ||
| original: Error; | ||
| } | ||
| export type WebhookTriggerRequestError = IncomingWebhookRequestError; |
There was a problem hiding this comment.
Safe move 🧠 I like it 💯
| }); | ||
| }); | ||
|
|
||
| describe('User-Agent header', () => { |
There was a problem hiding this comment.
Nice 💯
should we also add a tests that covers using addAppMetadata to expand the user-agent value?
| * A client for Slack's Workflow Builder webhook triggers | ||
| * @see {@link https://slack.com/help/articles/360041352714-Build-a-workflow--Create-a-workflow-that-starts-outside-of-Slack} | ||
| */ | ||
| export class WebhookTrigger { |
There was a problem hiding this comment.
Paise for mirroring existing behaviors 💯
Summary
This pull request adds a minimal
WebhookTriggerclass to@slack/webhookfor Workflow Builder webhook triggers.The package previously only supported incoming webhooks (
IncomingWebhook). Workflow Builder triggers accept arbitrary JSON payloads and return JSON responses, so consumers likeslack-github-actioncurrently fall back to rawfetch.The implementation is intentionally small and mirrors
IncomingWebhook:timeout,agent); rejects a missing or empty URL.send(payload?)POSTs the payload (defaults to{}) and resolves to{ ok, body }; HTTP and request failures reject.WebhookTrigger-named error types.Preview
🔗 https://github.com/slackapi/node-slack-sdk/tree/eden/webhook-trigger/packages/webhook#trigger-a-workflow-builder-workflow
Requirements