sending-notifications
Skill731 starsChanged 3 days agoMITView on GitHub
How to send real-time in-app notifications from PostHog backend code. Use when integrating notifications into a new feature, wiring up a notification source (alerts, comments, approvals, pipelines, issues), or choosing the right target type and priority for a notification.
2 other projects use a version of this.
Adopted by
Most recently taken up by
- DevinoSolutions/claude-pluginstheir own version, first seen Nov 15, 2026
- PostHog/posthogword for word, first seen Nov 14, 2026
Other versions2 projects use a version of this.
Word for word · 1
- PostHog/posthog★ 41k100% same
Edited · 0
None found.
Wrote their own version · 1
- DevinoSolutions/claude-plugins★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository127 other files it gives its agents.
- AGENTS.mdAGENTS.md
- common/AGENTS.mdAGENTS.md
- hog/AGENTS.mdAGENTS.md
- proto/AGENTS.mdAGENTS.md
- rust/AGENTS.mdAGENTS.md
- .cursor/rules/django-python.mdcCursor rule
- .cursor/rules/react-typescript.mdcCursor rule
- .cursor/rules/rust.mdcCursor rule
- adding-activity-loggingSkill
- adding-api-scopesSkill
- adding-inbound-webhooksSkill
- adding-inbox-sourcesSkill
- adding-ingestion-warningsSkill
- adding-mcp-store-serversSkill
- adding-personhog-rpcSkill
- adding-product-alertingSkill
- adding-project-secret-api-key-authSkill
- adding-today-highlightsSkill
- adopting-generated-api-typesSkill
- analyzing-experiment-precompute-canarySkill
- analyzing-experiment-query-performanceSkill
- analyzing-insights-across-teamsSkill
- announcing-behavior-changesSkill
- auditing-llm-gateway-paritySkill
- auditing-warehouse-source-coverageSkill
- authenticating-to-clickhouseSkill
- authoring-ci-workflowsSkill
- building-product-empty-statesSkill
- building-the-toolbarSkill
- clickhouse-migrationsSkill
- creating-customer-analytics-account-widgetsSkill
- debugging-ci-failuresSkill
- debugging-local-replaySkill
- debugging-local-task-agent-runsSkill
- debugging-mcp-analyticsSkill
- debugging-signals-pipelineSkill
- debugging-table-access-deniedSkill
- depot-ciSkill
- depot-container-buildsSkill
- depot-github-runnersSkill
- developing-subscriptionsSkill
- developing-the-cliSkill
- django-migrationsSkill
- django-startup-timeSkill
- documenting-warehouse-sourcesSkill
- editing-agents-mdSkill
- establishing-code-ownershipSkill
- extending-hobby-smoke-testsSkill
- extending-personhog-test-harnessSkill
- extending-the-admin-consoleSkill
- finding-llm-gateway-migration-candidatesSkill
- fixing-flaky-testsSkill
- formatting-slack-messagesSkill
- gating-production-deploysSkill
- gating-sensitive-actionsSkill
- generating-clickhouse-query-performance-reportsSkill
- hogliSkill
- implementing-mcp-toolsSkill
- implementing-mcp-ui-appsSkill
- implementing-warehouse-sourcesSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 1 is distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 14
All notification creation goes through a single function.
- Very specific: line 99
When resource_type matches an access-controlled resource (dashboard, feature_flag, experiment, etc.), recipients without viewer access are …
- Very specific: line 117
Add enum value in products/notifications/backend/facade/enums.py
- Very specific: line 118
Add icon mapping in frontend/src/lib/components/NotificationsMenu/notificationToasts.tsx (NOTIFICATION_TYPE_ICONS) — the single icon …
- Very specific: line 119
Add a label + description entry in frontend/src/lib/components/NotificationsMenu/NotificationRow.tsx (REALTIME_NOTIFICATION_TYPE_META) — …
≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Sending real-time notifications
When to use this
You're adding notification support to a PostHog feature — for example, notifying a user when they're mentioned in a comment, when an alert fires, or when an approval is requested.
The facade API
All notification creation goes through a single function. Import from the facade, not from internal modules:
from products.notifications.backend.facade.api import (
create_notification,
NotificationData,
NotificationType,
Priority,
TargetType,
)Build a NotificationData and call create_notification:
event = create_notification(
NotificationData(
team_id=team.id,
notification_type=NotificationType.ALERT_FIRING,
priority=Priority.CRITICAL,
title="Event ingestion latency > 30s",
body="Events are queuing up. Ingestion pipeline is degraded.",
target_type=TargetType.USER,
target_id=str(user.id),
resource_type="dashboard",
resource_id="42",
source_url="/dashboard/42",
)
)Returns a NotificationEvent on success, or None if the feature flag is disabled, no recipients were resolved, or the team doesn't exist. Safe to call in any context.
NotificationData fields
Required:
| Field | Type | Description |
team_id | int | Team context — used to look up the organization and check the feature flag |
notification_type | NotificationType | Determines the icon in the UI |
title | str | Notification headline (~100 chars recommended) |
body | str | Longer description shown on expand. Can be empty string |
target_type | TargetType | Who receives this: user, team, organization, or role |
target_id | str | ID of the target (user ID, team ID, org UUID, or role UUID as string) |
Optional:
| Field | Type | Default | Description |
resource_type | NotificationResourceType | None | None | Access-controlled types (e.g. "dashboard") auto-filter recipients without viewer access |
resource_id | str | "" | ID of the resource for linking |
source_url | str | "" | Relative URL path (e.g. /dashboard/42), shown as link icon in UI |
priority | Priority | NORMAL | normal = popover only; critical = popover + persistent toast |
archivable | bool | False | Opt in to a per-recipient "archive" (dismiss) action that moves the notification to the recipient's Archived tab. When False, recipients can only mark it read/unread (the default pattern) |
resolver | RecipientsResolver | None | None | Custom recipient resolver. Default handles user/team/org/role targeting |
Choosing parameters
Notification type
| Type | When to use |
comment_mention | User was @mentioned in a comment or discussion |
alert_firing | A monitoring alert threshold was breached |
approval_requested | A change requires the user's approval |
approval_resolved | An approval the user requested has been resolved |
pipeline_failure | A data pipeline or batch export failed |
issue_assigned | An error tracking issue was assigned to the user |
Priority
Be very careful with critical. It triggers a persistent toast popup that overlays the user's screen and must be manually dismissed. This is intentionally intrusive — reserve it for genuine emergencies like outages, security alerts, or SLA breaches. Overusing critical will train users to ignore notifications entirely. When in doubt, use normal.
Target type
| Target | target_id value | Recipients |
user | User ID | Just that user |
team | Team ID | All members of the team's organization |
organization | Organization ID | All organization members |
role | Role ID | All users with that RBAC role |
Resource type and access control
When resource_type matches an access-controlled resource (dashboard, feature_flag, experiment, etc.), recipients without viewer access are automatically excluded. For notification-only types (pipeline, approval, comment), no AC filtering is applied.
Delivery pipeline
Django (create_notification)
→ Postgres (NotificationEvent row)
→ Kafka (notification_events topic, on transaction commit)
→ Go livestream service (Kafka consumer)
→ Redis SPUBLISH (sharded pub/sub, keyed by org ID)
→ SSE (/notifications endpoint)
→ Browser (popover + optional toast)Kafka publish happens on transaction.on_commit — won't fire if the transaction rolls back.
Adding a new notification type
- Add enum value in
products/notifications/backend/facade/enums.py - Add icon mapping in
frontend/src/lib/components/NotificationsMenu/notificationToasts.tsx(NOTIFICATION_TYPE_ICONS) — the single icon source, read bygetNotificationIcon, which onlyNotificationRowcalls; the side panel gets the icon by rendering that row - Add a label + description entry in
frontend/src/lib/components/NotificationsMenu/NotificationRow.tsx(REALTIME_NOTIFICATION_TYPE_META) — drives the per-type notification preferences UI - Run
python manage.py makemigrations notifications
Testing
Mock the feature flag in tests:
from unittest.mock import patch
with patch("posthoganalytics.feature_enabled", side_effect=lambda flag, *a, **kw: flag == "real-time-notifications"):
event = create_notification(data)Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

