Repository navigation
feat(slack): approve or reject Chat's cards from Slack - #2439
Merged
Merged
Conversation
Part of ansvisor#2139 (N7). The "agent needs you" message gets Approve, Reject and Open in Ansvisor when the card can be decided from Slack. - Server: POST /webhooks/slack/interactivity, the Slack app's Interactivity Request URL. Every request is checked against SLACK_SIGNING_SECRET on its raw body (v0 HMAC-SHA256, constant-time, timestamp within 5 minutes); no secret, a bad signature or a stale timestamp is 401 and nothing happens. A verified click is answered 200 at once and handled after; a retry (X-Slack-Retry-Num) is dropped. - lib/slack/approvals.js: the button names our own slack_posts row, found only as Slack shows it (channel and ts); the brand must still use that post's connection, and the click must come from its Slack workspace (auth.test). The plan needs slack_approvals. Only the person the card waits for decides: the clicker must be the Slack user that users.lookupByEmail finds for their confirmed Ansvisor e-mail, in that workspace. No new table. The answer goes back on response_url: the message with who decided and when and no buttons, or a reply only the clicker sees, with Open in Ansvisor. - Web: /api/internal/chat/slack/card and /decide (CHAT_INTERNAL_SECRET). The card is read limited to the post's workspace, brand and agent run. A decision is the app's own prepareResume and driveRun, as the run's person, with no session; role, brand access, read-only and demo brand are checked before anything moves. Only a card whose change runs without a session (runsWithoutSession) is offered in Slack. - Activity: an Approve from Slack is logged as the app's, with via slack in summary_params, and shows as "Approved in Slack". - Help article, the Slack card's note, SLACK_SIGNING_SECRET in the env docs. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
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
Part of #2139 (N7). When an agent's run waits for an OK, its "agent needs you" message in the brand's Slack channel now shows what the change is, with Approve, Reject and Open in Ansvisor. Only the person the agent waits for can decide, through the same path as the app's Approve and Skip.
slack_approvals(Growth and up, self-host), and the server hasSLACK_SIGNING_SECRET.Changes
Server (where Slack and Composio live):
routes/slack-interactivity.js:POST /webhooks/slack/interactivity. Raw body kept for this path inserver.js. Checks the signature, answers 200 at once, then handles the click.lib/slack/signature.js: Slack's v0 signature check.lib/slack/approvals.js: the click handler (post, connection, workspace, plan, card, person, decision, reply).lib/slack/blocks/needs-you.js: the card's title and target, and the buttons (Approve asks "Approve this step?" first).lib/slack/blocks/approval.js: the decided message and the ephemeral replies.lib/slack/needs-you.js: reads the card from the web before posting.lib/slack/deliver.js:slackAllowed(org, feature); the message function gets itsslack_postsid.lib/chat-agents.js:postToChatInternalexported, with a timeout option.Web (where the Chat engine lives):
POST /api/internal/chat/slack/card(read only) andPOST /api/internal/chat/slack/decide(subscription guard first), both behindCHAT_INTERNAL_SECRET.lib/chat/slack-approval.ts: reads the card, limited to the post's workspace, brand and agent run. Decides throughprepareResumeanddriveRun, as the run's person, with no session.engine.ts:ResumeActionapprove takesvia: 'slack'.activity.tskeeps it insummary_params. The Activity log shows Approved in Slack.help/settings/slack.md),approved-articles.jsonregenerated.SLACK_SIGNING_SECRETinserver/.env.exampleanddocs/self-host/env-variables.mdx.No migration, no new dependency, no lockfile change.
Security
Each point has a test.
v0=+ HMAC-SHA256(secret,v0:{ts}:{raw body}), constant-time compare, timestamp within 5 minutes. A missing or bad signature, a stale timestamp or a body with one byte changed gets 401 and nothing happens. With no secret, every request gets 401. Failed checks count in the webhooks' per-IP 401 limiter.slack_postsrow is a sentneeds_youpost on the same channel and message ts. Its brand is read with the post's organization. Anything else is "not found".team.idanduser.team_idmust match the connection'sauth.testteam.run.userId). The clicker must be the Slack user thatusers.lookupByEmailfinds for that person's confirmed Ansvisor e-mail, in the same team, not deleted and not a bot. The person must still be a member.deny(for example an Analyst), is refused before the run moves. The engine decides again on resume, as it does for the app's Approve.slack-approval.tsis limited by organization and brand (agent run, conversation), and the run must be in the organization. A mismatch is "not found".prepareResumemoves the run from waiting to running once. A double click gets "already decided". Slack retries are dropped. The change runs under the step's idempotency key.subscriptionActiveForfirst. The engine'splan.writableand the plan'sslack_approvalswith an active subscription are checked too.https://hooks.slack.com/…response URLs.Setup for Gökhan
SLACK_SIGNING_SECRETon the API server.https://<API host>/webhooks/slack/interactivity, and save.CHAT_AGENTIC=true,CHAT_INTERNAL_SECRET(the same as the web's) andPUBLIC_APP_URL. The web needsCHAT_AGENTIC=trueand the sameCHAT_INTERNAL_SECRET.chat:write(already granted),users:read.email(already granted, used for the mention) andauth.test. Workspaces don't need to reconnect.End to end in a real Slack workspace:
How to test
cd server && npx vitest run src/lib/slack src/routes/slack-interactivity.test.js src/middleware/demo-brand.test.jscd web && npx vitest run src/lib/chat/slack-approval.test.ts src/app/api/internal/chat/slack src/lib/chat/engine.test.ts -t "sessionFree|slack"Checks
use-server-exports,subscription-guard-coverage,src/lib/help,src/i18n. 29 files, 705 tests pass.demo-brand.test.jsnow names the new route among the webhooks mounted outside/api.engine.test.tswarnings were there before.Decisions for the owner
sessionFreerows can run that way: drafts (create, update), Action Center actions, ready for review, opportunity status, dismissed suggestions. Their change runs as the person (runFor). Other changes, an EXECUTE's click and questions keep Open the run only. Opening more would mean giving rows arunFor.summary_params.via. Thesurfacecheck constraint doesn't allowslack, and adding it would need a migration.en.json.resolveAgentNeedsYouto call the server forchat.update, which is a follow-up.Generated by Claude Code