feat(tasks): send slack dms for channel thread @-mentions#72087
Draft
adboio wants to merge 1 commit into
Draft
Conversation
When a thread message @-mentions org members, a Celery task (dispatched on commit from the existing mention-indexing choke point) DMs each mentioned user who opted in, via the team's Slack integration. Opt-in is a new per-user CodeUserNotificationSettings model exposed at /api/code/user_settings/ for the PostHog Code client. Generated-By: PostHog Code Task-Id: 69e0939c-e6e1-4efa-9d5e-771b88f03b5a
Contributor
|
Hey @adboio! 👋 It looks like your git author email on this PR isn't your
You can fix it for this repo with: git config user.email "you@posthog.com"Or set it globally with |
adboio
added a commit
to PostHog/code
that referenced
this pull request
Jul 17, 2026
Opt-in setting (default off) in the Slack settings section, gated behind the project-bluebird flag. Reads/writes the new /api/code/user_settings/ endpoint; delivery itself is backend-driven via the team's Slack integration (PostHog/posthog#72087). Generated-By: PostHog Code Task-Id: 69e0939c-e6e1-4efa-9d5e-771b88f03b5a
2 tasks
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.
Problem
@-mentions in PostHog Code channel threads are pull-only today: they're indexed at write time (
TaskThreadMessageMention) and surfaced in the client's Activity feed via a 60s poll, with no push notification of any kind. If you're not in the app, you don't find out someone needs you.This adds an opt-in Slack DM when you're @-mentioned, reusing the team's existing Slack integration (raised in a project-bluebird channel task).
Changes
products/tasks/backend/slack_mention_notifications.py: builds and sends the DM ("Ann mentioned you in #growth" + task title + quoted excerpt + "Open in PostHog" link to the cloud task page). Content is mrkdwn-escaped and truncated; mention tokens render as plain@Name.products/tasks/backend/tasks.py, autodiscovered) fired viatransaction.on_commitfrom_index_thread_message_mentions— the single choke point both human- and agent-authored messages already flow through. Best-effort end to end: one recipient's failure never blocks the others, and nothing can fail message creation.CodeUserNotificationSettingsmodel (default off), exposed atGET/POST /api/code/user_settings/for the PostHog Code client. Recipients are resolved per team at send time (Integrationkindslack), so the preference itself doesn't need team scoping.SlackIntegration.lookup_user_id_by_emailpromoted onto the core helper (ported from the signals product's implementation) — usesusers_lookupByEmail, which is already in the always-granted scope set along withchat:write, so no new Slack scopes or re-auth.render_mention_tokensadded tomentions.py(pattern switched to named groups, behavior-preserving).Note
The preference defaults off and is only settable from the (flag-gated) PostHog Code settings UI, so there's no server-side flag check — an opt-in row is an explicit user signal. A companion PostHog Code PR adds the settings toggle.
How did you test this code?
Automated tests added (not run in this sandbox — no Django environment; CI will run them):
test_mentions.py:render_mention_tokenscases — catches the DM showing raw@[Name](email)tokens or mangling non-token text.test_mention_slack_notifications.py: opt-in filtering (no row / disabled row → no DM), missing integration and missing Slack account guards, per-recipient failure isolation, agent-author + channel-less fallbacks, escaping/truncation.test_channels_api.py: posting a mention dispatches exactly one DM throughon_commit+ eager Celery (catches the wiring being dropped); a Slack blow-up still returns 201; settings API defaults, upsert, per-user isolation, and auth.ruff checkandruff formatpass on all touched files. The migration was written by hand (mirrors sibling migrations,db_constraint=Falseon the user FK per the hot-table rule) — please verifymakemigrations --checkandhogli build:openapioutput; I couldn't run either here.Automatic notifications
Docs update
No docs under
docs/cover the mentions feed or Code notification settings yet.🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Authored by Claude via a PostHog Code cloud task, directed by the assignee. Repo skills read before writing:
/django-migrations,/improving-drf-endpoints,/writing-tests.Decisions along the way: Celery over Temporal for the send (matches the main app's comment-mention precedent; Temporal here is the long-running-run machinery), cloud web URL over a
posthog-code://deep link (matchespost_slack_update.py, works on mobile), a user-scoped opt-in model rather than reusing the signalsSignalUserAutonomyConfig(different product, and mentions DM the user directly instead of posting to a chosen channel), and promoting the email→Slack-id lookup ontoSlackIntegrationbecause the signals implementation sits behind a product boundary.Created with PostHog Code