: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
fix(conversations): reject empty @supporthog mentions (#68995)
Vojta Bartoš511bf99ad3a1
diff --git a/products/conversations/backend/api/tests/test_slack_message_routing.py b/products/conversations/backend/api/tests/test_slack_message_routing.pyindex 9ad696b71ca7..cd0eb728da5c 100644--- a/products/conversations/backend/api/tests/test_slack_message_routing.py+++ b/products/conversations/backend/api/tests/test_slack_message_routing.py@@ -106,6 +106,32 @@ class TestSlackMessageRouting(BaseTest):mock_create_or_update.assert_called_once()assert mock_create_or_update.call_args.kwargs["channel_detail"] == ChannelDetail.SLACK_BOT_MENTION+ @parameterized.expand(+ [+ ("bare_mention", "<@U0BOT001>", None, False),+ ("mention_with_whitespace", "<@U0BOT001> ", None, False),+ ("mention_with_only_other_mentions", "<@U0BOT001> <@U0USER99>", None, False),+ ("mention_with_text", "<@U0BOT001> help me", None, True),+ ("bare_mention_with_files", "<@U0BOT001>", [{"url_private": "https://x/y.png"}], True),+ ]+ )+ @patch(f"{MODULE}.create_or_update_slack_ticket")+ def test_empty_mention_does_not_create_ticket(self, _name, text, files, should_create, mock_create_or_update):+ handle_support_mention(+ {+ "type": "app_mention",+ "channel": "C_ANY",+ "ts": "1700000000.000100",+ "user": "U123",+ "text": text,+ "files": files,+ },+ self.team,+ "T123",+ )++ assert mock_create_or_update.called is should_create+@parameterized.expand([# No ticket yet: seed from the thread's parent message and backfill replies.diff --git a/products/conversations/backend/formatting.py b/products/conversations/backend/formatting.pyindex 47fa80e5b1f7..a7f426e46f4c 100644--- a/products/conversations/backend/formatting.py+++ b/products/conversations/backend/formatting.py@@ -153,6 +153,11 @@ def extract_slack_user_ids(text: str, blocks: list[JSON] | None = None) -> set[sreturn ids+def strip_slack_user_mentions(text: str) -> str:+ """Remove ``<@USERID>`` mention tokens, leaving only the message's own text."""+ return _RE_SLACK_USER_MENTION.sub("", text)++def content_to_slack_mrkdwn(content: str) -> str:"""Convert markdown comment content to Slack mrkdwn text."""if not content:diff --git a/products/conversations/backend/slack.py b/products/conversations/backend/slack.pyindex 134e1925c166..6afcdbf58c69 100644--- a/products/conversations/backend/slack.py+++ b/products/conversations/backend/slack.py@@ -35,7 +35,7 @@ from .cache import (set_cached_slack_user,slack_ticket_create_lock,)-from .formatting import extract_slack_user_ids, slack_to_content_and_rich_content+from .formatting import extract_slack_user_ids, slack_to_content_and_rich_content, strip_slack_user_mentionsfrom .models import Ticketfrom .models.constants import Channel, ChannelDetail, Statusfrom .services.attachments import (@@ -750,6 +750,17 @@ def handle_support_mention(event: dict, team: Team, slack_team_id: str) -> None:_backfill_thread_replies(client, team, ticket, channel, thread_ts)return+ # A bare "@supporthog" (mention only, no message or files) must not create an empty+ # ticket. The parent-seeding branch above already handled thread-escalation mentions.+ if not strip_slack_user_mentions(text).strip() and not files:+ logger.info(+ "slack_support_mention_empty_skipped",+ team_id=_get_team_id(team),+ slack_channel_id=channel,+ thread_ts=thread_ts,+ )+ return+create_or_update_slack_ticket(team=team,slack_channel_id=channel,