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.

feat(slack): invite Slack follow-ups on every report surface (#104264)

Vojta Bartoš884f7a9ff4d7
diff --git a/ee/tasks/subscriptions/slack_subscriptions.py b/ee/tasks/subscriptions/slack_subscriptions.py
index 3546279131aa..ef11567e11e1 100644
--- a/ee/tasks/subscriptions/slack_subscriptions.py
+++ b/ee/tasks/subscriptions/slack_subscriptions.py
@@ -9,7 +9,6 @@ import structlog
from slack_sdk.errors import SlackApiError
from posthog.dataclasses import frozen
-from posthog.helpers.slack_subscription_explore import build_explore_hint, build_explore_hint_text
from posthog.models.integration import Integration, SlackIntegration
from posthog.storage import object_storage
from posthog.sync import database_sync_to_async
@@ -17,6 +16,7 @@ from posthog.utils import absolute_uri
from products.exports.backend.models.exported_asset import ExportedAsset
from products.exports.backend.models.subscription import Subscription, SubscriptionResource
+from products.slack_app.backend.facade.api import slack_followup_invite, slack_followup_invite_text
from ee.tasks.subscriptions.subscription_utils import (
DEBUG_PLACEHOLDER_IMAGE_URL,
@@ -172,7 +172,7 @@ def _prepare_slack_gallery(
)
ai_enabled = bool(integration and integration.team.organization.is_ai_data_processing_approved)
- if explore_hint := build_explore_hint_text(integration, utm_tags=utm_tags, ai_enabled=ai_enabled):
+ if explore_hint := slack_followup_invite_text(integration, utm_tags=utm_tags, ai_enabled=ai_enabled):
lines.append(explore_hint)
return SlackGallery(
@@ -290,7 +290,7 @@ def _prepare_slack_message(
]
)
ai_enabled = bool(integration and integration.team.organization.is_ai_data_processing_approved)
- if explore_hint := build_explore_hint(integration, utm_tags=utm_tags, ai_enabled=ai_enabled):
+ if explore_hint := slack_followup_invite(integration, utm_tags=utm_tags, ai_enabled=ai_enabled):
blocks.append(explore_hint)
# Prepare additional messages for thread
diff --git a/ee/tasks/test/subscriptions/test_slack_subscriptions.py b/ee/tasks/test/subscriptions/test_slack_subscriptions.py
index 0e5dc7619f40..da65f8388b55 100644
--- a/ee/tasks/test/subscriptions/test_slack_subscriptions.py
+++ b/ee/tasks/test/subscriptions/test_slack_subscriptions.py
@@ -10,13 +10,13 @@ from parameterized import parameterized
from slack_sdk.errors import SlackApiError
from slack_sdk.web.async_slack_response import AsyncSlackResponse
-from posthog.helpers.slack_scopes import REQUIRED_SLACK_SCOPES
from posthog.models.integration import Integration
from products.dashboards.backend.models.dashboard import Dashboard
from products.exports.backend.models.exported_asset import ExportedAsset
from products.exports.backend.models.subscription import Subscription
from products.product_analytics.backend.facade.models import Insight
+from products.slack_app.backend.facade.testing import REQUIRED_SLACK_SCOPES
from ee.tasks.subscriptions import SLACK_USER_CONFIG_ERRORS
from ee.tasks.subscriptions.slack_subscriptions import (
diff --git a/posthog/helpers/slack_subscription_explore.py b/posthog/helpers/slack_subscription_explore.py
deleted file mode 100644
index 3d72d61d11cf..000000000000
--- a/posthog/helpers/slack_subscription_explore.py
+++ /dev/null
@@ -1,34 +0,0 @@
-# In core ``posthog`` so the delivery paths (``ee/tasks``, ``products/exports``) can import this
-# without crossing tach's ``products.slack_app`` boundary.
-
-from typing import Any
-
-from posthog.helpers.slack_scopes import bot_is_ready
-from posthog.models.integration import Integration
-
-BOT_SETUP_DOCS_URL = "https://posthog.com/docs/slack-app"
-
-
-def build_explore_hint_text(integration: Integration | None, *, utm_tags: str, ai_enabled: bool) -> str | None:
- """mrkdwn nudging the channel to @PostHog this report (or to set the bot up).
-
- Returns ``None`` when there's no Slack install or the org hasn't approved AI data processing —
- we don't nudge people toward the AI bot when their org hasn't opted into AI. Plain-text variant
- used where Slack only accepts mrkdwn (e.g. a gallery upload's ``initial_comment``).
- """
- if integration is None or not ai_enabled:
- return None
- if bot_is_ready(integration):
- return "💬 Reply in this thread and mention *@PostHog* with a question to dig into this report."
- return f"💬 <{BOT_SETUP_DOCS_URL}?{utm_tags}|Set up the @PostHog bot> to ask follow-up questions about your reports here."
-
-
-def build_explore_hint(integration: Integration | None, *, utm_tags: str, ai_enabled: bool) -> dict[str, Any] | None:
- """Slack context block nudging the channel to @PostHog this report (or to set the bot up).
-
- Returns ``None`` in the same cases as ``build_explore_hint_text``.
- """
- text = build_explore_hint_text(integration, utm_tags=utm_tags, ai_enabled=ai_enabled)
- if text is None:
- return None
- return {"type": "context", "elements": [{"type": "mrkdwn", "text": text}]}
diff --git a/posthog/temporal/ai_observability/eval_reports/delivery.py b/posthog/temporal/ai_observability/eval_reports/delivery.py
index f2ef29fbd8be..f2ff40c42fd6 100644
--- a/posthog/temporal/ai_observability/eval_reports/delivery.py
+++ b/posthog/temporal/ai_observability/eval_reports/delivery.py
@@ -34,6 +34,8 @@ _LEADING_HEADING_RE = re.compile(r"^\s*#{1,6}\s+(.+?)\s*(?:\r?\n|$)")
_md = MarkdownIt("commonmark", {"html": False}).enable("table")
_slack_converter = SlackMarkdownConverter()
+_INVITE_UTM_TAGS = "utm_source=posthog&utm_campaign=eval_report&utm_medium=slack"
+
# Inline styles for email-safe HTML (many clients strip <style> blocks)
_EMAIL_TABLE_STYLE = 'style="border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 14px;"'
_EMAIL_TH_STYLE = (
@@ -348,6 +350,8 @@ def deliver_slack_report(
"""
from posthog.models.integration import Integration, SlackIntegration
+ from products.slack_app.backend.facade.api import slack_followup_invite
+
content = EvalReportContent.from_dict(report_run.content)
citation_map = _build_citation_map(content.citations)
errors: list[str] = []
@@ -382,7 +386,11 @@ def deliver_slack_report(
continue
try:
- integration = Integration.objects.get(id=integration_id, team_id=team_id, kind="slack")
+ # The organization comes along because the follow-up invite below reads its AI consent
+ # flag, and this query already runs once per target.
+ integration = Integration.objects.select_related("team__organization").get(
+ id=integration_id, team_id=team_id, kind="slack"
+ )
client = SlackIntegration(integration).client
# Main message: header + context + metrics grid + first section (if any)
@@ -410,6 +418,11 @@ def deliver_slack_report(
}
)
+ # Read rather than assumed: nothing on this path enforces consent before generation.
+ ai_enabled = bool(integration.team.organization.is_ai_data_processing_approved)
+ if invite := slack_followup_invite(integration, utm_tags=_INVITE_UTM_TAGS, ai_enabled=ai_enabled):
+ blocks.append(invite)
+
result = client.chat_postMessage(
channel=channel_id,
blocks=blocks,
diff --git a/posthog/temporal/ai_observability/eval_reports/test/test_delivery.py b/posthog/temporal/ai_observability/eval_reports/test/test_delivery.py
index 79b973d1ae37..4589cfb95bd5 100644
--- a/posthog/temporal/ai_observability/eval_reports/test/test_delivery.py
+++ b/posthog/temporal/ai_observability/eval_reports/test/test_delivery.py
@@ -581,6 +581,37 @@ class TestDeliverSlackReport(SimpleTestCase):
for call in client.chat_postMessage.call_args_list:
self.assertEqual(call.kwargs["channel"], "C0B5CHB0JQH")
+ @patch("posthog.models.integration.SlackIntegration")
+ @patch("posthog.models.integration.Integration")
+ def test_root_message_carries_the_followup_invite(self, mock_integration, mock_slack_integration):
+ # The invite goes on the root message only, so a reader meets it once per report rather
+ # than under every section. Which of its two variants renders is the shared builder's
+ # decision, tested in products/slack_app; here it only has to be attached.
+ client = MagicMock()
+ client.chat_postMessage.return_value = {"ts": "123.456"}
+ mock_slack_integration.return_value.client = client
+
+ targets = [{"type": "slack", "integration_id": 1, "channel": "C0B5CHB0JQH|#evals"}]
+ errors = deliver_slack_report(
+ self._make_report_run(
+ sections=[
+ ReportSection(title="Summary", content="All good."),
+ ReportSection(title="Details", content="More detail."),
+ ]
+ ),
+ targets,
+ evaluation_name="Test Eval",
+ team_id=1,
+ project_id=1,
+ period_start="2026-03-01T00:00:00+00:00",
+ period_end="2026-03-02T00:00:00+00:00",
+ )
+
+ self.assertEqual(errors, [])
+ root_blocks = client.chat_postMessage.call_args_list[0].kwargs["blocks"]
+ self.assertIn("@PostHog", root_blocks[-1]["elements"][0]["text"])
+ self.assertNotIn("blocks", client.chat_postMessage.call_args_list[1].kwargs)
+
@patch("posthog.models.integration.SlackIntegration")
@patch("posthog.models.integration.Integration")
def test_empty_channel_id_fails_gracefully(self, mock_integration, mock_slack_integration):
diff --git a/products/exports/backend/temporal/subscriptions/ai_subscription/delivery.py b/products/exports/backend/temporal/subscriptions/ai_subscription/delivery.py
index 927284f60416..c8967d48fa0d 100644
--- a/products/exports/backend/temporal/subscriptions/ai_subscription/delivery.py
+++ b/products/exports/backend/temporal/subscriptions/ai_subscription/delivery.py
@@ -15,7 +15,6 @@ from slack_sdk.errors import SlackApiError
from posthog.email import EmailMessage, raise_if_delivery_rejected
from posthog.exceptions_capture import capture_exception
from posthog.helpers.markdown_safety import strip_external_links_markdown
-from posthog.helpers.slack_subscription_explore import build_explore_hint
from posthog.models import Team, User
from posthog.models.integration import Integration
from posthog.sync import database_sync_to_async
@@ -38,6 +37,7 @@ from products.exports.backend.temporal.subscriptions.ai_subscription.spec_genera
compute_report_window,
)
from products.exports.backend.temporal.subscriptions.types import AI_REPORT_WINDOW_END_KEY, SubscriptionTriggerType
+from products.slack_app.backend.facade.api import slack_followup_invite
from ee.tasks.subscriptions.slack_subscriptions import (
UTM_TAGS_BASE,
@@ -439,7 +439,7 @@ def _build_ai_slack_message(
)
# AI consent is enforced before report generation, so this renderer only applies the delivery option.
if subscription.includes_delivery_part("include_posthog_hint"):
- if explore_hint := build_explore_hint(integration, utm_tags=utm_tags, ai_enabled=True):
+ if explore_hint := slack_followup_invite(integration, utm_tags=utm_tags, ai_enabled=True):
footer_blocks.append(explore_hint)
if footer_blocks:
blocks.append({"type": "divider"})
diff --git a/products/exports/backend/temporal/subscriptions/ai_subscription/test/test_delivery.py b/products/exports/backend/temporal/subscriptions/ai_subscription/test/test_delivery.py
index dfb3e4582a63..1b2e5823df7f 100644
--- a/products/exports/backend/temporal/subscriptions/ai_subscription/test/test_delivery.py
+++ b/products/exports/backend/temporal/subscriptions/ai_subscription/test/test_delivery.py
@@ -10,8 +10,6 @@ from django.template.loader import render_to_string
from parameterized import parameterized
from slack_sdk.errors import SlackApiError
-from posthog.helpers.slack_scopes import REQUIRED_SLACK_SCOPES
-
from products.exports.backend.models.subscription import AIQueryPlanStatus, Subscription, SubscriptionDelivery
from products.exports.backend.temporal.subscriptions.ai_subscription.activities import _deliver_ai_subscription
from products.exports.backend.temporal.subscriptions.ai_subscription.delivery import (
@@ -40,6 +38,7 @@ from products.exports.backend.temporal.subscriptions.types import (
DeliverSubscriptionResult,
SubscriptionTriggerType,
)
+from products.slack_app.backend.facade.testing import REQUIRED_SLACK_SCOPES
from ee.tasks.subscriptions.slack_subscriptions import SlackMessage
from ee.tasks.subscriptions.teams_subscriptions import TEAMS_CARD_TEXT_BUDGET
diff --git a/products/signals/backend/scout_harness/slack_delivery.py b/products/signals/backend/scout_harness/slack_delivery.py
index 55d2b2c6f020..ee7fb31a9274 100644
--- a/products/signals/backend/scout_harness/slack_delivery.py
+++ b/products/signals/backend/scout_harness/slack_delivery.py
@@ -36,6 +36,7 @@ from products.signals.backend.slack_formatting import (
split_markdown_by_headings,
strip_chart_references,
)
+from products.slack_app.backend.facade.api import slack_followup_invite
logger = structlog.get_logger(__name__)
@@ -80,8 +81,7 @@ DELIVERABLE_REPORT_STATUSES = frozenset((SignalReport.Status.READY, SignalReport
# way.
MAX_SLACK_NOTE_SNAPSHOT_LEN = 6000
-# Posted as an in-thread reply under every scout Slack message, inviting @PostHog follow-ups.
-_SCOUT_SLACK_REPLY_TEXT = "💬 If you have questions, reply in this thread and mention *`@PostHog`*!"
+_SCOUT_INVITE_UTM_TAGS = "utm_source=posthog&utm_campaign=scout_report&utm_medium=slack"
@dataclass(frozen=True)
@@ -148,42 +148,27 @@ def _slack_retry_after_seconds(exc: Exception) -> int | None:
return min(retry_after, 3600) if retry_after is not None and retry_after > 0 else None
-def _post_scout_slack_reply(
- client: object,
- *,
- channel_id: str,
- thread_ts: object,
- scout_team_id: int,
- integration_team_id: int,
-) -> None:
- """Invite @PostHog follow-ups when the Slack connection uses the scout's environment.
+def _scout_invite_footer(integration: Integration, *, scout_team_id: int, channel_id: str) -> list[dict]:
+ """The follow-up invite footer, when the Slack connection uses the scout's environment.
+
+ A mention is answered from the connected project, so a connection pointing somewhere else would
+ answer the follow-up from data the reader never asked about. Better to say nothing.
- Best-effort and non-blocking: the scout message itself has already been delivered, so a failed
- or missing follow-up never fails the delivery (and so never re-posts the parent on retry).
+ The invite is the shared report footer, so an install that lacks the scopes the bot needs is
+ offered the setup link instead of a mention nothing would answer.
"""
- if integration_team_id != scout_team_id:
+ if integration.team_id != scout_team_id:
logger.info(
"scout_slack_followup_reply_skipped_environment_mismatch",
scout_team_id=scout_team_id,
- integration_team_id=integration_team_id,
- channel=channel_id,
- )
- return
- if not isinstance(thread_ts, str) or not thread_ts:
- return
- try:
- client.chat_postMessage( # type: ignore[attr-defined]
+ integration_team_id=integration.team_id,
channel=channel_id,
- thread_ts=thread_ts,
- blocks=[{"type": "context", "elements": [{"type": "mrkdwn", "text": _SCOUT_SLACK_REPLY_TEXT}]}],
- text=_SCOUT_SLACK_REPLY_TEXT,
- unfurl_links=False,
- unfurl_media=False,
)
- except Exception:
- # Swallow everything (not just SlackApiError): a transport-level failure here must never
- # fail the task and retry the already-delivered parent message.
- logger.warning("scout_slack_followup_reply_failed", channel=channel_id, exc_info=True)
+ return []
+ # Consent is enforced before a scout report is generated, so the report this footer closes is
+ # already the nudge the AI gate exists to withhold.
+ invite = slack_followup_invite(integration, utm_tags=_SCOUT_INVITE_UTM_TAGS, ai_enabled=True)
+ return [invite] if invite is not None else []
def _prettify_scout_name(skill_name: str) -> str:
@@ -293,11 +278,12 @@ def post_scout_emission_to_slack(
channel_id = _slack_channel_id(channel)
blocks, fallback = build_scout_slack_message(emission)
+ blocks.extend(_scout_invite_footer(integration, scout_team_id=emission.team_id, channel_id=channel_id))
slack = SlackIntegration(integration)
client = slack.client
try:
_ensure_dm_recipient_eligible(slack, channel_id)
- response = client.chat_postMessage(
+ client.chat_postMessage(
channel=channel_id,
blocks=blocks,
text=fallback,
@@ -316,14 +302,6 @@ def post_scout_emission_to_slack(
) from exc
raise
- _post_scout_slack_reply(
- client,
- channel_id=channel_id,
- thread_ts=response.get("ts"),
- scout_team_id=emission.team_id,
- integration_team_id=integration.team_id,
- )
-
def _report_header(report: SignalReport) -> str:
title = " ".join((report.title or "").split()) or "New scout report"
@@ -738,13 +716,17 @@ def post_scout_report_to_slack(
)
slack = SlackIntegration(integration)
client = slack.client
+ lead_blocks = [
+ *messages.lead_blocks,
+ *_scout_invite_footer(integration, scout_team_id=run.team_id, channel_id=channel_id),
+ ]
try:
_ensure_dm_recipient_eligible(slack, channel_id)
response = _post_scout_report_lead_message(
client,
channel_id=channel_id,
delivery_id=delivery_id,
- blocks=messages.lead_blocks,
+ blocks=lead_blocks,
fallback=messages.fallback,
)
except SlackApiError as exc:
@@ -767,11 +749,3 @@ def post_scout_report_to_slack(
fallback=messages.fallback,
schedule_retry=schedule_thread_reply_retry,
)
-
- _post_scout_slack_reply(
- client,
- channel_id=channel_id,
- thread_ts=thread_ts,
- scout_team_id=run.team_id,
- integration_team_id=integration.team_id,
- )
diff --git a/products/signals/backend/slack_inbox_notifications.py b/products/signals/backend/slack_inbox_notifications.py
index 40b37bb297d0..8fd0da44b841 100644
--- a/products/signals/backend/slack_inbox_notifications.py
+++ b/products/signals/backend/slack_inbox_notifications.py
@@ -52,6 +52,7 @@ from products.signals.backend.slack_formatting import (
strip_chart_references as _strip_chart_references,
)
from products.signals.backend.slack_notification_targets import is_slack_member_target, lookup_slack_user_id_by_email
+from products.slack_app.backend.facade.api import slack_followup_invite
# Actionability values shown in the inbox Reports tab. Slack notifications mirror that tab, so a
# report notifies iff its latest actionability judgment is one of these (and it's READY).
@@ -63,6 +64,7 @@ logger = logging.getLogger(__name__)
_SUMMARY_EXCERPT_MAX_LEN = 600
_SLACK_HEADER_MAX_LEN = 150
+_INBOX_INVITE_UTM_TAGS = "utm_source=posthog&utm_campaign=signals_inbox&utm_medium=slack"
# Bound message size / avoid pinging a crowd.
_MAX_REVIEWER_MENTIONS = 5
@@ -687,6 +689,12 @@ def _deliver_route_notification(
reviewer_mentions=mentions,
repository=repository,
)
+ # Added here rather than inside the block builder, which stays free of the integration so it
+ # can be tested without one. Approval is read now, not assumed from generation time: a
+ # reviewer can be added to a retained report after the org revoked it.
+ ai_enabled = bool(report.team.organization.is_ai_data_processing_approved)
+ if invite := slack_followup_invite(route.integration, utm_tags=_INBOX_INVITE_UTM_TAGS, ai_enabled=ai_enabled):
+ blocks.append(invite)
response = slack.client.chat_postMessage(channel=channel_id, blocks=blocks, text=text)
delivered = True
thread_ts = response.get("ts") if hasattr(response, "get") else None
diff --git a/products/signals/backend/test/test_scout_slack_delivery.py b/products/signals/backend/test/test_scout_slack_delivery.py
index 67ba501ed9d7..5650da72d300 100644
--- a/products/signals/backend/test/test_scout_slack_delivery.py
+++ b/products/signals/backend/test/test_scout_slack_delivery.py
@@ -35,6 +35,7 @@ from products.signals.backend.tasks import (
deliver_scout_slack_thread_replies,
enqueue_scout_slack_delivery,
)
+from products.slack_app.backend.facade.testing import REQUIRED_SLACK_SCOPES
class FakeSlackResponse(dict):
@@ -158,6 +159,7 @@ class TestScoutSlackDelivery(BaseTest):
f"{settings.SITE_URL}/project/{self.team.id}/inbox/scouts/signals-scout-error-tracking/checkout%2F500s"
)
assert fake_client.chat_postMessage.call_count == 1
+ assert call["blocks"][-1]["type"] == "actions"
def test_posts_report_with_safe_markdown_and_delivery_id(self) -> None:
emission = self._make_emission()
@@ -202,12 +204,12 @@ class TestScoutSlackDelivery(BaseTest):
# summary to mrkdwn: the converter lifted tables out before converting anything, then put
# the cells back untouched.
assert "[#93147 fix(checkout): retry 500s](https://example.com/pull/93147)" in markdown
- assert call["blocks"][-1]["elements"][0]["url"] == (
+ actions_block = next(block for block in call["blocks"] if block["type"] == "actions")
+ assert actions_block["elements"][0]["url"] == (
f"{settings.SITE_URL}/project/{self.team.id}/inbox/reports/{report.id}"
)
- reply = fake_client.chat_postMessage.call_args_list[1].kwargs
- assert reply["thread_ts"] == "1785418710.000200"
- assert reply["blocks"][0]["type"] == "context"
+ assert call["blocks"][-1]["type"] == "context"
+ assert fake_client.chat_postMessage.call_count == 1
def test_note_only_edit_delivers_the_note_instead_of_the_report(self) -> None:
# Without the edit_note branch a note-only edit re-posts the full report message, which is
@@ -247,7 +249,8 @@ class TestScoutSlackDelivery(BaseTest):
assert "<!channel>" not in markdown
assert "&lt;!channel&gt;" in markdown
assert "failed for many users" not in markdown
- assert call["blocks"][-1]["elements"][0]["url"] == (
+ actions_block = next(block for block in call["blocks"] if block["type"] == "actions")
+ assert actions_block["elements"][0]["url"] == (
f"{settings.SITE_URL}/project/{self.team.id}/inbox/reports/{report.id}"
)
@@ -424,9 +427,8 @@ class TestScoutSlackDelivery(BaseTest):
thread_reports=True,
)
- # The lead, one reply per top-level section, then the unconditional @PostHog follow-up.
calls = fake_client.chat_postMessage.call_args_list
- assert len(calls) == 4
+ assert len(calls) == 3
assert "thread_ts" not in calls[0].kwargs
lead_chunks = [block["text"] for block in calls[0].kwargs["blocks"] if block["type"] == "markdown"]
assert lead_chunks == ["Lead line."]
@@ -441,7 +443,7 @@ class TestScoutSlackDelivery(BaseTest):
assert "Detail" in first_reply["blocks"][0]["text"]
assert "Second" not in first_reply["blocks"][0]["text"]
assert "Second" in second_reply["blocks"][0]["text"]
- assert calls[3].kwargs["blocks"][0]["type"] == "context"
+ assert calls[0].kwargs["blocks"][-1]["type"] == "context"
sleep.assert_called_once_with(1)
def test_threaded_report_without_section_labels_posts_a_single_message(self) -> None:
@@ -471,14 +473,13 @@ class TestScoutSlackDelivery(BaseTest):
thread_reports=True,
)
- # Only the lead message and the unconditional @PostHog follow-up reply.
calls = fake_client.chat_postMessage.call_args_list
- assert len(calls) == 2
+ assert len(calls) == 1
assert "thread_ts" not in calls[0].kwargs
markdown_texts = [block["text"] for block in calls[0].kwargs["blocks"] if block["type"] == "markdown"]
assert len(markdown_texts) == 1
assert "second one" in markdown_texts[0]
- assert calls[1].kwargs["blocks"][0]["type"] == "context"
+ assert calls[0].kwargs["blocks"][-1]["type"] == "context"
def test_threaded_report_schedules_a_rate_limited_reply(self) -> None:
emission = self._make_emission()
@@ -520,7 +521,7 @@ class TestScoutSlackDelivery(BaseTest):
assert retry_kwargs["chunk_offset"] == 0
assert len(retry_kwargs["reply_blocks"]) == 2
assert "First body" in retry_kwargs["reply_blocks"][0][0]["text"]
- assert fake_client.chat_postMessage.call_count == 3
+ assert fake_client.chat_postMessage.call_count == 2
def test_thread_reply_retry_after_is_bounded_to_one_hour(self) -> None:
response = FakeSlackResponse({"error": "ratelimited"}, headers={"Retry-After": "7200"})
@@ -641,7 +642,7 @@ class TestScoutSlackDelivery(BaseTest):
assert retry_kwargs["chunk_offset"] == 0
assert len(retry_kwargs["reply_blocks"]) == 2
- def test_reply_posted_regardless_of_ai_approval(self) -> None:
+ def test_invite_posted_regardless_of_ai_approval(self) -> None:
# The Slack follow-up invite is unconditional — no AI-approval gate on scout output.
self.organization.is_ai_data_processing_approved = False
self.organization.save()
@@ -668,17 +669,27 @@ class TestScoutSlackDelivery(BaseTest):
"CSCOUTS|#scout-findings",
)
- assert fake_client.chat_postMessage.call_count == 2
- reply = fake_client.chat_postMessage.call_args_list[1].kwargs
- assert reply["thread_ts"] == "1785418710.000400"
+ assert fake_client.chat_postMessage.call_count == 1
+ blocks = fake_client.chat_postMessage.call_args.kwargs["blocks"]
+ assert "@PostHog" in blocks[-1]["elements"][0]["text"]
- def test_reply_transport_failure_does_not_fail_delivery(self) -> None:
- # The parent message already landed, so a failing follow-up reply — even a non-SlackApiError
- # transport error — must be swallowed rather than fail the task and retry the whole delivery.
+ @parameterized.expand(
+ [
+ ("bot_ready", REQUIRED_SLACK_SCOPES, "mention *@PostHog*"),
+ ("bot_not_ready", frozenset({"chat:write"}), "Set up the @PostHog bot"),
+ ]
+ )
+ def test_followup_invite_matches_install_readiness(
+ self, _name: str, scopes: frozenset[str], expected_fragment: str
+ ) -> None:
emission = self._make_emission()
- integration = Integration.objects.create(team=self.team, kind=Integration.IntegrationKind.SLACK)
+ integration = Integration.objects.create(
+ team=self.team,
+ kind=Integration.IntegrationKind.SLACK,
+ config={"scope": ",".join(sorted(scopes))},
+ )
fake_client = MagicMock()
- fake_client.chat_postMessage.side_effect = [{"ts": "1785418710.000500"}, ConnectionError("boom")]
+ fake_client.chat_postMessage.return_value = {"ts": "1785418710.000600"}
with patch("products.signals.backend.scout_harness.slack_delivery.SlackIntegration") as slack_integration:
slack_integration.return_value.client = fake_client
@@ -689,7 +700,8 @@ class TestScoutSlackDelivery(BaseTest):
channel="CSCOUTS|#scout-findings",
)
- assert fake_client.chat_postMessage.call_count == 2
+ blocks = fake_client.chat_postMessage.call_args.kwargs["blocks"]
+ assert expected_fragment in blocks[-1]["elements"][0]["text"]
@parameterized.expand(
[
@@ -1129,8 +1141,17 @@ class TestScoutSlackDelivery(BaseTest):
)
rejected, resent = (call.kwargs["blocks"] for call in fake_client.chat_postMessage.call_args_list[:2])
- assert [b["type"] for b in rejected] == ["context", "header", "markdown", "section", "image", "actions"]
- assert [b["type"] for b in resent] == ["context", "header", "markdown", "actions"]
+ # The strip-and-retry drops only chart blocks, so the invite footer rides both attempts.
+ assert [b["type"] for b in rejected] == [
+ "context",
+ "header",
+ "markdown",
+ "section",
+ "image",
+ "actions",
+ "context",
+ ]
+ assert [b["type"] for b in resent] == ["context", "header", "markdown", "actions", "context"]
def test_task_retries_transient_delivery_failure(self) -> None:
emission = self._make_emission()
diff --git a/products/signals/backend/test/test_slack_inbox_notifications.py b/products/signals/backend/test/test_slack_inbox_notifications.py
index b576ec36c63e..756c103655a7 100644
--- a/products/signals/backend/test/test_slack_inbox_notifications.py
+++ b/products/signals/backend/test/test_slack_inbox_notifications.py
@@ -378,8 +378,12 @@ def test_dispatch_skips_a_direct_message_to_an_ineligible_member(org_and_team):
@pytest.mark.django_db
-def test_dispatch_posts_to_team_channel_without_per_user_config(org_and_team):
[email protected]("ai_approved", [True, False])
+def test_dispatch_posts_to_team_channel_without_per_user_config(org_and_team, ai_approved):
org, team = org_and_team
+ if not ai_approved:
+ org.is_ai_data_processing_approved = False
+ org.save()
reviewer = _make_reviewer_user(org, "[email protected]", "team-bot")
_make_slack_integration(team, reviewer)
_set_team_channel(team, "CTEAM|#posthog-signals")
@@ -400,6 +404,10 @@ def test_dispatch_posts_to_team_channel_without_per_user_config(org_and_team):
call_kwargs = fake_client.chat_postMessage.call_args.kwargs
assert call_kwargs["channel"] == "CTEAM"
assert "<@U_TEAM>" in call_kwargs["blocks"][2]["elements"][0]["text"]
+ # The invite closes the message, and only while the org still approves AI data processing:
+ # a reviewer can be added to a retained report after that approval is revoked. Which of the
+ # two variants renders is the shared builder's decision, tested in products/slack_app.
+ assert ("@PostHog" in call_kwargs["blocks"][-1]["elements"][0]["text"]) is ai_approved
@pytest.mark.django_db
diff --git a/products/slack_app/backend/api.py b/products/slack_app/backend/api.py
index 9e9d7805ddfa..c39d438a025e 100644
--- a/products/slack_app/backend/api.py
+++ b/products/slack_app/backend/api.py
@@ -25,7 +25,6 @@ from temporalio.common import WorkflowIDConflictPolicy, WorkflowIDReusePolicy
from posthog.dataclasses import frozen
from posthog.event_usage import groups
from posthog.git import extract_explicit_repo, extract_linked_repo, extract_repo_from_scopes
-from posthog.helpers.slack_scopes import REQUIRED_SLACK_SCOPES
from posthog.models.integration import (
SLACK_INTEGRATION_KINDS,
Integration,
@@ -94,6 +93,7 @@ from products.slack_app.backend.services.slack_messages import (
parse_slack_file_refs,
post_slack_thread_reply,
)
+from products.slack_app.backend.services.slack_scopes import REQUIRED_SLACK_SCOPES
from products.slack_app.backend.services.slack_settings import resolve_untagged_followup_mode
from products.slack_app.backend.services.slack_user_info import (
clear_workspace_profile_cache,
diff --git a/products/slack_app/backend/facade/api.py b/products/slack_app/backend/facade/api.py
index 418b91989402..b0ba44eea78f 100644
--- a/products/slack_app/backend/facade/api.py
+++ b/products/slack_app/backend/facade/api.py
@@ -4,22 +4,39 @@ The ONLY module other products are allowed to import. Keep the surface narrow:
every function here lives behind a tach contract check, so each addition has a
cost in cross-product coupling.
-Today the facade exists for two jobs: letting core's OAuth callback invalidate
-the per-integration auth-state cache when a Slack install is reconnected, and
-answering whether a channel has been approved for PostHog to speak in. Both are
-stable re-exports so the implementations can move around inside slack_app
-without breaking their callers.
+Today the facade exists for three jobs: letting core's OAuth callback invalidate
+the per-integration auth-state cache when a Slack install is reconnected,
+answering whether a channel has been approved for PostHog to speak in, and
+telling a product that posts a report whether the bot can answer a follow-up.
+All are stable re-exports so the implementations can move around inside
+slack_app without breaking their callers.
+
+This module's import graph must not reach ``products.signals``. That product now imports this
+facade, and ``products.slack_app`` imports signals' facade in turn, so a module-level edge from
+here back into signals closes the loop and breaks Django startup. Reach signals from a function
+body instead, the way the handlers under ``backend/`` already do.
"""
from __future__ import annotations
-from posthog.helpers.slack_scopes import has_scopes
+from typing import Any
+
from posthog.models.integration import Integration
from products.slack_app.backend.models import SlackChannel
+from products.slack_app.backend.services.followup_invite import build_followup_invite, build_followup_invite_text
from products.slack_app.backend.services.slack_auth import invalidate_auth_state
+from products.slack_app.backend.services.slack_scopes import has_scopes
from products.slack_app.backend.services.slack_user_info import invalidate_workspace_bot_user_id
+__all__ = [
+ "invalidate_slack_integration_auth_state",
+ "slack_artifact_delivery_state_updates",
+ "slack_channel_is_approved",
+ "slack_followup_invite",
+ "slack_followup_invite_text",
+]
+
_SLACK_CANVAS_FILE_ADAPTER_SCOPES = frozenset({"canvases:write", "files:write"})
@@ -60,3 +77,21 @@ def slack_artifact_delivery_state_updates(integration: Integration) -> dict[str,
"""State that tells a task agent which Slack artifact adapters can deliver."""
mode = "canvas_file" if has_scopes(integration, _SLACK_CANVAS_FILE_ADAPTER_SCOPES) else "message"
return {"slack_artifact_delivery": mode, "slack_chart_delivery": True}
+
+
+def slack_followup_invite_text(integration: Integration | None, *, utm_tags: str, ai_enabled: bool) -> str | None:
+ """The mrkdwn line inviting a reader to ask the bot a follow-up about this message.
+
+ Returns ``None`` when there is nothing to invite: no Slack install, or an organization that has
+ not approved AI data processing. A workspace whose bot cannot answer a mention gets the setup
+ link instead, so a caller never has to check the install itself.
+
+ ``utm_tags`` attributes an install that starts from the setup link, so each caller passes its
+ own campaign.
+ """
+ return build_followup_invite_text(integration, utm_tags=utm_tags, ai_enabled=ai_enabled)
+
+
+def slack_followup_invite(integration: Integration | None, *, utm_tags: str, ai_enabled: bool) -> dict[str, Any] | None:
+ """``slack_followup_invite_text`` as a Slack context block, for a caller that appends blocks."""
+ return build_followup_invite(integration, utm_tags=utm_tags, ai_enabled=ai_enabled)
diff --git a/products/slack_app/backend/facade/testing.py b/products/slack_app/backend/facade/testing.py
new file mode 100644
index 000000000000..94b73bfcdde7
--- /dev/null
+++ b/products/slack_app/backend/facade/testing.py
@@ -0,0 +1,14 @@
+"""Test-support facade for slack_app.
+
+Sibling products' tests build a Slack ``Integration`` fixture standing for a workspace whose bot
+can answer a mention, which means writing the granted scope string the bot actually requires.
+
+``facade.api`` does not carry the scope set, because no production caller outside slack_app needs
+it: ``slack_followup_invite_text`` resolves readiness itself and returns the setup link when the
+install falls short. Exposing it here keeps that production surface closed while the fixtures that
+genuinely need the value still have one supported way to read it.
+"""
+
+from products.slack_app.backend.services.slack_scopes import REQUIRED_SLACK_SCOPES
+
+__all__ = ["REQUIRED_SLACK_SCOPES"]
diff --git a/products/slack_app/backend/feature_flags.py b/products/slack_app/backend/feature_flags.py
index b06b65b7d3f6..a7e89bbebead 100644
--- a/products/slack_app/backend/feature_flags.py
+++ b/products/slack_app/backend/feature_flags.py
@@ -37,10 +37,11 @@ from __future__ import annotations
import structlog
import posthoganalytics
-from posthog.helpers.slack_scopes import REQUIRED_SLACK_SCOPES, has_scopes
from posthog.models.integration import Integration
from posthog.utils import get_instance_region
+from products.slack_app.backend.services.slack_scopes import REQUIRED_SLACK_SCOPES, has_scopes
+
logger = structlog.get_logger(__name__)
diff --git a/products/slack_app/backend/services/followup_invite.py b/products/slack_app/backend/services/followup_invite.py
new file mode 100644
index 000000000000..5dafa8d32f40
--- /dev/null
+++ b/products/slack_app/backend/services/followup_invite.py
@@ -0,0 +1,47 @@
+"""The line under a PostHog-authored Slack message that invites the reader to ask a follow-up.
+
+What the line says depends on the install: a workspace whose bot can answer a mention is invited to
+send one, and a workspace whose bot cannot is offered the setup link instead. Other products reach
+these through ``facade.api``.
+"""
+
+from typing import Any
+
+from posthog.models.integration import Integration
+
+from products.slack_app.backend.services.slack_scopes import bot_is_ready
+
+BOT_SETUP_DOCS_URL = "https://posthog.com/docs/slack-app"
+
+
+def build_followup_invite_text(integration: Integration | None, *, utm_tags: str, ai_enabled: bool) -> str | None:
+ """mrkdwn nudging the channel to @PostHog this report (or to set the bot up).
+
+ Returns ``None`` when there's no Slack install or the org hasn't approved AI data processing —
+ we don't nudge people toward the AI bot when their org hasn't opted into AI. Plain-text variant
+ used where Slack only accepts mrkdwn (e.g. a gallery upload's ``initial_comment``).
+
+ The caller resolves ``ai_enabled`` rather than this function reading it off the integration,
+ for two reasons. Reading it costs two foreign-key traversals, which would raise
+ ``SynchronousOnlyOperation`` on the async delivery path in products/exports. And a caller that
+ enforces the consent earlier can say so instead of paying the lookup again.
+
+ ``utm_tags`` attributes an install that starts from the setup link, so each caller passes the
+ campaign that names its own surface.
+ """
+ if integration is None or not ai_enabled:
+ return None
+ if bot_is_ready(integration):
+ return "💬 Reply in this thread and mention *@PostHog* with a question to dig into this report."
+ return f"💬 <{BOT_SETUP_DOCS_URL}?{utm_tags}|Set up the @PostHog bot> to ask follow-up questions about your reports here."
+
+
+def build_followup_invite(integration: Integration | None, *, utm_tags: str, ai_enabled: bool) -> dict[str, Any] | None:
+ """Slack context block nudging the channel to @PostHog this report (or to set the bot up).
+
+ Returns ``None`` in the same cases as ``build_followup_invite_text``.
+ """
+ text = build_followup_invite_text(integration, utm_tags=utm_tags, ai_enabled=ai_enabled)
+ if text is None:
+ return None
+ return {"type": "context", "elements": [{"type": "mrkdwn", "text": text}]}
diff --git a/products/slack_app/backend/services/integration_resolver.py b/products/slack_app/backend/services/integration_resolver.py
index 2cb431657c3e..7c764afb0dd7 100644
--- a/products/slack_app/backend/services/integration_resolver.py
+++ b/products/slack_app/backend/services/integration_resolver.py
@@ -8,13 +8,13 @@ import structlog
from posthog.comment.formatting import escape_slack_mrkdwn
from posthog.dataclasses import frozen
-from posthog.helpers.slack_scopes import bot_is_ready
from posthog.models.integration import Integration
from posthog.models.user import User
from posthog.user_permissions import UserPermissions
from products.slack_app.backend.helpers import local_dev_slack_email
from products.slack_app.backend.models import SlackSettings, SlackThreadTaskMapping
+from products.slack_app.backend.services.slack_scopes import bot_is_ready
logger = structlog.get_logger(__name__)
diff --git a/posthog/helpers/slack_scopes.py b/products/slack_app/backend/services/slack_scopes.py
similarity index 82%
rename from posthog/helpers/slack_scopes.py
rename to products/slack_app/backend/services/slack_scopes.py
index a00b0e73b220..0d13cebcef90 100644
--- a/posthog/helpers/slack_scopes.py
+++ b/products/slack_app/backend/services/slack_scopes.py
@@ -1,6 +1,9 @@
-# In core ``posthog`` so the delivery paths (``ee/tasks``, ``products/exports``) and the
-# ``products.slack_app`` handlers can share the bot's required scopes without crossing tach
-# module boundaries.
+"""What the @PostHog bot needs an install to have granted, and whether a given install has it.
+
+The scope set is the Slack app's own contract with a workspace, so it lives with the app. No
+product outside slack_app reads it: the follow-up invite resolves readiness itself, and the
+fixtures that need the scope string take it from ``facade.testing``.
+"""
from collections.abc import Iterable
diff --git a/products/slack_app/backend/services/slack_welcome_messages.py b/products/slack_app/backend/services/slack_welcome_messages.py
index 11a1aaf0b42a..9035f847fa91 100644
--- a/products/slack_app/backend/services/slack_welcome_messages.py
+++ b/products/slack_app/backend/services/slack_welcome_messages.py
@@ -18,7 +18,6 @@ from typing import Any
from django.conf import settings
-from posthog.helpers.slack_subscription_explore import BOT_SETUP_DOCS_URL
from posthog.models.integration import Integration, SlackIntegration
from posthog.utils import absolute_uri
@@ -30,6 +29,7 @@ from products.slack_app.backend.inbox_channel import (
channel_id_from_target,
channel_name_from_target,
)
+from products.slack_app.backend.services.followup_invite import BOT_SETUP_DOCS_URL
from products.slack_app.backend.services.slack_messages import app_home_url, context_block, section_block
# Block Kit action ids for the onboarding DM, kept in sync with the interactivity router.
diff --git a/products/slack_app/backend/tests/services/test_project_routing.py b/products/slack_app/backend/tests/services/test_project_routing.py
index adad96f7dc03..bc5668035bf1 100644
--- a/products/slack_app/backend/tests/services/test_project_routing.py
+++ b/products/slack_app/backend/tests/services/test_project_routing.py
@@ -1,12 +1,12 @@
import pytest
-from posthog.helpers.slack_scopes import REQUIRED_SLACK_SCOPES
from posthog.models.integration import Integration
from posthog.models.organization import Organization, OrganizationMembership
from posthog.models.team.team import Team
from posthog.models.user import User
from products.slack_app.backend.services.integration_resolver import routable_projects
+from products.slack_app.backend.services.slack_scopes import REQUIRED_SLACK_SCOPES
WORKSPACE = "T_WS"
SLACK_USER = "U001"
diff --git a/products/slack_app/backend/tests/test_channel_onboarding_routing.py b/products/slack_app/backend/tests/test_channel_onboarding_routing.py
index 74ddb369fa58..3dc4cb437460 100644
--- a/products/slack_app/backend/tests/test_channel_onboarding_routing.py
+++ b/products/slack_app/backend/tests/test_channel_onboarding_routing.py
@@ -6,7 +6,6 @@ from django.test.client import RequestFactory
from parameterized import parameterized
-from posthog.helpers.slack_scopes import REQUIRED_SLACK_SCOPES
from posthog.models.integration import Integration
from posthog.models.organization import Organization, OrganizationMembership
from posthog.models.team.team import Team
@@ -20,6 +19,7 @@ from products.slack_app.backend.api import (
route_posthog_code_event_to_relevant_region,
)
from products.slack_app.backend.services.slack_auth import get_cached_auth_state, write_auth_state_ok
+from products.slack_app.backend.services.slack_scopes import REQUIRED_SLACK_SCOPES
MEMBER_EMAIL = "[email protected]"
diff --git a/products/slack_app/backend/tests/test_subscription_explore.py b/products/slack_app/backend/tests/test_followup_invite.py
similarity index 78%
rename from products/slack_app/backend/tests/test_subscription_explore.py
rename to products/slack_app/backend/tests/test_followup_invite.py
index b26f81f0bada..86f25317a92c 100644
--- a/products/slack_app/backend/tests/test_subscription_explore.py
+++ b/products/slack_app/backend/tests/test_followup_invite.py
@@ -2,12 +2,13 @@ from django.test import TestCase
from parameterized import parameterized
-from posthog.helpers.slack_scopes import REQUIRED_SLACK_SCOPES, bot_is_ready
-from posthog.helpers.slack_subscription_explore import build_explore_hint
from posthog.models.integration import Integration
from posthog.models.organization import Organization
from posthog.models.team import Team
+from products.slack_app.backend.services.followup_invite import build_followup_invite
+from products.slack_app.backend.services.slack_scopes import REQUIRED_SLACK_SCOPES, bot_is_ready
+
class TestBotIsReady(TestCase):
def setUp(self) -> None:
@@ -48,20 +49,20 @@ class TestBuildExploreHint(TestCase):
)
def test_no_integration_returns_none(self) -> None:
- assert build_explore_hint(None, utm_tags="utm", ai_enabled=True) is None
+ assert build_followup_invite(None, utm_tags="utm", ai_enabled=True) is None
def test_ai_disabled_returns_none(self) -> None:
# Org hasn't approved AI data processing — don't nudge toward the AI bot, even with a ready install.
- assert build_explore_hint(self._integration(REQUIRED_SLACK_SCOPES), utm_tags="utm", ai_enabled=False) is None
+ assert build_followup_invite(self._integration(REQUIRED_SLACK_SCOPES), utm_tags="utm", ai_enabled=False) is None
def test_bot_ready_nudges_mention(self) -> None:
- hint = build_explore_hint(self._integration(REQUIRED_SLACK_SCOPES), utm_tags="utm", ai_enabled=True)
+ hint = build_followup_invite(self._integration(REQUIRED_SLACK_SCOPES), utm_tags="utm", ai_enabled=True)
assert hint is not None
assert hint["type"] == "context"
assert "@PostHog" in hint["elements"][0]["text"]
def test_bot_not_ready_links_docs(self) -> None:
- hint = build_explore_hint(self._integration(frozenset({"chat:write"})), utm_tags="utm", ai_enabled=True)
+ hint = build_followup_invite(self._integration(frozenset({"chat:write"})), utm_tags="utm", ai_enabled=True)
assert hint is not None
text = hint["elements"][0]["text"]
assert "docs/slack-app?utm" in text
diff --git a/products/slack_app/backend/tests/test_link_unfurl.py b/products/slack_app/backend/tests/test_link_unfurl.py
index fa74f649c8d8..172c867ae445 100644
--- a/products/slack_app/backend/tests/test_link_unfurl.py
+++ b/products/slack_app/backend/tests/test_link_unfurl.py
@@ -10,7 +10,6 @@ from parameterized import parameterized
from structlog.testing import capture_logs
from posthog.constants import AvailableFeature
-from posthog.helpers.slack_scopes import REQUIRED_SLACK_SCOPES
from posthog.models import User
from posthog.models.comment import Comment
from posthog.models.integration import Integration
@@ -25,6 +24,7 @@ from products.product_analytics.backend.facade.models import Insight
from products.slack_app.backend.api import ROUTE_HANDLED_LOCALLY, route_posthog_code_event_to_relevant_region
from products.slack_app.backend.models import SlackChannel
from products.slack_app.backend.services.slack_auth import write_auth_state_ok
+from products.slack_app.backend.services.slack_scopes import REQUIRED_SLACK_SCOPES
from products.slack_app.backend.slack_link_unfurl import (
_insight_resource_label,
handle_posthog_link_unfurl,
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 2b2d7b92bbd6..e76f9f2f19e0 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
@@ -197,7 +197,7 @@ class TestPostHogCodeEventHandler(SimpleTestCase):
class TestRoutePostHogCodeEventToRelevantRegion(TestCase):
def setUp(self):
- from posthog.helpers.slack_scopes import REQUIRED_SLACK_SCOPES
+ from products.slack_app.backend.services.slack_scopes import REQUIRED_SLACK_SCOPES
cache.clear()
self.factory = RequestFactory()
@@ -1263,7 +1263,7 @@ class TestChannelApprovalGate(TestCase):
def setUp(self):
from django.utils import timezone
- from posthog.helpers.slack_scopes import REQUIRED_SLACK_SCOPES
+ from products.slack_app.backend.services.slack_scopes import REQUIRED_SLACK_SCOPES
cache.clear()
self.factory = RequestFactory()
@@ -1418,7 +1418,7 @@ class TestChannelApprovalGate(TestCase):
class TestAssistantEvents(TestCase):
def setUp(self):
- from posthog.helpers.slack_scopes import REQUIRED_SLACK_SCOPES
+ from products.slack_app.backend.services.slack_scopes import REQUIRED_SLACK_SCOPES
cache.clear()
self.factory = RequestFactory()
@@ -1539,7 +1539,7 @@ class TestQueueWorkflowDispatch(TestCase):
def setUp(self):
from django.utils import timezone
- from posthog.helpers.slack_scopes import REQUIRED_SLACK_SCOPES
+ from products.slack_app.backend.services.slack_scopes import REQUIRED_SLACK_SCOPES
cache.clear()
self.factory = RequestFactory()
diff --git a/products/slack_app/backend/tests/test_thread_message_routing.py b/products/slack_app/backend/tests/test_thread_message_routing.py
index 6cae579ff9a0..74c62d6458ef 100644
--- a/products/slack_app/backend/tests/test_thread_message_routing.py
+++ b/products/slack_app/backend/tests/test_thread_message_routing.py
@@ -27,7 +27,7 @@ class TestRouteThreadMessage(TestCase):
workflow so the webhook handler stays fast."""
def setUp(self):
- from posthog.helpers.slack_scopes import REQUIRED_SLACK_SCOPES
+ from products.slack_app.backend.services.slack_scopes import REQUIRED_SLACK_SCOPES
cache.clear()
self.factory = RequestFactory()
diff --git a/products/slack_app/backend/tests/views/test_slack_command.py b/products/slack_app/backend/tests/views/test_slack_command.py
index 4dd8244a4041..14108713b99a 100644
--- a/products/slack_app/backend/tests/views/test_slack_command.py
+++ b/products/slack_app/backend/tests/views/test_slack_command.py
@@ -18,13 +18,13 @@ from django.test.client import RequestFactory
from parameterized import parameterized
from rest_framework.test import APIClient
-from posthog.helpers.slack_scopes import REQUIRED_SLACK_SCOPES
from posthog.models.integration import Integration
from posthog.models.organization import Organization, OrganizationMembership
from posthog.models.team.team import Team
from posthog.models.user import User
from products.slack_app.backend.models import SlackUserProfileCache
+from products.slack_app.backend.services.slack_scopes import REQUIRED_SLACK_SCOPES
from products.slack_app.backend.tests.helpers import sign_slack_request
SIGNING_SECRET = "posthog-code-test-secret"
diff --git a/products/tasks/backend/logic/services/living_artifacts.py b/products/tasks/backend/logic/services/living_artifacts.py
index d48cbb1b1954..883142d3ae97 100644
--- a/products/tasks/backend/logic/services/living_artifacts.py
+++ b/products/tasks/backend/logic/services/living_artifacts.py
@@ -35,7 +35,7 @@ from products.tasks.backend.models import TaskArtifact, TaskRun
logger = structlog.get_logger(__name__)
-# Both scopes are approved but recent (see posthog/helpers/slack_scopes.py), so an install
+# Both scopes are approved but recent (see products/slack_app/backend/services/slack_scopes.py), so an install
# authorized earlier lacks them until it reconnects — the adapters check them at point of use
# and can name the one to grant.
SLACK_CANVAS_SCOPE = "canvases:write"
diff --git a/tach.toml b/tach.toml
index e04479451a3f..144093ee72b5 100644
--- a/tach.toml
+++ b/tach.toml
@@ -41,6 +41,8 @@ utility = true
[[modules]]
path = "ee"
depends_on = [
+ # Facade-only: a Slack subscription asks whether the bot can answer a follow-up on its report.
+ "products.slack_app",
"products.cohorts",
"posthog",
"products.access_control",
@@ -820,6 +822,9 @@ layer = "modules"
[[modules]]
path = "products.signals"
depends_on = [
+ # Facade-only: a scout report asks whether the bot can answer a follow-up on it. products.slack_app
+ # depends on products.signals in turn, so both directions stay facade-only to keep the pair honest.
+ "products.slack_app",
"ee",
"products.cohorts",
"posthog",
@@ -1501,7 +1506,8 @@ from = [
[[modules]]
path = "products.exports"
-depends_on = ["posthog", "products.actions", "products.dashboards", "ee", "products.annotations", "products.ai_observability", "products.posthog_ai", "products.product_analytics", "products.access_control"]
+# products.slack_app is facade-only: an AI subscription asks whether the bot can answer a follow-up.
+depends_on = ["posthog", "products.actions", "products.dashboards", "ee", "products.annotations", "products.ai_observability", "products.posthog_ai", "products.product_analytics", "products.access_control", "products.slack_app"]
layer = "modules"
[[modules]]