Skip to content

feat(server): Slack @aao-members user group for member @-mentions - #3388

Closed
bokelley wants to merge 4 commits into
mainfrom
claude/issue-2340-slack-member-badges
Closed

bokelley wants to merge 4 commits into
mainfrom
claude/issue-2340-slack-member-badges

Conversation

@bokelley

Copy link
Copy Markdown
Contributor

Closes #2340

Hooks into WorkOS organization_membership.{created,updated,deleted} webhooks to automatically add and remove members from a Slack user group (@aao-members), making AgenticAdvertising.org members visually identifiable in workspace conversations. The group is created on first use if it doesn't exist. Ops can pin the group ID or override the handle via SLACK_MEMBER_USER_GROUP_ID / SLACK_MEMBER_USER_GROUP_HANDLE env vars.

Non-breaking justification: additive server-side change only — new Slack API calls and webhook side-effects. No schema changes, no wire-format changes, no public API changes. Existing behavior is unchanged if ADDIE_BOT_TOKEN lacks usergroups:* scopes (ops must approve updated app manifest before this activates).

Deploy note: existing members at deploy time are not backfilled — they join @aao-members on their next membership event, or a workspace admin can manually add them.

Pre-PR review:

  • code-reviewer: approved after fixes — resolved: members handle collision (→ aao-members + env var override), outer badge-error log level promoted to warn, missing changeset, date_delete guard in group resolution. Remaining nits: read-then-write race is acknowledged (low-risk for internal tooling, no distributed lock needed at this scale)
  • adtech-product-expert: approved after fixes — resolved: include_disabled: false bool serialization bug (removed param, Slack default is false), addMemberBadge moved outside if (workosUser) guard, empty-array guard added to removeMemberBadge to avoid Slack invalid_users error

Triage-managed PR. This bot does not currently iterate on
review comments or PR conversation threads (only on the source
issue). To unblock:

  • Push fixup commits directly: gh pr checkout <num> →
    fix → push.
  • Or re-trigger: comment /triage execute on the source
    issue.

See #3121
for context.

Session: https://claude.ai/code/session_01MaC9AaSiVtFaVbbJFeN5a3


Generated by Claude Code

claude added 2 commits April 28, 2026 10:50
Hooks into WorkOS organization_membership.{created,updated,deleted}
webhooks to add/remove members from a Slack user group (@aao-members),
making AgenticAdvertising.org members visually identifiable in workspace
conversations.

The user group is auto-created on first use if it doesn't exist. Ops
can pin the group ID and handle via SLACK_MEMBER_USER_GROUP_ID /
SLACK_MEMBER_USER_GROUP_HANDLE env vars. Requires usergroups:read +
usergroups:write scopes on the bot token.

https://claude.ai/code/session_01MaC9AaSiVtFaVbbJFeN5a3
- Drop include_disabled param from getSlackUserGroups (bool false
  serializes as string "false" which Slack treats as truthy)
- Move addMemberBadge call outside if(workosUser) block so badge is
  assigned even when WorkOS user fetch fails
- Guard removeMemberBadge against empty member list (Slack rejects
  usergroups.users.update with zero users)

https://claude.ai/code/session_01MaC9AaSiVtFaVbbJFeN5a3
@bokelley bokelley added the claude-triaged Issue has been triaged by the Claude Code triage routine. Remove to re-triage. label Apr 28, 2026
@bokelley

Copy link
Copy Markdown
Contributor Author

Confirmed: Slack user groups don't show a visual badge next to usernames — they only matter for @-mentions. The actual mechanism for "badges" in Slack is overlaying an icon onto the user's profile photo and uploading it via users.setPhoto. Donut.app, Pyn, and similar member-tooling services do this.

Updated scope for this PR (or split into a stacked follow-up):

Keep the user-group plumbing from this PR — it's useful infrastructure for member-wide @-mentions. Add the photo-overlay layer as the actual visual badge.

