: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(posthog-ai): include the plan's support response time in /ticket confirmation (#74173)
Christiaan Hendriksen9abbe5b5f869
diff --git a/frontend/src/lib/components/Support/supportLogic.ts b/frontend/src/lib/components/Support/supportLogic.tsindex bd7ed2bb7e03..c7cadc64f7eb 100644--- a/frontend/src/lib/components/Support/supportLogic.ts+++ b/frontend/src/lib/components/Support/supportLogic.ts@@ -20,6 +20,7 @@ import { sidePanelStateLogic } from '~/layout/navigation-3000/sidepanel/sidePaneimport {AvailableFeature,BillingPlan,+ BillingPlanType,OrganizationBasicType,Region,SidePanelTab,@@ -32,6 +33,7 @@ import type { BillingType, PreflightStatus } from '../../../types'import type { FeatureFlagsSet } from '../../logic/featureFlagLogic'import { parseExceptionEvent } from './exceptionUtils'import { openSupportModal } from './SupportModal'+import { getSupportResponseTime } from './supportResponseTime'export function getPublicSupportSnippet(cloudRegion: Region | null | undefined,@@ -495,6 +497,8 @@ export type SupportFormFields = {// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface supportLogicValues {billing: BillingType | null // billingLogic+ billingPlan: BillingPlan | null // billingLogic+ supportPlans: BillingPlanType[] // billingLogicfeatureFlags: FeatureFlagsSet // featureFlagLogicisCurrentOrganizationNew: boolean // organizationLogicpreflight: PreflightStatus | null // preflightLogic@@ -522,6 +526,7 @@ export interface supportLogicValues {sendSupportRequestTouches: Record<string, boolean>sendSupportRequestValidationErrors: DeepPartialMap<SupportFormFields, ValidationErrorType>showSendSupportRequestErrors: boolean+ supportResponseTime: string | nulltargetArea: SupportTicketTargetArea | nulltitle: string}@@ -617,6 +622,12 @@ export interface supportLogicMeta {title: (arg: SupportFormFields) => stringtargetArea: (sendSupportRequest: SupportFormFields) => SupportTicketTargetArea | nullconversationsFlagEnabled: (featureFlags: FeatureFlagsSet) => boolean+ supportResponseTime: (+ billing: BillingType | null,+ billingPlan: BillingPlan | null,+ supportPlans: BillingPlanType[],+ user: UserType | null+ ) => string | null}}@@ -639,7 +650,7 @@ export const supportLogic = kea<supportLogicType>([userLogic,['hasAvailableFeature'],billingLogic,- ['billing'],+ ['billing', 'billingPlan', 'supportPlans'],organizationLogic,['isCurrentOrganizationNew'],sidePanelStateLogic,@@ -741,6 +752,21 @@ export const supportLogic = kea<supportLogicType>([(featureFlags: import('lib/logic/featureFlagLogic').FeatureFlagsSet): boolean =>!!featureFlags[FEATURE_FLAGS.PRODUCT_SUPPORT_SIDE_PANEL],],+ supportResponseTime: [+ (s) => [s.billing, s.billingPlan, s.supportPlans, s.user],+ (+ billing: BillingType | null,+ billingPlan: BillingPlan | null,+ supportPlans: BillingPlanType[],+ user: UserType | null+ ): string | null =>+ getSupportResponseTime({+ billing,+ billingPlan,+ supportPlans,+ organizationId: user?.organization?.id,+ }),+ ],}),listeners(({ actions, props, values }) => ({updateUrlParams: async () => {diff --git a/frontend/src/scenes/max/TicketPrompt.tsx b/frontend/src/scenes/max/TicketPrompt.tsxindex bc70a832ef64..6d9fd787a0b9 100644--- a/frontend/src/scenes/max/TicketPrompt.tsx+++ b/frontend/src/scenes/max/TicketPrompt.tsx@@ -8,11 +8,7 @@ import { SupportTicketTargetArea, supportLogic } from 'lib/components/Support/suimport { userLogic } from 'scenes/userLogic'import { maxThreadLogic } from './maxThreadLogic'-import { appendTicketMetadata, composeTicketBody } from './ticketUtils'--function formatConfirmationMessage(ticketId: string): string {- return `I've created a support ticket for you.\nYour ticket ID is #${ticketId}.\nOur support team will get back to you soon!`-}+import { appendTicketMetadata, composeTicketBody, formatTicketConfirmationMessage } from './ticketUtils'interface TicketPromptProps {conversationId: string@@ -43,7 +39,7 @@ export function TicketPrompt({const [hasSubmitted, setHasSubmitted] = useState(false)const [isSupportModalOpen, setIsSupportModalOpen] = useState(false)- const { sendSupportRequest, conversationsFlagEnabled } = useValues(supportLogic)+ const { sendSupportRequest, conversationsFlagEnabled, supportResponseTime } = useValues(supportLogic)const { resetSendSupportRequest, closeSupportForm } = useActions(supportLogic)const { appendMessageToConversation } = useActions(maxThreadLogic)const { user } = useValues(userLogic)@@ -52,7 +48,7 @@ export function TicketPrompt({function handleTicketCreated(ticketId: string): void {// Persist the confirmation message and add it to the thread- const confirmationMessage = formatConfirmationMessage(ticketId)+ const confirmationMessage = formatTicketConfirmationMessage(ticketId, supportResponseTime)appendMessageToConversation(confirmationMessage)submitInFlightRef.current = falsediff --git a/frontend/src/scenes/max/ticketUtils.test.ts b/frontend/src/scenes/max/ticketUtils.test.tsindex c49248ae9572..eb416961a439 100644--- a/frontend/src/scenes/max/ticketUtils.test.ts+++ b/frontend/src/scenes/max/ticketUtils.test.ts@@ -1,5 +1,12 @@import { ThreadMessage } from './maxLogic'-import { appendTicketMetadata, composeTicketBody, getTicketSummaryData, parseTicketTargetArea } from './ticketUtils'+import {+ appendTicketMetadata,+ composeTicketBody,+ formatTicketConfirmationMessage,+ getTicketSummaryData,+ isTicketConfirmationMessage,+ parseTicketTargetArea,+} from './ticketUtils'const human = (content: string): ThreadMessage => ({ type: 'human', content }) as unknown as ThreadMessageconst ai = (content: string): ThreadMessage => ({ type: 'ai', content }) as unknown as ThreadMessage@@ -49,6 +56,29 @@ describe('ticketUtils', () => {})})+ describe('formatTicketConfirmationMessage', () => {+ it('promises the response time the plan covers', () => {+ expect(formatTicketConfirmationMessage('4321', '48 hours')).toBe(+ "I've created a support ticket for you.\nYour ticket ID is #4321.\nOur support team aims to get back to you within 48 hours."+ )+ })++ it('promises no response time when the plan has none', () => {+ const message = formatTicketConfirmationMessage('4321', null)+ expect(message).toBe(+ "I've created a support ticket for you.\nYour ticket ID is #4321.\nOur support team will get back to you soon!"+ )+ expect(message).not.toContain('within')+ })++ it.each([+ ['with a response time', '48 hours'],+ ['without a response time', null],+ ])('stays detectable as a confirmation %s', (_name, responseTime) => {+ expect(isTicketConfirmationMessage(ai(formatTicketConfirmationMessage('4321', responseTime)))).toBe(true)+ })+ })+describe('composeTicketBody', () => {it.each([[diff --git a/frontend/src/scenes/max/ticketUtils.ts b/frontend/src/scenes/max/ticketUtils.tsindex f329fa53f2c6..34dee4583ec7 100644--- a/frontend/src/scenes/max/ticketUtils.ts+++ b/frontend/src/scenes/max/ticketUtils.ts@@ -14,6 +14,19 @@ export interface TicketPromptData {initialText?: string}+const TICKET_CONFIRMATION_LEAD = "I've created a support ticket for you"++/**+ * Builds the confirmation message shown once a ticket is created. The target response time is left+ * out when the plan has none, so a customer is never promised a reply their plan doesn't cover.+ */+export function formatTicketConfirmationMessage(ticketId: string, responseTime: string | null): string {+ const closingLine = responseTime+ ? `Our support team aims to get back to you within ${responseTime}.`+ : 'Our support team will get back to you soon!'+ return `${TICKET_CONFIRMATION_LEAD}.\nYour ticket ID is #${ticketId}.\n${closingLine}`+}+/*** Parses the "Topic: <area>" line the /ticket summarizer appends, returning the* target area only if it matches a known support target area.@@ -75,8 +88,7 @@ export function getTicketPromptData(threadGrouped: ThreadMessage[], streamingAct// If a ticket confirmation already exists, don't show the formif (isInitialTicketPrompt) {const hasConfirmationMessage = threadGrouped.some(- (msg) =>- msg?.type === 'ai' && 'content' in msg && msg.content?.includes("I've created a support ticket for you")+ (msg) => msg?.type === 'ai' && 'content' in msg && msg.content?.includes(TICKET_CONFIRMATION_LEAD))if (!hasConfirmationMessage) {const initialText =@@ -129,10 +141,7 @@ export function getTicketSummaryData(const messagesAfterSummary = threadGrouped.slice(ticketCommandIndex + 2)const userContinuedConversation = messagesAfterSummary.some((msg) => msg?.type === 'human')const hasConfirmationMessage = messagesAfterSummary.some(- (msg) =>- msg?.type === 'ai' &&- 'content' in msg &&- msg.content?.includes("I've created a support ticket for you")+ (msg) => msg?.type === 'ai' && 'content' in msg && msg.content?.includes(TICKET_CONFIRMATION_LEAD))if (hasConfirmationMessage) {@@ -204,6 +213,6 @@ export function isTicketConfirmationMessage(message: ThreadMessage): boolean {message.type !== 'human' &&'content' in message &&typeof message.content === 'string' &&- message.content.includes("I've created a support ticket for you")+ message.content.includes(TICKET_CONFIRMATION_LEAD))}diff --git a/products/conversations/frontend/components/SidePanel/sidepanelTicketsLogic.ts b/products/conversations/frontend/components/SidePanel/sidepanelTicketsLogic.tsindex 086e096bcae3..82d2532992e9 100644--- a/products/conversations/frontend/components/SidePanel/sidepanelTicketsLogic.ts+++ b/products/conversations/frontend/components/SidePanel/sidepanelTicketsLogic.ts@@ -16,7 +16,6 @@ import { subscriptions } from 'kea-subscriptions'import posthog from 'posthog-js'import { appendExceptionToMessage, supportLogic, warnIfMessageTooLong } from 'lib/components/Support/supportLogic'-import { getSupportResponseTime } from 'lib/components/Support/supportResponseTime'import { FEATURE_FLAGS } from 'lib/constants'import { EMAIL_SUPPORT_BUTTON, lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'@@ -24,7 +23,7 @@ import { billingLogic } from 'scenes/billing/billingLogic'import { organizationLogic } from 'scenes/organizationLogic'import { sidePanelStateLogic } from '~/layout/navigation-3000/sidepanel/sidePanelStateLogic'-import type { BillingPlan, BillingPlanType, BillingType, OrganizationType } from '~/types'+import type { BillingType } from '~/types'import type {SupportFormFields,@@ -62,10 +61,7 @@ function messageToRichContent(message: string): JSONContent {export interface sidepanelTicketsLogicValues {billing: BillingType | null // billingLogicbillingLoading: boolean // billingLogic- billingPlan: BillingPlan | null // billingLogic- supportPlans: BillingPlanType[] // billingLogicfeatureFlags: FeatureFlagsSet // featureFlagLogic- currentOrganization: OrganizationType | null // organizationLogicisCurrentOrganizationNew: boolean // organizationLogicsidePanelOpen: boolean // sidePanelStateLogicisEmailFormOpen: boolean // supportLogic@@ -75,6 +71,7 @@ export interface sidepanelTicketsLogicValues {status: string} | null // supportLogicsendSupportRequest: SupportFormFields // supportLogic+ supportResponseTime: string | null // supportLogictargetArea: SupportTicketTargetArea | null // supportLogiccanCreateTicket: booleancurrentTicket: ConversationTicket | null@@ -89,7 +86,6 @@ export interface sidepanelTicketsLogicValues {newTicketDraftRevision: numberrestoreError: string | nullrestoreState: RestoreFlowState- supportResponseTime: string | nulltickets: ConversationTicket[]ticketsLoading: booleantotalUnreadCount: number@@ -199,12 +195,6 @@ export interface sidepanelTicketsLogicMeta {hasBillingExemption: boolean) => booleanisBillingResolved: (billing: BillingType | null, billingLoading: boolean) => boolean- supportResponseTime: (- billing: BillingType | null,- supportPlans: BillingPlanType[],- billingPlan: BillingPlan | null,- currentOrganization: OrganizationType | null- ) => string | null}}@@ -224,11 +214,11 @@ export const sidepanelTicketsLogic = kea<sidepanelTicketsLogicType>([featureFlagLogic,['featureFlags'],supportLogic,- ['isEmailFormOpen', 'sendSupportRequest', 'pendingViewTicket', 'targetArea'],+ ['isEmailFormOpen', 'sendSupportRequest', 'pendingViewTicket', 'targetArea', 'supportResponseTime'],billingLogic,- ['billing', 'billingLoading', 'billingPlan', 'supportPlans'],+ ['billing', 'billingLoading'],organizationLogic,- ['currentOrganization', 'isCurrentOrganizationNew'],+ ['isCurrentOrganizationNew'],],actions: [supportLogic,@@ -386,21 +376,6 @@ export const sidepanelTicketsLogic = kea<sidepanelTicketsLogicType>([(s) => [s.billing, s.billingLoading],(billing: BillingType | null, billingLoading: boolean): boolean => !billingLoading && billing !== null,],- supportResponseTime: [- (s) => [s.billing, s.supportPlans, s.billingPlan, s.currentOrganization],- (- billing: BillingType | null,- supportPlans: BillingPlanType[],- billingPlan: BillingPlan | null,- currentOrganization: OrganizationType | null- ): string | null =>- getSupportResponseTime({- billing,- billingPlan,- supportPlans,- organizationId: currentOrganization?.id,- }),- ],}),listeners(({ actions, values, cache }) => ({initTickets: () => {