Skip to content

feat(slack): connect a Slack workspace per brand and pick its channel (API) - #2259

Merged
gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:feature/slack-connection
Nov 10, 2026
Merged

gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:feature/slack-connection

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

First of the Slack PRs (plan N1, approved by the owner on 2026-11-10). It is server only; the Settings card comes in a later PR.

  • A brand's Slack follows the brand access connection model (fix(mcp): read each brand's Google sign-in in list_connections (brand access PR 14) #2045, feat(web): let each brand choose its Google account in Brand settings > Integrations (brand access PR 15) #2112).

    • A Slack workspace's install is one more sign-in in the Account's pool (integration_accounts, provider slack, labelled with the workspace's name from auth.test).
    • Each brand names the one it uses (brand_integrations), as a brand's own Google login does.
    • The brand's channel and four send switches (Pulse, drops, daily suggestion, agents that need someone) live in that row's settings. They start over when the brand switches to another workspace, because a channel belongs to its workspace.
  • Composio, with Ansvisor's own Slack app.

    • The install runs through the Slackbot toolkit's auth config (COMPOSIO_SLACK_AUTH_CONFIG_ID), set up with our own Slack app. Composio's managed app works too, as the env fallback.
    • Composio keeps the bot token.
    • Slack is called through Composio's proxy, so we choose Slack's API and get its own error codes and Retry-After back. proxyRequest now POSTs a JSON body.
  • lib/slack/api.js: slackGet (reads, query) and slackPost (writes, JSON). Every failure is a SlackError that carries a code only, never Slack's or Composio's text.

  • lib/slack/connection.js: the brand's Slack, and where it stands:

    • not_connected;
    • refused: the workspace removed the app or revoked the token;
    • access_lost: whoever connected it can't see the brand any more, so nothing would be posted;
    • connected.

    It also lists channels (up to 5 pages of 200, archived ones left out), checks a channel, and posts the test message (blocks/connected.js, worded on the server as the e-mails are).

  • routes/slack.js, under /api/slack/brands/:brandId:

    • GET is open to anyone who can access the brand.
    • Admins and managers who can access the brand can call connect, activate, use (another brand's workspace), GET channels, PUT (channel and switches), test and DELETE.
    • Every write except Disconnect needs the plan's slack_notifications. Disconnect works on a read-only workspace.
    • Workspaces whose connector can't see this brand aren't offered for use and aren't posted to.
    • When Slack refuses the connection, the sign-in is marked auth_failed. A channel that is gone is cleared.
    • The demo brand connects nothing.
    • No Composio id or token is ever sent to the browser.
  • Plans (owner, 2026-11-10), in both plan files:

    • slack_notifications on Starter, Growth, Enterprise and self-hosted;
    • slack_approvals on Growth, Enterprise and self-hosted, for the later approvals PRs.
  • Guards and docs:

    • the demo guard lists every write route; the read-only middleware lets Disconnect through;
    • a new slackLimiter (60 calls per 15 minutes, like the CMS cards);
    • /api/integrations/config gets slack;
    • server/.env.example and docs/self-host/env-variables.mdx document the new env var.

No migration: the pool tables take a slack provider as they are. Nothing a person sees changes yet.

Related issue

Part of #2139.

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. cd server && npx vitest run src/routes/slack.test.js src/lib/slack src/lib/composio.test.js src/lib/brand-integrations-own.test.js src/routes/integrations-config.test.js src/middleware src/routes/write-roles.test.js.
  2. The Slack answers in the tests come from server/src/lib/slack/__fixtures__/slack-api.json. They are recorded in the shapes Slack documents (auth.test, conversations.list over two pages, conversations.info, chat.postMessage, and the error answers), with ids and names replaced.
  3. Live test with Gökhan, once the Ansvisor Slack app and its Composio auth config exist:
    • set COMPOSIO_SLACK_AUTH_CONFIG_ID;
    • POST /api/slack/brands/:id/connect with a callback on the app, open the address it returns, then POST /activate;
    • GET /channels, PUT { channelId }, POST /test: the test message arrives in the channel;
    • while live, re-record the fixtures from the real answers.

What Gökhan sets up first (about 1.5 hours):

  • The Slack app "Ansvisor":
    • bot scopes chat:write, chat:write.public, channels:read, groups:read, users:read, users:read.email;
    • Composio's callback URL as its redirect URL;
    • public distribution turned on.
  • A Composio custom auth config of the Slackbot toolkit with that app's client id and secret. The API key needs the "Proxy execute" permission (Merchant Center already needs it).
  • COMPOSIO_SLACK_AUTH_CONFIG_ID on the API server.

Fallback: a Composio-managed Slackbot auth config. Its consent screen says "Composio", and workspaces connected through it must reconnect when we switch to our own app.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/) — eslint src/config/plans.ts, the only web file changed
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/) — prettier --check on the changed file
  • Changes are focused — one concern per PR
  • Help article updated under help/ (or no user-visible change) — no user-visible change yet; help/settings/slack.md comes with the card

