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(workflows): suggest workflows from your data in the messaging wizard (#117752)

Meikel Ratzeb2ed9587cb2
diff --git a/products/workflows/frontend/setupGuide/suggestions/workflowDataSuggestionsLogic.test.ts b/products/workflows/frontend/setupGuide/suggestions/workflowDataSuggestionsLogic.test.ts
index 0943f1467d65..cd7e0b82aa19 100644
--- a/products/workflows/frontend/setupGuide/suggestions/workflowDataSuggestionsLogic.test.ts
+++ b/products/workflows/frontend/setupGuide/suggestions/workflowDataSuggestionsLogic.test.ts
@@ -1,4 +1,5 @@
import { router } from 'kea-router'
+import posthog from 'posthog-js'
import { lemonToast } from '@posthog/lemon-ui'
@@ -11,6 +12,7 @@ import {
workflowDataSuggestionsCurrent,
workflowDataSuggestionsGenerate,
} from '../../generated/api'
+import { workflowsOnboardingWizardLogic } from '../wizard/workflowsOnboardingWizardLogic'
import { SuggestionCard } from './suggestionCards'
import { workflowDataSuggestionsLogic } from './workflowDataSuggestionsLogic'
@@ -82,7 +84,11 @@ describe('workflowDataSuggestionsLogic', () => {
}
})
- it('opens the saved draft after a successful build', async () => {
+ it.each([
+ ['empty_state', false],
+ ['onboarding_wizard', true],
+ ] as const)('opens the saved draft after a successful build on the %s', async (surface, finishesWizard) => {
+ const capture = jest.spyOn(posthog, 'capture')
jest.mocked(workflowDataSuggestionsBuild).mockResolvedValue({
status: 'ready',
workflow: { name: 'Welcome new users' },
@@ -91,7 +97,10 @@ describe('workflowDataSuggestionsLogic', () => {
missing_inputs: [],
})
jest.mocked(hogFlowsCreate).mockResolvedValue({ id: 'workflow-1' } as any)
- const logic = workflowDataSuggestionsLogic({ surface: 'empty_state' })
+ if (finishesWizard) {
+ workflowsOnboardingWizardLogic.mount()
+ }
+ const logic = workflowDataSuggestionsLogic({ surface })
logic.mount()
await logic.asyncActions.startSuggestion(card)
@@ -104,6 +113,12 @@ describe('workflowDataSuggestionsLogic', () => {
expect(router.values.location.pathname).toContain('workflow-1')
expect(loadEntrySource('workflow-1')).toBe('data_suggestion')
expect(logic.values.buildingKey).toBeNull()
+ const wizardFinished = capture.mock.calls.filter(([event]) => event === 'workflows onboarding wizard finished')
+ expect(wizardFinished).toEqual(
+ finishesWizard
+ ? [['workflows onboarding wizard finished', { path: 'messaging', template_id: 'data_suggestion' }]]
+ : []
+ )
})
it.each([
diff --git a/products/workflows/frontend/setupGuide/suggestions/workflowDataSuggestionsLogic.ts b/products/workflows/frontend/setupGuide/suggestions/workflowDataSuggestionsLogic.ts
index 9ac26c52b6c6..718397855011 100644
--- a/products/workflows/frontend/setupGuide/suggestions/workflowDataSuggestionsLogic.ts
+++ b/products/workflows/frontend/setupGuide/suggestions/workflowDataSuggestionsLogic.ts
@@ -29,6 +29,7 @@ import {
workflowDataSuggestionsGenerate,
} from '../../generated/api'
import type { DataSuggestionsResponseApi } from '../../generated/api.schemas'
+import { workflowsOnboardingWizardLogic } from '../wizard/workflowsOnboardingWizardLogic'
import { SuggestionCard, cardFromSuggestion } from './suggestionCards'
// A background run or build usually takes 10 to 30 seconds. Past the deadline it counts as failed.
@@ -41,7 +42,7 @@ const POLL_REQUEST_TIMEOUT_MS = 10_000
const BUILD_FAILED_MESSAGE = "We couldn't build this workflow. Try again, or start from a template."
// pinned: analytics property values for the `workflows data suggestion*` events - renaming breaks dashboards
-export type WorkflowDataSuggestionsSurface = 'empty_state'
+export type WorkflowDataSuggestionsSurface = 'empty_state' | 'onboarding_wizard'
export interface WorkflowDataSuggestionsLogicProps {
surface: WorkflowDataSuggestionsSurface
@@ -103,7 +104,7 @@ export interface workflowDataSuggestionsLogicActions {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface workflowDataSuggestionsLogicMeta {
- key: 'empty_state'
+ key: WorkflowDataSuggestionsSurface
__keaTypeGenInternalSelectorTypes: {
cards: (aiResult: DataSuggestionsResponseApi | null) => SuggestionCard[]
generating: (
@@ -297,6 +298,9 @@ export const workflowDataSuggestionsLogic = kea<workflowDataSuggestionsLogicType
stage: card.stage,
uses_saved_template: built.uses_saved_template,
})
+ if (props.surface === 'onboarding_wizard') {
+ workflowsOnboardingWizardLogic.findMounted()?.actions.finishWithSuggestion()
+ }
router.actions.push(urls.workflow(workflow.id, 'workflow'))
} catch (error: any) {
if (isBreakpoint(error)) {
diff --git a/products/workflows/frontend/setupGuide/wizard/WizardSuggestionsStep.tsx b/products/workflows/frontend/setupGuide/wizard/WizardSuggestionsStep.tsx
new file mode 100644
index 000000000000..259a3837aebb
--- /dev/null
+++ b/products/workflows/frontend/setupGuide/wizard/WizardSuggestionsStep.tsx
@@ -0,0 +1,69 @@
+import { useActions, useValues } from 'kea'
+
+import { IconArrowRight, IconSparkles } from '@posthog/icons'
+import { LemonButton, LemonSkeleton, LemonTag, Spinner, Tooltip } from '@posthog/lemon-ui'
+
+import { workflowDataSuggestionsLogic } from '../suggestions/workflowDataSuggestionsLogic'
+import { WorkflowSuggestionCard } from '../suggestions/WorkflowSuggestionCard'
+import { workflowsOnboardingWizardLogic } from './workflowsOnboardingWizardLogic'
+
+export function WizardSuggestionsStep({ fallback }: { fallback: JSX.Element }): JSX.Element {
+ const { cards, generating } = useValues(workflowDataSuggestionsLogic({ surface: 'onboarding_wizard' }))
+ const { setTemplatesShown } = useActions(workflowsOnboardingWizardLogic)
+
+ if (!generating && cards.length === 0) {
+ return fallback
+ }
+
+ const [top, ...rest] = cards
+
+ return (
+ <div className="flex flex-col gap-4" data-attr="workflows-onboarding-wizard-suggestions">
+ <span className="inline-flex items-center gap-1 text-xs text-secondary">
+ {generating ? <Spinner className="size-3" /> : <IconSparkles className="size-3" />}
+ {generating
+ ? 'Suggesting workflows based on the events your project sends'
+ : 'Suggested from your data'}
+ <Tooltip title="AI writes these suggestions from your project's events. Check each draft before you turn it on.">
+ <LemonTag type="completion" size="small">
+ Beta
+ </LemonTag>
+ </Tooltip>
+ </span>
+ {generating ? (
+ <>
+ <LemonSkeleton className="h-44 rounded" />
+ <div className="grid grid-cols-2 gap-4">
+ <LemonSkeleton className="h-44 rounded" />
+ <LemonSkeleton className="h-44 rounded" />
+ </div>
+ </>
+ ) : (
+ <>
+ <WorkflowSuggestionCard card={top} surface="onboarding_wizard" primary />
+ {rest.length > 0 && (
+ <div className="@container">
+ <div className="grid grid-cols-1 gap-4 @xl:grid-cols-2">
+ {rest.map((card) => (
+ <WorkflowSuggestionCard key={card.key} card={card} surface="onboarding_wizard" />
+ ))}
+ </div>
+ </div>
+ )}
+ </>
+ )}
+ <div className="flex flex-wrap items-center gap-1 text-sm text-secondary">
+ <span>Not what you need?</span>
+ <LemonButton
+ type="tertiary"
+ size="small"
+ sideIcon={<IconArrowRight />}
+ onClick={() => setTemplatesShown(true)}
+ data-attr="workflows-onboarding-wizard-show-templates"
+ >
+ Start from a template or from scratch
+ </LemonButton>
+ </div>
+ </div>
+ )
+}
diff --git a/products/workflows/frontend/setupGuide/wizard/WizardTemplateStep.tsx b/products/workflows/frontend/setupGuide/wizard/WizardTemplateStep.tsx
index 7f26e643f12a..cda427142bb8 100644
--- a/products/workflows/frontend/setupGuide/wizard/WizardTemplateStep.tsx
+++ b/products/workflows/frontend/setupGuide/wizard/WizardTemplateStep.tsx
@@ -2,7 +2,8 @@ import '../../Workflows/templates/WorkflowTemplateChooser.scss'
import { useActions, useValues } from 'kea'
-import { IconPlus } from '@posthog/icons'
+import { IconArrowLeft, IconPlus } from '@posthog/icons'
+import { LemonButton } from '@posthog/lemon-ui'
import { Spinner } from 'lib/lemon-ui/Spinner'
@@ -10,13 +11,20 @@ import { WorkflowTemplateCard } from '../../Workflows/templates/WorkflowTemplate
import { WorkflowTemplateMeta } from '../../Workflows/templates/WorkflowTemplateMeta'
import { WorkflowTemplateSteps } from '../../Workflows/templates/WorkflowTemplateSteps'
import { BLANK_START_ID } from './onboardingWizardSteps'
+import { WizardSuggestionsStep } from './WizardSuggestionsStep'
import { workflowsOnboardingWizardLogic } from './workflowsOnboardingWizardLogic'
/** A template picker that selects, rather than creates, so the wizard can show more steps before it creates. */
export function WizardTemplateStep(): JSX.Element {
- const { templates, selectedTemplateId, workflowTemplatesLoading, startsBlank } =
- useValues(workflowsOnboardingWizardLogic)
- const { selectTemplate } = useActions(workflowsOnboardingWizardLogic)
+ const {
+ templates,
+ selectedTemplateId,
+ workflowTemplatesLoading,
+ startsBlank,
+ offersSuggestions,
+ suggestionsFirst,
+ } = useValues(workflowsOnboardingWizardLogic)
+ const { selectTemplate, setTemplatesShown } = useActions(workflowsOnboardingWizardLogic)
if (workflowTemplatesLoading && templates.length === 0) {
return (
@@ -26,7 +34,7 @@ export function WizardTemplateStep(): JSX.Element {
)
}
- return (
+ const templateGrid = (
<div className="WorkflowTemplateChooser">
<WorkflowTemplateCard
name="Start from scratch"
@@ -54,4 +62,27 @@ export function WizardTemplateStep(): JSX.Element {
))}
</div>
)
+
+ if (suggestionsFirst) {
+ return <WizardSuggestionsStep fallback={templateGrid} />
+ }
+ if (!offersSuggestions) {
+ return templateGrid
+ }
+ return (
+ <div className="flex flex-col gap-3">
+ <div>
+ <LemonButton
+ type="tertiary"
+ size="small"
+ icon={<IconArrowLeft />}
+ onClick={() => setTemplatesShown(false)}
+ data-attr="workflows-onboarding-wizard-show-suggestions"
+ >
+ Back to suggestions from your data
+ </LemonButton>
+ </div>
+ {templateGrid}
+ </div>
+ )
}
diff --git a/products/workflows/frontend/setupGuide/wizard/WorkflowsOnboardingWizard.tsx b/products/workflows/frontend/setupGuide/wizard/WorkflowsOnboardingWizard.tsx
index db71e53cbdee..1cdf6784d112 100644
--- a/products/workflows/frontend/setupGuide/wizard/WorkflowsOnboardingWizard.tsx
+++ b/products/workflows/frontend/setupGuide/wizard/WorkflowsOnboardingWizard.tsx
@@ -6,6 +6,7 @@ import { LemonCard } from 'lib/lemon-ui/LemonCard'
import { CustomerIOImportModal } from '../../OptOuts/CustomerIOImportModal'
import { OptOutCategories } from '../../OptOuts/OptOutCategories'
+import { workflowDataSuggestionsLogic } from '../suggestions/workflowDataSuggestionsLogic'
import type { WorkflowsOnboardingPath } from '../workflowsSetupGuideLogic'
import { OnboardingWizardStepper } from './OnboardingWizardStepper'
import { WIZARD_STEP_COPY } from './onboardingWizardSteps'
@@ -18,6 +19,10 @@ import { WizardPushStep } from './WizardPushStep'
import { WizardTemplateStep } from './WizardTemplateStep'
import { workflowsOnboardingWizardLogic } from './workflowsOnboardingWizardLogic'
+// Without suggestions the step falls back to the templates, so this copy fits both.
+const SUGGESTIONS_DESCRIPTION =
+ 'Start from a suggestion made from the events your project sends, a template, or scratch. It opens in the editor as a draft, so nothing sends until you launch it.'
+
const PATH_LABELS: Record<WorkflowsOnboardingPath, string> = {
messaging: 'Message your users',
automation: 'Automate a process',
@@ -35,6 +40,7 @@ export function WorkflowsOnboardingWizard(): JSX.Element {
isLastStep,
continueDisabledReason,
setupCheckFailed,
+ suggestionsFirst,
} = useValues(workflowsOnboardingWizardLogic)
const { setStepIndex, next, back, exit, loadHasMessagingWorkflow } = useActions(workflowsOnboardingWizardLogic)
@@ -48,6 +54,17 @@ export function WorkflowsOnboardingWizard(): JSX.Element {
? 'Skip for now'
: 'Continue'
+ const nextButton = (
+ <LemonButton
+ type={isSkip && !isLastStep ? 'secondary' : 'primary'}
+ onClick={next}
+ disabledReason={continueDisabledReason ?? undefined}
+ data-attr={`workflows-onboarding-wizard-next-${currentStep}`}
+ >
+ {continueLabel}
+ </LemonButton>
+ )
+
return (
<div className="mx-auto w-full max-w-4xl flex flex-col gap-6 py-4" data-attr="workflows-onboarding-wizard">
<div className="flex flex-wrap items-center justify-between gap-2">
@@ -81,7 +98,7 @@ export function WorkflowsOnboardingWizard(): JSX.Element {
/>
<div>
<h2 className="mb-1 text-xl font-bold">{copy.title}</h2>
- <p className="mb-0 text-secondary">{copy.description}</p>
+ <p className="mb-0 text-secondary">{suggestionsFirst ? SUGGESTIONS_DESCRIPTION : copy.description}</p>
</div>
<LemonCard hoverEffect={false} className="p-6">
{currentStep === 'channel' && <WizardChannelStep />}
@@ -106,15 +123,14 @@ export function WorkflowsOnboardingWizard(): JSX.Element {
</LemonButton>
)}
</div>
- <LemonButton
- type={isSkip && !isLastStep ? 'secondary' : 'primary'}
- onClick={next}
- disabledReason={continueDisabledReason ?? undefined}
- data-attr={`workflows-onboarding-wizard-next-${currentStep}`}
- >
- {continueLabel}
- </LemonButton>
+ {suggestionsFirst ? <HiddenWhileSuggesting>{nextButton}</HiddenWhileSuggesting> : nextButton}
</div>
</div>
)
}
+
+// Mounted only while suggestions lead the step, because mounting the suggestions logic starts an AI run.
+function HiddenWhileSuggesting({ children }: { children: JSX.Element }): JSX.Element | null {
+ const { cards, generating } = useValues(workflowDataSuggestionsLogic({ surface: 'onboarding_wizard' }))
+ return generating || cards.length > 0 ? null : children
+}
diff --git a/products/workflows/frontend/setupGuide/wizard/onboardingWizardSteps.ts b/products/workflows/frontend/setupGuide/wizard/onboardingWizardSteps.ts
index d35f18b10b09..68b89a9a7e51 100644
--- a/products/workflows/frontend/setupGuide/wizard/onboardingWizardSteps.ts
+++ b/products/workflows/frontend/setupGuide/wizard/onboardingWizardSteps.ts
@@ -20,6 +20,8 @@ export type WizardStepKey =
export const ONBOARDING_WIZARD_TAB = 'onboarding'
/** The `template` value for starting from an empty workflow instead of a template. */
export const BLANK_START_ID = 'blank'
+/** The `template_id` the finished event reports when a data suggestion created the workflow. */
+export const DATA_SUGGESTION_START_ID = 'data_suggestion'
export function onboardingWizardUrl(
path: WorkflowsOnboardingPath,
diff --git a/products/workflows/frontend/setupGuide/wizard/workflowsOnboardingWizardLogic.ts b/products/workflows/frontend/setupGuide/wizard/workflowsOnboardingWizardLogic.ts
index 8a73c8e20bb1..389f981b1b54 100644
--- a/products/workflows/frontend/setupGuide/wizard/workflowsOnboardingWizardLogic.ts
+++ b/products/workflows/frontend/setupGuide/wizard/workflowsOnboardingWizardLogic.ts
@@ -19,6 +19,7 @@ import type { SetupGuideStep } from '../setupGuideSteps'
import { WorkflowsOnboardingPath, workflowsSetupGuideLogic } from '../workflowsSetupGuideLogic'
import {
BLANK_START_ID,
+ DATA_SUGGESTION_START_ID,
ONBOARDING_WIZARD_TAB,
WIZARD_STEP_COPY,
WizardConnection,
@@ -46,6 +47,7 @@ export interface workflowsOnboardingWizardLogicValues {
initialized: boolean
isLastStep: boolean
missingConnections: WizardConnection[]
+ offersSuggestions: boolean
pushEnabled: boolean
pushSetupStarted: boolean
selectedTemplate: HogFlowTemplate | null
@@ -55,7 +57,9 @@ export interface workflowsOnboardingWizardLogicValues {
stepDone: Partial<Record<WizardStepKey, boolean>> | null
stepIndex: number
stepKeys: readonly WizardStepKey[]
+ suggestionsFirst: boolean
templates: HogFlowTemplate[]
+ templatesShown: boolean
wizardPath: WorkflowsOnboardingPath
}
@@ -94,6 +98,9 @@ export interface workflowsOnboardingWizardLogicActions {
finish: () => {
value: true
}
+ finishWithSuggestion: () => {
+ value: true
+ }
initWizard: (
path: WorkflowsOnboardingPath,
step: WizardStepKey | null,
@@ -120,6 +127,9 @@ export interface workflowsOnboardingWizardLogicActions {
setStepIndex: (index: number) => {
index: number
}
+ setTemplatesShown: (shown: boolean) => {
+ shown: boolean
+ }
startPushSetup: () => {
value: true
}
@@ -131,6 +141,8 @@ export interface workflowsOnboardingWizardLogicMeta {
pushEnabled: (featureFlags: FeatureFlagsSet) => boolean
stepKeys: (wizardPath: WorkflowsOnboardingPath, pushEnabled: boolean) => readonly WizardStepKey[]
currentStep: (stepKeys: readonly WizardStepKey[], stepIndex: number) => WizardStepKey
+ offersSuggestions: (wizardPath: WorkflowsOnboardingPath, featureFlags: FeatureFlagsSet) => boolean
+ suggestionsFirst: (offersSuggestions: boolean, currentStep: WizardStepKey, templatesShown: boolean) => boolean
isLastStep: (stepKeys: readonly WizardStepKey[], stepIndex: number) => boolean
templates: (workflowTemplates: HogFlowTemplate[], wizardPath: WorkflowsOnboardingPath) => HogFlowTemplate[]
selectedTemplate: (
@@ -208,6 +220,8 @@ export const workflowsOnboardingWizardLogic = kea<workflowsOnboardingWizardLogic
positionAtFirstOpenStep: (index: number) => ({ index }),
positionIfReady: true,
startPushSetup: true,
+ setTemplatesShown: (shown: boolean) => ({ shown }),
+ finishWithSuggestion: true,
}),
reducers({
wizardPath: [
@@ -249,6 +263,15 @@ export const workflowsOnboardingWizardLogic = kea<workflowsOnboardingWizardLogic
initWizard: () => true,
},
],
+ // A person who comes back with a template picked, or picks one, stays on the template list.
+ templatesShown: [
+ false,
+ {
+ initWizard: (_, { templateId }) => templateId !== null,
+ selectTemplate: () => true,
+ setTemplatesShown: (_, { shown }) => shown,
+ },
+ ],
pushSetupStarted: [
false,
{
@@ -279,6 +302,18 @@ export const workflowsOnboardingWizardLogic = kea<workflowsOnboardingWizardLogic
(stepKeys: readonly WizardStepKey[], stepIndex: number): WizardStepKey =>
stepKeys[Math.min(stepIndex, stepKeys.length - 1)],
],
+ // The suggestions logic starts an AI run when it mounts, so nothing mounts it without the flag. Suggestions are
+ // messages to users, so the automation path never offers them.
+ offersSuggestions: [
+ (s) => [s.wizardPath, s.featureFlags],
+ (wizardPath: WorkflowsOnboardingPath, featureFlags: FeatureFlagsSet): boolean =>
+ wizardPath === 'messaging' && !!featureFlags[FEATURE_FLAGS.WORKFLOWS_DATA_SUGGESTIONS],
+ ],
+ suggestionsFirst: [
+ (s) => [s.offersSuggestions, s.currentStep, s.templatesShown],
+ (offersSuggestions: boolean, currentStep: WizardStepKey, templatesShown: boolean): boolean =>
+ offersSuggestions && currentStep === 'journey' && !templatesShown,
+ ],
isLastStep: [
(s) => [s.stepKeys, s.stepIndex],
(stepKeys: readonly WizardStepKey[], stepIndex: number): boolean => stepIndex >= stepKeys.length - 1,
@@ -433,6 +468,20 @@ export const workflowsOnboardingWizardLogic = kea<workflowsOnboardingWizardLogic
})
actions.createWorkflowFromTemplate(template)
},
+ // A suggestion card creates and opens the workflow itself, so it skips `next` and `finish`.
+ finishWithSuggestion: () => {
+ // pinned: analytics event name - renaming breaks dashboards
+ posthog.capture('workflows onboarding wizard step completed', {
+ path: values.wizardPath,
+ step: values.currentStep,
+ skipped: false,
+ })
+ // pinned: analytics event name - renaming breaks dashboards
+ posthog.capture('workflows onboarding wizard finished', {
+ path: values.wizardPath,
+ template_id: DATA_SUGGESTION_START_ID,
+ })
+ },
exit: () => {
// pinned: analytics event name - renaming breaks dashboards
posthog.capture('workflows onboarding wizard exited', {