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(signals): add team-wide Slack channel picker to inbox settings (#69908)

Vojta Bartoš8b420aa36a0c
diff --git a/frontend/src/lib/integrations/SlackIntegrationHelpers.tsx b/frontend/src/lib/integrations/SlackIntegrationHelpers.tsx
index 70451e569d7d..5cfac869b013 100644
--- a/frontend/src/lib/integrations/SlackIntegrationHelpers.tsx
+++ b/frontend/src/lib/integrations/SlackIntegrationHelpers.tsx
@@ -81,6 +81,7 @@ export type SlackChannelPickerProps = {
}
export function SlackChannelPicker({ onChange, value, integration, disabled }: SlackChannelPickerProps): JSX.Element {
+ const logic = slackIntegrationLogic({ id: integration.id })
const {
slackChannels,
slackChannelsForPicker,
@@ -90,10 +91,8 @@ export function SlackChannelPicker({ onChange, value, integration, disabled }: S
isMemberOfSlackChannel,
isPrivateChannelWithoutAccess,
getChannelRefreshButtonDisabledReason,
- } = useValues(slackIntegrationLogic({ id: integration.id }))
- const { loadAllSlackChannels, loadSlackChannelById, loadSlackChannelByIdSuccess } = useActions(
- slackIntegrationLogic({ id: integration.id })
- )
+ } = useValues(logic)
+ const { loadAllSlackChannels, loadSlackChannelById, loadSlackChannelByIdSuccess } = useActions(logic)
const [localValue, setLocalValue] = useState<string | null>(null)
// Gates the empty-val recovery reload: LemonInputSelect's setInputValue('') on blur and
// after-select would otherwise flicker the "first page of channels" hint on every focus cycle.
@@ -134,10 +133,14 @@ export function SlackChannelPicker({ onChange, value, integration, disabled }: S
}, [value, slackChannels])
useEffect(() => {
- if (!disabled) {
+ // Multiple pickers can mount for the same workspace (e.g. team + per-user channel), so skip
+ // the fetch when the shared logic already has channels or a load in flight. Read live logic
+ // values rather than the render closure: sibling pickers mount within the same commit, before
+ // the first one's dispatch is reflected in a re-render.
+ if (!disabled && !logic.values.slackChannels.length && !logic.values.allSlackChannelsLoading) {
loadAllSlackChannels()
}
- }, [loadAllSlackChannels, disabled])
+ }, [logic, loadAllSlackChannels, disabled])
// Workspaces with hundreds of channels can have the saved channel beyond the first page that
// /channels returns. Without a direct lookup the channel never makes it into slackChannels, so
diff --git a/frontend/src/scenes/inbox/components/config/SlackNotificationsSection.tsx b/frontend/src/scenes/inbox/components/config/SlackNotificationsSection.tsx
index 46fa15362e27..6643dfa045ee 100644
--- a/frontend/src/scenes/inbox/components/config/SlackNotificationsSection.tsx
+++ b/frontend/src/scenes/inbox/components/config/SlackNotificationsSection.tsx
@@ -1,4 +1,5 @@
import { useActions, useMountedLogic, useValues } from 'kea'
+import { ReactNode, useState } from 'react'
import { IconChevronRight } from '@posthog/icons'
import { LemonSelect, LemonSkeleton, LemonSwitch, Link } from '@posthog/lemon-ui'
@@ -8,6 +9,9 @@ import { SlackChannelPicker } from 'lib/integrations/SlackIntegrationHelpers'
import { IconSlack } from 'lib/lemon-ui/icons'
import { urls } from 'scenes/urls'
+import { IntegrationType } from '~/types'
+
+import { signalTeamConfigLogic } from '../../logics/signalTeamConfigLogic'
import { userAutonomyLogic } from '../../logics/userAutonomyLogic'
import { SignalReportPriority } from '../../types'
@@ -23,6 +27,19 @@ const MIN_PRIORITY_OPTIONS: { value: SignalReportPriority | typeof NOTIFY_ALL_VA
{ value: 'P4', label: 'P4 and above' },
]
+/** Icon + title + description header shared by all the Slack cards in this section. */
+function SlackCardHeader({ title, description }: { title: string; description: ReactNode }): JSX.Element {
+ return (
+ <div className="flex items-start gap-3 min-w-0">
+ <IconSlack className="size-5 shrink-0 mt-0.5 grayscale" />
+ <div className="min-w-0">
+ <div className="font-medium text-sm text-default">{title}</div>
+ <p className="text-xs text-secondary mt-0.5 mb-0 max-w-xl">{description}</p>
+ </div>
+ </div>
+ )
+}
+
/** Shown when there's no Slack workspace connected – links out to integration settings. */
function ConnectSlackPrompt(): JSX.Element {
return (
@@ -30,21 +47,73 @@ function ConnectSlackPrompt(): JSX.Element {
to={urls.settings('environment-integrations', 'integration-slack')}
className="group flex items-center justify-between gap-3 rounded border bg-bg-light px-3 py-2.5 no-underline transition-colors hover:border-primary-3000 hover:bg-bg-3000"
>
- <div className="flex items-start gap-3 min-w-0">
- <IconSlack className="size-5 shrink-0 mt-0.5 grayscale" />
- <div className="min-w-0">
- <div className="font-medium text-sm text-default">Connect a Slack workspace</div>
- <p className="text-xs text-secondary mt-0.5 mb-0 max-w-xl">
- Connect Slack to get pinged in your own channel when you're a suggested reviewer on a new inbox
- item.
- </p>
- </div>
- </div>
+ <SlackCardHeader
+ title="Connect a Slack workspace"
+ description="Connect Slack to post reports to a team channel and get pinged when you're a suggested reviewer."
+ />
<IconChevronRight className="size-4 shrink-0 text-muted transition-colors group-hover:text-default" />
</Link>
)
}
+/**
+ * Team-wide channel where every actionable report is posted regardless of the suggested reviewer,
+ * backed by `default_slack_notification_channel` on `signalTeamConfigLogic`. Toggling off (or
+ * clearing the channel) disables the team default. The backend routes the team channel through the
+ * team's first Slack integration (`_get_team_slack_integration`), so we target `integrations[0]`
+ * here too.
+ */
+function TeamChannelCard({ integration }: { integration: IntegrationType }): JSX.Element {
+ const { teamConfig, teamConfigLoading } = useValues(signalTeamConfigLogic)
+ const { patchTeamConfig } = useActions(signalTeamConfigLogic)
+ // Local view state: the toggle is on but no channel has been picked yet. A saved
+ // channel implies enabled on its own, so this only bridges the picking moment.
+ const [pickerExpanded, setPickerExpanded] = useState(false)
+
+ const channel = teamConfig?.default_slack_notification_channel ?? null
+ const showPicker = pickerExpanded || !!channel
+
+ const onToggleEnabled = (enabled: boolean): void => {
+ setPickerExpanded(enabled)
+ if (!enabled && channel) {
+ patchTeamConfig({ default_slack_notification_channel: null })
+ }
+ }
+
+ return (
+ <div className="flex flex-col gap-3 rounded border bg-bg-light px-3 py-2.5">
+ <div className="flex items-start justify-between gap-4">
+ <SlackCardHeader
+ title="Notify the whole team"
+ description={
+ <>
+ Post every report to one channel, whether or not a reviewer is suggested. PostHog must be in
+ the channel – invite it with <code>/invite @PostHog</code>.
+ </>
+ }
+ />
+ <LemonSwitch
+ checked={showPicker}
+ onChange={onToggleEnabled}
+ disabled={teamConfigLoading && teamConfig === null}
+ aria-label="Enable team-wide Slack notifications"
+ />
+ </div>
+
+ {showPicker && (
+ <div className="flex flex-col gap-1 min-w-0 max-w-md border-t border-primary border-dashed pt-3">
+ <span className="text-xs text-secondary">Channel</span>
+ <SlackChannelPicker
+ integration={integration}
+ value={channel ?? undefined}
+ onChange={(next) => patchTeamConfig({ default_slack_notification_channel: next })}
+ />
+ </div>
+ )}
+ </div>
+ )
+}
+
/**
* Per-user Slack notification controls – a cloud port of desktop's
* `SlackInboxNotificationsSettings` / `SignalSlackNotificationsSettings`.
@@ -52,22 +121,10 @@ function ConnectSlackPrompt(): JSX.Element {
* enable toggle clears them to disable. Min-priority gates which reports ping.
* Backed by the `slack_notification_*` fields on `userAutonomyLogic`.
*/
-export function SlackNotificationsSection(): JSX.Element {
- useMountedLogic(integrationsLogic)
- useMountedLogic(userAutonomyLogic)
- const { slackIntegrations, integrationsLoading } = useValues(integrationsLogic)
+function PerUserChannelCard({ integrations }: { integrations: IntegrationType[] }): JSX.Element {
const { autonomyConfig, autonomyConfigLoading, slackPickersExpanded } = useValues(userAutonomyLogic)
const { updateSlackNotifications, setSlackPickersExpanded } = useActions(userAutonomyLogic)
- if (integrationsLoading && slackIntegrations === undefined) {
- return <LemonSkeleton className="h-20 w-full" />
- }
-
- const integrations = slackIntegrations ?? []
- if (integrations.length === 0) {
- return <ConnectSlackPrompt />
- }
-
// Workspace is shared with the team default. Default to the only workspace, or the user's saved pick.
const selectedIntegrationId = autonomyConfig?.slack_notification_integration_id ?? null
const effectiveIntegration =
@@ -122,16 +179,15 @@ export function SlackNotificationsSection(): JSX.Element {
return (
<div className="flex flex-col gap-3 rounded border bg-bg-light px-3 py-2.5">
<div className="flex items-start justify-between gap-4">
- <div className="flex items-start gap-3 min-w-0">
- <IconSlack className="size-5 shrink-0 mt-0.5 grayscale" />
- <div className="min-w-0">
- <div className="font-medium text-sm text-default">Notify me directly</div>
- <p className="text-xs text-secondary mt-0.5 mb-0 max-w-xl">
+ <SlackCardHeader
+ title="Notify me directly"
+ description={
+ <>
When you're a suggested reviewer, get pinged in your own channel. PostHog must be in the
channel – invite it with <code>/invite @PostHog</code>.
- </p>
- </div>
- </div>
+ </>
+ }
+ />
<LemonSwitch
checked={showPickers}
onChange={onToggleEnabled}
@@ -184,3 +240,29 @@ export function SlackNotificationsSection(): JSX.Element {
</div>
)
}
+
+/** Slack inbox notification settings: a team-wide channel plus per-user reviewer pings. */
+export function SlackNotificationsSection(): JSX.Element {
+ useMountedLogic(integrationsLogic)
+ useMountedLogic(userAutonomyLogic)
+ // Mounted here (not just in TeamChannelCard) so the team config fetch runs in
+ // parallel with the integrations load instead of waiting out the skeleton.
+ useMountedLogic(signalTeamConfigLogic)
+ const { slackIntegrations, integrationsLoading } = useValues(integrationsLogic)
+
+ if (integrationsLoading && slackIntegrations === undefined) {
+ return <LemonSkeleton className="h-20 w-full" />
+ }
+
+ const integrations = slackIntegrations ?? []
+ if (integrations.length === 0) {
+ return <ConnectSlackPrompt />
+ }
+
+ return (
+ <div className="flex flex-col gap-3">
+ <TeamChannelCard integration={integrations[0]} />
+ <PerUserChannelCard integrations={integrations} />
+ </div>
+ )
+}
diff --git a/frontend/src/scenes/inbox/components/shell/AgentSetupColumn.tsx b/frontend/src/scenes/inbox/components/shell/AgentSetupColumn.tsx
index caec01b19fe1..c1e45f5aab0c 100644
--- a/frontend/src/scenes/inbox/components/shell/AgentSetupColumn.tsx
+++ b/frontend/src/scenes/inbox/components/shell/AgentSetupColumn.tsx
@@ -14,6 +14,7 @@ import { cn } from 'lib/utils/css-classes'
import { urls } from 'scenes/urls'
import { scoutFleetLogic } from '../../logics/scoutFleetLogic'
+import { signalTeamConfigLogic } from '../../logics/signalTeamConfigLogic'
import { userAutonomyLogic } from '../../logics/userAutonomyLogic'
import { signalSourcesLogic } from '../../signalSourcesLogic'
import { ScoutsFleetSection } from '../config/scouts/ScoutsFleetSection'
@@ -245,10 +246,18 @@ function NotificationsWidget(): JSX.Element {
useMountedLogic(userAutonomyLogic)
const { slackIntegrations, integrationsLoading } = useValues(integrationsLogic)
const { autonomyConfig } = useValues(userAutonomyLogic)
+ const { teamConfig } = useValues(signalTeamConfigLogic)
const { openSetupModal } = useActions(agentSetupModalLogic)
- const channel = autonomyConfig?.slack_notification_channel ?? null
- const notifying = (slackIntegrations?.length ?? 0) > 0 && !!channel
+ // Either target counts as set up: the team-wide channel catches every actionable report,
+ // the personal channel pings the suggested reviewer. The status names each configured one.
+ const teamChannel = teamConfig?.default_slack_notification_channel ?? null
+ const userChannel = autonomyConfig?.slack_notification_channel ?? null
+ const channelLabels = [
+ teamChannel ? `Team ${slackChannelDisplayName(teamChannel)}` : null,
+ userChannel ? `You ${slackChannelDisplayName(userChannel)}` : null,
+ ].filter(Boolean)
+ const notifying = (slackIntegrations?.length ?? 0) > 0 && channelLabels.length > 0
return (
<SetupWidgetCard
icon={<IconSlack className="grayscale" />}
@@ -256,7 +265,7 @@ function NotificationsWidget(): JSX.Element {
size="md"
tone={notifying ? 'done' : 'todo'}
loading={integrationsLoading && slackIntegrations === undefined}
- status={notifying && channel ? `Slack ${slackChannelDisplayName(channel)}` : 'Not connected'}
+ status={notifying ? channelLabels.join(' · ') : 'Not connected'}
onClick={() => openSetupModal('slack')}
/>
)
diff --git a/frontend/src/scenes/inbox/logics/signalTeamConfigLogic.ts b/frontend/src/scenes/inbox/logics/signalTeamConfigLogic.ts
index ba4af14d5d0e..02a5e1fbb06a 100644
--- a/frontend/src/scenes/inbox/logics/signalTeamConfigLogic.ts
+++ b/frontend/src/scenes/inbox/logics/signalTeamConfigLogic.ts
@@ -1,25 +1,29 @@
-import { actions, kea, listeners, path, reducers } from 'kea'
+import { actions, afterMount, kea, listeners, path, reducers } from 'kea'
import { loaders } from 'kea-loaders'
import { lemonToast } from '@posthog/lemon-ui'
import api from 'lib/api'
-import type { SignalReportPriority, SignalTeamConfig } from '../types'
+import type { SignalTeamConfig } from '../types'
import type { signalTeamConfigLogicType } from './signalTeamConfigLogicType'
/**
* Team-level Self-driving config (singleton per team). Wraps the
- * `signals/team_config` endpoint via `api.signalTeamConfig`. The field surfaced
- * here is the team-wide default PR auto-start threshold, which seeds every
- * user's effective threshold until they set a personal override
- * (`userAutonomyLogic`). The backend field is non-nullable (P0–P4), so unlike
- * the per-user override there is no "Never" option here.
+ * `signals/team_config` endpoint via `api.signalTeamConfig`. Surfaces the
+ * team-wide default PR auto-start threshold (which seeds every user's effective
+ * threshold until they set a personal override in `userAutonomyLogic`) and the
+ * team-wide default Slack notification channel, where every actionable report is
+ * posted regardless of whether a suggested reviewer resolves. The auto-start
+ * field is non-nullable (P0–P4), so unlike the per-user override there is no
+ * "Never" option; the channel is nullable and `null` disables the team default.
*/
export const signalTeamConfigLogic = kea<signalTeamConfigLogicType>([
path(['scenes', 'inbox', 'logics', 'signalTeamConfigLogic']),
actions({
- setDefaultAutostartPriority: (priority: SignalReportPriority) => ({ priority }),
+ // Partial update of the singleton, e.g. `{ default_slack_notification_channel: null }`
+ // to clear the team channel. One action serves every patchable field.
+ patchTeamConfig: (patch: Partial<SignalTeamConfig>) => ({ patch }),
}),
loaders({
teamConfig: [
@@ -32,26 +36,25 @@ export const signalTeamConfigLogic = kea<signalTeamConfigLogicType>([
],
}),
reducers({
- // Optimistically reflect the chosen priority so the select doesn't flicker
- // back to the stale value while the request is in flight.
+ // Optimistically reflect the patched values so the controls don't flicker
+ // back to the stale ones while the request is in flight.
teamConfig: {
- setDefaultAutostartPriority: (state, { priority }) => ({
- ...(state ?? { default_autostart_priority: null }),
- default_autostart_priority: priority,
- }),
+ patchTeamConfig: (state, { patch }) => (state ? { ...state, ...patch } : state),
},
}),
listeners(({ actions }) => ({
- setDefaultAutostartPriority: async ({ priority }) => {
+ patchTeamConfig: async ({ patch }) => {
try {
- await api.signalTeamConfig.update({ default_autostart_priority: priority })
+ const config = await api.signalTeamConfig.update(patch)
+ actions.loadTeamConfigSuccess(config)
} catch (error: any) {
- lemonToast.error(
- error?.detail ?? error?.message ?? 'Failed to update team default auto-start threshold'
- )
- } finally {
+ lemonToast.error(error?.detail ?? error?.message ?? 'Failed to update team self-driving settings')
+ // Resync so the optimistic value doesn't linger after a failed update.
actions.loadTeamConfig()
}
},
})),
+ afterMount(({ actions }) => {
+ actions.loadTeamConfig()
+ }),
])