Skip to content

feat(slack): post the Daily Pulse to the brand's Slack channel (00515) - #2263

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

gkhngyk merged 4 commits into
ansvisor:mainfrom
cihan-gyk:feature/slack-pulse

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Builds on #2259 (merged). This is plan N3:

  • the delivery module that every Slack message will go through;
  • its first message, the Daily Pulse.

The Settings card that lets a brand turn it on comes in the next PR, stacked on this one.

lib/slack/deliver.js posts one message to a brand's channel, and only when every check passes:

  • Slack is set up on this server, and the brand isn't the demo brand;
  • the brand uses a connected workspace, has picked a channel, and has this kind turned on;
  • the workspace's plan has slack_notifications: every paid plan, the trial included, and self-host always;
  • the person who connected the workspace can still see the brand (owner, 2026-11-10).

Once the checks pass:

  • Once only: the message is saved in slack_posts before it is sent, unique per brand and dedupe key (pulse:{date} for the Pulse). A retried job or a second server sends nothing twice.
  • Rate limits: posts from this server to one channel are at least 1.1 s apart. Slack takes about one message a second per channel.
  • One retry:
    • a 429 is tried again after Slack's Retry-After (up to 30 s; longer gives up);
    • a 5xx, a timeout or a lost call is tried again after 2 s;
    • every other failure is recorded at once.
  • The card stays true:
    • if Slack refuses the workspace (token_revoked, invalid_auth…), it is marked so the card asks to reconnect;
    • if the channel is gone or the app was removed from it, the channel is cleared so the card asks for another.
  • Errors: logs carry the brand, the kind and codes only. slack_posts.error_code keeps Slack's code. It never throws.
  • Wording only when it goes: a message can be passed as a function, called only once every check has passed.

The Pulse's Slack leg runs after the e-mail and webhook legs, on cloud and self-host alike.

  • Content: its blocks (blocks/pulse.js) carry the e-mail's numbers, highlights and warnings: Visibility, 7-day trend, Mentions, Citations, Positive sentiment and Prompts you appear in. They also carry the degraded-data note, lists capped at five items, and links to Visibility and the Pulse settings.
  • Frequency: it follows the brand's Pulse setting: Daily, Weekly (titled "Weekly Pulse"), or Only when notable. Off means none.
  • Recording: sent_pulses.slack_sent is written in its own update, so a database without 00515 still records the e-mail and webhook legs.

Migration 00515

  • Table slack_posts: organization, brand, the workspace's sign-in, kind, dedupe key, channel, status sending|sent|failed, Slack's ts, error code, attempts.
    • The kinds are pulse, drop, suggestion and needs_you; the last three come in N4–N6.
    • It is server only: RLS on, no client policy, and the policy test lists it as server-only.
  • Column sent_pulses.slack_sent.
  • schema.sql is rebuilt; the demo coverage skips the table, since a demo brand never posts.

Smaller changes

  • The test message (feat(slack): connect a Slack workspace per brand and pick its channel (API) #2259) now says only what is posted: "{brand}'s Daily Pulse will be posted here."
  • The Pulse's platform names and signed numbers move to pulse/format.js, shared by the e-mail and Slack. The e-mail is unchanged.
  • The messages use links, not the buttons drawn in the mockup. A Slack button makes Slack call the app's interactivity address, and nothing answers it until the approvals PRs. Buttons can come with those.

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/lib/slack src/lib/pulse src/lib/demo/coverage.test.js src/lib/brand-access-policies.test.js. The tests cover:
    • every check that skips a post;
    • once per dedupe key, and the spacing;
    • the 429, 5xx and give-up paths;
    • a refused workspace marked, and a gone channel cleared;
    • codes only in the logs, and the message worded only when it goes;
    • the Pulse leg's dedupe key and slack_sent;
    • the blocks' content and escaping.
  2. bash supabase/build-schema.sh leaves schema.sql unchanged.
  3. Live test with Gökhan, once the Ansvisor Slack app, its Composio auth config and the card PR are in:
    • connect a brand, pick a channel and leave Daily Pulse on;
    • run the brand's daily tracking: the Pulse appears in the channel once, with the same numbers as the e-mail;
    • archive the channel and run again: the card asks for another channel, and slack_posts.error_code says is_archived.

Needs migration on prod: 00515. It only adds a table and a column, and depends on nothing newer than 00470.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/) — no web change
  • yarn typecheck passes (run from web/) — no web change
  • yarn format:check passes (run from web/) — no web change
  • Changes are focused — one concern per PR
  • Help article updated under help/ (or no user-visible change) — nothing can switch it on until the card PR, which brings the Help for both

Checks on 39b9c13:

  • Server: npm run format:check and npm run lint pass. npm test: 447 files, 6,174 passed, 4 skipped.
  • bash supabase/build-schema.sh run, and schema.sql committed with the migration.

After merging main (18c6c41):


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
Part of ansvisor#2139 (N3), on the Slack connection (N1).

- lib/slack/deliver.js: one message to a brand's channel, through every
  check: Slack set up, not the demo brand, a connected workspace, a channel,
  the kind turned on, a plan with Slack notifications (every paid plan,
  trial included; self-host always), and a connector who can still see the
  brand. Kept in slack_posts before it is sent (unique per brand and dedupe
  key), so it goes once. Posts to one channel are spaced by 1.1 s; a 429 is
  tried once more after Retry-After (up to 30 s), a 5xx, timeout or lost
  call after 2 s. Slack refusing the workspace marks it for a reconnect; a
  channel that is gone, or the app was removed from, is cleared. Logs carry
  codes only, and it never throws.
- The Pulse's Slack leg, after its e-mail and webhook legs: the e-mail's
  numbers, highlights and warnings in Block Kit (blocks/pulse.js), worded
  only when it goes, with links to Visibility and the Pulse settings. It
  follows the brand's Pulse frequency. sent_pulses.slack_sent records it,
  apart from the other legs.
- Migration 00515: slack_posts (server only, no policy) and
  sent_pulses.slack_sent; schema.sql rebuilt; the demo skips it.
- The test message now says only what is posted: the Daily Pulse.
- The Pulse's platform names and signed numbers move to pulse/format.js,
  shared by the e-mail and Slack.

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

@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 e940dde into ansvisor:main Nov 10, 2026
13 checks passed
cihan-gyk pushed a commit to cihan-gyk/ansvisor that referenced this pull request Nov 10, 2026
…nect

The Slack PRs (ansvisor#2263, ansvisor#2264) added a Team and alerts group where this
branch adds the CRM group: both groups are kept, Slack's first, with
both strings and both tests.

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

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants