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(replay-vision): pick a webhook delivery destination (#74079)

Kim Svatos Dugan8355cdd32e2f
diff --git a/products/replay_vision/frontend/replay_scanners/ActionEditorScene.tsx b/products/replay_vision/frontend/replay_scanners/ActionEditorScene.tsx
index fa57652b4144..d77a591c45d5 100644
--- a/products/replay_vision/frontend/replay_scanners/ActionEditorScene.tsx
+++ b/products/replay_vision/frontend/replay_scanners/ActionEditorScene.tsx
@@ -2,7 +2,7 @@ import { useActions, useValues } from 'kea'
import { Form } from 'kea-forms'
import { useMemo } from 'react'
-import { LemonButton, LemonInput, LemonInputSelect, LemonSegmentedButton, LemonSelect } from '@posthog/lemon-ui'
+import { LemonButton, LemonInput, LemonInputSelect, LemonSegmentedButton, LemonSelect, Link } from '@posthog/lemon-ui'
import { IntegrationChoice } from 'lib/components/CyclotronJob/integrations/IntegrationChoice'
import { NotFound } from 'lib/components/NotFound'
@@ -27,6 +27,7 @@ import { ProductKey } from '~/queries/schema/schema-general'
import { ReplayVisionFeedbackButton } from '../components/ReplayVisionFeedbackButton'
import {
AlertConfigFrequencyEnumApi,
+ DeliveryTargetTypeEnumApi,
VisionActionModeEnumApi,
VisionAlertDirectionEnumApi,
VisionAlertMetricEnumApi,
@@ -532,6 +533,30 @@ function ConditionSection({ scannerId }: { scannerId: string }): JSX.Element {
}
function DeliverySection(): JSX.Element {
+ const { actionForm } = useValues(actionEditorSceneLogic)
+ const { setActionFormValue } = useActions(actionEditorSceneLogic)
+ const noun = actionForm.mode === VisionActionModeEnumApi.Alert ? 'alert' : 'digest'
+
+ return (
+ <div className="flex flex-col gap-2">
+ <LemonSelect
+ value={actionForm.delivery_type}
+ onChange={(value) => setActionFormValue('delivery_type', value)}
+ options={[
+ { value: DeliveryTargetTypeEnumApi.Slack, label: 'Slack' },
+ { value: DeliveryTargetTypeEnumApi.Webhook, label: 'Webhook' },
+ ]}
+ />
+ {actionForm.delivery_type === DeliveryTargetTypeEnumApi.Webhook ? (
+ <WebhookDelivery noun={noun} />
+ ) : (
+ <SlackDelivery noun={noun} />
+ )}
+ </div>
+ )
+}
+
+function SlackDelivery({ noun }: { noun: string }): JSX.Element {
const { actionForm } = useValues(actionEditorSceneLogic)
const { setActionFormValue } = useActions(actionEditorSceneLogic)
const { slackIntegrations, integrationsLoading } = useValues(integrationsLogic)
@@ -549,7 +574,7 @@ function DeliverySection(): JSX.Element {
const selectedIntegration = slackIntegrations.find((i) => i.id === integration_id)
return (
- <div className="flex flex-col gap-2">
+ <>
<IntegrationChoice
integration="slack"
value={integration_id ?? undefined}
@@ -571,11 +596,37 @@ function DeliverySection(): JSX.Element {
)}
{!actionForm.channel && (
<span className="text-xs text-muted">
- No channel selected — this {actionForm.mode === VisionActionModeEnumApi.Alert ? 'alert' : 'digest'}{' '}
- will appear on the scanner page and in its run history, without a Slack notification.
+ No channel selected. This {noun} will appear on the scanner page and in its run history, without a
+ Slack notification.
</span>
)}
- </div>
+ </>
+ )
+}
+
+function WebhookDelivery({ noun }: { noun: string }): JSX.Element {
+ const { actionForm } = useValues(actionEditorSceneLogic)
+
+ return (
+ <>
+ <LemonField name="webhook_url" label="Webhook URL">
+ {({ value, onChange }) => (
+ <LemonInput value={value} onChange={onChange} placeholder="https://example.com/webhook" />
+ )}
+ </LemonField>
+ <span className="text-xs text-muted">
+ We POST a JSON payload to this URL.{' '}
+ <Link to="https://posthog.com/docs/replay-vision/webhooks" target="_blank">
+ See the payload format
+ </Link>
+ .
+ </span>
+ {!actionForm.webhook_url && (
+ <span className="text-xs text-muted">
+ No URL set. This {noun} will appear on the scanner page and in its run history, without a webhook.
+ </span>
+ )}
+ </>
)
}
@@ -692,7 +743,7 @@ export function ActionEditorSceneComponent(): JSX.Element {
)}
<div>
- <h4 className="mb-1">Deliver to Slack (optional)</h4>
+ <h4 className="mb-1">Delivery (optional)</h4>
<DeliverySection />
</div>
diff --git a/products/replay_vision/frontend/replay_scanners/VisionActionScene.tsx b/products/replay_vision/frontend/replay_scanners/VisionActionScene.tsx
index b99b45b973de..e1f3d5ba7506 100644
--- a/products/replay_vision/frontend/replay_scanners/VisionActionScene.tsx
+++ b/products/replay_vision/frontend/replay_scanners/VisionActionScene.tsx
@@ -1,10 +1,12 @@
import { BindLogic, useActions, useValues } from 'kea'
+import type { ReactNode } from 'react'
import { IconPencil, IconPlay } from '@posthog/icons'
import { LemonButton, LemonCard, SpinnerOverlay } from '@posthog/lemon-ui'
import { NotFound } from 'lib/components/NotFound'
import { FEATURE_FLAGS } from 'lib/constants'
+import { slackChannelDisplayName } from 'lib/integrations/slackChannel'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { appLogic } from 'scenes/appLogic'
import { SceneExport } from 'scenes/sceneTypes'
@@ -15,7 +17,7 @@ import { SceneTitleSection } from '~/layout/scenes/components/SceneTitleSection'
import { ProductKey } from '~/queries/schema/schema-general'
import type { VisionActionApi } from '../generated/api.schemas'
-import { VisionActionModeEnumApi } from '../generated/api.schemas'
+import { DeliveryTargetTypeEnumApi, VisionActionModeEnumApi } from '../generated/api.schemas'
import { getReplayVisionEditDisabledReason } from '../utils/accessControl'
import { humanizeCadence, parseRruleToCadence } from './cadence'
import { VisionActionRuns } from './components/VisionActionRuns'
@@ -29,18 +31,86 @@ export const scene: SceneExport = {
productKey: ProductKey.REPLAY_VISION,
}
-// The title bar and current-guidance panel, shown once the action loads. Edit links to the action
-// editor page.
-function ActionOverview({
+function ConfigRow({ label, children }: { label: string; children: ReactNode }): JSX.Element {
+ return (
+ <div className="flex flex-col sm:flex-row sm:gap-4">
+ <div className="text-xs font-semibold uppercase text-secondary sm:w-32 sm:shrink-0 sm:pt-0.5">{label}</div>
+ <div className="flex-1 min-w-0">{children}</div>
+ </div>
+ )
+}
+
+function deliveryRow(action: VisionActionApi, noun: string): JSX.Element {
+ const target = action.delivery_config?.[0]
+ if (target?.type === DeliveryTargetTypeEnumApi.Webhook) {
+ return (
+ <p className="m-0">
+ Webhook at <span className="font-mono text-sm break-all">{target.url}</span>
+ </p>
+ )
+ }
+ if (target?.type === DeliveryTargetTypeEnumApi.Slack) {
+ return <p className="m-0">Slack in {slackChannelDisplayName(target.channel ?? '') || 'a channel'}</p>
+ }
+ return (
+ <p className="m-0 text-muted italic">
+ Not sent anywhere. Edit the action to deliver this {noun} to Slack or a webhook.
+ </p>
+ )
+}
+
+// One card summarizing the action's config — schedule, guidance (digests), and delivery — so it's all
+// visible without opening the editor.
+function ConfigCard({
action,
scheduleLabel,
+ noun,
}: {
action: VisionActionApi
scheduleLabel: string | null
+ noun: string
}): JSX.Element {
+ const isAlert = action.mode === VisionActionModeEnumApi.Alert
const guidance = action.synthesis_config?.prompt_guide?.trim()
+
+ return (
+ <LemonCard hoverEffect={false} className="p-4">
+ <div className="flex flex-col gap-3">
+ <ConfigRow label={isAlert ? 'Checks' : 'Schedule'}>
+ <p className="m-0">
+ {isAlert
+ ? action.alert_config?.frequency === 'every_match'
+ ? 'Every few minutes; each alert covers the new matches since the last check'
+ : 'About every hour; notifies when the threshold starts being crossed'
+ : scheduleLabel || 'Not scheduled'}
+ </p>
+ </ConfigRow>
+ {!isAlert && (
+ <ConfigRow label="Guidance">
+ {guidance ? (
+ <p className="m-0 whitespace-pre-wrap">{guidance}</p>
+ ) : (
+ <p className="m-0 text-muted italic">
+ None set. The AI summarizes this scanner's observations freely.
+ </p>
+ )}
+ </ConfigRow>
+ )}
+ <ConfigRow label="Delivery">{deliveryRow(action, noun)}</ConfigRow>
+ </div>
+ </LemonCard>
+ )
+}
+
+// The title bar and config summary, shown once the action loads. Edit links to the action editor page.
+function ActionOverview({
+ action,
+ scheduleLabel,
+}: {
+ action: VisionActionApi
+ scheduleLabel: string | null
+}): JSX.Element {
const isAlert = action.mode === VisionActionModeEnumApi.Alert
- const everyMatch = action.alert_config?.frequency === 'every_match'
// `action.scanner` is only the id — the action's own user_access_level would just reflect the
// replay_scanner resource default, not a per-scanner object grant, so load the scanner itself.
const { scanner } = useValues(replayScannerLogic({ id: action.scanner }))
@@ -52,17 +122,6 @@ function ActionOverview({
<>
<SceneTitleSection
name={action.name}
- description={
- isAlert
- ? everyMatch
- ? 'Checked every few minutes; each alert covers the new matches since the last check'
- : 'Checked about every hour; notifies when the threshold starts being crossed'
- : scheduleLabel
- ? // Lowercase only the leading "Daily"/"Weekly" so it reads as a sentence;
- // keep weekday names and the timezone acronym (e.g. PDT) in their own case.
- `Runs ${scheduleLabel.charAt(0).toLowerCase()}${scheduleLabel.slice(1)}`
- : undefined
- }
resourceType={{ type: 'replay_vision' }}
actions={
<>
@@ -92,19 +151,7 @@ function ActionOverview({
</>
}
/>
- {!isAlert && (
- <LemonCard hoverEffect={false} className="p-4">
- <div className="text-xs font-semibold uppercase text-secondary mb-1">Digest guidance</div>
- {guidance ? (
- <p className="m-0 whitespace-pre-wrap">{guidance}</p>
- ) : (
- <p className="m-0 text-muted italic">
- No guidance set — the AI summarizes this scanner's observations freely. Edit the action to
- steer it.
- </p>
- )}
- </LemonCard>
- )}
+ <ConfigCard action={action} scheduleLabel={scheduleLabel} noun={isAlert ? 'alert' : 'digest'} />
</>
)
}
diff --git a/products/replay_vision/frontend/replay_scanners/actionEditorSceneLogic.test.ts b/products/replay_vision/frontend/replay_scanners/actionEditorSceneLogic.test.ts
index 5398d3735123..76cfced2a763 100644
--- a/products/replay_vision/frontend/replay_scanners/actionEditorSceneLogic.test.ts
+++ b/products/replay_vision/frontend/replay_scanners/actionEditorSceneLogic.test.ts
@@ -37,6 +37,12 @@ const summarizerAlert = {
selection: {},
} as unknown as VisionActionApi
+const webhookAction = {
+ ...existingAction,
+ id: 'wh',
+ delivery_config: [{ type: 'webhook', url: 'https://example.com/hook' }],
+} as unknown as VisionActionApi
+
describe('actionEditorSceneLogic', () => {
let logic: ReturnType<typeof actionEditorSceneLogic.build>
@@ -44,7 +50,13 @@ describe('actionEditorSceneLogic', () => {
useMocks({
get: {
'/api/projects/:team/vision/actions/:id/': ({ params }) =>
- params.id === 'al1' ? existingAlert : params.id === 'al2' ? summarizerAlert : existingAction,
+ params.id === 'al1'
+ ? existingAlert
+ : params.id === 'al2'
+ ? summarizerAlert
+ : params.id === 'wh'
+ ? webhookAction
+ : existingAction,
'/api/projects/:team/vision/scanners/:id/': ({ params }) =>
params.id === 's2'
? { id: 's2', name: 'Digest scanner', scanner_type: 'summarizer' }
@@ -101,8 +113,10 @@ describe('actionEditorSceneLogic', () => {
cadence: { weekdays: [0, 2], hour: 14, minute: 30 },
timezone: 'Europe/Prague',
prompt_guide: 'focus on checkout',
+ delivery_type: 'slack',
integration_id: 5,
channel: 'C123',
+ webhook_url: '',
verdict: ['yes'],
tags: [],
min_score: 2,
@@ -124,6 +138,18 @@ describe('actionEditorSceneLogic', () => {
})
})
+ it('the edit route seeds the webhook delivery type and url from a webhook action', async () => {
+ router.actions.push(urls.replayVisionActionEdit('wh'))
+ await expectLogic(logic)
+ .toFinishAllListeners()
+ .toMatchValues({
+ actionForm: expect.objectContaining({
+ delivery_type: 'webhook',
+ webhook_url: 'https://example.com/hook',
+ }),
+ })
+ })
+
it('editing an alert seeds the mode and condition instead of flipping to summary', async () => {
router.actions.push(urls.replayVisionActionEdit('al1'))
await expectLogic(logic)
diff --git a/products/replay_vision/frontend/replay_scanners/actionEditorSceneLogic.ts b/products/replay_vision/frontend/replay_scanners/actionEditorSceneLogic.ts
index c53e8572f980..4348610a691f 100644
--- a/products/replay_vision/frontend/replay_scanners/actionEditorSceneLogic.ts
+++ b/products/replay_vision/frontend/replay_scanners/actionEditorSceneLogic.ts
@@ -18,6 +18,7 @@ import {
} from '../generated/api'
import {
AlertConfigFrequencyEnumApi,
+ DeliveryTargetTypeEnumApi,
VisionActionModeEnumApi,
VisionAlertDirectionEnumApi,
VisionAlertMetricEnumApi,
@@ -405,8 +406,10 @@ export const actionEditorSceneLogic = kea<actionEditorSceneLogicType>([
cadence: parseRruleToCadence(action.trigger_config?.rrule),
timezone: action.trigger_config?.timezone || dayjs.tz.guess(),
prompt_guide: action.synthesis_config?.prompt_guide ?? '',
+ delivery_type: action.delivery_config?.[0]?.type ?? DeliveryTargetTypeEnumApi.Slack,
integration_id: action.delivery_config?.[0]?.integration_id ?? null,
channel: action.delivery_config?.[0]?.channel ?? '',
+ webhook_url: action.delivery_config?.[0]?.url ?? '',
mode: action.mode ?? VisionActionModeEnumApi.GroupSummary,
alert_frequency: alertFrequency,
alert_metric: alertMetric,
diff --git a/products/replay_vision/frontend/replay_scanners/visionActionsLogic.test.ts b/products/replay_vision/frontend/replay_scanners/visionActionsLogic.test.ts
index 5ba07ed5d0ef..69b10380da30 100644
--- a/products/replay_vision/frontend/replay_scanners/visionActionsLogic.test.ts
+++ b/products/replay_vision/frontend/replay_scanners/visionActionsLogic.test.ts
@@ -7,6 +7,28 @@ import type { VisionActionApi } from '../generated/api.schemas'
import { DeliveryTargetTypeEnumApi } from '../generated/api.schemas'
import { buildActionBody, type VisionActionForm, visionActionsLogic } from './visionActionsLogic'
+// A fully-populated Slack digest form; the webhook cases spread this and override the delivery fields.
+const slackForm: VisionActionForm = {
+ name: ' Daily digest ',
+ cadence: { weekdays: [0, 2], hour: 14, minute: 30 },
+ timezone: 'Europe/Prague',
+ prompt_guide: 'focus on checkout',
+ delivery_type: DeliveryTargetTypeEnumApi.Slack,
+ integration_id: 5,
+ channel: 'C123|#general',
+ webhook_url: '',
+ verdict: ['yes'],
+ tags: ['bug'],
+ min_score: 1,
+ max_score: 5,
+ mode: 'group_summary',
+ alert_frequency: 'on_breach',
+ alert_metric: 'count',
+ alert_threshold: 1,
+ alert_direction: 'above',
+ alert_window_days: 1,
+}
+
const action = (id: string, enabled = true): VisionActionApi => ({
id,
name: `action-${id}`,
@@ -109,25 +131,7 @@ describe('visionActionsLogic', () => {
})
it('buildActionBody maps the form to the API body, including a Slack delivery target and targeting', () => {
- const form: VisionActionForm = {
- name: ' Daily digest ',
- cadence: { weekdays: [0, 2], hour: 14, minute: 30 },
- timezone: 'Europe/Prague',
- prompt_guide: 'focus on checkout',
- integration_id: 5,
- channel: 'C123|#general',
- verdict: ['yes'],
- tags: ['bug'],
- min_score: 1,
- max_score: 5,
- mode: 'group_summary',
- alert_frequency: 'on_breach',
- alert_metric: 'count',
- alert_threshold: 1,
- alert_direction: 'above',
- alert_window_days: 1,
- }
- expect(buildActionBody(form, 's1')).toEqual({
+ expect(buildActionBody(slackForm, 's1')).toEqual({
name: 'Daily digest', // trimmed
scanner: 's1',
mode: 'group_summary',
@@ -140,14 +144,39 @@ describe('visionActionsLogic', () => {
})
})
+ it('buildActionBody maps a webhook delivery target from the url, ignoring stale slack fields', () => {
+ const form: VisionActionForm = {
+ ...slackForm,
+ delivery_type: DeliveryTargetTypeEnumApi.Webhook,
+ // A slack integration/channel left over from switching type must not leak into a webhook target.
+ integration_id: 5,
+ channel: 'C123|#general',
+ webhook_url: 'https://example.com/hook',
+ }
+ expect(buildActionBody(form, 's1').delivery_config).toEqual([
+ { type: DeliveryTargetTypeEnumApi.Webhook, url: 'https://example.com/hook' },
+ ])
+ })
+
+ it('buildActionBody emits empty delivery_config for a webhook type with no url', () => {
+ const form: VisionActionForm = {
+ ...slackForm,
+ delivery_type: DeliveryTargetTypeEnumApi.Webhook,
+ webhook_url: '',
+ }
+ expect(buildActionBody(form, 's1').delivery_config).toEqual([])
+ })
+
it('buildActionBody emits empty delivery_config and selection when nothing is set', () => {
const form: VisionActionForm = {
name: 'No delivery',
cadence: { weekdays: [0, 1, 2, 3, 4, 5, 6], hour: 9, minute: 0 },
timezone: 'UTC',
prompt_guide: '',
+ delivery_type: DeliveryTargetTypeEnumApi.Slack,
integration_id: null,
channel: '',
+ webhook_url: '',
verdict: [],
tags: [],
min_score: null,
@@ -173,8 +202,10 @@ describe('visionActionsLogic', () => {
cadence: { weekdays: [0, 1, 2, 3, 4, 5, 6], hour: 9, minute: 0 },
timezone: 'UTC',
prompt_guide: 'leftover from summary mode',
+ delivery_type: DeliveryTargetTypeEnumApi.Slack,
integration_id: null,
channel: '',
+ webhook_url: '',
verdict: [],
tags: ['rage-click'],
min_score: null,
diff --git a/products/replay_vision/frontend/replay_scanners/visionActionsLogic.ts b/products/replay_vision/frontend/replay_scanners/visionActionsLogic.ts
index 44ffecb2d241..9ee194a22608 100644
--- a/products/replay_vision/frontend/replay_scanners/visionActionsLogic.ts
+++ b/products/replay_vision/frontend/replay_scanners/visionActionsLogic.ts
@@ -31,8 +31,11 @@ export interface VisionActionForm {
cadence: CadenceState
timezone: string
prompt_guide: string
+ // Which delivery destination the form is editing. Slack uses integration_id + channel; webhook uses url.
+ delivery_type: DeliveryTargetTypeEnumApi
integration_id: number | null
channel: string
+ webhook_url: string
// Targeting ("run this on…") — empty means all of the scanner's observations.
verdict: VerdictEnumApi[]
tags: string[]
@@ -52,8 +55,10 @@ export const NEW_ACTION_FORM = (): VisionActionForm => ({
cadence: { ...DEFAULT_CADENCE },
timezone: dayjs.tz.guess(),
prompt_guide: '',
+ delivery_type: DeliveryTargetTypeEnumApi.Slack,
integration_id: null,
channel: '',
+ webhook_url: '',
verdict: [],
tags: [],
min_score: null,
@@ -119,21 +124,31 @@ export function buildActionBody(form: VisionActionForm, scannerId: string): Para
},
}
: {}),
- delivery_config:
- form.integration_id && form.channel
- ? [
- {
- type: DeliveryTargetTypeEnumApi.Slack,
- integration_id: form.integration_id,
- // Store the `${id}|#${name}` picker composite so the table can show the
- // channel name; delivery.py strips it to the bare id for the Slack destination.
- channel: form.channel,
- },
- ]
- : [],
+ delivery_config: buildDeliveryConfig(form),
}
}
+// Map the form's chosen destination to a delivery target, or [] when it's incomplete (no channel
+// picked / no URL) — an empty config leaves the run in-app only, matching the "optional" delivery UX.
+function buildDeliveryConfig(
+ form: VisionActionForm
+): NonNullable<Parameters<typeof visionActionsCreate>[1]['delivery_config']> {
+ if (form.delivery_type === DeliveryTargetTypeEnumApi.Webhook) {
+ return form.webhook_url ? [{ type: DeliveryTargetTypeEnumApi.Webhook, url: form.webhook_url }] : []
+ }
+ return form.integration_id && form.channel
+ ? [
+ {
+ type: DeliveryTargetTypeEnumApi.Slack,
+ integration_id: form.integration_id,
+ // Store the `${id}|#${name}` picker composite so the table can show the channel name;
+ // delivery.py strips it to the bare id for the Slack destination.
+ channel: form.channel,
+ },
+ ]
+ : []
+}
+
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface visionActionsLogicValues {
togglingIds: string[]