: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(slack-app): send untagged posts to the classifier without a posthog mention (#122510)
Vojta Bartoš8c2d2ce5d0ef
diff --git a/products/slack_app/backend/api.py b/products/slack_app/backend/api.pyindex be129747b703..b622485e247b 100644--- a/products/slack_app/backend/api.py+++ b/products/slack_app/backend/api.py@@ -2605,6 +2605,9 @@ def _route_untagged_question(return ROUTE_HANDLED_LOCALLYif target.id not in enabled_integration_ids:return ROUTE_HANDLED_LOCALLY+ # A post that tags the app also arrives as an ``app_mention``, and the mention pipeline answers that copy.+ if _message_tags_bot(event, target):+ return ROUTE_HANDLED_LOCALLYlogger.info("slack_app_untagged_question_dispatched",diff --git a/products/slack_app/backend/logic/untagged_question.py b/products/slack_app/backend/logic/untagged_question.pyindex 4848d4ddefdd..9e0e6c7f2d57 100644--- a/products/slack_app/backend/logic/untagged_question.py+++ b/products/slack_app/backend/logic/untagged_question.py@@ -8,22 +8,13 @@ UNTAGGED_QUESTION_MAX_CHARS = 2000UNTAGGED_QUESTION_MIN_WORDS = 3# A message for another bot or a typed Slack command, such as "/remind" or "!deploy"._COMMAND_PATTERN = re.compile(r"^[/!]\S")-_POSTHOG_PATTERN = re.compile(r"\bpost\s?hog\b", re.IGNORECASE)-# Slack wraps links, channels and tags in angle brackets. A PostHog URL alone does not name PostHog.-_SLACK_MARKUP_PATTERN = re.compile(r"<[^>]*>")---def mentions_posthog(text: str) -> bool:- """Whether the words of a post name PostHog, outside links."""- return bool(_POSTHOG_PATTERN.search(_SLACK_MARKUP_PATTERN.sub(" ", text)))def is_untagged_question_candidate(event: dict[str, Any]) -> bool:"""Whether a top-level post nobody tagged the app in could be a question for PostHog.Text-only checks, because every top-level post in every channel the app is in comes through- here. The post must name PostHog, so the classifier sees what people ask about PostHog in any- phrasing, with or without a ``?``. The classifier makes the real decision later.+ here. The classifier makes the real decision later."""# ``group`` is a private channel. Group DMs (``mpim``) are private conversations between people.if event.get("channel_type") not in ("channel", "group"):@@ -31,12 +22,6 @@ def is_untagged_question_candidate(event: dict[str, Any]) -> bool:text = (event.get("text") or "").strip()if not UNTAGGED_QUESTION_MIN_CHARS <= len(text) <= UNTAGGED_QUESTION_MAX_CHARS:return False- # A tag of the app arrives as its own ``app_mention``. A tag of anyone else, a user group or- # the whole channel addresses them, not PostHog.- if "<@" in text or "<!" in text:- return Falseif len(text.split()) < UNTAGGED_QUESTION_MIN_WORDS:return False- if _COMMAND_PATTERN.match(text):- return False- return mentions_posthog(text)+ return not _COMMAND_PATTERN.match(text)diff --git a/products/slack_app/backend/tests/logic/test_untagged_question.py b/products/slack_app/backend/tests/logic/test_untagged_question.pyindex c9a56fffee84..d925d8a8b32c 100644--- a/products/slack_app/backend/tests/logic/test_untagged_question.py+++ b/products/slack_app/backend/tests/logic/test_untagged_question.py@@ -11,8 +11,8 @@ class TestIsUntaggedQuestionCandidate(SimpleTestCase):("a question that names PostHog", "how many signups does PostHog show for last week?", True),("a request without a question word", "need signups by country from posthog for last month", True),("a statement that names PostHog", "the Post Hog funnel looks off since the deploy", True),- ("a question that does not name PostHog", "how many people signed up last week?", False),- ("PostHog only in a link", "how many signups here <https://us.posthog.com/project/2/insights/abc>", False),+ ("a question that does not name PostHog", "how many people signed up last week?", True),+ ("a question that tags a person", "<@U_ALICE> how many people signed up last week?", True),("a command", "/remind me to check posthog signups tomorrow", False),("a command for another bot", "!deploy posthog to staging now", False),("too few words", "posthog???????????", False),diff --git a/products/slack_app/backend/tests/test_thread_message_routing.py b/products/slack_app/backend/tests/test_thread_message_routing.pyindex ee34be18cf46..b9bd29af3667 100644--- a/products/slack_app/backend/tests/test_thread_message_routing.py+++ b/products/slack_app/backend/tests/test_thread_message_routing.py@@ -176,9 +176,17 @@ class TestRouteThreadMessage(TestCase):True,None,False,+ True,+ ),+ ("a question to a person", {"text": "<@U_ALICE> how many signups last week?"}, True, None, False, True),+ (+ "a question that tags the app",+ {"text": "<@U0BOT> how many signups last week?"},+ True,+ None,+ False,False,),- ("a question to a person", {"text": "<@U_ALICE> how many signups last week?"}, True, None, False, False),("a group DM", {"channel_type": "mpim"}, True, None, False, False),("the flag is off", {}, False, None, False, False),("the author picks up only tagged messages", {}, True, UntaggedFollowupMode.NEVER, False, False),@@ -196,6 +204,7 @@ class TestRouteThreadMessage(TestCase):event = self._make_question_event(**overrides)with (patch("products.slack_app.backend.api.is_slack_app_unprompted_answers_enabled", return_value=flag_on),+ patch("products.slack_app.backend.api.get_cached_bot_user_id", return_value="U0BOT"),patch("products.slack_app.backend.api._start_mention_workflow") as mock_start,patch("products.slack_app.backend.api._post_user_resolution_failure_reply") as mock_failure_reply,):