:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
from __future__ import annotations
from django.db import models
from posthog.models.scoping.root_mixin import TeamScopedRootMixin
from posthog.models.utils import CreatedMetaFields, UpdatedMetaFields, UUIDModel
from posthog.utils import generate_short_id
class Announcement(TeamScopedRootMixin, UUIDModel, CreatedMetaFields, UpdatedMetaFields):
class Status(models.TextChoices):
PENDING = "pending", "Pending"
SENDING = "sending", "Sending"
SENT = "sent", "Sent"
PARTIALLY_FAILED = "partially_failed", "Partially failed"
FAILED = "failed", "Failed"
class SendAs(models.TextChoices):
BOT = "bot", "SupportHog"
USER = "user", "The person who created it"
all_teams = models.Manager() # noqa: DJ012
team = models.ForeignKey("posthog.Team", on_delete=models.CASCADE, db_constraint=False, related_name="+")
created_by = models.ForeignKey(
"posthog.User", on_delete=models.SET_NULL, null=True, blank=True, db_constraint=False, related_name="+"
)
short_id = models.CharField(max_length=12, blank=True, default=generate_short_id)
message = models.TextField()
status = models.CharField(max_length=20, choices=Status.choices, default=Status.PENDING)
send_as = models.CharField(max_length=20, choices=SendAs.choices, default=SendAs.BOT)
# Slack name and avatar resolved from created_by when send_as is USER. Snapshotted at
# create time so every channel gets the same identity, even if the Slack profile
# changes (or becomes unresolvable) while the send task runs.
sender_display_name = models.CharField(max_length=200, blank=True, default="")
sender_icon_url = models.TextField(blank=True, default="")
total_channels = models.PositiveIntegerField(default=0)
sent_count = models.PositiveIntegerField(default=0)
failed_count = models.PositiveIntegerField(default=0)
sent_at = models.DateTimeField(null=True, blank=True)
class Meta(TeamScopedRootMixin.Meta):
default_manager_name = "all_teams"
indexes = [
models.Index(fields=["team_id", "-created_at"], name="ca_announcement_team_idx"),
]
def __str__(self) -> str:
return f"Announcement({self.short_id}, status={self.status})"