Implementation outline

  1. Webhook handler (already wired here): on organization_membership.created, look up the member's Slack user via the existing slack_user_mappings table.
  2. Fetch current photo: users.profile.get → profile.image_512 (or fall back to image_192 if 512 isn't set; some users only have low-res).
  3. Composite the badge: small image-comp util (sharp or jimp). Standard pattern is bottom-right corner overlay, ~25-30% of source dimensions, with a thin white ring so the badge survives both light and dark backgrounds.
  4. Upload via users.setPhoto: requires admin token + users.profile:write scope. The token already on the bolt app should have it; verify in server/src/slack/client.ts.
  5. Persist the original photo URL on the member record (new column on members or slack_user_mappings: original_slack_photo_url). On organization_membership.deleted, fetch original and re-upload to revert.
  6. Edge cases:
    • User has no photo (Slack default initials avatar): use a generated 512×512 monogram + badge.
    • User changes their photo after we badge them: original is stale; on next membership event, refresh original from current and re-overlay. Worth a daily reconcile job that detects "photo changed without admin" and re-applies badge.
    • User who left and rejoined: ensure we don't double-apply.
  7. Consent: flag for product. Slack will show "set by admin" tooltip on the photo. Some workspaces are fine with this; some aren't. Recommend Mary opt-in via admin-settings toggle before we run a backfill.

Asset needed from product

A 256×256 (or vector → render) PNG of the AAO badge with transparent background. The badge itself is the load-bearing visual — needs design review before backfill.

Suggested split

If this PR is getting too big, keep the user-group plumbing here and rename the PR/changeset to "feat(server): Slack @aao-members user group for member @-mentions". File a stacked follow-up PR (or new commit on this branch) titled "feat(slack): photo-overlay badge for AAO members" that implements steps 2-6 above. The user-group infra is independently useful even before the badge ships.

Reference: https://www.reddit.com/r/Slack/comments/1fwo9nt/badges_for_slack/ — confirms there's no native badge API; photo overlay is the convention.

…roup @-mention scope

Per @bokelley's review: Slack user groups don't show visual badges —
they only enable member-wide @-mentions. Renaming addMemberBadge /
removeMemberBadge to addToMemberUserGroup / removeFromMemberUserGroup,
and updating log messages and changeset accordingly.

Photo-overlay badge (users.setPhoto) is a separate follow-up that
needs a design asset and consent/admin-settings decision first.

https://claude.ai/code/session_017Ypq6RvZxi7gpP6WY873pw
@bokelley bokelley changed the title feat(server): automated Slack user group badges for members feat(server): Slack @aao-members user group for member @-mentions Apr 28, 2026
@bokelley

Copy link
Copy Markdown
Contributor Author

Good catch — taking the split path. User groups are @-mention infrastructure only; you're right that the visual badge requires photo overlay.

What just shipped on this branch (commit 010f861):

  • Renamed addMemberBadge / removeMemberBadge → addToMemberUserGroup / removeFromMemberUserGroup so the function names match what they actually do
  • Updated log messages and changeset to describe the @aao-members user group for member @-mentions, not a visual badge
  • PR title updated to match

What's deferred to a follow-up:
The photo-overlay badge (steps 2–6 in your outline) needs two things before it can start:

  1. Design asset — a 256×256 PNG with transparent background from design
  2. Consent decision — whether to ship behind an admin-settings toggle before backfilling (recommend yes, per your outline)

Once those land, the implementation outline you wrote is solid. The slack_user_mappings table already has everything needed to look up slack_user_id from workos_user_id, so the photo fetch / composite / upload loop can wire in cleanly alongside this group logic.

One heads-up: the users.setPhoto upload requires the admin token (not the bot token), so the scope check in server/src/slack/client.ts will need to verify that separately from the usergroups:* scopes this PR added.

Session: https://claude.ai/code/session_017Ypq6RvZxi7gpP6WY873pw


Generated by Claude Code

@bokelley

Copy link
Copy Markdown
Contributor Author

Acknowledged — the rename to addToMemberUserGroup / removeFromMemberUserGroup reads cleanly.

Admin-token note captured: when the photo-overlay follow-up starts, the scope check in server/src/slack/client.ts will need a separate path for the users.setPhoto call (admin token, not bot token). Worth dropping that into the deferred issue so it doesn't get lost.

No changes needed on this PR from the comment.


Triaged by Claude Code. Session: https://claude.ai/code/session_01CGRda5StGzhtRsokW4tEUs


Generated by Claude Code

@bokelley

Copy link
Copy Markdown
Contributor Author

Refining the scope — we can build the photo-overlay infrastructure independently of the badge asset and the opt-in policy. Both layers should ship in this PR; only the placeholder badge needs to be swapped for the final design later.

Decoupling

Layer Ship now Gate
WorkOS webhook → Slack user lookup ✅ none
Photo fetch (users.profile.get) ✅ none
Image-composite util (bottom-right overlay, ~28%, white ring) ✅ none
Photo upload (users.setPhoto) ✅ gated by admin-settings toggle
Original-photo persistence (new column, e.g. slack_user_mappings.original_photo_url) ✅ none
Revert on organization_membership.deleted ✅ gated by toggle
Daily reconcile job (detect user-changed photos, re-overlay) ✅ gated by toggle
Admin-settings toggle: auto_apply_aao_badge (default OFF) ✅ none — but default OFF means no production effect until Mary flips it
"Apply to all members" backfill button + dry-run ✅ toggle must be ON
Per-user opt-out (e.g. /aao-badge off slash command or admin-side per-user toggle) ✅ toggle must be ON
Final badge asset PNG ❌ — design call swap into server/public/assets/aao-member-badge.png later

The placeholder asset can be a generated 256×256 SVG with "AAO" text + the existing brand color so the compositing/upload path is exercisable end-to-end before the real asset ships. The diff between placeholder and real-asset versions is one binary file swap.

Status of the user-group plumbing

Keep it. @aao-members user group has independent value (member-wide @-mentions). Just rename the changeset and PR description so it's clear this PR ships two things:

  1. @aao-members Slack user group (sync via WorkOS webhooks)
  2. Member-photo badge overlay infrastructure (gated by auto_apply_aao_badge admin toggle, default OFF)

Closes #2340 once both layers are in. The asset swap and toggle-flip are ops decisions that don't block the merge.

Ships the second independent Slack member-identity layer requested in
PR review: composite an AgenticAdvertising.org badge onto a member's
Slack profile photo, fully gated by the auto_apply_aao_badge toggle
(default OFF — no production effect until ops flips it).

Key pieces:
- sharp-based compositing (photo-badge.ts); placeholder SVG badge now,
  swap for final asset via aao-member-badge.png later
- DB migration 448 adds original_photo_url, badge_photo_applied_at,
  badge_applied_photo_url, badge_opt_out to slack_user_mappings
- badge_applied_photo_url stores the post-upload CDN URL so the daily
  reconcile job can detect when a member changes their own photo
  without stacking the overlay on an already-composited image
- SSRF guard in fetchImageBuffer rejects non Slack CDN hostnames
- apply/revert on organization_membership.{created,updated,deleted}
- auto_apply_aao_badge toggle in admin settings (default OFF)
- backfill endpoint (POST /api/admin/slack/apply-member-badge-backfill)
  requires toggle to be ON; dry_run=true available for counting
- per-user opt-out via /aao badge off slash command and admin API
- daily member-badge-reconcile job re-applies badge after photo change

https://claude.ai/code/session_01LD4FXUvaYs1bbjbUJBZuw5
@bokelley

Copy link
Copy Markdown
Contributor Author

Done — photo-badge infrastructure is now in the branch alongside the user-group layer.

What was added (commit 49313bf):

  • server/src/slack/photo-badge.ts — sharp-based compositing; placeholder SVG badge embeds AgAd initials in brand teal. Swap the SVG constant for the final PNG once design delivers it.
  • server/src/db/migrations/448_slack_badge_photo_columns.sql — adds original_photo_url, badge_photo_applied_at, badge_applied_photo_url, badge_opt_out to slack_user_mappings
  • applyMemberPhotoBadge / revertMemberPhotoBadge / reconcileMemberPhotoBadges in sync.ts, all gated by auto_apply_aao_badge toggle (default OFF)
  • Webhook hooks: apply on membership.created/updated (active status), revert on deleted/inactivation
  • auto_apply_aao_badge toggle wired into admin settings (GET/PUT /api/admin/settings)
  • POST /api/admin/slack/apply-member-badge-backfill?dry_run=true — requires toggle ON; dry-run returns eligible count without applying
  • POST /api/admin/slack/:slackUserId/badge-opt-out — per-user opt-out; reverts photo immediately if badge was active
  • /aao badge off / /aao badge on slash-command support
  • member-badge-reconcile daily job (re-applies badge if user changed their own photo)

Expert-review fixes applied before push:

  • Added badge_applied_photo_url column — stores the Slack CDN URL of the composited photo after upload. The daily reconcile now compares the current profile URL against this value (not original_photo_url), which was the root cause of the stacking bug (badge would re-composite onto an already-composited image every day).
  • SSRF guard in fetchImageBuffer — rejects any URL whose hostname doesn't end in .slack.com or .slack-edge.com.
  • getMembersWithBadgeApplied query now filters workos_user_id IS NOT NULL (consistent with the eligible-for-badge query).
  • Backfill endpoint returns 400 if the toggle is OFF (prevents misleading success counts).
  • Removed stale pre-check on badge_photo_applied_at in handleBadgeCommand — revertMemberPhotoBadge already guards internally.
  • MEMBER_BADGE_RECONCILE added to exported JOB_NAMES.
  • Removed unused image_original field from SlackUserProfileFull.
  • .rotate() replaces no-op .resize(width, height) for EXIF auto-orientation.

Ops checklist before enabling:

  1. Confirm SLACK_ADMIN_USER_TOKEN is set (user token, not bot token, with users:write + users.profile:read)
  2. Drop the placeholder SVG → swap in server/public/assets/aao-member-badge.png (or update the inline SVG constant)
  3. Flip auto_apply_aao_badge toggle ON via admin settings
  4. Run backfill: POST /api/admin/slack/apply-member-badge-backfill (dry-run first to check eligible count)

Both layers close #2340. The badge asset swap and toggle-flip are separate ops decisions that don't block merge.


Generated by Claude Code

@bokelley

Copy link
Copy Markdown
Contributor Author

Noted — photo-badge layer received. The expert-review fixes (stacking bug root cause, SSRF guard, workos_user_id filter, backfill 400 guard, reconcile flag cleanup) look solid. Ops checklist captured above is the only remaining gate before enabling. No further action from me on this pass.


Generated by Claude Code

@bokelley

Copy link
Copy Markdown
Contributor Author

Acknowledged — thank you for the pass. PR is parked in draft pending the ops checklist gate. No further bot action on this thread until the source issue is re-triggered or the ops checklist items are checked off.


Generated by Claude Code


Generated by Claude Code

@bokelley

Copy link
Copy Markdown
Contributor Author

Sunsetting — triage-bot draft sat 3 weeks with broken-links failing; source issue #2340 remains open and can be re-triggered with /triage execute when there's bandwidth to rescue. Closing the PR not the work.

@bokelley bokelley closed this May 19, 2026
bokelley added a commit that referenced this pull request Oct 26, 2026
* chore(deps): migrate to @adcp/sdk 17.0.0-beta.0 (AdCP 3.3 beta)

Move to @adcp/sdk 17.0.0-beta.0, which pins the signed AdCP 3.3.0-beta.0
bundle and retains stable 3.2.7, 3.1.29 and 3.0.25 bundles. Move
@adcp/reporting-storage to 0.2.1-beta.0, the beta-train release whose peer
range accepts SDK 17 (0.1.0 requires ^16.0.0 and left the tree invalid).

- catalog runner: forward the SDK-native fixture_preparation phase in the
  private audit record instead of a repo-shaped {disposition, phase}. The
  supplied-hook refusal stays: SDK 16.5 added the preparation authorizer
  (#3389), but this adapter's capability preflight still precedes it
  (adcp-client#3435).
- learner and production guidance names the stable SDK on npm latest
  (16.5.0); the choose-your-SDK page states SDK 17 beta support for the 3.3
  beta. tests/helpers/sdk-checkpoint.cjs encodes the rule.
- tests: discovery failure is terminal since SDK 16.5 (adcp-client#3392);
  context_key is echoed (#3396); the identity33 house-authority fix shipped
  (#3388); a prerelease pin needs the exact advertised preview.
- SDK response-conformance baseline re-recorded under 17.0.0-beta.0 with
  identical evidence apart from the version.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* fix(training-agent): keep SDK 17 storyboard and preparation evidence native

- Routed requires: [multi_agent] storyboards: the runner's http loopback
  made identity.brand_json_url schema-invalid (3.2+ needs https), and SDK
  16.5+ fails discovery for capability-gated storyboards on invalid
  capabilities. A harness-only TRAINING_AGENT_IDENTITY_URL keeps the public
  https identity for those runs; deployments never set it.
- Catalog runner: when a native result omits producer records, fill the
  SDK-native fixture_resolutions and fixture_preparation (protected captures
  stripped) instead of a repo-shaped per-record failure.
- Reporting tests assert SDK 16.5+ native failed-preparation evidence.
- Known limitations: SDK #3395 is fixed upstream by adcp-client#3439, not
  yet released.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* docs(reference): add changeset for the SDK known-limitations update

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* fix(training-agent): let test harnesses that disable rate limits skip the buyer OAuth limiter

SDK 17 opens more MCP sessions per client, which pushed the buyer OAuth
integration test's loopback traffic past the per-IP 60/min buyer limiter.
createTrainingAgentRouter({ disableRateLimit: true }) now also skips that
limiter; production keeps it (default on, unit-tested).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

claude-triaged Issue has been triaged by the Claude Code triage routine. Remove to re-triage.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add member badges to Slack workspace

2 participants