: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): answer commands privately, and move help to /posthog (#86457)
Vojta Bartoš983f0a7c5f0b
diff --git a/posthog/temporal/ai/slack_app/activities/rules.py b/posthog/temporal/ai/slack_app/activities/rules.pyindex cbde52a1c32e..292d7347c991 100644--- a/posthog/temporal/ai/slack_app/activities/rules.py+++ b/posthog/temporal/ai/slack_app/activities/rules.py@@ -9,7 +9,7 @@ from posthog.temporal.ai.slack_app.types import ()from posthog.temporal.common.utils import close_db_connections-from products.slack_app.backend.services.slack_messages import post_slack_thread_reply+from products.slack_app.backend.services.slack_messages import post_slack_ephemeral, post_slack_thread_replylogger = structlog.get_logger(__name__)@@ -47,7 +47,6 @@ def handle_posthog_code_rules_command_activity(integration,channel=channel,thread_ts=thread_ts,- trigger_ts=inputs.event.get("ts") or "",slack_user_id=slack_user_id,slack_workspace_id=inputs.slack_team_id,user_id=user_id,@@ -165,7 +164,8 @@ def handle_posthog_code_slack_mention_command_activity("This Slack workspace is connected to multiple PostHog projects. "f"Use `{inputs.command_prefix} project <id>` to set a default first, then re-run your command.")- SlackIntegration(candidates[0]).client.chat_postEphemeral(+ post_slack_ephemeral(+ SlackIntegration(candidates[0]).client,channel=channel,user=slack_user_id,thread_ts=thread_ts,@@ -192,9 +192,6 @@ def handle_posthog_code_slack_mention_command_activity(target,channel=channel,thread_ts=thread_ts,- # The command message itself, which a top-level reply is answering even though it- # is deliberately placed at channel root. A slash command creates no message.- trigger_ts=event.get("ts") or "",slack_user_id=slack_user_id,slack_workspace_id=inputs.slack_team_id,user_id=user_id,diff --git a/posthog/temporal/ai/slack_app/posthog_code_slack_mention_command.py b/posthog/temporal/ai/slack_app/posthog_code_slack_mention_command.pyindex f42ed70b01c1..e79309aecd92 100644--- a/posthog/temporal/ai/slack_app/posthog_code_slack_mention_command.py+++ b/posthog/temporal/ai/slack_app/posthog_code_slack_mention_command.py@@ -82,7 +82,11 @@ class PostHogCodeSlackMentionCommandWorkflow(PostHogWorkflow):event = inputs.eventchannel = event.get("channel")- thread_ts = event.get("thread_ts") or event.get("ts")+ # A command posted at channel root is answered at channel root. Falling back to the+ # message's own ``ts`` would open a thread under it, putting the answer where only+ # someone already reading that thread would find it. A command sent inside a thread+ # still keeps its answer there.+ thread_ts = event.get("thread_ts") or ""slack_user_id = event.get("user")if not isinstance(channel, str) or not isinstance(thread_ts, str) or not isinstance(slack_user_id, str):returndiff --git a/products/slack_app/backend/services/commands.py b/products/slack_app/backend/services/commands.pyindex 6ad2069ac7f3..5d0e72ef8666 100644--- a/products/slack_app/backend/services/commands.py+++ b/products/slack_app/backend/services/commands.py@@ -2,12 +2,18 @@ from typing import TYPE_CHECKINGfrom posthog.models.integration import Integration, SlackIntegration-from products.slack_app.backend.services.slack_messages import post_slack_thread_reply+from products.slack_app.backend.services.slack_messages import post_slack_ephemeralif TYPE_CHECKING:from products.slack_app.backend.api import RulesCommandfrom products.slack_app.backend.services.integration_resolver import ResolutionResult+MENTION_COMMAND_PREFIX = "@PostHog"++MENTION_HELP_REDIRECT = (+ "Run `/posthog help` to see the available commands. To start a task, mention me with a description of the work."+)+def _handle_help(slack: SlackIntegration,@@ -16,26 +22,23 @@ def _handle_help(thread_ts: str,slack_user_id: str,*,- trigger_ts: str = "",- command_prefix: str = "@PostHog",+ command_prefix: str,) -> None:+ """Post the command listing. Only the slash surface reaches this; see ``dispatch_rules_command``."""from products.slack_app.backend.services.slack_user_info import is_slack_workspace_admin- # Task creation only makes sense on the mention surface — slash commands lack the thread- # context the workflow needs, so omit it when the user discovered help via ``/posthog``.- lines = ["*Available commands:*\n"]- if command_prefix == "@PostHog":- lines.append(f"`{command_prefix} <task description>` — Create a task for the agent to work on")- lines.extend(- [- f"`{command_prefix} rules list` — Show all routing rules",- f'`{command_prefix} rules add "description" org/repo` — Add a routing rule',- f'`{command_prefix} rules add "description"` — Add a routing rule (pick repo from list)',- f"`{command_prefix} rules remove <number(s)>` — Remove routing rules by number (e.g. `remove 1` or `remove 1,2`)",- f"`{command_prefix} project` — Show which PostHog project your mentions route to in this workspace",- f"`{command_prefix} project <id>` — Set the PostHog project your mentions route to in this workspace",- ]- )+ # Task creation and thread follow-ups have no slash equivalent, but this listing is the only+ # help a user can reach, so it documents them under the mention prefix they actually type.+ lines = [+ "*Available commands:*\n",+ f"`{MENTION_COMMAND_PREFIX} <task description>` — Create a task for the agent to work on",+ f"`{command_prefix} rules list` — Show all routing rules",+ f'`{command_prefix} rules add "description" org/repo` — Add a routing rule',+ f'`{command_prefix} rules add "description"` — Add a routing rule (pick repo from list)',+ f"`{command_prefix} rules remove <number(s)>` — Remove routing rules by number (e.g. `remove 1` or `remove 1,2`)",+ f"`{command_prefix} project` — Show which PostHog project your mentions route to in this workspace",+ f"`{command_prefix} project <id>` — Set the PostHog project your mentions route to in this workspace",+ ]# The workspace-wide default is admins/owners-only, so only surface it to them.if is_slack_workspace_admin(slack, integration, slack_user_id):@@ -44,11 +47,14 @@ def _handle_help()lines.append(f"`{command_prefix} help` — Show this message\n")- if command_prefix == "@PostHog":- lines.append("You can also reply in an active thread to send follow-up messages to the agent.")+ lines.append("You can also reply in an active thread to send follow-up messages to the agent.")- post_slack_thread_reply(- slack.client, channel=channel, thread_ts=thread_ts, trigger_ts=trigger_ts, text="\n".join(lines)+ post_slack_ephemeral(+ slack.client,+ channel=channel,+ user=slack_user_id,+ thread_ts=thread_ts,+ text="\n".join(lines),)@@ -58,18 +64,18 @@ def _handle_rules_list(channel: str,thread_ts: str,*,- trigger_ts: str = "",- command_prefix: str = "@PostHog",+ slack_user_id: str,+ command_prefix: str = MENTION_COMMAND_PREFIX,) -> None:from posthog.models.repo_routing_rule import RepoRoutingRulerules = list(RepoRoutingRule.objects.filter(team_id=integration.team_id).order_by("priority", "id"))if not rules:- post_slack_thread_reply(+ post_slack_ephemeral(slack.client,channel=channel,+ user=slack_user_id,thread_ts=thread_ts,- trigger_ts=trigger_ts,text=(f'No routing rules configured. Add one with `{command_prefix} rules add "description" '"[org/repo]`. Omit the repo to pick from a list."@@ -78,11 +84,11 @@ def _handle_rules_list(returnlines = [f"{i + 1}. {r.rule_text} → `{r.repository}`" for i, r in enumerate(rules)]- post_slack_thread_reply(+ post_slack_ephemeral(slack.client,channel=channel,+ user=slack_user_id,thread_ts=thread_ts,- trigger_ts=trigger_ts,text="*Routing rules:*\n" + "\n".join(lines),)@@ -96,7 +102,7 @@ def _handle_rules_add(rule_text: str,repository: str,*,- trigger_ts: str = "",+ slack_user_id: str,) -> None:from posthog.models.repo_routing_rule import RepoRoutingRule@@ -104,22 +110,22 @@ def _handle_rules_add(all_repos = _get_full_repo_names(integration, user_id=user_id)if not all_repos:- post_slack_thread_reply(+ post_slack_ephemeral(slack.client,channel=channel,+ user=slack_user_id,thread_ts=thread_ts,- trigger_ts=trigger_ts,text="No connected GitHub repositories found for your account.",)returnmatched_repo = _extract_explicit_repo(repository, all_repos)if not matched_repo:- post_slack_thread_reply(+ post_slack_ephemeral(slack.client,channel=channel,+ user=slack_user_id,thread_ts=thread_ts,- trigger_ts=trigger_ts,text=f"Repository `{repository}` is not connected to this project.",)return@@ -138,11 +144,11 @@ def _handle_rules_add(priority=max_priority,created_by_id=user_id,)- post_slack_thread_reply(+ post_slack_ephemeral(slack.client,channel=channel,+ user=slack_user_id,thread_ts=thread_ts,- trigger_ts=trigger_ts,text=f"Added rule: {rule_text} → `{matched_repo}`",)@@ -154,17 +160,17 @@ def _handle_rules_remove(thread_ts: str,rule_numbers: list[int] | None,*,- trigger_ts: str = "",- command_prefix: str = "@PostHog",+ slack_user_id: str,+ command_prefix: str = MENTION_COMMAND_PREFIX,) -> None:from posthog.models.repo_routing_rule import RepoRoutingRuleif not rule_numbers or any(n < 1 for n in rule_numbers):- post_slack_thread_reply(+ post_slack_ephemeral(slack.client,channel=channel,+ user=slack_user_id,thread_ts=thread_ts,- trigger_ts=trigger_ts,text=f"Please provide valid rule number(s). Use `{command_prefix} rules list` to see current rules.",)return@@ -172,11 +178,11 @@ def _handle_rules_remove(rules = list(RepoRoutingRule.objects.filter(team_id=integration.team_id).order_by("priority", "id"))invalid = [n for n in rule_numbers if n > len(rules)]if invalid:- post_slack_thread_reply(+ post_slack_ephemeral(slack.client,channel=channel,+ user=slack_user_id,thread_ts=thread_ts,- trigger_ts=trigger_ts,text=f"Rule {'number' if len(invalid) == 1 else 'numbers'} {', '.join(f'#{n}' for n in invalid)} {'does' if len(invalid) == 1 else 'do'} not exist. There are {len(rules)} rule(s). Use `{command_prefix} rules list` to see them.",)return@@ -189,11 +195,11 @@ def _handle_rules_remove(rule.delete()removed.reverse()- post_slack_thread_reply(+ post_slack_ephemeral(slack.client,channel=channel,+ user=slack_user_id,thread_ts=thread_ts,- trigger_ts=trigger_ts,text=f"Removed rule{'s' if len(removed) > 1 else ''} {', '.join(removed)}",)@@ -207,7 +213,7 @@ def _handle_project_show(user_id: int,workspace_candidates: list[Integration] | None = None,*,- command_prefix: str = "@PostHog",+ command_prefix: str = MENTION_COMMAND_PREFIX,) -> None:from posthog.models.user import User@@ -235,7 +241,8 @@ def _handle_project_show(if result.integration is not None:target = result.integration- slack.client.chat_postEphemeral(+ post_slack_ephemeral(+ slack.client,channel=channel,user=slack_user_id,thread_ts=thread_ts,@@ -248,7 +255,8 @@ def _handle_project_show(returnif not result.candidates:- slack.client.chat_postEphemeral(+ post_slack_ephemeral(+ slack.client,channel=channel,user=slack_user_id,thread_ts=thread_ts,@@ -257,7 +265,8 @@ def _handle_project_show(returnlines = format_project_candidate_list(result.candidates)- slack.client.chat_postEphemeral(+ post_slack_ephemeral(+ slack.client,channel=channel,user=slack_user_id,thread_ts=thread_ts,@@ -286,7 +295,8 @@ def _handle_project_set(user = User.objects.get(id=user_id)if not user.teams.filter(id=target_team_id).exists():- slack.client.chat_postEphemeral(+ post_slack_ephemeral(+ slack.client,channel=channel,user=slack_user_id,thread_ts=thread_ts,@@ -307,7 +317,8 @@ def _handle_project_set(.first())if target is None:- slack.client.chat_postEphemeral(+ post_slack_ephemeral(+ slack.client,channel=channel,user=slack_user_id,thread_ts=thread_ts,@@ -320,7 +331,8 @@ def _handle_project_set(slack_user_id=slack_user_id,defaults={"default_integration": target},)- slack.client.chat_postEphemeral(+ post_slack_ephemeral(+ slack.client,channel=channel,user=slack_user_id,thread_ts=thread_ts,@@ -343,7 +355,7 @@ def _handle_project_set_workspace(target_team_id: int,workspace_candidates: list[Integration] | None = None,*,- command_prefix: str = "@PostHog",+ command_prefix: str = MENTION_COMMAND_PREFIX,) -> None:"""Set the workspace-wide default project (the ``slack_user_id IS NULL`` row),which applies to every Slack user in the workspace without a personal default.@@ -355,7 +367,8 @@ def _handle_project_set_workspace(from products.slack_app.backend.services.slack_user_info import is_slack_workspace_adminif not is_slack_workspace_admin(slack, integration, slack_user_id):- slack.client.chat_postEphemeral(+ post_slack_ephemeral(+ slack.client,channel=channel,user=slack_user_id,thread_ts=thread_ts,@@ -365,7 +378,8 @@ def _handle_project_set_workspace(user = User.objects.get(id=user_id)if not user.teams.filter(id=target_team_id).exists():- slack.client.chat_postEphemeral(+ post_slack_ephemeral(+ slack.client,channel=channel,user=slack_user_id,thread_ts=thread_ts,@@ -386,7 +400,8 @@ def _handle_project_set_workspace(.first())if target is None:- slack.client.chat_postEphemeral(+ post_slack_ephemeral(+ slack.client,channel=channel,user=slack_user_id,thread_ts=thread_ts,@@ -399,7 +414,8 @@ def _handle_project_set_workspace(slack_user_id=None,defaults={"default_integration": target},)- slack.client.chat_postEphemeral(+ post_slack_ephemeral(+ slack.client,channel=channel,user=slack_user_id,thread_ts=thread_ts,@@ -468,14 +484,13 @@ def dispatch_rules_command(slack: SlackIntegration,integration: Integration,*,- trigger_ts: str = "",channel: str,thread_ts: str,slack_user_id: str,slack_workspace_id: str,user_id: int,workspace_candidates: list[Integration] | None = None,- command_prefix: str = "@PostHog",+ command_prefix: str = MENTION_COMMAND_PREFIX,) -> None:"""Run the right handler for a parsed ``RulesCommand``. Assumes the caller hasalready resolved a single ``integration`` to act on; project commands also@@ -488,20 +503,37 @@ def dispatch_rules_command(``command_prefix`` is the entry-point token surfaced in user-facing help anderror strings — ``@PostHog`` for mentions, ``/posthog`` for the slash commandsurface. Defaults preserve the mention copy for existing callers.++ Commands configure the app rather than produce work: routing rules, project+ defaults, the help listing. The answer concerns whoever ran the command, so+ every reply below goes out ephemerally, on both surfaces."""if command.action == "help":- _handle_help(- slack, integration, channel, thread_ts, slack_user_id, trigger_ts=trigger_ts, command_prefix=command_prefix- )+ # The slash command owns the listing, so a mention only points at it. Answering here+ # rather than inside the handler keeps the Slack users.info call the listing needs off+ # the mention path entirely.+ if command_prefix == MENTION_COMMAND_PREFIX:+ post_slack_ephemeral(+ slack.client, channel=channel, user=slack_user_id, thread_ts=thread_ts, text=MENTION_HELP_REDIRECT+ )+ else:+ _handle_help(slack, integration, channel, thread_ts, slack_user_id, command_prefix=command_prefix)elif command.action == "list":- _handle_rules_list(slack, integration, channel, thread_ts, trigger_ts=trigger_ts, command_prefix=command_prefix)+ _handle_rules_list(+ slack,+ integration,+ channel,+ thread_ts,+ slack_user_id=slack_user_id,+ command_prefix=command_prefix,+ )elif command.action == "add":if not command.repository:- post_slack_thread_reply(+ post_slack_ephemeral(slack.client,channel=channel,+ user=slack_user_id,thread_ts=thread_ts,- trigger_ts=trigger_ts,text=f'Please specify the repo inline: `{command_prefix} rules add "description" org/repo`.',)else:@@ -513,7 +545,7 @@ def dispatch_rules_command(user_id,command.rule_text or "",command.repository,- trigger_ts=trigger_ts,+ slack_user_id=slack_user_id,)elif command.action == "remove":_handle_rules_remove(@@ -522,7 +554,7 @@ def dispatch_rules_command(channel,thread_ts,command.rule_numbers,- trigger_ts=trigger_ts,+ slack_user_id=slack_user_id,command_prefix=command_prefix,)elif command.action == "project_show":diff --git a/products/slack_app/backend/services/slack_messages.py b/products/slack_app/backend/services/slack_messages.pyindex 270cf6768632..d3040d4976ac 100644--- a/products/slack_app/backend/services/slack_messages.py+++ b/products/slack_app/backend/services/slack_messages.py@@ -309,6 +309,28 @@ def post_slack_thread_reply(return client.chat_postMessage(channel=channel, **kwargs)+def post_slack_ephemeral(+ client: WebClient,+ *,+ channel: str,+ user: str,+ thread_ts: str | None = None,+ **kwargs: Any,+) -> Any:+ """Post a reply only ``user`` can see.++ The counterpart funnel to ``post_slack_thread_reply``, for answers that concern one person,+ which today means command output. No deleted-prompt check applies, because an ephemeral answer+ reaches nobody but its reader.++ ``thread_ts`` places the reply, and a falsy one is omitted rather than sent empty, which posts+ at channel root. Slack rejects an empty ``thread_ts`` instead of reading it as "no anchor".+ """+ if thread_ts:+ return client.chat_postEphemeral(channel=channel, user=user, thread_ts=thread_ts, **kwargs)+ return client.chat_postEphemeral(channel=channel, user=user, **kwargs)++# `conversations.replies` answers `thread_not_found` for a ts that no longer resolves to a# message; `message_not_found` is carried alongside it because Slack uses that spelling on# neighbouring methods and the two mean the same thing here.diff --git a/products/slack_app/backend/tests/test_guess_repository.py b/products/slack_app/backend/tests/test_guess_repository.pyindex 719fba564b0f..ff17f689658d 100644--- a/products/slack_app/backend/tests/test_guess_repository.py+++ b/products/slack_app/backend/tests/test_guess_repository.py@@ -22,6 +22,7 @@ from products.slack_app.backend.api import (_user_repo_list_cache_key,parse_rules_command,)+from products.slack_app.backend.services.commands import MENTION_HELP_REDIRECTdef _repo_dict(org: str, name: str, repo_id: int = 1) -> dict:@@ -462,11 +463,11 @@ class TestHandleRulesCommandActivity:)assert result.status == "handled"- msg = mock_slack.client.chat_postMessage.call_args+ msg = mock_slack.client.chat_postEphemeral.call_argsassert "No routing rules" in msg.kwargs["text"]@patch("posthog.models.integration.SlackIntegration")- def test_help_uses_posthog_commands(self, mock_slack_cls):+ def test_help_points_at_the_slash_command(self, mock_slack_cls):mock_slack = MagicMock()mock_slack_cls.return_value = mock_slack@@ -480,10 +481,10 @@ class TestHandleRulesCommandActivity:self.user.id,)+ # The mention is still consumed as a command rather than becoming a task.assert result.status == "handled"- msg = mock_slack.client.chat_postMessage.call_args- assert "@PostHog <task description>" in msg.kwargs["text"]- assert "@PostHog Desktop" not in msg.kwargs["text"]+ msg = mock_slack.client.chat_postEphemeral.call_args+ assert msg.kwargs["text"] == MENTION_HELP_REDIRECT@patch("posthog.models.integration.SlackIntegration")def test_list_shows_rules(self, mock_slack_cls):@@ -508,7 +509,7 @@ class TestHandleRulesCommandActivity:)assert result.status == "handled"- msg = mock_slack.client.chat_postMessage.call_args+ msg = mock_slack.client.chat_postEphemeral.call_argsassert "JS SDK bugs" in msg.kwargs["text"]assert "Backend issues" in msg.kwargs["text"]@@ -534,7 +535,7 @@ class TestHandleRulesCommandActivity:rule = RepoRoutingRule.objects.get(team=self.team)assert rule.rule_text == "JS SDK bugs"assert rule.repository == "posthog/posthog-js"- msg = mock_slack.client.chat_postMessage.call_args+ msg = mock_slack.client.chat_postEphemeral.call_argsassert "Added rule" in msg.kwargs["text"]def test_add_without_repo_returns_needs_picker(self):@@ -569,7 +570,7 @@ class TestHandleRulesCommandActivity:assert result.status == "handled"assert RepoRoutingRule.objects.filter(team=self.team).count() == 0- msg = mock_slack.client.chat_postMessage.call_args+ msg = mock_slack.client.chat_postEphemeral.call_argsassert "not connected" in msg.kwargs["text"]@patch("posthog.models.integration.SlackIntegration")@@ -614,7 +615,7 @@ class TestHandleRulesCommandActivity:assert result.status == "handled"assert RepoRoutingRule.objects.filter(team=self.team).count() == 1- msg = mock_slack.client.chat_postMessage.call_args+ msg = mock_slack.client.chat_postEphemeral.call_argsassert "does not exist" in msg.kwargs["text"]def test_non_command_returns_not_a_command(self):diff --git a/products/slack_app/backend/tests/test_mention_command_activity.py b/products/slack_app/backend/tests/test_mention_command_activity.pyindex 9b2bb423113e..a3ed51f2920a 100644--- a/products/slack_app/backend/tests/test_mention_command_activity.py+++ b/products/slack_app/backend/tests/test_mention_command_activity.py@@ -10,6 +10,8 @@ from posthog.models.user import Userfrom posthog.temporal.ai.slack_app.activities.rules import handle_posthog_code_slack_mention_command_activityfrom posthog.temporal.ai.slack_app.types import PostHogCodeSlackMentionCommandWorkflowInputs+from products.slack_app.backend.services.commands import MENTION_HELP_REDIRECT+class TestMentionCommandActivity:@pytest.fixture(autouse=True)@@ -38,15 +40,15 @@ class TestMentionCommandActivity:@parameterized.expand([- # A slash command outside a thread carries neither ts nor thread_ts; the- # reply anchors to the channel root and speaks the ``/posthog`` surface.- ("slash_outside_thread", "/posthog", {}, ""),+ # A slash command outside a thread carries neither ts nor thread_ts, so the reply+ # anchors to the channel root.+ ("slash_outside_thread", "/posthog", {}, "", "*Available commands:*"),# A top-level mention carries only its own ts (no thread_ts). The reply# must anchor to the channel root, not that ts — a thread-anchored reply# is invisible to a user who isn't already viewing the thread.- ("mention_top_level", "@PostHog", {"ts": "111.1"}, ""),+ ("mention_top_level", "@PostHog", {"ts": "111.1"}, "", MENTION_HELP_REDIRECT),# A mention inside a real thread carries thread_ts; the reply threads there.- ("mention_in_thread", "@PostHog", {"ts": "222.2", "thread_ts": "111.1"}, "111.1"),+ ("mention_in_thread", "@PostHog", {"ts": "222.2", "thread_ts": "111.1"}, "111.1", MENTION_HELP_REDIRECT),])@patch("products.slack_app.backend.services.slack_user_info.get_slack_user_info")@@ -57,6 +59,7 @@ class TestMentionCommandActivity:command_prefix: str,event_extra: dict[str, str],expected_thread_ts: str,+ expected_text: str,mock_slack_cls,mock_info,) -> None:@@ -68,7 +71,9 @@ class TestMentionCommandActivity:)assert result.status == "done"- client.chat_postMessage.assert_called_once()+ # Both surfaces answer only the caller, so nothing lands in the channel.+ assert client.chat_postMessage.call_count == 0+ client.chat_postEphemeral.assert_called_once()# A channel-root reply carries no anchor at all rather than an empty one.- assert client.chat_postMessage.call_args.kwargs.get("thread_ts", "") == expected_thread_ts- assert command_prefix in client.chat_postMessage.call_args.kwargs["text"]+ assert client.chat_postEphemeral.call_args.kwargs.get("thread_ts", "") == expected_thread_ts+ assert expected_text in client.chat_postEphemeral.call_args.kwargs["text"]diff --git a/products/slack_app/backend/tests/test_project_set_workspace.py b/products/slack_app/backend/tests/test_project_set_workspace.pyindex 922e2635ea11..70f839b824f8 100644--- a/products/slack_app/backend/tests/test_project_set_workspace.py+++ b/products/slack_app/backend/tests/test_project_set_workspace.py@@ -1,15 +1,23 @@import pytestfrom unittest.mock import MagicMock, patch+from parameterized import parameterized+from posthog.models.integration import Integrationfrom posthog.models.organization import Organizationfrom posthog.models.team.team import Teamfrom posthog.models.user import User+from products.slack_app.backend.api import RulesCommandfrom products.slack_app.backend.models import SlackSettings-from products.slack_app.backend.services.commands import _handle_help, _handle_project_set_workspace+from products.slack_app.backend.services.commands import (+ MENTION_HELP_REDIRECT,+ _handle_project_set_workspace,+ dispatch_rules_command,+)-WORKSPACE_HELP_LINE = "`@PostHog project workspace <id>`"+SLASH_COMMAND_PREFIX = "/posthog"+WORKSPACE_HELP_LINE = "`/posthog project workspace <id>`"def _slack_user_info(*, is_admin: bool = False, is_owner: bool = False) -> dict:@@ -116,11 +124,23 @@ class TestHandleHelp:integration_id="T_WS",sensitive_config={"access_token": "xoxb-a"},)+ self.user = User.objects.create_and_join(self.organization, "[email protected]", "pw")self.slack = MagicMock()- def _help_text(self) -> str:- _handle_help(self.slack, self.integration, "C1", "111.1", "U1")- return self.slack.client.chat_postMessage.call_args.kwargs["text"]+ def _help_text(self, command_prefix: str = SLASH_COMMAND_PREFIX) -> str:+ """Dispatch `help` the way a real command does, so the surface branch is exercised too."""+ dispatch_rules_command(+ RulesCommand(action="help"),+ self.slack,+ self.integration,+ channel="C1",+ thread_ts="111.1",+ slack_user_id="U1",+ slack_workspace_id="T_WS",+ user_id=self.user.id,+ command_prefix=command_prefix,+ )+ return self.slack.client.chat_postEphemeral.call_args.kwargs["text"]@patch("products.slack_app.backend.services.slack_user_info.get_slack_user_info")def test_admin_sees_workspace_line(self, mock_info):@@ -139,3 +159,23 @@ class TestHandleHelp:assert WORKSPACE_HELP_LINE not in text# The rest of the help is still posted.assert "Available commands" in text++ @patch("products.slack_app.backend.services.slack_user_info.get_slack_user_info")+ def test_slash_help_documents_mention_only_capabilities(self, mock_info):+ mock_info.return_value = _slack_user_info(is_admin=False, is_owner=False)+ text = self._help_text()+ assert "`@PostHog <task description>`" in text+ assert "reply in an active thread" in text++ @parameterized.expand([("slash", SLASH_COMMAND_PREFIX), ("mention", "@PostHog")])+ @patch("products.slack_app.backend.services.slack_user_info.get_slack_user_info")+ def test_help_is_ephemeral_to_the_caller(self, _name, command_prefix, mock_info):+ mock_info.return_value = _slack_user_info(is_admin=False, is_owner=False)+ self._help_text(command_prefix=command_prefix)+ assert self.slack.client.chat_postMessage.call_count == 0+ assert self.slack.client.chat_postEphemeral.call_args.kwargs["user"] == "U1"++ def test_mention_help_redirects_to_the_slash_command(self):+ text = self._help_text(command_prefix="@PostHog")+ assert text == MENTION_HELP_REDIRECT+ assert "Available commands" not in textdiff --git a/products/slack_app/backend/views/slack_command.py b/products/slack_app/backend/views/slack_command.pyindex 1550c0a42c74..2ca85aa3edf7 100644--- a/products/slack_app/backend/views/slack_command.py+++ b/products/slack_app/backend/views/slack_command.py@@ -2,9 +2,10 @@Handles ``POST /slack/command-callback`` — the webhook Slack hits when a userruns ``/posthog ...`` in a channel or DM. The vocabulary mirrors the-``@PostHog <command>`` mention path (``help``, ``rules ...``, ``project ...``);-free-text task creation stays on the mention path because slash commands lack-the thread context the task workflow depends on.+``@PostHog <command>`` mention path (``rules ...``, ``project ...``), and+``help`` is answered here only: a mention of it replies with a pointer back to+this surface. Free-text task creation stays on the mention path because slash+commands lack the thread context the task workflow depends on.Slack imposes a hard 3-second response budget on slash commands — a slow firstresponse surfaces to the user as ``operation_timeout``. Cheap validation and