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.

fix(conversations): attach recipient email to outbound tickets (#74197)

Jovan Sakovica9730fbd9e71
diff --git a/products/conversations/backend/api/tests/test_tickets.py b/products/conversations/backend/api/tests/test_tickets.py
index 04f650686a6d..6bbe32b8bee9 100644
--- a/products/conversations/backend/api/tests/test_tickets.py
+++ b/products/conversations/backend/api/tests/test_tickets.py
@@ -1930,6 +1930,24 @@ class TestComposeTicketAPI(APIBaseTest):
ticket = Ticket.objects.get(team=self.team)
assert ticket.identity_verified is None
+ def test_composed_ticket_stores_recipient_email_in_traits(self, mock_on_commit):
+ response = self._compose(
+ {
+ "recipient_email": "[email protected]",
+ "email_config_id": str(self.email_config.id),
+ "message": "Hello!",
+ }
+ )
+ assert response.status_code == status.HTTP_201_CREATED
+ ticket = Ticket.objects.get(team=self.team)
+ assert ticket.anonymous_traits == {"email": "[email protected]"}
+
+ search = self.client.get(
+ f"/api/projects/{self.team.id}/conversations/tickets/[email protected]",
+ )
+ assert search.status_code == status.HTTP_200_OK
+ assert [t["id"] for t in search.json()["results"]] == [str(ticket.id)]
+
class TestTicketPersonalAPIKeyScopes(APIBaseTest):
def _auth_with_pak(self, scopes: list[str]) -> None:
diff --git a/products/conversations/backend/api/tickets.py b/products/conversations/backend/api/tickets.py
index 7808ca3b8988..00823c8828e7 100644
--- a/products/conversations/backend/api/tickets.py
+++ b/products/conversations/backend/api/tickets.py
@@ -1467,8 +1467,11 @@ class TicketViewSet(TaggedItemViewSetMixin, TeamAndOrgViewSetMixin, AccessContro
status=Status.OPEN,
widget_session_id=str(uuid.uuid4()),
email_config=email_config,
- email_from=data["recipient_email"],
+ email_from=recipient_email,
email_subject=data.get("email_subject", ""),
+ # Ticket search, the person display and restore-by-email all read the
+ # customer's address from traits, so outbound tickets must carry it too.
+ anonymous_traits={"email": recipient_email},
# The recipient hasn't proven control of this address — a team member just typed it —
# so leave identity unknown. It's promoted to verified if/when they reply and authenticate.
identity_verified=None,
diff --git a/products/conversations/frontend/scenes/ticket/supportTicketSceneLogic.ts b/products/conversations/frontend/scenes/ticket/supportTicketSceneLogic.ts
index bc46c3ca0b44..660ba302f085 100644
--- a/products/conversations/frontend/scenes/ticket/supportTicketSceneLogic.ts
+++ b/products/conversations/frontend/scenes/ticket/supportTicketSceneLogic.ts
@@ -1074,7 +1074,9 @@ export const supportTicketSceneLogic = kea<supportTicketSceneLogicType>([
impersonationNoticeLogic.findMounted()?.actions.setTicketContext({
ticketId: ticket.id,
- email: ticket.anonymous_traits?.email || '',
+ // email_from is the customer's address on email tickets, and it's the only
+ // place it lives on tickets whose traits were never populated.
+ email: ticket.anonymous_traits?.email || ticket.email_from || '',
region: regionFromUrl(ticket.session_context?.current_url),
})