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(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.ts
index 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/sidePane
import {
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[] // billingLogic
featureFlags: FeatureFlagsSet // featureFlagLogic
isCurrentOrganizationNew: boolean // organizationLogic
preflight: PreflightStatus | null // preflightLogic
@@ -522,6 +526,7 @@ export interface supportLogicValues {
sendSupportRequestTouches: Record<string, boolean>
sendSupportRequestValidationErrors: DeepPartialMap<SupportFormFields, ValidationErrorType>
showSendSupportRequestErrors: boolean
+ supportResponseTime: string | null
targetArea: SupportTicketTargetArea | null
title: string
}
@@ -617,6 +622,12 @@ export interface supportLogicMeta {
title: (arg: SupportFormFields) => string
targetArea: (sendSupportRequest: SupportFormFields) => SupportTicketTargetArea | null
conversationsFlagEnabled: (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.tsx
index 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/su
import { 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 = false
diff --git a/frontend/src/scenes/max/ticketUtils.test.ts b/frontend/src/scenes/max/ticketUtils.test.ts
index 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 ThreadMessage
const 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.ts
index 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 form
if (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.ts
index 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 // billingLogic
billingLoading: boolean // billingLogic
- billingPlan: BillingPlan | null // billingLogic
- supportPlans: BillingPlanType[] // billingLogic
featureFlags: FeatureFlagsSet // featureFlagLogic
- currentOrganization: OrganizationType | null // organizationLogic
isCurrentOrganizationNew: boolean // organizationLogic
sidePanelOpen: boolean // sidePanelStateLogic
isEmailFormOpen: boolean // supportLogic
@@ -75,6 +71,7 @@ export interface sidepanelTicketsLogicValues {
status: string
} | null // supportLogic
sendSupportRequest: SupportFormFields // supportLogic
+ supportResponseTime: string | null // supportLogic
targetArea: SupportTicketTargetArea | null // supportLogic
canCreateTicket: boolean
currentTicket: ConversationTicket | null
@@ -89,7 +86,6 @@ export interface sidepanelTicketsLogicValues {
newTicketDraftRevision: number
restoreError: string | null
restoreState: RestoreFlowState
- supportResponseTime: string | null
tickets: ConversationTicket[]
ticketsLoading: boolean
totalUnreadCount: number
@@ -199,12 +195,6 @@ export interface sidepanelTicketsLogicMeta {
hasBillingExemption: boolean
) => boolean
isBillingResolved: (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: () => {