feat(slack): parse interactivity payloads and slash commands - #1540
Draft
cosmicBboy wants to merge 1 commit into
Draft
feat(slack): parse interactivity payloads and slash commands#1540cosmicBboy wants to merge 1 commit into
cosmicBboy wants to merge 1 commit into
Conversation
The Slack provider only understood Events API JSON, but a real Slack app
receives two more delivery shapes on the same signing scheme: interactivity
payloads (Block Kit actions, shortcuts, modals -- form-encoded JSON under a
`payload` field) and slash commands (form-encoded fields). Internal agents
like Cally (`@app.action("send_to_customer")`) and Nodey (`/hi-nodey`)
could not move onto the plugin without them: those deliveries failed in
`parse` with a 400.
- parse() now sniffs form-encoded bodies and normalizes both shapes: a
block action registers as `block_actions.<action_id>`, a shortcut as its
callback_id, a slash command as `command.<name>`; the full Slack JSON
(actions, container, message, response_url) rides in event.payload
- interactions dedupe per click via action_ts/trigger_id, so a Slack
redelivery is a no-op but two clicks of one button are two events
- handshake() answers the `ssl_check` probe Slack sends to interactivity
and slash-command URLs, so those Request URL fields verify themselves
- new events.Interaction and events.Command constants; README documents
pointing all three Request URLs at the same /webhook/slack route
Verified end to end through WebhookAppEnvironment with signed
Cally/Nodey-shaped deliveries: dispatch, dedupe keys, 401 on unsigned,
and the JSON Events API path unchanged.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NwQixBcyR5va6BC75jaQx3
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.
Why
The Slack provider only understood Events API JSON, but a real Slack app receives two more delivery shapes signed with the same v0 HMAC:
application/x-www-form-urlencodedwith the JSON under apayloadfieldInternal agents like Cally (
@app.action("send_to_customer"),/hi-cally) and Nodey (/hi-nodey,app_mention) need all three shapes; today they run hand-rolled slack_bolt servers partly because the plugin 400s on anything form-encoded. This closes that gap.What
parse()sniffs form-encoded bodies and normalizes both shapes:block_actions.<action_id>(e.g.on_event("block_actions.send_to_customer")), a shortcut/message action as itscallback_id, a modal asview_submission.<callback_id>command.<name>(e.g.on_event("command.hi-nodey")for/hi-nodey)actions,container,message,response_url— rides inevent.payload, which is everything Cally's handlers read todayaction_ts(unique per click), so a Slack redelivery is a no-op but two clicks of one button are two events; slash commands key ontrigger_idhandshake()now also answers thessl_checkprobe Slack sends to interactivity and slash-command Request URLs, so those fields verify themselves likeurl_verificationalready didevents.Interactionandevents.Commandconstants; README documents pointing Event Subscriptions, Interactivity & Shortcuts, and each slash command at the same/webhook/slackrouteverify()unchanged — the v0 HMAC signs raw bytes regardless of encoding (test added proving form bodies verify)Validation
WebhookAppEnvironment+ FastAPI TestClient with signed, Cally/Nodey-shaped deliveries: block action dispatched to itsblock_actions.send_to_customerhandler,/hi-nodeyto itscommand.hi-nodeyhandler,ssl_checkanswered 200, JSONapp_mentionpath unchanged, unsigned delivery refused with 401Notes
Slack expects interactivity/command acks within 3 seconds; handlers should do nothing slower than
run_once.aioand post progress back viaslack_sdkfrom the launched task (README now says so). Replying viaresponse_urlfrom the receiver is deliberately left to handler code.🤖 Generated with Claude Code
https://claude.ai/code/session_01NwQixBcyR5va6BC75jaQx3