: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
chore(conversations): add local Slack setup skill (#71253)
Xander42341c37164a
diff --git a/products/conversations/.gitignore b/products/conversations/.gitignoreindex 2ce9f756f840..e47dc1f75be8 100644--- a/products/conversations/.gitignore+++ b/products/conversations/.gitignore@@ -1 +1 @@-skills/\ No newline at end of file+skills/review-support-reply/diff --git a/products/conversations/skills/setting-up-support-slack-locally/SKILL.md b/products/conversations/skills/setting-up-support-slack-locally/SKILL.mdnew file mode 100644index 000000000000..31134573c6f2--- /dev/null+++ b/products/conversations/skills/setting-up-support-slack-locally/SKILL.md@@ -0,0 +1,120 @@+---+name: setting-up-support-slack-locally+description: >+ Connect a real Slack workspace to local PostHog Conversations (the SupportHog Slack app) so Slack+ messages become support tickets and replies post back. Use when the user wants to test the conversations+ Slack integration locally, hits "Support Slack OAuth client ID is not configured", gets a white screen or+ "Network error" on the OAuth callback, or asks how to set SUPPORT_SLACK_APP_CLIENT_ID / a tunnel for+ supporthog Slack events. Covers the Slack app + scopes, the SUPPORT_SLACK_* dynamic settings, and the+ key split: localhost for OAuth and the UI, a public tunnel only for inbound events.+---++# Setting up Support Slack locally++Slack is SaaS-only, so "local" means a throwaway Slack workspace + app whose OAuth and events reach your+laptop. The job has one non-obvious idea that avoids almost every wall: **the OAuth connect and the event+webhook have opposite reachability needs, so you point them at different places.**++- **OAuth connect** is browser-mediated. Your browser follows the redirect, so `localhost` is reachable.+ No tunnel needed.+- **Inbound events** (Slack POSTing messages so they become tickets) are server-to-server from Slack's+ cloud. Slack cannot reach `localhost`, so this one needs a public tunnel.++Keep the whole app and the OAuth flow on `localhost`, and point only Event Subscriptions (and Interactivity)+at the tunnel. This also sidesteps free-tier tunnel rate limits, since the tunnel then carries only Slack's+low-volume event POSTs rather than the entire SPA.++This is the conversations/SupportHog variant of the general+[Slack local setup guide](../../../../docs/internal/slack-local-setup-guide.md); that guide covers the+PostHog Code / notifications Slack app (`SLACK_APP_*`, `/integrations/slack/callback`). Conversations uses+its own `SUPPORT_SLACK_*` credentials and `/api/conversations/v1/slack/*` routes, but the tunnel and+`SITE_URL` mechanics are identical.++## The endpoints++All under `products/conversations/backend/api/urls.py`, prefixed `/api/conversations/`:++| Route | Purpose | Reachability |+| ------------------------ | ------------------------------------------------------------- | ------------------------ |+| `v1/slack/authorize` | returns the Slack OAuth URL (auth-gated) | browser (localhost) |+| `v1/slack/callback` | OAuth redirect target; built from `SITE_URL`, no forced https | browser (localhost) |+| `v1/slack/events` | inbound event webhook | Slack's servers (tunnel) |+| `v1/slack/interactivity` | interactive component callbacks | Slack's servers (tunnel) |++The callback requires an authenticated session on whatever origin `SITE_URL` resolves to, because the+session cookie is per-origin. Keep `SITE_URL` on `localhost` and log in there, and the callback keeps your+session.++## Step 1 — credentials++`SUPPORT_SLACK_APP_CLIENT_ID`, `SUPPORT_SLACK_APP_CLIENT_SECRET`, and `SUPPORT_SLACK_SIGNING_SECRET` are+django-constance dynamic settings (`posthog/settings/dynamic_settings.py`) that default to the matching env+var. Empty client id is what produces "Support Slack OAuth client ID is not configured". Put your Slack+app's values in `.env.local` (gitignored) and restart the backend:++```bash+SUPPORT_SLACK_APP_CLIENT_ID=<client id>+SUPPORT_SLACK_APP_CLIENT_SECRET=<client secret>+SUPPORT_SLACK_SIGNING_SECRET=<signing secret>+```++Constance stores values in the DB, and a stored value overrides the env default. If it still reads as+unconfigured after a restart, check `/admin/constance/config/` for a blank stored value and set it there+instead.++## Step 2 — the Slack app++At [api.slack.com/apps](https://api.slack.com/apps), create an app in a throwaway workspace, then:++1. **App Home** → enable a **bot user** (give it a display name). Without this, install fails with "requesting+ permission to install a bot ... but it's not currently configured with a bot".+2. **OAuth & Permissions → Bot Token Scopes** — the flow requests these (from `SUPPORTHOG_SLACK_SCOPE` in+ `products/conversations/backend/api/slack_oauth.py`): `channels:history`, `channels:read`, `chat:write`,+ `chat:write.customize`, `groups:history`, `groups:read`, `reactions:read`, `users:read`,+ `users:read.email`.+3. **OAuth & Permissions → Redirect URLs** — add `http://localhost:8010/api/conversations/v1/slack/callback`+ and Save. If Slack refuses a plain-http localhost URL, use the tunnel URL for the callback too and log in+ once on the tunnel origin (see [references/troubleshooting.md](references/troubleshooting.md)).+4. Copy the Client ID, Client Secret, and Signing Secret from Basic Information into `.env.local` (Step 1).++## Step 3 — tunnel for inbound events++Run any HTTPS tunnel pointed at Caddy on **8010**, rewriting the upstream `Host` header to `localhost` (the+dev Caddy only answers for the `localhost` host; without the rewrite you get an empty `200` and a white page):++```bash+ngrok http --host-header=localhost 8010+# or, free with no rate limit:+cloudflared tunnel --url http://localhost:8010 --http-host-header localhost+```++Verify it reaches Django, not just Caddy:++```bash+curl -sS https://<tunnel-host>/_preflight | head -c 120 # want JSON, server: granian+```++Then in the Slack app set **Event Subscriptions → Request URL** (and **Interactivity → Request URL** if+testing buttons) to `https://<tunnel-host>/api/conversations/v1/slack/events` (and `.../interactivity`).+Slack sends a synchronous `url_verification` challenge on save, so the backend must be up; the handler+echoes it back automatically.++The Request URL alone only passes verification; it delivers nothing until you subscribe to events. Under+**Event Subscriptions → Subscribe to bot events**, add the events the backend handles (`SUPPORT_EVENT_TYPES`+in `products/conversations/backend/api/slack_events.py`):++- `app_mention`+- `message.channels` (and `message.groups` for private channels), both arriving as the inner `message` event+- `reaction_added`+- `member_joined_channel`, `member_left_channel`++Reinstall the app after changing scopes/events so the new grants take effect.++## Step 4 — connect and test++Browse the app at `http://localhost:8010`, log in, go to Support settings, and connect Slack. The OAuth+round-trip completes on localhost. Then invite the bot to a channel in your dev workspace and post a+message; it should arrive as a ticket, and a reply from the ticket should post back to the thread.++For the failure modes worth recognizing (white screen, "Network error", redirect mismatch, region routing),+see [references/troubleshooting.md](references/troubleshooting.md).diff --git a/products/conversations/skills/setting-up-support-slack-locally/references/troubleshooting.md b/products/conversations/skills/setting-up-support-slack-locally/references/troubleshooting.mdnew file mode 100644index 000000000000..9b51bfb36091--- /dev/null+++ b/products/conversations/skills/setting-up-support-slack-locally/references/troubleshooting.md@@ -0,0 +1,65 @@+# Troubleshooting Support Slack local setup++The walls you actually hit, in the order they tend to appear, plus a way to verify the event path without+touching Slack.++## Failure modes++| Symptom | Cause / fix |+| --------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |+| `Error: Support Slack OAuth client ID is not configured` (503 from `authorize`) | `SUPPORT_SLACK_APP_CLIENT_ID` is empty. Set the three `SUPPORT_SLACK_*` vars in `.env.local` and restart the backend. If still empty, a blank value stored in constance overrides the env default — set it at `/admin/constance/config/` instead. |+| Slack: "redirect_uri did not match any configured URIs" | The exact callback URL isn't in the Slack app's **Redirect URLs**. Add `http://localhost:8010/api/conversations/v1/slack/callback` (matches `SITE_URL`) and click **Save URLs**. Match is exact: scheme, host, port, path. |+| Slack: "requesting permission to install a bot ... but it's not currently configured with a bot" | No bot user on the app. Slack app → **App Home** → enable a bot user with a display name. |+| OAuth returns to the callback URL as a **white page** (URL bar still on `/slack/callback`) | The callback ran without a session. The callback needs an authenticated session on the origin `SITE_URL` resolves to. Log in on that same origin before connecting. The blank look is the `401` JSON being hidden by its `Content-Security-Policy: default-src 'none'`. |+| Any page over the tunnel is a **white page**, and `curl https://<tunnel>/_preflight` returns `200` with an **empty body** and `server: Caddy` | The tunnel isn't rewriting the upstream `Host` to `localhost`, so the dev Caddy (which only answers for the `localhost` host) drops through to nothing. Add the host rewrite: ngrok `--host-header=localhost` (or `host_header: localhost` in the config), cloudflared `--http-host-header localhost`. A correct hit shows `server: granian`. |+| Lots of **"Network error — There was an issue loading the requested resource"** across the SPA when browsing over the tunnel | Free-tier tunnel rate limiting. The ngrok request inspector shows many `/api/...` calls with status `0` (dropped). The SPA fires dozens of requests per scene, past `ngrok-free.app`'s per-minute cap. Fix: don't browse the SPA over the tunnel — keep the app and OAuth on `localhost`, and use the tunnel only for inbound events (low volume). Or switch to Cloudflare Tunnel (no such limit), or a paid ngrok plan. |+| Events reach the tunnel but no ticket appears | Check the celery worker log for `process_supporthog_event`, and confirm `team_exists_for_slack_workspace` matches the `slack_team_id` saved by your OAuth connect. Also confirm the bot is in the channel. |++## Two things that look like problems but aren't++- **`http://localhost:8234` assets from an https tunnel page.** Browsers treat `localhost` as a secure+ context, so those dev-server scripts and the `ws://localhost:8234` HMR socket are not blocked as mixed+ content. The white page over a tunnel is the Host-header issue above, not mixed content.+- **Region routing proxying your events away.** In `DEBUG`, `PRIMARY_REGION_DOMAIN` is `urlparse(SITE_URL).netloc`+ (`products/conversations/backend/services/region_routing.py`). With `SITE_URL=http://localhost:8010` the+ primary is `localhost:8010`, but the tunnel rewrites Host to `localhost`, so `is_primary_region` is false+ and `slack_events.py` processes the event locally instead of proxying. If you ever set the tunnel to+ forward the port too, the host would match and events would proxy to `localhost:8000` — keep the rewrite+ at bare `localhost`.++## Verify the event path without Slack++Because `validate_support_request` (`products/conversations/backend/support_slack.py`) is standard Slack+HMAC signing, you can replay exactly what Slack sends on save — a signed `url_verification` — and confirm+the whole path (tunnel → Caddy → Django → signature check → handler) works. A `{"challenge": ...}` response+with `server: granian` proves it end to end and isolates any problem away from Slack's config.++```bash+SECRET=$(grep '^SUPPORT_SLACK_SIGNING_SECRET=' .env.local | cut -d= -f2)+TS=$(date +%s)+BODY='{"type":"url_verification","challenge":"local-test-123"}'+SIG="v0=$(printf '%s' "v0:${TS}:${BODY}" | openssl dgst -sha256 -hmac "$SECRET" | awk '{print $NF}')"+curl -sS -i -X POST "https://<tunnel-host>/api/conversations/v1/slack/events" \+ -H "Content-Type: application/json" \+ -H "X-Slack-Request-Timestamp: ${TS}" \+ -H "X-Slack-Signature: ${SIG}" \+ --data "$BODY"+```++- `{"challenge": "local-test-123"}` + `server: granian` → path is good; if real events still don't arrive,+ the Slack app's Event Subscriptions Request URL isn't pointed at the tunnel.+- `403 Invalid request` → the secret used to sign the request doesn't match the backend's active signing+ secret. The command signs with the `.env.local` value, but the backend uses the Constance-stored value+ when one exists, so this can 403 even against a correctly configured backend. Causes: `.env.local` not+ loaded, backend not restarted after editing it, or a different value saved in Constance+ (`/admin/constance/config/`). Sign with the active (Constance) value if one is set, or clear it so the env+ default applies.+- empty `200`, `server: Caddy` → Host-header rewrite missing (see the table).+- no response / status `0` → tunnel dropped it (rate limit or tunnel down).++## Watching real events++The tunnel's request inspector (`http://localhost:4040` for ngrok) shows each Slack POST and its response.+A real `event_callback` returns `202` (accepted and enqueued, `slack_events.py:98`); `url_verification`+returns `200`. `X-Slack-Retry-Num` on a request means Slack is retrying because a previous delivery didn't+`200`/`202` in time.