Skip to content

: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.

feat(conversations): emit message sent event for private team notes (#76685)

Christian Rafferty3a76c664856b
diff --git a/frontend/src/taxonomy/core-filter-definitions-by-group.json b/frontend/src/taxonomy/core-filter-definitions-by-group.json
index 26bff736d078..12168c9b0a4b 100644
--- a/frontend/src/taxonomy/core-filter-definitions-by-group.json
+++ b/frontend/src/taxonomy/core-filter-definitions-by-group.json
@@ -3850,6 +3850,10 @@
"description": "Fires when a message is sent in a support conversation.",
"label": "Conversation message sent"
},
+ "$conversation_private_message_sent": {
+ "description": "Fires when a team member sends a private note in a support conversation.",
+ "label": "Conversation private message sent"
+ },
"$conversation_ticket_assigned": {
"description": "Fires when a support conversation ticket is assigned to an actor.",
"label": "Conversation ticket assigned"
diff --git a/posthog/taxonomy/taxonomy.py b/posthog/taxonomy/taxonomy.py
index b0d2ab9cdd45..42d173dd0f20 100644
--- a/posthog/taxonomy/taxonomy.py
+++ b/posthog/taxonomy/taxonomy.py
@@ -455,6 +455,10 @@ CORE_FILTER_DEFINITIONS_BY_GROUP: dict[str, dict[str, CoreFilterDefinition]] = {
"label": "Conversation message sent",
"description": "Fires when a message is sent in a support conversation.",
},
+ "$conversation_private_message_sent": {
+ "label": "Conversation private message sent",
+ "description": "Fires when a team member sends a private note in a support conversation.",
+ },
"$conversation_message_received": {
"label": "Conversation message received",
"description": "Fires when a message is received in a support conversation.",
diff --git a/products/conversations/backend/api/tests/test_signals.py b/products/conversations/backend/api/tests/test_signals.py
index e0aabe7cb814..aeb0fc5e11b1 100644
--- a/products/conversations/backend/api/tests/test_signals.py
+++ b/products/conversations/backend/api/tests/test_signals.py
@@ -208,6 +208,34 @@ class TestTicketMessageSignals(BaseTest):
assert self.ticket.last_message_at == public_msg.created_at # Unchanged
assert self.ticket.updated_at == public_msg.created_at # Unchanged
+ @patch("products.conversations.backend.events.capture_internal")
+ def test_private_team_note_emits_private_message_sent_event(self, mock_capture, mock_on_commit):
+ self._create_team_message("Private note", is_private=True)
+
+ self.ticket.refresh_from_db()
+ assert self.ticket.message_count == 0
+ mock_capture.assert_called_once()
+ call_kwargs = mock_capture.call_args.kwargs
+ assert call_kwargs["event_name"] == "$conversation_private_message_sent"
+ assert call_kwargs["properties"]["actor_id"] == self.user.id
+ # The note body must never reach the event stream: analytics events are
+ # team-scoped and bypass ticket-level access controls
+ assert "message_content" not in call_kwargs["properties"]
+ assert "Private note" not in str(call_kwargs["properties"])
+
+ @patch("products.conversations.backend.events.capture_internal")
+ def test_private_ai_message_emits_no_event(self, mock_capture, mock_on_commit):
+ # Private AI messages have no human actor; emitting them would fire workflows with an empty actor
+ Comment.objects.create(
+ team=self.team,
+ scope="conversations_ticket",
+ item_id=str(self.ticket.id),
+ content="AI draft suggestion",
+ item_context={"author_type": "AI", "is_private": True},
+ )
+
+ mock_capture.assert_not_called()
+
def test_soft_delete_private_message_does_not_decrement_count(self, mock_on_commit):
"""Deleting a private message should not decrement message_count (since it wasn't counted)."""
self._create_customer_message("Public message")
diff --git a/products/conversations/backend/events.py b/products/conversations/backend/events.py
index d9446dbe6fef..76326178bdbb 100644
--- a/products/conversations/backend/events.py
+++ b/products/conversations/backend/events.py
@@ -523,16 +523,17 @@ def capture_ticket_assigned(
)
-def capture_message_sent(
+def _capture_team_message(
ticket: Ticket,
message_id: str,
- message_content: str,
- author: User | None = None,
+ message_content: str | None,
+ author: User | None,
+ event_name: str,
) -> None:
- """Team member sent a message on a ticket."""
properties = _get_ticket_base_properties(ticket)
properties["message_id"] = message_id
- properties["message_content"] = (message_content or "")[:1000]
+ if message_content is not None:
+ properties["message_content"] = (message_content or "")[:1000]
properties["author_type"] = "team"
properties.update(_get_actor_properties(author, "user"))
properties.update(_get_customer_properties(ticket, include_distinct_id=True))
@@ -541,7 +542,7 @@ def capture_message_sent(
capture_internal(
token=ticket.team.api_token,
- event_name="$conversation_message_sent",
+ event_name=event_name,
event_source=EVENT_SOURCE,
distinct_id=_get_actor_distinct_id(ticket, author, "user"),
timestamp=None,
@@ -549,6 +550,33 @@ def capture_message_sent(
)
+def capture_message_sent(
+ ticket: Ticket,
+ message_id: str,
+ message_content: str,
+ author: User | None = None,
+) -> None:
+ """Team member sent a public reply on a ticket."""
+ _capture_team_message(ticket, message_id, message_content, author, "$conversation_message_sent")
+
+
+def capture_private_message_sent(
+ ticket: Ticket,
+ message_id: str,
+ author: User | None = None,
+) -> None:
+ """Team member sent a private internal note on a ticket.
+
+ Deliberately a separate event from `$conversation_message_sent`: existing
+ workflows trigger on that event to notify customers, and private notes must
+ never flow through those.
+
+ The note body is deliberately omitted. Analytics events are queryable by any
+ project member, so including it would bypass ticket-level access controls.
+ """
+ _capture_team_message(ticket, message_id, None, author, "$conversation_private_message_sent")
+
+
def capture_message_received(ticket: Ticket, message_id: str, message_content: str) -> None:
"""Customer sent a message on a ticket."""
properties = _get_ticket_base_properties(ticket)
diff --git a/products/conversations/backend/signals.py b/products/conversations/backend/signals.py
index 29e84266bceb..7944bb3cc048 100644
--- a/products/conversations/backend/signals.py
+++ b/products/conversations/backend/signals.py
@@ -17,7 +17,7 @@ from posthog.models.instance_setting import get_instance_setting
from posthog.models.signals import secret_api_token_rotated
from .cache import invalidate_messages_cache, invalidate_tickets_cache
-from .events import capture_message_received, capture_message_sent, capture_ticket_created
+from .events import capture_message_received, capture_message_sent, capture_private_message_sent, capture_ticket_created
from .models import EmailOutboxMessage, SigningSecret, Ticket
from .models.constants import Channel
from .tasks import (
@@ -103,6 +103,7 @@ def update_ticket_on_message(sender, instance: Comment, created: bool, **kwargs)
Private messages are excluded from denormalized stats to prevent leaking
to widget via last_message_text and to keep message_count accurate for customers.
+ Human team notes emit `$conversation_private_message_sent` instead of the public event.
Uses transaction.on_commit() to defer work and avoid blocking the request.
"""
@@ -125,12 +126,27 @@ def update_ticket_on_message(sender, instance: Comment, created: bool, **kwargs)
created_by_id = _get_comment_created_by_id(instance)
def do_update():
- # Private messages don't update denormalized stats (to avoid leaking to widget)
+ author_type = item_context.get("author_type") if isinstance(item_context, dict) else None
+
+ # Private messages don't update denormalized stats (to avoid leaking to widget).
+ # Human team notes emit `$conversation_private_message_sent` — a separate event
+ # that carries no note body — so workflows on `$conversation_message_sent`
+ # (e.g. customer notifications) never receive private content, and the event
+ # stream never exposes note text to members without access to the ticket.
if _is_private_message(item_context):
+ if not (created_by_id and author_type != "customer"):
+ return
+ try:
+ ticket = Ticket.objects.select_related("team").get(id=item_id, team_id=team_id)
+ author = User.objects.filter(id=created_by_id).first()
+ capture_private_message_sent(ticket, comment_id, author=author)
+ except Ticket.DoesNotExist:
+ pass
+ except Exception as e:
+ capture_exception(e, {"ticket_id": item_id})
return
# New message: update denormalized stats
- author_type = item_context.get("author_type") if isinstance(item_context, dict) else None
is_team_message = (created_by_id and author_type != "customer") or (
author_type == "AI" and not _is_private_message(item_context)
)
diff --git a/products/product_analytics/frontend/insights/trends/shared/humanizeSeriesLabel.ts b/products/product_analytics/frontend/insights/trends/shared/humanizeSeriesLabel.ts
index 2f20c9aa891b..993e55ef4f38 100644
--- a/products/product_analytics/frontend/insights/trends/shared/humanizeSeriesLabel.ts
+++ b/products/product_analytics/frontend/insights/trends/shared/humanizeSeriesLabel.ts
@@ -14,6 +14,7 @@ const POSTHOG_EVENT_DISPLAY_NAMES: Record<string, string> = {
$capture_metrics: 'Capture metrics',
$conversation_message_received: 'Conversation message received',
$conversation_message_sent: 'Conversation message sent',
+ $conversation_private_message_sent: 'Conversation private message sent',
$conversation_ticket_assigned: 'Conversation ticket assigned',
$conversation_ticket_created: 'Conversation ticket created',
$conversation_ticket_priority_changed: 'Conversation ticket priority changed',
diff --git a/products/workflows/frontend/Workflows/hogflows/registry/triggers/conversations.tsx b/products/workflows/frontend/Workflows/hogflows/registry/triggers/conversations.tsx
index 26be95f4ed3f..79b2712743df 100644
--- a/products/workflows/frontend/Workflows/hogflows/registry/triggers/conversations.tsx
+++ b/products/workflows/frontend/Workflows/hogflows/registry/triggers/conversations.tsx
@@ -85,6 +85,10 @@ const SUPPORT_TRIGGER_META: Record<string, { name: string; description: string }
name: 'Ticket message sent',
description: 'This trigger runs when a teammate sends a reply on a ticket.',
},
+ $conversation_private_message_sent: {
+ name: 'Ticket private note sent',
+ description: 'This trigger runs when a teammate sends a private note on a ticket.',
+ },
$conversation_ticket_assigned: {
name: 'Ticket assigned',
description: 'This trigger runs when a ticket is assigned to a teammate or team.',
@@ -186,6 +190,22 @@ registerTriggerType({
ConfigComponent: StepTriggerConfigurationSupportFilters,
})
+registerTriggerType({
+ value: 'support_private_message_sent',
+ label: 'Ticket private note sent',
+ icon: <IconBolt />,
+ description: 'Trigger when a teammate sends a private note on a ticket',
+ group: 'Support',
+ matchConfig: (config) => config.type === 'event' && getEventId(config) === '$conversation_private_message_sent',
+ buildConfig: () => ({
+ type: 'event',
+ filters: {
+ events: [{ id: '$conversation_private_message_sent', type: 'events', name: 'Ticket private note sent' }],
+ },
+ }),
+ ConfigComponent: StepTriggerConfigurationSupportFilters,
+})
+
registerTriggerType({
value: 'support_message_received',
label: 'Ticket message received',