Also run on this branch (c29093a, which merges cleanly into current main):

  • Server: npm run format:check and npm run lint pass.
    • npm test ran on 5638028: 445 files, 6,147 passed, 4 skipped.
    • The last commit only changes how a plan refusal is worded. After it, slack.test.js and write-roles.test.js passed again (48 tests).
  • Web: src/config/plans.ts is the only web file. The plan-related tests (src/config, plan-facts, precedence, access, src/components/settings, src/components/billing, src/lib/white-label, src/lib/billing) pass: 62 files, 729 tests.
  • No migration, so build-schema.sh isn't needed. No web route changed, so yarn build wasn't run.

Generated by Claude Code

… (API)

Part of ansvisor#2139 (N1). Server only; the card comes next.

- A brand's Slack is one more sign-in in the Account's pool
  (integration_accounts, provider `slack`, labelled with the workspace's
  name from auth.test), used through brand_integrations as a brand's own
  Google login is. Its channel and the four send switches (Pulse, drops,
  daily suggestion, agents that need someone) live in the row's settings.
- Composio: Slack's install through the Slackbot toolkit's auth config
  (COMPOSIO_SLACK_AUTH_CONFIG_ID: Ansvisor's own Slack app, or Composio's
  managed one as a fallback). Slack is called through Composio's proxy
  (proxyRequest now POSTs a JSON body), so the bot token stays with
  Composio and Slack's own codes and Retry-After come back.
- lib/slack/api.js: slackGet / slackPost, every failure a SlackError with a
  code only. lib/slack/connection.js: the brand's Slack, where it stands
  (not connected, refused, access lost, connected), channels page by page,
  the test message (blocks/connected.js).
- routes/slack.js under /api/slack/brands/:brandId: read for anyone who can
  access the brand; connect, activate, use another brand's workspace,
  channels, PUT channel and switches, test message, disconnect for admins
  and managers. Writes but Disconnect need the plan's slack_notifications.
  A workspace whose connector can't see the brand isn't offered or posted
  to. Slack refusing the connection marks the sign-in; a channel that is
  gone is cleared. The demo brand connects nothing.
- A brand's settings on a sign-in start over when it uses another one.
- Plans: slack_notifications (Starter, Growth, Enterprise, self-hosted) and
  slack_approvals (Growth, Enterprise, self-hosted), in both plan files.
- Demo and read-only guards, slackLimiter, /api/integrations/config's
  `slack`, env docs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
The web opens the plan dialog on error plan_limit; the routes said it only in
code.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
@mintlify

mintlify Bot commented Nov 10, 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 c29093a.

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 280375d into ansvisor:main Nov 10, 2026
14 checks passed
cihan-gyk pushed a commit to cihan-gyk/ansvisor that referenced this pull request Nov 10, 2026
ansvisor#2259 was squash-merged, so its file came back as an add/add conflict:
this branch's connected.js is kept (its test message names the Daily
Pulse only). schema.sql is rebuilt with 00510 and 00515.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
cihan-gyk pushed a commit to cihan-gyk/ansvisor that referenced this pull request Nov 10, 2026
Brings in upstream/main through feature/slack-pulse: ansvisor#2259 (squash-merged)
and the MCP OAuth PRs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
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