Skip to content

feat(slack): approve or reject Chat's cards from Slack - #2439

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:feature/slack-approvals
Nov 16, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:feature/slack-approvals

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

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.

  • Buttons show only when the change can run from Slack (see Decisions), the plan has slack_approvals (Growth and up, self-host), and the server has SLACK_SIGNING_SECRET.
  • After a decision, the message shows who decided and when, without buttons.
  • A click on a card already decided in Ansvisor says so, removes the buttons and changes nothing.
  • Anyone else gets a reply only they see, saying why, with Open in Ansvisor.

Changes

Server (where Slack and Composio live):

  • routes/slack-interactivity.js: POST /webhooks/slack/interactivity. Raw body kept for this path in server.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 its slack_posts id.
  • lib/chat-agents.js: postToChatInternal exported, with a timeout option.

Web (where the Chat engine lives):

  • POST /api/internal/chat/slack/card (read only) and POST /api/internal/chat/slack/decide (subscription guard first), both behind CHAT_INTERNAL_SECRET.
  • lib/chat/slack-approval.ts: reads the card, limited to the post's workspace, brand and agent run. Decides through prepareResume and driveRun, as the run's person, with no session.
  • engine.ts: ResumeAction approve takes via: 'slack'. activity.ts keeps it in summary_params. The Activity log shows Approved in Slack.
  • Slack card note, Help article (help/settings/slack.md), approved-articles.json regenerated.
  • SLACK_SIGNING_SECRET in server/.env.example and docs/self-host/env-variables.mdx.

No migration, no new dependency, no lockfile change.

Security

Each point has a test.

  • Signature: 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.
  • Ids in the payload: the button's post id is used only when that slack_posts row is a sent needs_you post on the same channel and message ts. Its brand is read with the post's organization. Anything else is "not found".
  • Other Slack workspace or other Ansvisor workspace: the brand must still use the post's own connection, in the post's organization. The click's team.id and user.team_id must match the connection's auth.test team.
  • Who decides: only the person the card waits for, as in the app (run.userId). The clicker must be the Slack user that users.lookupByEmail finds 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.
  • Role and brand access: the web reads the precedence context for that person. No access to the brand, or a decision of 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.
  • Admin client: every read in slack-approval.ts is limited by organization and brand (agent run, conversation), and the run must be in the organization. A mismatch is "not found".
  • One decision: prepareResume moves 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.
  • Demo brand and read-only: a demo-brand post is refused on the server, and the web checks again. The decide route checks subscriptionActiveFor first. The engine's plan.writable and the plan's slack_approvals with an active subscription are checked too.
  • Replies: sent only to https://hooks.slack.com/… response URLs.
  • Logs: codes only, never words.

Setup for Gökhan

  1. Use Ansvisor's own Slack app. Composio's managed app can't take clicks.
  2. In the Slack app, open Basic Information › App Credentials and copy the Signing Secret. Set it as SLACK_SIGNING_SECRET on the API server.
  3. In the Slack app, open Interactivity & Shortcuts: turn it on, set the Request URL to https://<API host>/webhooks/slack/interactivity, and save.
  4. Make sure the API server has CHAT_AGENTIC=true, CHAT_INTERNAL_SECRET (the same as the web's) and PUBLIC_APP_URL. The web needs CHAT_AGENTIC=true and the same CHAT_INTERNAL_SECRET.
  5. No new scope is needed. It uses chat:write (already granted), users:read.email (already granted, used for the mention) and auth.test. Workspaces don't need to reconnect.
  6. Restart the API server.

End to end in a real Slack workspace:

  1. On a Growth workspace, connect Slack for a brand, pick a channel, and leave Agents that need someone on.
  2. As the person the agent acts for, set Notify me when an agent needs me to Inbox + Slack. That person's Ansvisor e-mail must match their Slack e-mail.
  3. Make an agent with I approve first whose step creates or updates a draft or an Action Center action, then click Run now.
  4. The channel gets the message with the change and the three buttons. Click Approve and confirm. The message should show "Approved by … in Slack · time" with no buttons. The run goes on, and Activity shows Approved in Slack.
  5. Run it again. Click Reject from another Slack account: you should get a private "Only … can approve or reject this" and nothing should change. Then reject as the person.
  6. Run it again and approve in Ansvisor first. Click Approve in Slack: the message should lose its buttons, and you should get a private "already decided" reply.

How to test

  • cd server && npx vitest run src/lib/slack src/routes/slack-interactivity.test.js src/middleware/demo-brand.test.js
  • cd 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"
  • The Slack API, Composio and response URLs are mocked. Nothing calls Slack.

Checks

  • Web typecheck: passes.
  • Web tests: Slack approval, internal routes, the Chat engine (all 337), write, agent-driver, agent-sweep, undo, Activity (view, log view, action), the chat run routes, the Slack card, use-server-exports, subscription-guard-coverage, src/lib/help, src/i18n. 29 files, 705 tests pass.
  • Server suite: 505 files, 6,897 tests pass (4 skipped). demo-brand.test.js now names the new route among the webhooks mounted outside /api.
  • ESLint and Prettier on the changed files: clean. The two engine.test.ts warnings were there before.
  • About 1,050 changed lines without tests (about 1,120 with tests). That is over the 600 target because the click comes into the server (Slack, Composio) and the decision is made in the web (the Chat engine). That needs a route on each side and a check at every hop. About 180 of those lines are comments.

Decisions for the owner

  • Only cards that can run without a session get buttons. A change approved from Slack has no browser session. Only sessionFree rows 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 a runFor.
  • Only the run's person can decide, as in the app. No one else (an Admin, a Manager) can, from Slack or the app.
  • How Slack users are linked: by e-mail at click time, as the mention already does. No new table. If a Slack admin can change a member's Slack e-mail, they could match someone else. A stored, confirmed link would need a migration and a migration number.
  • Reject = Skip. The button says Reject, as asked. In Ansvisor the step shows "Skipped".
  • "From Slack" lives in summary_params.via. The surface check constraint doesn't allow slack, and adding it would need a migration.
  • Slack message words are on the server, as the other Slack messages and e-mails are. Only the card note and the Activity label are in en.json.
  • The message isn't updated by itself when the card is decided in the app. It updates on the next click. Updating it right away would need the web's resolveAgentNeedsYou to call the server for chat.update, which is a follow-up.
  • An already rejected card doesn't say where it was rejected. A skip leaves no Activity row.

Generated by Claude Code

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
@mintlify

mintlify Bot commented Nov 15, 2026

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit ead839b.

Approve preview

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@gkhngyk
gkhngyk merged commit 676926b into ansvisor:main Nov 16, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants