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): allowlist ticketable slack message subtypes (#68949)

Luke Belton60d80eeac071
diff --git a/products/conversations/.gitignore b/products/conversations/.gitignore
new file mode 100644
index 000000000000..2ce9f756f840
--- /dev/null
+++ b/products/conversations/.gitignore
@@ -0,0 +1 @@
+skills/
\ No newline at end of file
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 c61b86518d06..9ad696b71ca7 100644
--- a/products/conversations/backend/api/tests/test_slack_message_routing.py
+++ b/products/conversations/backend/api/tests/test_slack_message_routing.py
@@ -250,6 +250,61 @@ class TestSlackMessageRouting(BaseTest):
mock_create_or_update.assert_not_called()
+ @parameterized.expand(
+ [
+ ("channel_join",),
+ ("channel_leave",),
+ ("channel_topic",),
+ ("channel_purpose",),
+ ("pinned_item",),
+ ("message_changed",),
+ ("message_deleted",),
+ # An unrecognized subtype must be treated as noise, not silently ticketed —
+ # this is the whole point of using an allowlist over a blocklist.
+ ("some_future_subtype",),
+ ]
+ )
+ @patch(f"{MODULE}.create_or_update_slack_ticket")
+ def test_system_message_subtype_does_not_create_ticket(self, subtype, mock_create_or_update):
+ handle_support_message(
+ {
+ "type": "message",
+ "subtype": subtype,
+ "channel": "C_CONFIG",
+ "ts": "1700000000.000100",
+ "user": "U123",
+ "text": "<@U123> has joined the channel",
+ },
+ self.team,
+ "T123",
+ )
+
+ mock_create_or_update.assert_not_called()
+
+ @parameterized.expand(
+ [
+ ("file_share",),
+ ("me_message",),
+ ("thread_broadcast",),
+ ]
+ )
+ @patch(f"{MODULE}.create_or_update_slack_ticket")
+ def test_content_bearing_subtype_creates_ticket(self, subtype, mock_create_or_update):
+ handle_support_message(
+ {
+ "type": "message",
+ "subtype": subtype,
+ "channel": "C_CONFIG",
+ "ts": "1700000000.000100",
+ "user": "U123",
+ "text": "I need help with something",
+ },
+ self.team,
+ "T123",
+ )
+
+ mock_create_or_update.assert_called_once()
+
@patch(f"{MODULE}.get_bot_user_id", return_value="U_OWN_BOT")
@patch(f"{MODULE}.get_slack_client")
@patch(f"{MODULE}.create_or_update_slack_ticket")
diff --git a/products/conversations/backend/slack.py b/products/conversations/backend/slack.py
index 1393707d58ea..134e1925c166 100644
--- a/products/conversations/backend/slack.py
+++ b/products/conversations/backend/slack.py
@@ -50,6 +50,27 @@ logger = structlog.get_logger(__name__)
SLACK_DOWNLOAD_TIMEOUT_SECONDS = 10
MAX_REDIRECTS = 5
+# Slack message subtypes that carry real, user-authored content and may open or update a
+# ticket. A normal message has no subtype at all; these few subtypes also count as content
+# (file uploads, /me, and thread replies echoed to the channel). ``bot_message`` is handled
+# separately via the ``is_bot`` path. Every other subtype is system noise — channel
+# join/leave, topic/purpose/name changes, pins, edits, deletions, huddles, and so on — and
+# must never create a ticket. This is an allowlist on purpose: Slack keeps adding subtypes,
+# so anything unrecognized is treated as noise rather than silently opening tickets.
+# https://docs.slack.dev/reference/events/message/#subtypes
+TICKETABLE_MESSAGE_SUBTYPES = frozenset({"file_share", "me_message", "thread_broadcast"})
+
+
+def _is_ticketable_message(event: dict, *, is_bot: bool) -> bool:
+ """True when a Slack message event carries real user content worth ticketing.
+
+ ``bot_message`` is allowed through here so the caller's bot handling can decide
+ (top-level bot posts are dropped, thread replies from other bots become comments).
+ """
+ subtype = event.get("subtype")
+ return not subtype or subtype in TICKETABLE_MESSAGE_SUBTYPES or is_bot
+
+
# Slack ID shapes — guard against malformed payloads before interpolating into mrkdwn.
# Permissive on charset (underscores allowed) but blocks angle brackets, @, #, and spaces.
_SLACK_USER_ID_RE = re.compile(r"^[UW][A-Z0-9_]+$")
@@ -576,12 +597,12 @@ def handle_support_message(event: dict, team: Team, slack_team_id: str) -> None:
if not channel:
return
- # Always skip non-message subtypes
- if event.get("subtype") in ("message_changed", "message_deleted"):
- return
-
is_bot = bool(event.get("bot_id") or event.get("subtype") == "bot_message")
+ # Only real user content opens or updates a ticket; system-message subtypes are noise.
+ if not _is_ticketable_message(event, is_bot=is_bot):
+ return
+
slack_user_id = event.get("user")
text = event.get("text", "")
blocks = event.get("blocks")
@@ -787,7 +808,8 @@ def _backfill_thread_replies(
team_message_count = 0
for reply in thread_replies:
- if reply.get("subtype") in ("message_changed", "message_deleted"):
+ reply_is_bot = bool(reply.get("bot_id") or reply.get("subtype") == "bot_message")
+ if not _is_ticketable_message(reply, is_bot=reply_is_bot):
continue
# Skip our own bot's messages to prevent loops, but allow other bots