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: add allow AI suggestions setting (#63569)

Alex Vf82d775997df
diff --git a/frontend/src/scenes/settings/SettingsMap.tsx b/frontend/src/scenes/settings/SettingsMap.tsx
index 3588cf41ff86..e2097b2a7762 100644
--- a/frontend/src/scenes/settings/SettingsMap.tsx
+++ b/frontend/src/scenes/settings/SettingsMap.tsx
@@ -41,6 +41,7 @@ import {
} from '~/layout/navigation-3000/sidepanel/panels/access_control/RolesAccessControls'
import { AccessControlLevel, AccessControlResourceType, Realm } from '~/types'
+import { AISection } from 'products/conversations/frontend/scenes/settings/AISection'
import { ChannelsSection } from 'products/conversations/frontend/scenes/settings/ChannelsSection'
import { GeneralSection } from 'products/conversations/frontend/scenes/settings/GeneralSection'
import { NotificationsSection } from 'products/conversations/frontend/scenes/settings/NotificationsSection'
@@ -1137,6 +1138,16 @@ export const SETTINGS_MAP: SettingSection[] = [
'browser',
],
},
+ {
+ id: 'conversations-ai',
+ title: 'AI',
+ description:
+ 'Automatically generate AI-powered reply suggestions grounded in your business knowledge sources.',
+ component: <AISection />,
+ flag: 'PRODUCT_SUPPORT_AI_SUGGESTION',
+ allowForTeam: (t) => !!t?.conversations_enabled,
+ keywords: ['ai', 'suggestion', 'auto', 'reply', 'support', 'conversation'],
+ },
],
},
{
diff --git a/frontend/src/scenes/settings/types.ts b/frontend/src/scenes/settings/types.ts
index ff715fe9a4ea..45032f087fd7 100644
--- a/frontend/src/scenes/settings/types.ts
+++ b/frontend/src/scenes/settings/types.ts
@@ -107,6 +107,7 @@ export type SettingId =
| 'changelog'
| 'channel-type'
| 'connected-apps'
+ | 'conversations-ai'
| 'conversations-channels'
| 'conversations-general'
| 'conversations-notifications'
diff --git a/frontend/src/types.ts b/frontend/src/types.ts
index 168868661547..b5f571c63cdf 100644
--- a/frontend/src/types.ts
+++ b/frontend/src/types.ts
@@ -712,6 +712,7 @@ export interface ConversationsSettings {
github_enabled?: boolean
github_integration_id?: number | null
github_repos?: string[] | null
+ ai_suggestions_enabled?: boolean
}
export interface LogsSettings {
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index e1184b2bc084..b78a82af07a3 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -349,7 +349,7 @@ importers:
version: 0.25.12
jest:
specifier: ^29.7.0
puppeteer:
specifier: 19.0.0
version: 19.0.0([email protected])
@@ -2461,6 +2461,9 @@ importers:
jest:
specifier: ^29.7.0
+ kea-test-utils:
+ specifier: 'catalog:'
products/core_events: {}
@@ -32031,7 +32034,7 @@ snapshots:
'@swc/core': 1.15.18
'@swc/jest': 0.2.37(@swc/[email protected])
expect-playwright: 0.8.0
jest-circus: 29.7.0
jest-environment-node: 29.7.0
jest-junit: 16.0.0
@@ -39690,7 +39693,7 @@ snapshots:
dependencies:
expect-playwright: 0.8.0
jest-circus: 29.7.0
jest-environment-node: 29.7.0
jest-process-manager: 0.4.0
@@ -40125,7 +40128,7 @@ snapshots:
dependencies:
ansi-escapes: 6.0.0
chalk: 5.6.2
jest-regex-util: 29.6.3
jest-watcher: 29.7.0
slash: 5.1.0
diff --git a/products/conversations/frontend/scenes/settings/AISection.tsx b/products/conversations/frontend/scenes/settings/AISection.tsx
new file mode 100644
index 000000000000..18ef69239124
--- /dev/null
+++ b/products/conversations/frontend/scenes/settings/AISection.tsx
@@ -0,0 +1,33 @@
+import { useActions, useValues } from 'kea'
+
+import { LemonCard, LemonSwitch } from '@posthog/lemon-ui'
+
+import { SceneSection } from '~/layout/scenes/components/SceneSection'
+
+import { supportSettingsLogic } from './supportSettingsLogic'
+
+export function AISection(): JSX.Element {
+ const { aiSuggestionsEnabled, aiSuggestionsLoading } = useValues(supportSettingsLogic)
+ const { setAiSuggestionsEnabled } = useActions(supportSettingsLogic)
+
+ return (
+ <SceneSection
+ title="AI suggestions"
+ className="my-8"
+ description="When enabled, PostHog will automatically generate a suggested reply as a private note whenever a new ticket arrives. Suggestions are grounded in your business knowledge sources."
+ >
+ <LemonCard hoverEffect={false} className="flex flex-col gap-y-3 max-w-[800px] px-4 py-3">
+ <LemonSwitch
+ checked={aiSuggestionsEnabled}
+ onChange={(checked) => setAiSuggestionsEnabled(checked)}
+ loading={aiSuggestionsLoading}
+ label="Allow AI suggestions"
+ />
+ <p className="text-xs text-muted-alt mb-0">
+ Requires AI data processing consent at the organization level and at least one ready business
+ knowledge source.
+ </p>
+ </LemonCard>
+ </SceneSection>
+ )
+}
diff --git a/products/conversations/frontend/scenes/settings/SupportSettingsScene.tsx b/products/conversations/frontend/scenes/settings/SupportSettingsScene.tsx
index 677e1c8a020a..b928b7c51053 100644
--- a/products/conversations/frontend/scenes/settings/SupportSettingsScene.tsx
+++ b/products/conversations/frontend/scenes/settings/SupportSettingsScene.tsx
@@ -16,6 +16,7 @@ const VALID_SETTING_IDS = new Set<SettingId>([
'conversations-general',
'conversations-channels',
'conversations-notifications',
+ 'conversations-ai',
])
const DEFAULT_SETTING_ID: SettingId = 'conversations-general'
diff --git a/products/conversations/frontend/scenes/settings/supportSettingsLogic.test.ts b/products/conversations/frontend/scenes/settings/supportSettingsLogic.test.ts
new file mode 100644
index 000000000000..7d6a2c7c6021
--- /dev/null
+++ b/products/conversations/frontend/scenes/settings/supportSettingsLogic.test.ts
@@ -0,0 +1,77 @@
+import { expectLogic } from 'kea-test-utils'
+
+import { useMocks } from '~/mocks/jest'
+import { initKeaTests } from '~/test/init'
+import { TeamType } from '~/types'
+
+import { supportSettingsLogic } from './supportSettingsLogic'
+
+describe('supportSettingsLogic', () => {
+ let logic: ReturnType<typeof supportSettingsLogic.build>
+
+ beforeEach(() => {
+ useMocks({
+ get: {
+ 'api/conversations/v1/email/status': { configs: [] },
+ },
+ post: {
+ 'api/environments/:team_id/': (req: any) => [200, req.body],
+ },
+ })
+ initKeaTests()
+ })
+
+ afterEach(() => {
+ logic?.unmount()
+ })
+
+ describe('aiSuggestionsEnabled selector', () => {
+ it.each([
+ ['conversations_settings is undefined', undefined, false],
+ ['ai_suggestions_enabled is not set', { widget_enabled: true }, false],
+ ['ai_suggestions_enabled is true', { ai_suggestions_enabled: true }, true],
+ ])('%s', async (_label, settings, expected) => {
+ if (settings) {
+ initKeaTests(true, { conversations_settings: settings } as unknown as TeamType)
+ }
+ logic = supportSettingsLogic()
+ logic.mount()
+ await expectLogic(logic).toMatchValues({ aiSuggestionsEnabled: expected })
+ })
+ })
+
+ describe('setAiSuggestionsEnabled', () => {
+ it('sets loading state and dispatches updateCurrentTeam', async () => {
+ logic = supportSettingsLogic()
+ logic.mount()
+
+ await expectLogic(logic, () => {
+ logic.actions.setAiSuggestionsEnabled(true)
+ })
+ .toDispatchActions(['setAiSuggestionsLoading', 'updateCurrentTeam'])
+ .toMatchValues({ aiSuggestionsLoading: true })
+ })
+
+ it('clears loading state on updateCurrentTeamSuccess', async () => {
+ logic = supportSettingsLogic()
+ logic.mount()
+
+ logic.actions.setAiSuggestionsLoading(true)
+ expect(logic.values.aiSuggestionsLoading).toBe(true)
+
+ logic.actions.updateCurrentTeamSuccess({} as TeamType)
+ expect(logic.values.aiSuggestionsLoading).toBe(false)
+ })
+
+ it('clears loading state on updateCurrentTeamFailure', async () => {
+ logic = supportSettingsLogic()
+ logic.mount()
+
+ logic.actions.setAiSuggestionsLoading(true)
+ expect(logic.values.aiSuggestionsLoading).toBe(true)
+
+ logic.actions.updateCurrentTeamFailure('update failed')
+ expect(logic.values.aiSuggestionsLoading).toBe(false)
+ })
+ })
+})
diff --git a/products/conversations/frontend/scenes/settings/supportSettingsLogic.ts b/products/conversations/frontend/scenes/settings/supportSettingsLogic.ts
index c30f3efe8e8d..b68fab8f62ea 100644
--- a/products/conversations/frontend/scenes/settings/supportSettingsLogic.ts
+++ b/products/conversations/frontend/scenes/settings/supportSettingsLogic.ts
@@ -23,7 +23,10 @@ export const supportSettingsLogic = kea<supportSettingsLogicType>([
path(['products', 'conversations', 'frontend', 'scenes', 'settings', 'supportSettingsLogic']),
connect(() => ({
values: [teamLogic, ['currentTeam', 'currentTeamLoading']],
- actions: [teamLogic, ['updateCurrentTeam', 'updateCurrentTeamSuccess', 'loadCurrentTeam']],
+ actions: [
+ teamLogic,
+ ['updateCurrentTeam', 'updateCurrentTeamSuccess', 'updateCurrentTeamFailure', 'loadCurrentTeam'],
+ ],
})),
actions({
generateNewToken: true,
@@ -96,6 +99,9 @@ export const supportSettingsLogic = kea<supportSettingsLogicType>([
disconnectGithub: true,
setGithubRepos: (repos: string[]) => ({ repos }),
loadGithubRepos: true,
+ // AI suggestions
+ setAiSuggestionsEnabled: (enabled: boolean) => ({ enabled }),
+ setAiSuggestionsLoading: (loading: boolean) => ({ loading }),
}),
reducers({
conversationsEnabledLoading: [
@@ -241,6 +247,14 @@ export const supportSettingsLogic = kea<supportSettingsLogicType>([
disconnectTeams: () => null,
},
],
+ aiSuggestionsLoading: [
+ false,
+ {
+ setAiSuggestionsLoading: (_, { loading }) => loading,
+ updateCurrentTeamSuccess: () => false,
+ updateCurrentTeamFailure: () => false,
+ },
+ ],
slackTicketEmojiValue: [
null as string | null,
{
@@ -422,6 +436,10 @@ export const supportSettingsLogic = kea<supportSettingsLogicType>([
(s) => [s.currentTeam],
(currentTeam): string[] => currentTeam?.conversations_settings?.github_repos || [],
],
+ aiSuggestionsEnabled: [
+ (s) => [s.currentTeam],
+ (currentTeam): boolean => !!currentTeam?.conversations_settings?.ai_suggestions_enabled,
+ ],
}),
listeners(({ values, actions }) => ({
connectSlack: async ({ nextPath }) => {
@@ -791,6 +809,15 @@ export const supportSettingsLogic = kea<supportSettingsLogicType>([
}
actions.loadCurrentTeam()
},
+ setAiSuggestionsEnabled: ({ enabled }) => {
+ actions.setAiSuggestionsLoading(true)
+ actions.updateCurrentTeam({
+ conversations_settings: {
+ ...values.currentTeam?.conversations_settings,
+ ai_suggestions_enabled: enabled,
+ },
+ })
+ },
connectGithub: async ({ integrationId }) => {
try {
// nosemgrep: prefer-codegen-api
diff --git a/products/conversations/package.json b/products/conversations/package.json
index dd2f484e5306..a66bf09eed5f 100644
--- a/products/conversations/package.json
+++ b/products/conversations/package.json
@@ -15,7 +15,8 @@
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^14.3.1",
"@testing-library/user-event": "^14.6.1",
- "jest": "^29.7.0"
+ "jest": "^29.7.0",
+ "kea-test-utils": "catalog:"
},
"peerDependencies": {
"@posthog/icons": "*",