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(conversations): add draft mode for ticket replies (#71093)

Xander6d2bcd69a08a
diff --git a/products/conversations/frontend/components/Chat/ChatView.tsx b/products/conversations/frontend/components/Chat/ChatView.tsx
index f6bb21cf6089..0d833e312942 100644
--- a/products/conversations/frontend/components/Chat/ChatView.tsx
+++ b/products/conversations/frontend/components/Chat/ChatView.tsx
@@ -36,6 +36,12 @@ export interface ChatViewProps {
extraActions?: React.ReactNode
/** Blocks sending customer-facing messages (private notes stay available) */
replyDisabledReason?: string | JSX.Element
+ /** Whether draft mode is on: tints the composer green and confirms the recipient before sending */
+ draftMode?: boolean
+ /** Called when the draft-mode toggle changes */
+ onDraftModeChange?: (enabled: boolean) => void
+ /** Recipient description shown in the draft-mode send confirmation */
+ sendConfirmationMessage?: string
latestAiMessageId?: string | null
feedbackByMessageId?: Record<string, AiReplyFeedbackRating>
showAiReplyFeedback?: boolean
@@ -62,6 +68,9 @@ export function ChatView({
onPrivateChange,
extraActions,
replyDisabledReason,
+ draftMode,
+ onDraftModeChange,
+ sendConfirmationMessage,
latestAiMessageId,
feedbackByMessageId,
showAiReplyFeedback,
@@ -100,6 +109,9 @@ export function ChatView({
onPrivateChange={onPrivateChange}
extraActions={extraActions}
replyDisabledReason={replyDisabledReason}
+ draftMode={draftMode}
+ onDraftModeChange={onDraftModeChange}
+ sendConfirmationMessage={sendConfirmationMessage}
/>
</div>
</LemonCard>
diff --git a/products/conversations/frontend/components/Chat/MessageInput.tsx b/products/conversations/frontend/components/Chat/MessageInput.tsx
index efd7bdea25ec..119fc8356796 100644
--- a/products/conversations/frontend/components/Chat/MessageInput.tsx
+++ b/products/conversations/frontend/components/Chat/MessageInput.tsx
@@ -2,9 +2,10 @@ import { JSONContent } from '@tiptap/core'
import { useEffect, useRef, useState } from 'react'
import { IconLock } from '@posthog/icons'
-import { LemonButton, LemonCheckbox, Tooltip } from '@posthog/lemon-ui'
+import { LemonButton, LemonCheckbox, LemonSwitch, Tooltip } from '@posthog/lemon-ui'
import { RichContentEditorType } from 'lib/components/RichContentEditor/types'
+import { LemonDialog } from 'lib/lemon-ui/LemonDialog'
import { SupportEditor, serializeToMarkdown } from '../Editor'
@@ -28,6 +29,12 @@ export interface MessageInputProps {
extraActions?: React.ReactNode
/** Blocks sending customer-facing messages (private notes stay available). Shown as the button's disabled tooltip. */
replyDisabledReason?: string | JSX.Element
+ /** Whether draft mode is on: tints the composer green and confirms the recipient before sending */
+ draftMode?: boolean
+ /** Called when the draft-mode toggle changes; when provided, the toggle renders left of the send button */
+ onDraftModeChange?: (enabled: boolean) => void
+ /** Recipient description shown in the draft-mode send confirmation (e.g. "This will send to ...") */
+ sendConfirmationMessage?: string
}
export function MessageInput({
@@ -43,6 +50,9 @@ export function MessageInput({
onPrivateChange,
extraActions,
replyDisabledReason,
+ draftMode = false,
+ onDraftModeChange,
+ sendConfirmationMessage,
}: MessageInputProps): JSX.Element {
const [isEmpty, setIsEmpty] = useState(!draftContent)
const [isUploading, setIsUploading] = useState(false)
@@ -58,23 +68,39 @@ export function MessageInput({
const setIsPrivate = onPrivateChange ?? setLocalIsPrivate
const handleSubmit = (): void => {
- // Guards the Cmd+Enter path too, not just the (disabled) button
+ // These guard the Cmd+Enter path, which bypasses the (disabled) button.
if (replyDisabledReason && !isPrivate) {
return
}
+ if (messageSending || isUploading) {
+ return
+ }
if (editorRef.current && !isEmpty) {
const richContent = editorRef.current.getJSON()
const content = serializeToMarkdown(richContent)
- onSendMessage(content, richContent, isPrivate, () => {
- editorRef.current?.clear()
- setIsEmpty(true)
- onDraftChange?.(null)
- if (onPrivateChange) {
- onPrivateChange(false)
- } else {
- setLocalIsPrivate(false)
- }
- })
+ const doSend = (): void => {
+ onSendMessage(content, richContent, isPrivate, () => {
+ editorRef.current?.clear()
+ setIsEmpty(true)
+ onDraftChange?.(null)
+ if (onPrivateChange) {
+ onPrivateChange(false)
+ } else {
+ setLocalIsPrivate(false)
+ }
+ })
+ }
+ // Private notes are never sent externally, so they skip the draft-mode confirmation.
+ if (draftMode && !isPrivate && sendConfirmationMessage) {
+ LemonDialog.open({
+ title: 'Ready to send?',
+ description: sendConfirmationMessage,
+ primaryButton: { children: 'Send', type: 'primary', onClick: doSend },
+ secondaryButton: { children: 'Cancel' },
+ })
+ } else {
+ doSend()
+ }
}
}
@@ -101,7 +127,13 @@ export function MessageInput({
onUploadingChange={setIsUploading}
disabled={messageSending}
minRows={minRows}
- className={isPrivate ? 'bg-warning-highlight border-warning' : undefined}
+ className={
+ isPrivate
+ ? 'bg-warning-highlight border-warning'
+ : draftMode
+ ? 'bg-success-highlight border-success'
+ : undefined
+ }
/>
<div className="flex justify-between items-center mt-2">
{showPrivateOption ? (
@@ -123,6 +155,13 @@ export function MessageInput({
<div />
)}
<div className="flex items-center gap-2">
+ {onDraftModeChange && (
+ <Tooltip title="In draft mode, sending asks you to confirm the recipient first.">
+ <span>
+ <LemonSwitch checked={draftMode} onChange={onDraftModeChange} label="Draft mode" />
+ </span>
+ </Tooltip>
+ )}
{extraActions}
<LemonButton
type="primary"
diff --git a/products/conversations/frontend/scenes/settings/DraftModeSection.tsx b/products/conversations/frontend/scenes/settings/DraftModeSection.tsx
new file mode 100644
index 000000000000..d60bb3f47272
--- /dev/null
+++ b/products/conversations/frontend/scenes/settings/DraftModeSection.tsx
@@ -0,0 +1,33 @@
+import { useActions, useValues } from 'kea'
+
+import { LemonCard, LemonSwitch } from '@posthog/lemon-ui'
+
+import { SceneSection } from '~/layout/scenes/components/SceneSection'
+
+import { conversationsDraftModeLogic } from './conversationsDraftModeLogic'
+
+export function DraftModeSection(): JSX.Element {
+ const { draftModeDefault } = useValues(conversationsDraftModeLogic)
+ const { setDraftModeDefault } = useActions(conversationsDraftModeLogic)
+
+ return (
+ <SceneSection
+ title="Draft mode"
+ titleSize="sm"
+ className="my-8"
+ description="Adds a confirmation step before a reply is sent. This is a default applied to each ticket you open. You can still turn it off for a single ticket."
+ >
+ <LemonCard hoverEffect={false} className="flex flex-col gap-y-3 max-w-[800px] px-4 py-3">
+ <div className="flex items-center gap-4 justify-between">
+ <div>
+ <label className="font-medium">Turn on draft mode by default</label>
+ <p className="text-xs text-muted-alt mb-0">
+ When on, sending a reply asks you to confirm the recipient first.
+ </p>
+ </div>
+ <LemonSwitch checked={draftModeDefault} onChange={setDraftModeDefault} />
+ </div>
+ </LemonCard>
+ </SceneSection>
+ )
+}
diff --git a/products/conversations/frontend/scenes/settings/GeneralSection.tsx b/products/conversations/frontend/scenes/settings/GeneralSection.tsx
index 56e5468b9aa5..794d5c8b5a16 100644
--- a/products/conversations/frontend/scenes/settings/GeneralSection.tsx
+++ b/products/conversations/frontend/scenes/settings/GeneralSection.tsx
@@ -11,6 +11,7 @@ import { SceneSection } from '~/layout/scenes/components/SceneSection'
import { AuthorizedDomains } from './AuthorizedDomains'
import { ChannelsSection } from './ChannelsSection'
+import { DraftModeSection } from './DraftModeSection'
import { SecretApiKeySection } from './SecretApiKeySection'
import { supportSettingsLogic } from './supportSettingsLogic'
@@ -170,6 +171,7 @@ export function GeneralSection(): JSX.Element {
</LemonCard>
</SceneSection>
<SecretApiKeySection />
+ <DraftModeSection />
</>
)}
</>
diff --git a/products/conversations/frontend/scenes/settings/conversationsDraftModeLogic.ts b/products/conversations/frontend/scenes/settings/conversationsDraftModeLogic.ts
new file mode 100644
index 000000000000..d87a1c1473ce
--- /dev/null
+++ b/products/conversations/frontend/scenes/settings/conversationsDraftModeLogic.ts
@@ -0,0 +1,36 @@
+import { MakeLogicType, actions, kea, path, reducers } from 'kea'
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface conversationsDraftModeLogicValues {
+ draftModeDefault: boolean
+}
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface conversationsDraftModeLogicActions {
+ setDraftModeDefault: (enabled: boolean) => {
+ enabled: boolean
+ }
+}
+
+export type conversationsDraftModeLogicType = MakeLogicType<
+ conversationsDraftModeLogicValues,
+ conversationsDraftModeLogicActions
+>
+
+// Browser-local default for the ticket composer's draft mode. Each ticket seeds its own
+// toggle from this on open; flipping the per-ticket toggle does not write back here.
+export const conversationsDraftModeLogic = kea<conversationsDraftModeLogicType>([
+ path(['products', 'conversations', 'frontend', 'scenes', 'settings', 'conversationsDraftModeLogic']),
+ actions({
+ setDraftModeDefault: (enabled: boolean) => ({ enabled }),
+ }),
+ reducers({
+ draftModeDefault: [
+ false,
+ { persist: true, storageKey: 'conversations_draft_mode_default' },
+ {
+ setDraftModeDefault: (_, { enabled }) => enabled,
+ },
+ ],
+ }),
+])
diff --git a/products/conversations/frontend/scenes/ticket/SupportTicketScene.tsx b/products/conversations/frontend/scenes/ticket/SupportTicketScene.tsx
index 5be0c7166bd2..ff9422016dae 100644
--- a/products/conversations/frontend/scenes/ticket/SupportTicketScene.tsx
+++ b/products/conversations/frontend/scenes/ticket/SupportTicketScene.tsx
@@ -81,6 +81,8 @@ export function SupportTicketScene({ ticketId }: { ticketId: string }): JSX.Elem
hasUnsavedChanges,
draftContent,
draftIsPrivate,
+ draftModeEnabled,
+ replyRecipientDescription,
snoozedUntil,
knowledgeGaps,
knowledgeGapsLoading,
@@ -99,6 +101,7 @@ export function SupportTicketScene({ ticketId }: { ticketId: string }): JSX.Elem
loadOlderMessages,
setDraftContent,
setDraftIsPrivate,
+ setDraftModeEnabled,
dismissKnowledgeGap,
submitAiReplyFeedback,
} = useActions(logic)
@@ -209,6 +212,9 @@ export function SupportTicketScene({ ticketId }: { ticketId: string }): JSX.Elem
onDraftChange={setDraftContent}
isPrivate={draftIsPrivate}
onPrivateChange={setDraftIsPrivate}
+ draftMode={draftModeEnabled}
+ onDraftModeChange={setDraftModeEnabled}
+ sendConfirmationMessage={`This will send to ${replyRecipientDescription}`}
replyDisabledReason={replyDisabledReason}
minHeight="min(400px, calc(100svh - 20rem))"
maxHeight="calc(100svh - 20rem)"
diff --git a/products/conversations/frontend/scenes/ticket/supportTicketSceneLogic.test.ts b/products/conversations/frontend/scenes/ticket/supportTicketSceneLogic.test.ts
index 54d1f6aaacc1..da2545f77141 100644
--- a/products/conversations/frontend/scenes/ticket/supportTicketSceneLogic.test.ts
+++ b/products/conversations/frontend/scenes/ticket/supportTicketSceneLogic.test.ts
@@ -212,3 +212,40 @@ describe('getEmailReplyBlockedReason', () => {
expect(getEmailReplyBlockedReason(ticket, settings)).toBe(expected)
})
})
+
+describe('supportTicketSceneLogic replyRecipientDescription', () => {
+ let logic: ReturnType<typeof supportTicketSceneLogic.build>
+
+ beforeEach(() => {
+ initKeaTests()
+ logic = supportTicketSceneLogic({ id: 'new' })
+ logic.mount()
+ })
+
+ // This string is shown in the draft-mode "This will send to ..." confirmation. Regressions
+ // that swap email_from (customer) for email_to (our sending identity), drop cc recipients, or
+ // mislabel a channel would tell the agent they're sending somewhere they aren't.
+ test.each<[string, Partial<Ticket>, string]>([
+ [
+ 'email uses the customer address, not our sending identity',
+ { channel_source: 'email', email_from: '[email protected]', email_to: '[email protected]' },
+ ],
+ [
+ 'email includes cc participants',
+ {
+ channel_source: 'email',
+ email_from: '[email protected]',
+ cc_participants: ['[email protected]', '[email protected]'],
+ },
+ ],
+ ['slack', { channel_source: 'slack' }, 'the linked Slack thread'],
+ ['teams', { channel_source: 'teams' }, 'the linked Microsoft Teams channel'],
+ ['github', { channel_source: 'github' }, 'the linked GitHub issue'],
+ ['widget', { channel_source: 'widget' }, 'the customer'],
+ ])('%s', (_name, overrides, expected) => {
+ logic.actions.setTicket({ ...makeTicket(), ...overrides })
+ expect(logic.values.replyRecipientDescription).toBe(expected)
+ })
+})
diff --git a/products/conversations/frontend/scenes/ticket/supportTicketSceneLogic.ts b/products/conversations/frontend/scenes/ticket/supportTicketSceneLogic.ts
index 0e0a037a473c..58279c9a9b26 100644
--- a/products/conversations/frontend/scenes/ticket/supportTicketSceneLogic.ts
+++ b/products/conversations/frontend/scenes/ticket/supportTicketSceneLogic.ts
@@ -49,6 +49,7 @@ import type {
TicketPriority,
TicketStatus,
} from '../../types'
+import { conversationsDraftModeLogic } from '../settings/conversationsDraftModeLogic'
import { supportTicketsSceneLogic } from '../tickets/supportTicketsSceneLogic'
const MESSAGE_POLL_INTERVAL = 5000 // 5 seconds
@@ -163,6 +164,7 @@ export function getEmailReplyBlockedReason(
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface supportTicketSceneLogicValues {
+ draftModeDefault: boolean // conversationsDraftModeLogic
currentTeam: TeamPublicType | TeamType | null // teamLogic
assignee: TicketAssignee
breadcrumbs: Breadcrumb[]
@@ -170,6 +172,7 @@ export interface supportTicketSceneLogicValues {
chatPanelWidth: (desiredSize: number | null) => number
draftContent: JSONContent | null
draftIsPrivate: boolean
+ draftModeEnabled: boolean
emailReplyBlockedReason: EmailReplyBlockedReason | null
eventsQuery: DataTableNode | null
exceptionsQuery: DataTableNode | null
@@ -189,6 +192,7 @@ export interface supportTicketSceneLogicValues {
previousTickets: Ticket[]
previousTicketsLoading: boolean
priority: TicketPriority | null
+ replyRecipientDescription: string
snoozedUntil: string | null
status: TicketStatus | null
tags: string[]
@@ -306,6 +310,9 @@ export interface supportTicketSceneLogicActions {
setDraftIsPrivate: (isPrivate: boolean) => {
isPrivate: boolean
}
+ setDraftModeEnabled: (enabled: boolean) => {
+ enabled: boolean
+ }
setHasMoreMessages: (hasMore: boolean) => {
hasMore: boolean
}
@@ -370,6 +377,7 @@ export interface supportTicketSceneLogicMeta {
ticket: Ticket | null,
currentTeam: TeamPublicType | TeamType | null
) => EmailReplyBlockedReason | null
+ replyRecipientDescription: (ticket: Ticket | null) => string
hasUnsavedChanges: (
status: TicketStatus | null,
priority: TicketPriority | null,
@@ -399,7 +407,7 @@ export const supportTicketSceneLogic = kea<supportTicketSceneLogicType>([
key((props) => props.id),
connect(() => ({
actions: [supportTicketsSceneLogic, ['loadTickets']],
- values: [teamLogic, ['currentTeam']],
+ values: [teamLogic, ['currentTeam'], conversationsDraftModeLogic, ['draftModeDefault']],
})),
actions({
loadTicket: true,
@@ -447,6 +455,8 @@ export const supportTicketSceneLogic = kea<supportTicketSceneLogicType>([
// Draft message state (persists across tab switches)
setDraftContent: (content: JSONContent | null) => ({ content }),
setDraftIsPrivate: (isPrivate: boolean) => ({ isPrivate }),
+ // Per-ticket draft mode override, seeded from the browser-local default on open
+ setDraftModeEnabled: (enabled: boolean) => ({ enabled }),
submitAiReplyFeedback: (messageId: string, rating: AiReplyFeedbackRating, feedbackText?: string) => ({
messageId,
@@ -639,6 +649,12 @@ export const supportTicketSceneLogic = kea<supportTicketSceneLogicType>([
setDraftIsPrivate: (_, { isPrivate }) => isPrivate,
},
],
+ draftModeEnabled: [
+ false,
+ {
+ setDraftModeEnabled: (_, { enabled }) => enabled,
+ },
+ ],
feedbackByMessageId: [
{} as Record<string, AiReplyFeedbackRating>,
{ persist: true, storageKey: 'conversations_ai_reply_feedback' },
@@ -674,6 +690,26 @@ export const supportTicketSceneLogic = kea<supportTicketSceneLogicType>([
): EmailReplyBlockedReason | null =>
getEmailReplyBlockedReason(ticket, currentTeam?.conversations_settings),
],
+ replyRecipientDescription: [
+ (s) => [s.ticket],
+ (ticket: Ticket | null): string => {
+ switch (ticket?.channel_source) {
+ case 'email': {
+ // email_from is the customer's address; email_to is our sending identity.
+ const recipients = [ticket.email_from, ...(ticket.cc_participants ?? [])].filter(Boolean)
+ return recipients.length ? recipients.join(', ') : 'the customer'
+ }
+ case 'slack':
+ return 'the linked Slack thread'
+ case 'teams':
+ return 'the linked Microsoft Teams channel'
+ case 'github':
+ return 'the linked GitHub issue'
+ default:
+ return 'the customer'
+ }
+ },
+ ],
hasUnsavedChanges: [
(s) => [s.status, s.priority, s.assignee, s.tags, s.snoozedUntil, s.ticket],
(
@@ -993,7 +1029,8 @@ export const supportTicketSceneLogic = kea<supportTicketSceneLogicType>([
}
},
})),
- afterMount(({ actions, props }) => {
+ afterMount(({ actions, props, values }) => {
+ actions.setDraftModeEnabled(values.draftModeDefault)
if (props.id !== 'new') {
actions.loadTicket()
}