: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(slack-app): let anyone join by default and DM the thread join ask (#128070)
Vojta Bartoš20c66f26ea70
diff --git a/products/slack_app/backend/api.py b/products/slack_app/backend/api.pyindex 6b56d95549da..0f802d878b74 100644--- a/products/slack_app/backend/api.py+++ b/products/slack_app/backend/api.py@@ -4249,13 +4249,15 @@ def post_thread_join_prompt()home_tab_url = app_home_url(integration)home_tab_label = f"<{home_tab_url}|PostHog app Home tab>" if home_tab_url else "PostHog app Home tab"+ thread_url = _thread_permalink(slack, channel, thread_ts)+ thread_label = f"<{thread_url}|your thread>" if thread_url else "your thread"blocks: list[dict[str, Any]] = [{"type": "section","block_id": f"{THREAD_JOIN_BLOCK_ID_PREFIX}:{context_token}","text": {"type": "mrkdwn",- "text": f"<@{joiner_slack_user_id}> wants to work with me in your thread. "+ "text": f"<@{joiner_slack_user_id}> wants to work with me in {thread_label}. "+ ("Let anyone join this thread?" if opens_thread else "Let them join?"),},},@@ -4289,10 +4291,9 @@ def post_thread_join_prompt(},]try:- slack.client.chat_postEphemeral(- channel=channel,- user=owner_slack_user_id,- thread_ts=thread_ts,+ # A DM notifies the creator. An ephemeral message in the thread does not, so they often miss it.+ slack.client.chat_postMessage(+ channel=owner_slack_user_id,text="Someone wants to join your PostHog thread.",blocks=blocks,)@@ -4314,13 +4315,22 @@ def post_thread_join_prompt(capture_slack_event(integration, "slack app thread join requested", slack_user_id=joiner_slack_user_id)+def _thread_permalink(slack: SlackIntegration, channel: str, thread_ts: str) -> str | None:+ try:+ permalink = slack.client.chat_getPermalink(channel=channel, message_ts=thread_ts).get("permalink")+ except Exception:+ logger.warning("slack_app_thread_join_permalink_failed", slack_channel_id=channel, exc_info=True)+ return None+ return permalink if isinstance(permalink, str) else None++def _thread_join_context(payload: dict) -> tuple[str, dict[str, Any]] | None:"""The live join prompt this click answers, when the thread creator is the one clicking."""context_token = _extract_context_token(payload)context = _decode_picker_context(context_token) if context_token else Noneif not context or context.get("kind") != THREAD_JOIN_CONTEXT_KIND:return None- # The prompt is ephemeral, so only the creator sees it, but the answer acts for them.+ # The prompt goes to the creator's DM, but the answer acts for them, so the clicker is checked.if payload.get("user", {}).get("id", "") != context.get("owner_slack_user_id"):return Nonereturn context_token, contextdiff --git a/products/slack_app/backend/logic/thread_join.py b/products/slack_app/backend/logic/thread_join.pyindex f921486573c7..a33992a4b8ca 100644--- a/products/slack_app/backend/logic/thread_join.py+++ b/products/slack_app/backend/logic/thread_join.py@@ -28,13 +28,7 @@ def decide_thread_join(A person's approval holds whatever the mode is now, because a mode change applies to newpeople only."""- from products.tasks.backend.facade import api as tasks_facade-- mode = resolve_thread_join_mode(- integration,- mapping.mentioning_slack_user_id,- own_subscription=tasks_facade.uses_own_subscription(mapping.task_run.state),- )+ mode = resolve_thread_join_mode(integration, mapping.mentioning_slack_user_id)if mode == ThreadJoinMode.ALLOW:return ThreadJoinDecision.ALLOWapproved = set(diff --git a/products/slack_app/backend/models.py b/products/slack_app/backend/models.pyindex c3c1fc7ec2d5..04c1c5e60062 100644--- a/products/slack_app/backend/models.py+++ b/products/slack_app/backend/models.py@@ -151,8 +151,7 @@ class UntaggedFollowupMode(models.TextChoices):class ThreadJoinMode(models.TextChoices):"""What PostHog does when someone else tags it in a thread a user started.- Read from the thread creator's settings row. An unset row resolves to ``ALLOW``, or to- ``ASK_PER_THREAD`` when the thread's run bills to the creator's own plan.+ Read from the thread creator's settings row. An unset row resolves to ``ALLOW``.Under ``ASK_PER_THREAD`` the creator's first approval in a thread lets anyone join it."""@@ -227,8 +226,7 @@ class SlackSettings(UUIDModel):choices=UntaggedFollowupMode.choices,help_text="What PostHog does with this user's top-level channel questions that do not tag the app.",)- # NULL means the user has never picked, which resolves to ``ALLOW`` (``ASK_PER_THREAD`` on- # a run that bills to the creator's own plan).+ # NULL means the user has never picked, which resolves to ``ALLOW``.thread_join_mode = models.CharField(max_length=16,null=True,diff --git a/products/slack_app/backend/services/slack_settings.py b/products/slack_app/backend/services/slack_settings.pyindex f1e7ef192463..ab53a3086e36 100644--- a/products/slack_app/backend/services/slack_settings.py+++ b/products/slack_app/backend/services/slack_settings.py@@ -112,14 +112,11 @@ def _set_untagged_mode(slack_workspace_id: str, slack_user_id: str, column: str,)-def resolve_thread_join_mode(- integration: WorkspaceIntegration, slack_user_id: str | None, *, own_subscription: bool = False-) -> ThreadJoinMode:+def resolve_thread_join_mode(integration: WorkspaceIntegration, slack_user_id: str | None) -> ThreadJoinMode:"""Resolve what happens when someone else tags PostHog in a thread this Slack user started.- An absent row or empty column resolves to `ALLOW`, so anyone can join until the creator picks- a stricter mode. When the thread's run bills to the creator's own plan, it resolves to- `ASK_PER_THREAD` instead, so nobody uses that plan before the creator approves.+ An absent row or empty column resolves to `ALLOW`, also when the run bills to the creator's own+ plan, so anyone can join until the creator picks a stricter mode.An unknown value resolves to `NEVER`."""if not slack_user_id:@@ -129,7 +126,7 @@ def resolve_thread_join_mode(slack_user_id,"thread_join_mode",ThreadJoinMode,- unset=ThreadJoinMode.ASK_PER_THREAD if own_subscription else ThreadJoinMode.ALLOW,+ unset=ThreadJoinMode.ALLOW,unknown=ThreadJoinMode.NEVER,)diff --git a/products/slack_app/backend/tests/test_followup_forwarding.py b/products/slack_app/backend/tests/test_followup_forwarding.pyindex 13ffca7e04ff..99838e1aef54 100644--- a/products/slack_app/backend/tests/test_followup_forwarding.py+++ b/products/slack_app/backend/tests/test_followup_forwarding.py@@ -1358,16 +1358,17 @@ class TestForwardPostHogCodeFollowupActivity(TestCase):@parameterized.expand([- # A creator who never picked a mode is asked once per thread when the run bills to their plan.- ("unset", None, False, True),+ # A creator who never picked a mode lets anyone join, also when the run bills to their plan.+ ("unset", None, True, False),("allow", ThreadJoinMode.ALLOW, True, False),+ ("ask_per_thread", ThreadJoinMode.ASK_PER_THREAD, False, True),])@patch("products.slack_app.backend.api.post_thread_join_prompt")@patch("products.tasks.backend.facade.api.signal_task_run_user_message", return_value=True)@patch("products.slack_app.backend.api.resolve_slack_user")@patch("posthog.models.integration.SlackIntegration")- def test_a_run_on_the_creators_own_plan_asks_before_others_join_by_default(+ def test_a_run_on_the_creators_own_plan_follows_the_creators_join_mode(self, _name, mode, delivered, prompted, mock_slack_cls, mock_resolve, mock_signal, mock_prompt):self.task_run.state = {"claude_model_access": "own-subscription", "claude_subscription_user_id": self.user.id}diff --git a/products/slack_app/backend/tests/test_untagged_followup_interactivity.py b/products/slack_app/backend/tests/test_untagged_followup_interactivity.pyindex 0a8923a53fa0..3a94ed901c10 100644--- a/products/slack_app/backend/tests/test_untagged_followup_interactivity.py+++ b/products/slack_app/backend/tests/test_untagged_followup_interactivity.py@@ -304,7 +304,9 @@ class TestUntaggedFollowupInteractivity(TestCase):opens_thread=False,)- assert [c.kwargs["user"] for c in slack.client.chat_postEphemeral.call_args_list] == ["U_ALICE", "U_BOB"]+ # The creator gets a DM, which notifies them. The joiner hears in the thread that the creator was asked.+ assert [c.kwargs["channel"] for c in slack.client.chat_postMessage.call_args_list] == ["U_ALICE"]+ assert [c.kwargs["user"] for c in slack.client.chat_postEphemeral.call_args_list] == ["U_BOB"]@parameterized.expand([("thread_creator", "U_ALICE", True), ("someone_else", "U_MALLORY", False)])def test_only_the_thread_creator_can_let_someone_join(diff --git a/products/tasks/backend/facade/api.py b/products/tasks/backend/facade/api.pyindex e2e52efe5803..ece277439179 100644--- a/products/tasks/backend/facade/api.py+++ b/products/tasks/backend/facade/api.py@@ -281,7 +281,6 @@ __all__ = ["own_subscription_cloud_enabled","can_bill_plan_unattended","unattended_model_access_state",- "uses_own_subscription","beacon_task_presence","bootstrap_task_run","MAX_SANDBOX_TTL_SECONDS",@@ -4262,12 +4261,6 @@ def get_run_plan(state: dict[str, Any] | None) -> contracts.RunPlan | None:return contracts.RunPlan(plan_name=SUBSCRIPTION_PLAN_NAMES[access.adapter], owner_user_id=access.owner_id)-def uses_own_subscription(state: dict[str, Any] | None) -> bool:- """Whether a run bills to its owner's plan rather than to PostHog credits."""- run_state = state or {}- return any(run_state.get(f"{adapter}_model_access") == "own-subscription" for adapter in SUBSCRIPTION_PLAN_NAMES)--def ensure_subscription_owner(state: dict[str, Any] | None, actor_user_id: int | None) -> None:"""Refuse anyone but the owner of the plan a run bills to. A run on PostHog credits allows everyone."""run_state = state or {}