feat(slack): dynamic botToken resolver and custom webhookVerifier#421
Merged
Conversation
Allow `botToken` to be a function returning `string | Promise<string>` so apps can rotate or lazily fetch tokens; the resolver is invoked per API call. Add `webhookVerifier: (request) => string | Promise<string>` as an alternative to `signingSecret` for custom request verification — returns the verified body text or throws to produce a 401. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
- scheduleMessage cancel(): re-resolve token in single-workspace mode so rotation works. Slack rotated tokens have a 12h TTL and scheduled messages can outlive their schedule-time token, leaving cancel() with stale auth. Multi-workspace still snapshots ctx.token since cancel() runs outside the AsyncLocalStorage frame. - webhookVerifier: when it returns a string, use it as the verified body for downstream parsing. JSDoc previously implied this contract; the code only checked truthiness. - webhookVerifier JSDoc: explicit SECURITY note that timestamp/replay protection is the implementer's responsibility when bypassing signingSecret. - Tests: cover Attachment.fetchData snapshot semantics — multi-workspace uses the ctx token captured at attachment creation; single-workspace re-resolves the default provider per fetch (rotation-safe).
A webhookVerifier passed in config was being silently shadowed by SLACK_SIGNING_SECRET in the env (read by both createSlackAdapter and the SlackAdapter constructor). An explicit verifier now opts out of that fallback in both code paths. Added a regression test that stubs the env var via vi.stubEnv.
handleReactionEvent does async work (conversations.replies, users.info) before delegating to chat.processReaction, which is the only point that registers a waitUntil task. The outer prep work was untracked, so callers that drained waitUntil tasks could complete before the reaction handler finished — flaky in CI under tight microtask scheduling. Track the outer promise too so the full handler is awaited.
dancer
approved these changes
Apr 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SlackAdapterConfig.botTokennow acceptsstring | (() => string | Promise<string>). The resolver is invoked per API call, enabling token rotation or lazy fetch from a secret manager. Defaults (env var fallback, single- vs multi-workspace mode detection) are unchanged.SlackAdapterConfig.webhookVerifier: (request: Request) => string | Promise<string>runs in place ofsigningSecretwhen set (andsigningSecretis not). It receives the incomingRequestand must return the verified raw body text; throwing yields401 Invalid signature.signingSecretwins if both are configured.getToken()/withToken()are now async;WebClientis constructed without a static token (every call passes one explicitly). AttachmentfetchDatasnapshots the per-requestctx.tokenat creation and defers default-provider resolution to fetch time.Test plan
pnpm --filter @chat-adapter/slack typecheckpnpm --filter @chat-adapter/slack test— 360 tests passing, including:botToken as function(sync resolver, async resolver, per-call rotation, single-workspaceauth.testwiring, error propagation)handleWebhook - webhookVerifier(used in place ofsigningSecret, throws → 401,signingSecretprecedence)pnpm --filter @chat-adapter/integration-tests test src/replay-multi-workspace-slack.test.tspnpm --filter @chat-adapter/slack buildpnpm -w run check packages/adapter-slack/src🤖 Generated with Claude Code