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(cdp): only require slack scopes on the fields that use them (#94943)

Ben White662168b143ae
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 5d0c3495f8cb..55eb290b8aa8 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -360,6 +360,18 @@ snapshots:
hash: v1.k794b7964.f0f8951a5448201b2d9c7de51e001a5362f2e9db94ac75a0ea9fcd8dad5a8c52.2Qbajc9eXagGQ2c6ZwRzSAg7I5680r33G6PqAY4L1WM
components-currencydropdown--currency-dropdown-story--light:
hash: v1.k794b7964.cf1bfb2ab4acaa1a053d7964d8bbc2a356fd3e927b47bbb80469230c7ae8b7d4.TUxSw7ch7Iwn8kEcWO0_Yi0XhOHosR5J4nbLixw2rpA
+ components-cyclotron-job-inputs--slack-fully-scoped--dark:
+ hash: v1.k794b7964.6b6600488927bbc94b6119dc8a21b54cbc0fe761f00895302a4ffefb511a232e.bFlPCqbnurnWbgMJhocUIlVsoYJmJc1psMBdEBGlk74
+ components-cyclotron-job-inputs--slack-fully-scoped--light:
+ hash: v1.k794b7964.09c6b6060ccce1f0b0a49bb46a765200b5f68d8fdb61f39a18edae4b3d21b540.MvepyS3jqjmSn57ZsxLmzfXAWToxK17vDYihdF9C7sU
+ components-cyclotron-job-inputs--slack-missing-optional-scope--dark:
+ hash: v1.k794b7964.e1d728f9adfdbda45275626876d376e2ae98c00186201f683628413badc3057c.rhwyg4RHd41vvfGl97Oh6I06VUC-DdT6fjd12qqiT4M
+ components-cyclotron-job-inputs--slack-missing-optional-scope--light:
+ hash: v1.k794b7964.1241f841266fed8307e644949d4fa6317253e930c2ad315fa3c71d816bdff7b1.7QmLkiKC8l2Fjhy9YLCjfb3AQJCggwx1d6NO7Ei-e0M
+ components-cyclotron-job-inputs--slack-missing-required-scope--dark:
+ hash: v1.k794b7964.632486ff7aefa1b8f51da6d5a7c2bc638f494a7b5db9c736b187ec89de6ced23.YVHF9x8aZnG5RuygbYdVOrYm1iMEKxV--fMovqtHbXs
+ components-cyclotron-job-inputs--slack-missing-required-scope--light:
+ hash: v1.k794b7964.23aac2138e1992b6185127ac270c052a26a3661e6fd74b0687b4f1c7202a1bb7.P5NQ0GHxctH-r9RzeyctpASV3TfIMOXhhyIOlK1pKsw
components-date-picker--clearable--dark:
hash: v1.k794b7964.b7266885dd76d695e18fd842cc560821d4e8ced76555b06fc8bcab144c621883.IgiHE2iUIHF7K8Vk42p9fnmWZhjXpb0j7EW1bGnsIEQ
components-date-picker--clearable--light:
@@ -7245,13 +7257,13 @@ snapshots:
scenes-app-hogfunctions-destination--backfills-with-data--light:
hash: v1.k794b7964.f971c9b24daa779751f4ca9c4a58a6d640b1f1dc482c989521b5aed68d07f5ee.MRVlqmTBTYcUbMQypG59y05w-tbxT3zVWBzTz0rPUF4
scenes-app-hogfunctions-destination--configuration--dark:
- hash: v1.k794b7964.5ee8d8fbd95482d0ec4fc96006c0da77d57091bb7acd5a0cd54c1b3ba907ec24.pRaOdL0cSRtedB8YTIiJpdwxQAdw-eFYdCDAfb_xGPA
+ hash: v1.k794b7964.2bcff54f9ad6358506cae8685b866588768a6bf3b12e1206b44e12117af66b74.x8785_1cTWDDTOKUZ6bo_aaCdCmZqaw7gMW6Z-1UP_Y
scenes-app-hogfunctions-destination--configuration--light:
- hash: v1.k794b7964.dfc65287a34e16ee3ed96c9cb2a5bfb72f4f416e2c20229e69abacfc073689d6.0D_P1H14B51ctokSo5g98e6RMM72I68wpNyYQ5VwDLU
+ hash: v1.k794b7964.017e810f0318afd1c39d5cd1c6aa5940e90b4ff3c973fea41bdf97d18e990c0a.wJQCOhdVG5nS7tEsBg8jhn7KTQ3zJ0PYP_ufsrJGy4o
scenes-app-hogfunctions-destination--configuration-with-templating-warning--dark:
- hash: v1.k794b7964.c36181fed9cb3bef026b10d3c8099bbe0a834b51865a03f486deaa4eb857df55.aR5CI-Z04Q3dPHdBUsFpEAvfiF6ukw7ppBDR6Mgm62E
+ hash: v1.k794b7964.793141fe3d94b1fc2cbf718756a6cb44ab776174a97e321234e27850b146b9ba.OjefoswkkLvUsu435xadckHvuPxGVLgweiuoodY5xoY
scenes-app-hogfunctions-destination--configuration-with-templating-warning--light:
- hash: v1.k794b7964.08a4398a7b8f0a595099a74d52bf22a855b686af82e52f07ef2046757bfc516f.Q7FOzrqFB60h8Y-USRsO7SS3k97joRpoOOu98rkRTY4
+ hash: v1.k794b7964.98b862f4cb9ecf895257d7fc7ad7b65e9c3a08dc5a25411c06d734c86889c8b9.aKGEVkwwOS7j02ELp_ad65_LC2FN1XlQ1shJO9olgRs
scenes-app-hogfunctions-destination--runs-empty--dark:
hash: v1.k794b7964.9338d457e2d64f5a491115541fa681db1c44ab049531d9eec24d58fa056a31f0.mhgFOxcURq4YcXhnV16BaRPW4OAZ5mFkUBgjhDazfhg
scenes-app-hogfunctions-destination--runs-empty--light:
@@ -8917,21 +8929,21 @@ snapshots:
scenes-app-surveys--surveys-list--light:
hash: v1.k794b7964.cf5d73f8325b5294303cd755262266b76376caf5d2181dc8fdb7d52bbbf45ca4.j1dVq5PZXR13I9Zx2LZMfuZ23EghxOvikpJ8affvZgY
scenes-app-surveys-surveyresponsekeysreference--discord--dark:
- hash: v1.k794b7964.35875b97e4528079527fd2f016f59e8c038a3c6d285a761107ee746781d183d8.qdcZcujC8bNrArhO4WGpyIEObDm4t45-Eye7ufMCJIA
+ hash: v1.k794b7964.e838d7a7be567a6699af309c1bc51c6a785eec57fad43fb6bfcf11c3552e11ae.p63PN2zY4GcsfbvIyvhy4FuxqxvDpB-iRGH3rAGMVa0
scenes-app-surveys-surveyresponsekeysreference--discord--light:
- hash: v1.k794b7964.3ac7d69a2cf7e79fd0a8b87c1a38dc588d53f4d3215ccf6c9cc902152432c3c3._0e4etpwtMtP-UbVKp7EZbKvX0Yns65sRUBJYZ5UiEU
+ hash: v1.k794b7964.a4feae941d475c67c4c5b7812aaacb4e30d27625cdaabf768aa6ad03e3bcacd0.Jed53h2ZmCEa8_w_mRKa6Mo6I1WhTHvFOC-nAHCtRMw
scenes-app-surveys-surveyresponsekeysreference--microsoft-teams--dark:
- hash: v1.k794b7964.1f7c45597ed3ad2555dfedf1090fea70e36c0514c85ce4a0cfea8ef73892ff7b.TDKISilq7lcRtwEmT2RKheRosZrRNbWB8hatx-v_SRw
+ hash: v1.k794b7964.c5d10116e71df6e055e46895262bdd64613de75b49a914a647f8b499aea1d514.Od8_105Ifyf99GJAyf46-o5dRg3ijT18pvZAiAHIAmQ
scenes-app-surveys-surveyresponsekeysreference--microsoft-teams--light:
- hash: v1.k794b7964.f2db056f31b73711a63f5be80b6e527320f602a7d676b1a0264436e3e80396f5.uQocxIwkVvB_fDtrI9aAKAs-6KsQhQc6Pj5alO2iW0M
+ hash: v1.k794b7964.5802f49b465f16ff4a7aed1a62630f9e819ca8d58fa27765fe11713aed0bc063.0dVstXErA7bB2KeKSRtHKMI53cifZWRuBUIPjW1CMgQ
scenes-app-surveys-surveyresponsekeysreference--slack--dark:
- hash: v1.k794b7964.de79c49c388cd9083507c8919793dd56fb9f2b61f7a8ea1052192cc84b38fbf9.YtSTxWPvLDcf4V-_73R8UV-BWi73TVe1QXPju0WhhDE
+ hash: v1.k794b7964.289666e695e09b95dc35deb2a8f2171cc743a37a62a5b78b04aae6085bb65ccd.aPcl_6XoL9phMkL5VwuTRZdDgUB-AuuNWEDacNkPSHE
scenes-app-surveys-surveyresponsekeysreference--slack--light:
- hash: v1.k794b7964.5f7bf0b22045254fa9efffa49b6077f42cd7ad7cfe36f2c3e67fc0c2cd8a7e5d.NgeAIX_k770HDqI1h5Swkqrsxz754QhKS-Z7dlj7SM0
+ hash: v1.k794b7964.2abfd2d26e26fbf28873c3f73c6953eceb8cad34c476437cd01fbb53902e825b.LmLxQZyECr3qvQOgRSV4p-x3PAl4_WQ0dOaGF45hNY4
scenes-app-surveys-surveyresponsekeysreference--webhook--dark:
- hash: v1.k794b7964.6a758d478468b2e8d2c375227d3952e543a3880c5024eebed74432bdedd4c7de.rERkgM9QmxIEOUSnJ462vuApLdtQEPHcYfl3LNPpkkQ
+ hash: v1.k794b7964.77756df88375db077db0cab89072ecde78bc9f4dddc2902522914789709473a7.jeV_5jxogQcflTArm0snEBzFpFYE0tVWEJtzZP4x2ME
scenes-app-surveys-surveyresponsekeysreference--webhook--light:
- hash: v1.k794b7964.d1b5990c419ba81a718674107ef032126e0931aaffee0b2214f01caf425894c8.yjpNAjkX1uJIayGtXXge8xuVCAloNPgNhPIyEeeh8wQ
+ hash: v1.k794b7964.6cd0cfc5275afb494c4fd479d8cfc045b61c21403edc5d967dd7a6b0a95ea4c6.3SHmed00NzWos23UqElIz7GB8Ip0D3B3-HNFTSuMRqw
scenes-app-tasks--empty--dark:
hash: v1.k794b7964.d112f05471a711379792d3010c0c6471fe0c24765510d4b9f00ebd1f858e4016.6JBRci6NsHBPP7tehgmjAOGfr8AMPqfwMs8Mc8DWWzA
scenes-app-tasks--empty--light:
diff --git a/frontend/src/lib/components/CyclotronJob/CyclotronJobInputs.stories.tsx b/frontend/src/lib/components/CyclotronJob/CyclotronJobInputs.stories.tsx
new file mode 100644
index 000000000000..e68a490f4790
--- /dev/null
+++ b/frontend/src/lib/components/CyclotronJob/CyclotronJobInputs.stories.tsx
@@ -0,0 +1,114 @@
+import { Meta, StoryObj } from '@storybook/react'
+
+import { useStorybookMocks } from '~/mocks/browser'
+import { mockBasicUser, mockSlackChannels } from '~/test/mocks'
+import { CyclotronJobInputSchemaType, IntegrationType } from '~/types'
+
+import { CyclotronJobInputs } from './CyclotronJobInputs'
+
+// Mirrors nodejs/src/cdp/templates/_destinations/slack/slack.template.ts, trimmed to the inputs
+// that carry scopes. `requiredScopes` on the connection is a hard requirement; on a field it is
+// the scope only that field needs.
+const SLACK_INPUTS_SCHEMA: CyclotronJobInputSchemaType[] = [
+ {
+ key: 'slack_workspace',
+ type: 'integration',
+ integration: 'slack',
+ label: 'Slack workspace',
+ requiredScopes: 'chat:write',
+ required: true,
+ },
+ {
+ key: 'channel',
+ type: 'integration_field',
+ integration_key: 'slack_workspace',
+ integration_field: 'slack_channel',
+ requiredScopes: 'channels:read groups:read',
+ label: 'Channel to post to',
+ required: true,
+ },
+ {
+ key: 'icon_emoji',
+ type: 'string',
+ label: 'Emoji icon',
+ integration_key: 'slack_workspace',
+ requiredScopes: 'chat:write.customize',
+ required: false,
+ },
+ {
+ key: 'username',
+ type: 'string',
+ label: 'Bot name',
+ integration_key: 'slack_workspace',
+ requiredScopes: 'chat:write.customize',
+ required: false,
+ },
+]
+
+const SLACK_INPUTS = {
+ slack_workspace: { value: 1 },
+ channel: { value: 'C1' },
+ icon_emoji: { value: ':hedgehog:' },
+ username: { value: 'PostHog' },
+}
+
+const EVERY_SCOPE = 'channels:read groups:read chat:write chat:write.customize'
+
+const slackIntegration = (scope: string): IntegrationType => ({
+ id: 1,
+ kind: 'slack',
+ display_name: 'PostHog HQ',
+ icon_url: '',
+ config: { scope, team: { id: '123', name: 'PostHog' } },
+ created_at: '2024-01-01T00:00:00Z',
+ created_by: mockBasicUser,
+})
+
+type StoryArgs = { scope: string }
+
+const meta: Meta<StoryArgs> = {
+ title: 'Components/Cyclotron job inputs',
+ parameters: { layout: 'padded', viewMode: 'story' },
+ render: ({ scope }) => {
+ useStorybookMocks({
+ get: {
+ '/api/environments/:team_id/integrations': {
+ results: [slackIntegration(scope)],
+ },
+ '/api/environments/:team_id/integrations/:intId/channels': {
+ // is_member, so the picker doesn't add an unrelated "app is not in this channel" warning
+ channels: mockSlackChannels.map((channel) => ({ ...channel, is_member: true })),
+ },
+ },
+ })
+ return (
+ <div className="max-w-2xl">
+ <CyclotronJobInputs
+ configuration={{ inputs_schema: SLACK_INPUTS_SCHEMA, inputs: SLACK_INPUTS }}
+ showSource={false}
+ sampleGlobalsWithInputs={null}
+ />
+ </div>
+ )
+ },
+}
+export default meta
+
+type Story = StoryObj<StoryArgs>
+
+// Nothing to say: no banner on the connection, no hint on any field.
+export const SlackFullyScoped: Story = {
+ args: { scope: EVERY_SCOPE },
+}
+
+// Without chat:write the destination cannot post at all, so the connection itself errors and
+// offers a reconnect.
+export const SlackMissingRequiredScope: Story = {
+ args: { scope: 'channels:read groups:read chat:write.customize' },
+}
+
+// The destination posts fine, so the connection stays clean. Only the two fields that need
+// chat:write.customize say what they are missing.
+export const SlackMissingOptionalScope: Story = {
+ args: { scope: 'channels:read groups:read chat:write' },
+}
diff --git a/frontend/src/lib/components/CyclotronJob/CyclotronJobInputs.tsx b/frontend/src/lib/components/CyclotronJob/CyclotronJobInputs.tsx
index 70f2c82aff00..df72137ff37c 100644
--- a/frontend/src/lib/components/CyclotronJob/CyclotronJobInputs.tsx
+++ b/frontend/src/lib/components/CyclotronJob/CyclotronJobInputs.tsx
@@ -49,6 +49,8 @@ import { CyclotronJobTemplateSuggestionsButton } from './CyclotronJobTemplateSug
import { CyclotronJobInputIntegration } from './integrations/CyclotronJobInputIntegration'
import { CyclotronJobInputIntegrationField } from './integrations/CyclotronJobInputIntegrationField'
import { CyclotronJobInputIntegrationMulti } from './integrations/CyclotronJobInputIntegrationMulti'
+import { declaresFieldScopes } from './integrations/fieldScopes'
+import { MissingScopesHint } from './integrations/MissingScopesHint'
import { CyclotronJobInputConfiguration } from './types'
export const EXTEND_OBJECT_KEY = '$$_extend_object'
@@ -983,11 +985,20 @@ function CyclotronJobInputWithSchema({
<LemonField.Pure
error={error}
help={
- typeof schema.description === 'string' ? (
- <LemonMarkdown className="max-w-[30rem]" lowKeyHeadings>
- {schema.description}
- </LemonMarkdown>
- ) : undefined
+ <>
+ {typeof schema.description === 'string' ? (
+ <LemonMarkdown className="max-w-[30rem]" lowKeyHeadings>
+ {schema.description}
+ </LemonMarkdown>
+ ) : null}
+ {declaresFieldScopes(schema) ? (
+ <MissingScopesHint
+ schema={schema}
+ configuration={configuration}
+ parentConfiguration={parentConfiguration}
+ />
+ ) : null}
+ </>
}
>
<>
diff --git a/frontend/src/lib/components/CyclotronJob/integrations/MissingScopesHint.test.tsx b/frontend/src/lib/components/CyclotronJob/integrations/MissingScopesHint.test.tsx
new file mode 100644
index 000000000000..53a6299e1cdc
--- /dev/null
+++ b/frontend/src/lib/components/CyclotronJob/integrations/MissingScopesHint.test.tsx
@@ -0,0 +1,99 @@
+import '@testing-library/jest-dom'
+
+import { cleanup, render, screen, waitFor } from '@testing-library/react'
+import { Provider } from 'kea'
+
+import { useMocks } from '~/mocks/jest'
+import { initKeaTests } from '~/test/init'
+
+import { CyclotronJobInputs } from '../CyclotronJobInputs'
+
+const slackIntegration = (scope: string): Record<string, any> => ({
+ id: 1,
+ kind: 'slack',
+ display_name: 'PostHog HQ',
+ icon_url: '',
+ config: { scope },
+ created_by: null,
+ created_at: '2026-01-01T00:00:00Z',
+})
+
+const CONFIGURATION = {
+ inputs_schema: [
+ { key: 'slack_workspace', type: 'integration' as const, integration: 'slack', label: 'Slack workspace' },
+ {
+ key: 'icon_emoji',
+ type: 'string' as const,
+ label: 'Emoji icon',
+ integration_key: 'slack_workspace',
+ requiredScopes: 'chat:write.customize',
+ },
+ ],
+ inputs: { slack_workspace: { value: 1 }, icon_emoji: { value: ':hedgehog:' } },
+}
+
+describe('MissingScopesHint', () => {
+ afterEach(() => {
+ cleanup()
+ })
+
+ // A workspace connected before chat:write.customize was requested still posts messages, so the
+ // customization fields must say what they need rather than the whole connection erroring.
+ it.each([
+ ['the connection lacks the scope', 'chat:write', true],
+ ['the connection granted the scope', 'chat:write chat:write.customize', false],
+ ])('given %s', async (_name, scope, expectHint) => {
+ useMocks({
+ get: {
+ '/api/environments/:team_id/integrations': () => [200, { results: [slackIntegration(scope)] }],
+ },
+ })
+ initKeaTests()
+
+ render(
+ <Provider>
+ <CyclotronJobInputs configuration={CONFIGURATION} showSource={false} sampleGlobalsWithInputs={null} />
+ </Provider>
+ )
+
+ await waitFor(() => {
+ expect(screen.getByText('Emoji icon')).toBeInTheDocument()
+ })
+ await waitFor(() => {
+ expect(screen.queryByText('chat:write.customize')).toEqual(expectHint ? expect.anything() : null)
+ })
+ })
+
+ // The hint subscribes to every integration on the team. A form with no scope-carrying input must
+ // not mount that subscription, or a plain webhook config would load integrations it never uses.
+ it('does not load integrations for a form without scope-carrying inputs', async () => {
+ let loads = 0
+ useMocks({
+ get: {
+ '/api/environments/:team_id/integrations': () => {
+ loads += 1
+ return [200, { results: [] }]
+ },
+ },
+ })
+ initKeaTests()
+
+ render(
+ <Provider>
+ <CyclotronJobInputs
+ configuration={{
+ inputs_schema: [{ key: 'url', type: 'string', label: 'Webhook URL' }],
+ inputs: { url: { value: 'https://example.com/hook' } },
+ }}
+ showSource={false}
+ sampleGlobalsWithInputs={null}
+ />
+ </Provider>
+ )
+
+ await waitFor(() => {
+ expect(screen.getByText('Webhook URL')).toBeInTheDocument()
+ })
+ expect(loads).toEqual(0)
+ })
+})
diff --git a/frontend/src/lib/components/CyclotronJob/integrations/MissingScopesHint.tsx b/frontend/src/lib/components/CyclotronJob/integrations/MissingScopesHint.tsx
new file mode 100644
index 000000000000..415814545a8d
--- /dev/null
+++ b/frontend/src/lib/components/CyclotronJob/integrations/MissingScopesHint.tsx
@@ -0,0 +1,47 @@
+import api from 'lib/api'
+import { getIntegrationNameFromKind } from 'lib/integrations/utils'
+import { Link } from 'lib/lemon-ui/Link'
+
+import { CyclotronJobInputSchemaType } from '~/types'
+
+import { CyclotronJobInputConfiguration } from '../types'
+import { useFieldMissingScopes } from './fieldScopes'
+
+/**
+ * Sits under a field whose connection is missing a permission only that field needs. What a missing
+ * permission costs differs per field — an unusable picker, a value the destination drops — so this
+ * states the permission and the way to grant it, and leaves the consequence to the field itself.
+ *
+ * Render it only where ``declaresFieldScopes`` holds: it subscribes to every integration on the team.
+ */
+export function MissingScopesHint({
+ schema,
+ configuration,
+ parentConfiguration,
+}: {
+ schema: CyclotronJobInputSchemaType
+ configuration?: CyclotronJobInputConfiguration
+ parentConfiguration?: CyclotronJobInputConfiguration
+}): JSX.Element | null {
+ const fieldScopes = useFieldMissingScopes(schema, configuration, parentConfiguration)
+ if (!fieldScopes) {
+ return null
+ }
+
+ const { integration, missingScopes } = fieldScopes
+ const name = getIntegrationNameFromKind(integration.kind)
+
+ return (
+ <p className="mb-0 text-warning">
+ This field needs the <code>{missingScopes.join(' ')}</code>{' '}
+ {missingScopes.length === 1 ? 'permission' : 'permissions'}, which your {name} connection does not have.{' '}
+ <Link
+ disableClientSideRouting
+ to={api.integrations.authorizeUrl({ kind: integration.kind, next: window.location.pathname })}
+ >
+ Reconnect {name}
+ </Link>{' '}
+ to grant {missingScopes.length === 1 ? 'it' : 'them'}.
+ </p>
+ )
+}
diff --git a/frontend/src/lib/components/CyclotronJob/integrations/fieldScopes.ts b/frontend/src/lib/components/CyclotronJob/integrations/fieldScopes.ts
new file mode 100644
index 000000000000..162126368b57
--- /dev/null
+++ b/frontend/src/lib/components/CyclotronJob/integrations/fieldScopes.ts
@@ -0,0 +1,48 @@
+import { useValues } from 'kea'
+
+import { getMissingScopes } from 'lib/integrations/IntegrationScopesWarning'
+import { integrationsLogic } from 'lib/integrations/integrationsLogic'
+
+import { CyclotronJobInputSchemaType, IntegrationType } from '~/types'
+
+import { CyclotronJobInputConfiguration } from '../types'
+
+export type FieldScopes = { integration: IntegrationType; missingScopes: string[] } | null
+
+/**
+ * Whether an input asks for scopes of its own, rather than for the connection as a whole. Scopes on
+ * the `integration` input are that connection's hard requirement, handled by
+ * ``IntegrationScopesWarning``.
+ *
+ * A plain check, not a hook, so a form whose inputs declare no scopes never mounts
+ * ``integrationsLogic`` and never loads the team's integrations.
+ */
+export function declaresFieldScopes(schema: CyclotronJobInputSchemaType): boolean {
+ return schema.type !== 'integration' && !!schema.requiredScopes && !!schema.integration_key
+}
+
+/**
+ * Scopes an input declares in `requiredScopes` that the connection it names in `integration_key`
+ * hasn't granted. Returns null for a connection with no recorded scopes — same fail-open behavior as
+ * the connection-level banner.
+ */
+export function useFieldMissingScopes(
+ schema: CyclotronJobInputSchemaType,
+ configuration?: CyclotronJobInputConfiguration,
+ parentConfiguration?: CyclotronJobInputConfiguration
+): FieldScopes {
+ const { integrations } = useValues(integrationsLogic)
+
+ if (!declaresFieldScopes(schema)) {
+ return null
+ }
+
+ const inputs = { ...configuration?.inputs, ...parentConfiguration?.inputs }
+ const integration = integrations?.find((i) => i.id === inputs[schema.integration_key as string]?.value)
+ if (!integration) {
+ return null
+ }
+
+ const missingScopes = getMissingScopes(integration, (schema.requiredScopes as string).split(' '))
+ return missingScopes.length ? { integration, missingScopes } : null
+}
diff --git a/nodejs/src/cdp/templates/_destinations/slack/slack.template.test.ts b/nodejs/src/cdp/templates/_destinations/slack/slack.template.test.ts
index f5aac99299f4..580ddc589ff1 100644
--- a/nodejs/src/cdp/templates/_destinations/slack/slack.template.test.ts
+++ b/nodejs/src/cdp/templates/_destinations/slack/slack.template.test.ts
@@ -85,6 +85,45 @@ describe('slack template', () => {
expect(bodyOf(response.invocation.queueParameters)).not.toHaveProperty('thread_ts')
})
+ // Both fields carry a default, so a connection without chat:write.customize would send them and
+ // have Slack refuse the whole message. The granted scopes decide, not the saved value.
+ it.each([
+ ['the scope is granted', 'chat:write,chat:write.customize', true],
+ ['the scope list has spaces', 'chat:write, chat:write.customize', true],
+ // An install predating the recorded scope list keeps its customization, the same fail-open
+ // the config UI applies.
+ ['no scopes are recorded', '', true],
+ ['the scope is absent', 'channels:read,groups:read,chat:write', false],
+ // A prefix match on the granted list would wrongly accept this one.
+ ['only the chat:write prefix is granted', 'chat:write', false],
+ ])('given %s, sends the appearance fields: %s', async (_name, scope, expected) => {
+ const response = await tester.invoke({
+ ...commonInputs,
+ slack_workspace: { access_token: 'xoxb-1234', scope },
+ })
+
+ expect(response.error).toBeUndefined()
+ const body = bodyOf(response.invocation.queueParameters)
+ expect(['icon_emoji' in body, 'username' in body]).toEqual([expected, expected])
+ })
+
+ // Clearing these has to keep the request inside chat:write, so a workspace that never granted
+ // chat:write.customize has a way to make the destination work. The UI writes '' on clear, but an
+ // API caller can leave the input unset or null, and neither may reach Slack either.
+ it.each([
+ ['icon_emoji', 'cleared in the UI', ''],
+ ['icon_emoji', 'unset', undefined],
+ ['icon_emoji', 'null', null],
+ ['username', 'cleared in the UI', ''],
+ ['username', 'unset', undefined],
+ ['username', 'null', null],
+ ])('should omit %s when it is %s', async (key, _name, value) => {
+ const response = await tester.invoke({ ...commonInputs, [key]: value })
+
+ expect(response.error).toBeUndefined()
+ expect(bodyOf(response.invocation.queueParameters)).not.toHaveProperty(key)
+ })
+
it.each([
['a non-200 status', { status: 400, body: { ok: true } }, "Failed to post message to Slack: 400: {'ok': true}"],
['ok: false', { status: 200, body: { ok: false } }, "Failed to post message to Slack: 200: {'ok': false}"],
diff --git a/nodejs/src/cdp/templates/_destinations/slack/slack.template.ts b/nodejs/src/cdp/templates/_destinations/slack/slack.template.ts
index 96c7e413f1f1..a496e6237474 100644
--- a/nodejs/src/cdp/templates/_destinations/slack/slack.template.ts
+++ b/nodejs/src/cdp/templates/_destinations/slack/slack.template.ts
@@ -13,8 +13,6 @@ export const template: HogFunctionTemplate = {
code: `
let body := {
'channel': inputs.channel,
- 'icon_emoji': inputs.icon_emoji,
- 'username': inputs.username,
'blocks': inputs.blocks,
'text': inputs.text
};
@@ -24,6 +22,20 @@ if (not empty(inputs.thread_ts)) {
body['thread_ts'] := inputs.thread_ts;
}
+// Slack refuses the whole message when these two are present without chat:write.customize, and both
+// carry a default, so drop them when the connection records a scope list that lacks it. An install
+// with no recorded scopes keeps its customization, matching what the config UI reports.
+let granted := replaceAll(inputs.slack_workspace.scope ?? '', ' ', '');
+let can_customize := empty(granted) or has(splitByString(',', granted), 'chat:write.customize');
+
+if (can_customize and not empty(inputs.icon_emoji)) {
+ body['icon_emoji'] := inputs.icon_emoji;
+}
+
+if (can_customize and not empty(inputs.username)) {
+ body['username'] := inputs.username;
+}
+
let res := fetch('https://slack.com/api/chat.postMessage', {
'body': body,
'method': 'POST',
@@ -43,7 +55,7 @@ if (res.status != 200 or res.body.ok == false) {
type: 'integration',
integration: 'slack',
label: 'Slack workspace',
- requiredScopes: 'channels:read groups:read chat:write chat:write.customize',
+ requiredScopes: 'chat:write',
secret: false,
hidden: false,
required: true,
@@ -53,6 +65,7 @@ if (res.status != 200 or res.body.ok == false) {
type: 'integration_field',
integration_key: 'slack_workspace',
integration_field: 'slack_channel',
+ requiredScopes: 'channels:read groups:read',
label: 'Channel to post to',
description:
'Select the channel to post to. Channel IDs (e.g. C0123ABC, returned by integrations-channels-retrieve) are preferred; #channel-name (e.g. #general) is also accepted. The PostHog app must be installed in the workspace. For private channels, the PostHog app must be a member of the channel.',
@@ -64,6 +77,8 @@ if (res.status != 200 or res.body.ok == false) {
key: 'icon_emoji',
type: 'string',
label: 'Emoji icon',
+ integration_key: 'slack_workspace',
+ requiredScopes: 'chat:write.customize',
default: ':hedgehog:',
required: false,
secret: false,
@@ -73,6 +88,8 @@ if (res.status != 200 or res.body.ok == false) {
key: 'username',
type: 'string',
label: 'Bot name',
+ integration_key: 'slack_workspace',
+ requiredScopes: 'chat:write.customize',
default: 'PostHog',
required: false,
secret: false,
diff --git a/nodejs/src/cdp/types.ts b/nodejs/src/cdp/types.ts
index 7b8ac35b0cfe..1d1ba47fee61 100644
--- a/nodejs/src/cdp/types.ts
+++ b/nodejs/src/cdp/types.ts
@@ -536,6 +536,12 @@ export type HogFunctionInputSchemaType = {
requires_field?: string
integration_field?: string
platform?: 'android' | 'ios'
+ /**
+ * Space-separated OAuth scopes. On an `integration` input these are the scopes the connection
+ * must grant, and a connection missing one gets an error banner. On any other input, paired
+ * with `integration_key`, they are the scopes only that field needs — a connection without them
+ * still works, so the field just says what it is missing. Neither is enforced at runtime.
+ */
requiredScopes?: string
/**
* templating: true indicates the field supports templating. Alternatively
diff --git a/nodejs/tests/fixtures/hog-bytecode/1aa1663cc2ed5c78338db44f40b78f31bf8bc91fb364e84e4b8bc1b49de46632.json b/nodejs/tests/fixtures/hog-bytecode/1aa1663cc2ed5c78338db44f40b78f31bf8bc91fb364e84e4b8bc1b49de46632.json
new file mode 100644
index 000000000000..dd43d8cf7d03
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/1aa1663cc2ed5c78338db44f40b78f31bf8bc91fb364e84e4b8bc1b49de46632.json
@@ -0,0 +1 @@
+["_H",1,32,"chat:write",38]
diff --git a/nodejs/tests/fixtures/hog-bytecode/5c29eb1dae56571c699c20d8a4d4f5434949ddcb463e9cf7731b442a74fb706a.json b/nodejs/tests/fixtures/hog-bytecode/5c29eb1dae56571c699c20d8a4d4f5434949ddcb463e9cf7731b442a74fb706a.json
new file mode 100644
index 000000000000..a00bc5777ace
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/5c29eb1dae56571c699c20d8a4d4f5434949ddcb463e9cf7731b442a74fb706a.json
@@ -0,0 +1 @@
+["_H",1,32,"chat:write, chat:write.customize",38]
diff --git a/nodejs/tests/fixtures/hog-bytecode/763561a56ebc2c7e9722b7e2405091cc6e5fe52a34a0d0972802139108b5bcdc.json b/nodejs/tests/fixtures/hog-bytecode/763561a56ebc2c7e9722b7e2405091cc6e5fe52a34a0d0972802139108b5bcdc.json
new file mode 100644
index 000000000000..49f99da5c657
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/763561a56ebc2c7e9722b7e2405091cc6e5fe52a34a0d0972802139108b5bcdc.json
@@ -0,0 +1 @@
+["_H",1,32,"channel",32,"channel",32,"inputs",1,2,32,"blocks",32,"blocks",32,"inputs",1,2,32,"text",32,"text",32,"inputs",1,2,42,3,32,"thread_ts",32,"inputs",1,2,2,"empty",1,5,40,11,36,0,32,"thread_ts",32,"thread_ts",32,"inputs",1,2,46,32,"scope",32,"slack_workspace",32,"inputs",1,3,47,3,35,32,"",32," ",32,"",2,"replaceAll",3,36,1,2,"empty",1,32,",",36,1,2,"splitByString",2,32,"chat:write.customize",2,"has",2,4,2,36,2,32,"icon_emoji",32,"inputs",1,2,2,"empty",1,5,3,2,40,11,36,0,32,"icon_emoji",32,"icon_emoji",32,"inputs",1,2,46,36,2,32,"username",32,"inputs",1,2,2,"empty",1,5,3,2,40,11,36,0,32,"username",32,"username",32,"inputs",1,2,46,32,"https://slack.com/api/chat.postMessage",32,"body",36,0,32,"method",32,"POST",32,"headers",32,"Authorization",32,"Bearer ",32,"access_token",32,"slack_workspace",32,"inputs",1,3,2,"concat",2,32,"Content-Type",32,"application/json",42,2,42,3,2,"fetch",2,33,200,36,3,32,"status",45,12,30,36,3,32,"body",45,32,"ok",45,11,4,2,40,21,32,"Failed to post message to Slack: ",36,3,32,"status",45,32,": ",36,3,32,"body",45,2,"concat",4,2,"Error",1,49,35,35,35,35]
diff --git a/nodejs/tests/fixtures/hog-bytecode/cbb1816c6119c9182e347e4bdbb8483fbc13496e262d6328f52b227fbff16fe5.json b/nodejs/tests/fixtures/hog-bytecode/cbb1816c6119c9182e347e4bdbb8483fbc13496e262d6328f52b227fbff16fe5.json
new file mode 100644
index 000000000000..8c49fc236751
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/cbb1816c6119c9182e347e4bdbb8483fbc13496e262d6328f52b227fbff16fe5.json
@@ -0,0 +1 @@
+["_H",1,32,"chat:write,chat:write.customize",38]
diff --git a/nodejs/tests/fixtures/hog-bytecode/ce595dceebdb5f281957a00d7131111a90776024176e9228aaa184ffd33ddd8e.json b/nodejs/tests/fixtures/hog-bytecode/ce595dceebdb5f281957a00d7131111a90776024176e9228aaa184ffd33ddd8e.json
new file mode 100644
index 000000000000..b49d1a9f148e
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/ce595dceebdb5f281957a00d7131111a90776024176e9228aaa184ffd33ddd8e.json
@@ -0,0 +1 @@
+["_H",1,32,"channel",32,"channel",32,"inputs",1,2,32,"blocks",32,"blocks",32,"inputs",1,2,32,"text",32,"text",32,"inputs",1,2,42,3,32,"thread_ts",32,"inputs",1,2,2,"empty",1,5,40,11,36,0,32,"thread_ts",32,"thread_ts",32,"inputs",1,2,46,32,"icon_emoji",32,"inputs",1,2,2,"empty",1,5,40,11,36,0,32,"icon_emoji",32,"icon_emoji",32,"inputs",1,2,46,32,"username",32,"inputs",1,2,2,"empty",1,5,40,11,36,0,32,"username",32,"username",32,"inputs",1,2,46,32,"https://slack.com/api/chat.postMessage",32,"body",36,0,32,"method",32,"POST",32,"headers",32,"Authorization",32,"Bearer ",32,"access_token",32,"slack_workspace",32,"inputs",1,3,2,"concat",2,32,"Content-Type",32,"application/json",42,2,42,3,2,"fetch",2,33,200,36,1,32,"status",45,12,30,36,1,32,"body",45,32,"ok",45,11,4,2,40,21,32,"Failed to post message to Slack: ",36,1,32,"status",45,32,": ",36,1,32,"body",45,2,"concat",4,2,"Error",1,49,35,35]
diff --git a/nodejs/tests/fixtures/hog-bytecode/ebb4241ae92699a802c01746b0c5f087ce2f012bb5d38370322b69e4464586a4.json b/nodejs/tests/fixtures/hog-bytecode/ebb4241ae92699a802c01746b0c5f087ce2f012bb5d38370322b69e4464586a4.json
new file mode 100644
index 000000000000..c74ecce7f941
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/ebb4241ae92699a802c01746b0c5f087ce2f012bb5d38370322b69e4464586a4.json
@@ -0,0 +1 @@
+["_H",1,32,"channels:read,groups:read,chat:write",38]