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): route the Slack ticket button by who clicks it (#102113)

Alex V10d1ffbf3456
diff --git a/products/conversations/backend/api/tests/test_slack_message_routing.py b/products/conversations/backend/api/tests/test_slack_message_routing.py
index 88557efa0a8b..bdae874f7595 100644
--- a/products/conversations/backend/api/tests/test_slack_message_routing.py
+++ b/products/conversations/backend/api/tests/test_slack_message_routing.py
@@ -28,6 +28,7 @@ from products.conversations.backend.slack import (
handle_support_mention,
handle_support_message,
handle_support_reaction,
+ my_tickets_link,
ticket_created_blocks,
ticket_deep_link,
)
@@ -1398,20 +1399,23 @@ class TestSupporthogInteractivity(BaseTest):
assert kwargs["user"] == "U_CLICKER"
assert kwargs["thread_ts"] == MESSAGE_TS
assert ticket_deep_link(ticket, self.team) in kwargs["text"]
+ assert my_tickets_link(ticket) not in kwargs["text"]
client.chat_postMessage.assert_not_called()
client.chat_update.assert_not_called()
assert self._link_click_properties()["is_org_member"] is True
@patch(f"{TASKS_MODULE}.resolve_slack_user")
@patch(f"{TASKS_MODULE}.get_slack_client")
- def test_view_withholds_the_link_from_a_non_member(self, mock_get_client, mock_resolve_user):
+ def test_view_sends_a_non_member_to_their_own_ticket_list(self, mock_get_client, mock_resolve_user):
ticket = _create_slack_ticket(self.team)
mock_resolve_user.return_value = {"name": "Customer", "email": "[email protected]", "team_id": "T123"}
process_supporthog_interactivity(self._view_payload(ticket.ticket_number), "T123")
text = mock_get_client.return_value.chat_postEphemeral.call_args.kwargs["text"]
+ # The internal ticket view is never named; the requester-facing list is.
assert ticket_deep_link(ticket, self.team) not in text
+ assert my_tickets_link(ticket) in text
assert "reply in this thread" in text.lower()
assert self._link_click_properties()["is_org_member"] is False
@@ -1427,6 +1431,7 @@ class TestSupporthogInteractivity(BaseTest):
text = mock_get_client.return_value.chat_postEphemeral.call_args.kwargs["text"]
assert ticket_deep_link(ticket, self.team) not in text
+ assert my_tickets_link(ticket) in text
assert self._link_click_properties()["is_org_member"] is False
@parameterized.expand([("unknown_number", 4242), ("malformed_value", None)])
@@ -1449,7 +1454,7 @@ class TestTicketConfirmationBlocks(BaseTest):
def test_confirmation_carries_a_view_button_and_no_url(self):
ticket = _create_slack_ticket(self.team)
- blocks = ticket_created_blocks(ticket, self.team)
+ blocks = ticket_created_blocks(ticket)
assert ticket_deep_link(ticket, self.team) not in json.dumps(blocks)
actions = [block for block in blocks if block["type"] == "actions"]
@@ -1466,4 +1471,10 @@ class TestTicketConfirmationBlocks(BaseTest):
)
def test_no_button_without_a_ticket(self):
- assert [block["type"] for block in ticket_created_blocks(None, self.team)] == ["section"]
+ assert [block["type"] for block in ticket_created_blocks(None)] == ["section"]
+
+ def test_my_tickets_link_opens_the_requester_list_on_this_ticket(self):
+ ticket = _create_slack_ticket(self.team)
+
+ # The requester scene addresses a ticket by UUID, unlike the Support scene's number.
+ assert my_tickets_link(ticket).endswith(f"/my-tickets?ticket={ticket.id}")
diff --git a/products/conversations/backend/slack.py b/products/conversations/backend/slack.py
index e00bbeaf93db..2aaf0c1ffcd3 100644
--- a/products/conversations/backend/slack.py
+++ b/products/conversations/backend/slack.py
@@ -14,7 +14,7 @@ import json
from dataclasses import dataclass
from datetime import UTC, datetime
from typing import Any, Literal, NamedTuple
-from urllib.parse import urljoin, urlparse
+from urllib.parse import urlencode, urljoin, urlparse
from urllib.request import HTTPRedirectHandler, Request, build_opener
from django.conf import settings
@@ -149,7 +149,21 @@ def ticket_deep_link(ticket: "Ticket", team: Team) -> str:
return f"{settings.SITE_URL}/project/{_get_team_id(team)}/support/tickets/{ticket.ticket_number}"
-def ticket_created_blocks(ticket: "Ticket | None", team: Team) -> list[dict]:
+def my_tickets_link(ticket: "Ticket") -> str:
+ """Deep link into the requester's own ticket list, opened on this ticket.
+
+ A Slack ticket is keyed by the author's Slack profile email and created
+ ``identity_verified``, which is what the widget's email bridge matches on
+ (``api/widget.py:_identity_ticket_filter``), so it reaches a requester whose verified
+ PostHog email is that same address. For anyone else the scene clears the unresolvable
+ id and renders their plain list, so the link degrades instead of erroring. The id is
+ not a capability: widget access is decided by the viewer's session and attested email,
+ never by knowing a ticket's UUID.
+ """
+ return f"{settings.SITE_URL}/my-tickets?{urlencode({'ticket': str(ticket.id)})}"
+
+
+def ticket_created_blocks(ticket: "Ticket | None") -> list[dict]:
"""Blocks for the ticket confirmation, carrying a "View ticket" button when there is a ticket.
The button holds the ticket number rather than the link, so the channel never shows the URL.
@@ -632,7 +646,7 @@ def create_or_update_slack_ticket(
"channel": slack_channel_id,
"thread_ts": thread_ts,
"text": f"Ticket #{ticket.ticket_number} created.",
- "blocks": ticket_created_blocks(ticket, team),
+ "blocks": ticket_created_blocks(ticket),
}
bot_display_name = support_settings.get("slack_bot_display_name")
bot_icon_url = support_settings.get("slack_bot_icon_url")
diff --git a/products/conversations/backend/tasks/slack.py b/products/conversations/backend/tasks/slack.py
index f5d457f9ef63..c50cdb457208 100644
--- a/products/conversations/backend/tasks/slack.py
+++ b/products/conversations/backend/tasks/slack.py
@@ -68,6 +68,7 @@ from products.conversations.backend.slack import (
handle_support_mention,
handle_support_message,
handle_support_reaction,
+ my_tickets_link,
nudge_event_properties,
ticket_created_blocks,
ticket_created_text,
@@ -331,11 +332,13 @@ def _post_ticket_link(
) -> None:
"""Answer a "View ticket" click with an ephemeral link, so only the clicker sees the URL.
- The button rides on a public confirmation, so anyone in the channel can click it. Two checks
- gate the link: the clicker belongs to the workspace the app is installed in, and their Slack
- profile email matches a member of the team's organization. The workspace check is what makes
- the email check worth anything — an external (Slack Connect) participant's profile email is
- set by their own workspace, so it can claim a teammate's address.
+ The button rides on a public confirmation, so anyone in the channel can click it, and both
+ kinds of clicker get somewhere useful: a member of the team's organization gets the ticket
+ in Support, and everyone else gets their own ticket list. Nobody is told the other view
+ exists. Two checks decide which: the clicker belongs to the workspace the app is installed
+ in, and their Slack profile email matches an organization member. The workspace check is
+ what makes the email check worth anything — an external (Slack Connect) participant's
+ profile email is set by their own workspace, so it can claim a teammate's address.
Best-effort: a failure leaves the click unanswered rather than retrying.
"""
@@ -360,9 +363,13 @@ def _post_ticket_link(
link = ticket_deep_link(ticket, team)
text = f"<{link}|Ticket #{ticket.ticket_number}>. Only you can see this message."
else:
+ # Not "no access". The clicker is usually the requester, whose own list carries
+ # this ticket, but a bystander in the channel gets the same answer and only sees
+ # their own list, so the copy stays true either way. Replying always works.
text = (
- f"Ticket #{ticket.ticket_number} opens in PostHog, which only the support team can reach. "
- "Reply in this thread and they'll see it."
+ f"Ticket #{ticket.ticket_number} is with our support team. "
+ f"If you raised it, follow it in <{my_tickets_link(ticket)}|your PostHog tickets>, "
+ "or just reply in this thread."
)
client.chat_postEphemeral(channel=channel, user=clicker, thread_ts=thread_ts or None, text=text)
capture_support_event(
@@ -496,7 +503,7 @@ def _handle_supporthog_interactivity(
prompt_channel,
prompt_ts,
text,
- blocks=ticket_created_blocks(ticket, team) if ticket else None,
+ blocks=ticket_created_blocks(ticket) if ticket else None,
)
prompt_can_be_updated = bool(prompt_channel and prompt_ts)
if final_update == "transient" and prompt_can_be_updated: