: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
feat(conversations): include author_email on ticket messages (#91034)
Christiaan Hendriksene67c5a7bc7ea
diff --git a/products/conversations/backend/api/tests/test_tickets.py b/products/conversations/backend/api/tests/test_tickets.pyindex f3aa6ba40845..e94c8b4914ea 100644--- a/products/conversations/backend/api/tests/test_tickets.py+++ b/products/conversations/backend/api/tests/test_tickets.py@@ -2265,6 +2265,7 @@ class TestTicketMessagesAPI(APIBaseTest):"rich_content","author_type","author_name",+ "author_email","is_private","has_full_email_content","created_at",@@ -2285,6 +2286,49 @@ class TestTicketMessagesAPI(APIBaseTest):assert response.status_code == status.HTTP_200_OKassert len(response.json()["results"]) == 1+ def test_messages_support_author_uses_full_name(self, mock_on_commit):+ self.user.first_name = "Jane"+ self.user.last_name = "Doe"+ self.user.save()+ Comment.objects.create(+ team=self.team,+ created_by=self.user,+ scope="conversations_ticket",+ item_id=str(self.ticket.id),+ content="On it",+ item_context={"author_type": "support", "is_private": False},+ )++ response = self.client.get(self.url)+ assert response.status_code == status.HTTP_200_OK+ assert response.json()["results"][0]["author_name"] == "Jane Doe"++ def test_messages_author_email_only_for_posthog_users(self, mock_on_commit):+ base = timezone.now()+ for offset, (content, author_type, author) in enumerate(+ [+ ("Hello from customer", "customer", None),+ ("Hi there!", "support", self.user),+ ("Summary", "AI", None),+ ]+ ):+ comment = Comment.objects.create(+ team=self.team,+ created_by=author,+ scope="conversations_ticket",+ item_id=str(self.ticket.id),+ content=content,+ item_context={"author_type": author_type, "is_private": False},+ )+ Comment.objects.filter(id=comment.id).update(created_at=base + timedelta(seconds=offset))++ response = self.client.get(self.url)+ assert response.status_code == status.HTTP_200_OK+ body = response.json()["results"]+ assert body[0]["author_email"] is None+ assert body[1]["author_email"] == self.user.email+ assert body[2]["author_email"] is None+@parameterized.expand([("customer_with_name", {"name": "Bob", "email": "[email protected]"}, "customer", {}, "Bob"),@@ -2486,7 +2530,7 @@ class TestTicketReplyAPI(APIBaseTest):assert body["content"] == "A reply"assert body["author_type"] == "support"assert body["is_private"] is is_private- assert body["author_name"] == (self.user.first_name or self.user.email)+ assert body["author_name"] == (f"{self.user.first_name} {self.user.last_name}".strip() or self.user.email)comment = Comment.objects.get(id=body["id"])assert comment.created_by == self.userdiff --git a/products/conversations/backend/api/tickets.py b/products/conversations/backend/api/tickets.pyindex e14aeb8349f5..ed0921ca5f7e 100644--- a/products/conversations/backend/api/tickets.py+++ b/products/conversations/backend/api/tickets.py@@ -119,6 +119,14 @@ class TicketMessageSerializer(serializers.Serializer):rich_content = serializers.JSONField(read_only=True, allow_null=True, help_text="TipTap rich content JSON, if any.")author_type = serializers.CharField(read_only=True, help_text="One of: customer, support, AI.")author_name = serializers.CharField(read_only=True, help_text="Display name of the author.")+ author_email = serializers.EmailField(+ read_only=True,+ allow_null=True,+ help_text=(+ "Email of the authoring PostHog user, when the message was written by one "+ "(support replies and internal notes). Null for customer and AI messages."+ ),+ )is_private = serializers.BooleanField(read_only=True, help_text="True for internal notes not visible to the customer.")@@ -1371,7 +1379,9 @@ class TicketViewSet(TaggedItemViewSetMixin, TeamAndOrgViewSetMixin, AccessContro)if comment.created_by:- author_name = comment.created_by.first_name or comment.created_by.email+ author_name = (+ f"{comment.created_by.first_name} {comment.created_by.last_name}".strip() or comment.created_by.email+ )elif author_type == "AI":author_name = "PostHog Assistant"elif context_author_name:@@ -1388,6 +1398,7 @@ class TicketViewSet(TaggedItemViewSetMixin, TeamAndOrgViewSetMixin, AccessContro"rich_content": comment.rich_content,"author_type": author_type,"author_name": author_name,+ "author_email": comment.created_by.email if comment.created_by else None,"is_private": item_context.get("is_private") is True,"has_full_email_content": item_context.get("has_full_email_content") is True,"version": comment.version,diff --git a/products/conversations/frontend/generated/api.schemas.ts b/products/conversations/frontend/generated/api.schemas.tsindex 47aea9cf4ff2..3a347ff101db 100644--- a/products/conversations/frontend/generated/api.schemas.ts+++ b/products/conversations/frontend/generated/api.schemas.ts@@ -395,6 +395,11 @@ export interface TicketMessageApi {readonly author_type: string/** Display name of the author. */readonly author_name: string+ /**+ * Email of the authoring PostHog user, when the message was written by one (support replies and internal notes). Null for customer and AI messages.+ * @nullable+ */+ readonly author_email: string | null/** True for internal notes not visible to the customer. */readonly is_private: boolean/** True when the complete inbound email body can be retrieved. */diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 2f6639a48ad7..960562290f96 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -58665,6 +58665,11 @@ export namespace Schemas {readonly author_type: string;/** Display name of the author. */readonly author_name: string;+ /**+ * Email of the authoring PostHog user, when the message was written by one (support replies and internal notes). Null for customer and AI messages.+ * @nullable+ */+ readonly author_email: string | null;/** True for internal notes not visible to the customer. */readonly is_private: boolean;/** True when the complete inbound email body can be retrieved. */