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(slack-app): point unmatched slack users to account linking (#109519)

posthog[bot]e9a183c3975a
diff --git a/products/slack_app/backend/api.py b/products/slack_app/backend/api.py
index fc774121ad37..99513989a817 100644
--- a/products/slack_app/backend/api.py
+++ b/products/slack_app/backend/api.py
@@ -2007,7 +2007,13 @@ def _post_user_resolution_failure_reply(
"""
if not channel or not thread_ts or not slack_user_id:
return False
- text = user_resolution_failure_reply(failure_reason, slack_email=slack_email)
+ linking_available = is_slack_app_oauth_enabled(probe)
+ text = user_resolution_failure_reply(
+ failure_reason,
+ slack_email=slack_email,
+ linking_available=linking_available,
+ home_tab_url=app_home_url(probe) if linking_available else None,
+ )
if text is None:
return False
slack_client = SlackIntegration(probe)
@@ -2023,7 +2029,7 @@ def _post_user_resolution_failure_reply(
posted = _post_slack_user_feedback(
slack_client, channel, slack_user_id, thread_ts, text, prefer_thread_message=True
)
- if failure_reason == "user_not_found" and is_slack_app_oauth_enabled(probe):
+ if failure_reason == "user_not_found" and linking_available:
invite_url = build_invite_url(
slack_user_id=slack_user_id,
slack_team_id=probe.integration_id,
diff --git a/products/slack_app/backend/services/integration_resolver.py b/products/slack_app/backend/services/integration_resolver.py
index a24e3fdafaba..d611f5f22c20 100644
--- a/products/slack_app/backend/services/integration_resolver.py
+++ b/products/slack_app/backend/services/integration_resolver.py
@@ -33,7 +33,11 @@ UserResolutionFailure = Literal["user_not_found", "no_team_access"]
def user_resolution_failure_reply(
- failure_reason: UserResolutionFailure | None, *, slack_email: str | None
+ failure_reason: UserResolutionFailure | None,
+ *,
+ slack_email: str | None,
+ linking_available: bool = False,
+ home_tab_url: str | None = None,
) -> str | None:
"""Map a ``UserAndIntegrationsResolution.failure_reason`` to the user-facing
text, mentioning ``slack_email`` when known so the user sees which address
@@ -42,17 +46,40 @@ def user_resolution_failure_reply(
Wording mirrors the per-integration ``resolve_slack_user`` precedent in
``api.py`` — same "Sorry, …" register, same actionable next step.
+
+ ``linking_available`` says whether the install can link a Slack identity to a
+ PostHog user. When it can, the reply points to linking first: an invite only
+ works for the exact email it was sent to, so it can't help a user whose
+ existing PostHog account uses a different email.
+
+ ``home_tab_url`` deep-links to the app's Home tab, which carries the same link
+ button. The reader is already in Slack, so the hint names the tab first.
"""
if failure_reason == "user_not_found":
+ if home_tab_url:
+ link_hint = (
+ "If you already have a PostHog account with a different email, link it to Slack from "
+ f"<{home_tab_url}|my Home tab>, or in PostHog under Settings > Personal integrations."
+ )
+ else:
+ link_hint = (
+ "If you already have a PostHog account with a different email, link it to Slack in PostHog "
+ "under Settings > Personal integrations."
+ )
if slack_email:
- return (
- f"Sorry, I couldn't find {slack_email} in any PostHog organization connected to this "
- "Slack workspace. Ask an admin to invite you, then mention me again."
+ prefix = (
+ f"Sorry, I couldn't find {slack_email} in any PostHog organization connected to this Slack workspace."
)
- return (
+ if linking_available:
+ return f"{prefix} {link_hint} If you don't have an account, ask an admin to invite {slack_email}. Then mention me again."
+ return f"{prefix} Ask an admin to invite you, then mention me again."
+ prefix = (
"Sorry, I couldn't find your email address in Slack. "
"Please make sure your email is visible in your Slack profile."
)
+ if linking_available:
+ return f"{prefix} {link_hint}"
+ return prefix
if failure_reason == "no_team_access":
# The membership lookup succeeded by email, so it's always known here.
subject = slack_email or "your account"
diff --git a/products/slack_app/backend/tests/test_posthog_code_event_handler.py b/products/slack_app/backend/tests/test_posthog_code_event_handler.py
index 3b28c5db7720..871d0992ceed 100644
--- a/products/slack_app/backend/tests/test_posthog_code_event_handler.py
+++ b/products/slack_app/backend/tests/test_posthog_code_event_handler.py
@@ -602,6 +602,8 @@ class TestRoutePostHogCodeEventToRelevantRegion(TestCase):
# No workflow starts.
SlackUserProfileCache.objects.filter(slack_user_id="U123").delete()
self._seed_slack_user_cache("U123", "[email protected]")
+ self.posthog_code_integration.config = {**self.posthog_code_integration.config, "app_id": "A123"}
+ self.posthog_code_integration.save()
mock_post_feedback.return_value = True
from products.slack_app.backend.api import (
@@ -622,6 +624,10 @@ class TestRoutePostHogCodeEventToRelevantRegion(TestCase):
mock_post_feedback.assert_called_once()
feedback_text = mock_post_feedback.call_args.args[4]
assert "[email protected]" in feedback_text
+ # The install holds the identity scopes, so the reply points to linking an existing
+ # account. An invite to the Slack email can't be accepted from a different email.
+ assert "Settings > Personal integrations" in feedback_text
+ assert "<slack://app?team=T12345&id=A123&tab=home|my Home tab>" in feedback_text
assert mock_post_feedback.call_args.kwargs.get("prefer_thread_message") is True
# The mention is still reported to analytics with ``posthog_user_identified=False``