: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(workflows): add support ticket templates with blank message steps (#124606)
Alex V38758eb141ec
diff --git a/products/conversations/backend/api/tests/test_events.py b/products/conversations/backend/api/tests/test_events.pyindex 186bc9bdbfd2..2c1aa5d4f3d2 100644--- a/products/conversations/backend/api/tests/test_events.py+++ b/products/conversations/backend/api/tests/test_events.py@@ -20,6 +20,7 @@ from products.conversations.backend.events import (_resolve_groups_from_analytics,capture_message_received,capture_message_sent,+ capture_private_message_sent,capture_ticket_assigned,capture_ticket_created,capture_ticket_priority_changed,@@ -165,8 +166,9 @@ class TestConversationEvents(BaseTest):assert properties["assignee_id"] == expected_idassert properties["assignee_role_name"] == expected_role_name+ @patch("products.conversations.backend.events.produce_internal_event")@patch("products.conversations.backend.events.capture_internal")- def test_capture_message_sent_uses_team_token(self, mock_capture):+ def test_capture_message_sent_uses_team_token(self, mock_capture, mock_produce_internal_event):capture_message_sent(self.ticket, "msg-123", "Hello customer", author=self.user)mock_capture.assert_called_once()@@ -185,6 +187,22 @@ class TestConversationEvents(BaseTest):assert call_kwargs["properties"]["customer_email"] == "[email protected]"assert call_kwargs["properties"]["customer_distinct_id"] == self.ticket.distinct_id+ mock_produce_internal_event.assert_called_once()+ team_id, internal_event = mock_produce_internal_event.call_args.args+ assert team_id == self.team.id+ assert internal_event.event == "$conversation_message_sent"+ assert internal_event.properties["message_id"] == "msg-123"+ assert internal_event.properties["customer_email"] == "[email protected]"+ assert "message_content" not in internal_event.properties++ @patch("products.conversations.backend.events.produce_internal_event")+ @patch("products.conversations.backend.events.capture_internal")+ def test_capture_private_message_sent_emits_no_internal_event(self, mock_capture, mock_produce_internal_event):+ capture_private_message_sent(self.ticket, "msg-123", author=self.user)++ assert mock_capture.call_args.kwargs["event_name"] == "$conversation_private_message_sent"+ mock_produce_internal_event.assert_not_called()+@parameterized.expand([(diff --git a/products/conversations/backend/events.py b/products/conversations/backend/events.pyindex 9479da90d61f..1b12a09d19ed 100644--- a/products/conversations/backend/events.py+++ b/products/conversations/backend/events.py@@ -6,6 +6,7 @@ Staff/system actions use the actor's distinct_id; customer actions use the tickeEvents are sent to the customer's PostHog project via their team's API token."""+import uuidfrom collections.abc import Mappingfrom datetime import datetimefrom typing import Literal@@ -28,6 +29,7 @@ from posthog.personhog_client.caller_tag import personhog_caller_tagfrom posthog.settings import SITE_URLfrom products.access_control.backend.models.role import Role+from products.cdp.backend.internal_events import InternalEventEvent, produce_internal_eventfrom products.conversations.backend.cache import get_cached_resolved_groups, set_cached_resolved_groupsfrom products.conversations.backend.models import Ticket, TicketAssignmentfrom products.conversations.backend.models.constants import Channel, OrganizationIdSource@@ -36,6 +38,9 @@ logger = structlog.get_logger(__name__)EVENT_SOURCE = "conversations_events"+# Fixed namespace so a retried reply produces the same internal event uuid.+_TEAM_REPLY_INTERNAL_EVENT_NAMESPACE = uuid.UUID("3f6c2a8e-5b1d-4e7a-9c0f-2d8b7e4a1c6f")+# Events that can carry message text or a customer email. The ticket purge files# an event-removal request for this set, scoped to one ticket id.CONVERSATION_ANALYTICS_EVENTS = (@@ -615,23 +620,18 @@ def capture_ticket_assigned()-def _capture_team_message(- ticket: Ticket,- message_id: str,- message_content: str | None,- author: User | None,- event_name: str,-) -> None:+def _team_message_properties(ticket: Ticket, message_id: str, author: User | None) -> dict:properties = _get_ticket_base_properties(ticket)properties["message_id"] = message_id- if message_content is not None:- properties["message_content"] = (message_content or "")[:1000]properties["author_type"] = "team"properties.update(_get_actor_properties(author, "user"))properties.update(_get_customer_properties(ticket, include_distinct_id=True))properties.update(_get_assignment_properties(ticket))properties.update(_get_sla_properties(ticket, timezone.now()))+ return properties++def _capture_team_message(ticket: Ticket, properties: dict, author: User | None, event_name: str) -> None:capture_internal(token=ticket.team.api_token,event_name=event_name,@@ -642,6 +642,31 @@ def _capture_team_message()+def _produce_team_reply_internal_event(ticket: Ticket, properties: dict, author: User | None) -> None:+ """Emit the reply as an internal event, so a workflow can trust it.++ Anyone with the public project token can capture `$conversation_message_sent` with any+ properties, so a workflow that emails the customer must not trigger on that analytics event.+ Only the server writes to the internal events topic. The reply body stays out, so the payload+ holds nothing that the analytics event does not already show to project members.+ """+ try:+ produce_internal_event(+ ticket.team_id,+ InternalEventEvent(+ event="$conversation_message_sent",+ distinct_id=_get_actor_distinct_id(ticket, author, "user"),+ properties=properties,+ uuid=str(+ uuid.uuid5(_TEAM_REPLY_INTERNAL_EVENT_NAMESPACE, f"{ticket.team_id}:{properties['message_id']}")+ ),+ ),+ )+ except Exception:+ # The reply is already saved, and a workflow that misses one notification is better than a failed reply.+ logger.exception("conversations_team_reply_internal_event_failed", ticket_id=str(ticket.id))++def capture_message_sent(ticket: Ticket,message_id: str,@@ -649,7 +674,14 @@ def capture_message_sent(author: User | None = None,) -> None:"""Team member sent a public reply on a ticket."""- _capture_team_message(ticket, message_id, message_content, author, "$conversation_message_sent")+ properties = _team_message_properties(ticket, message_id, author)+ _capture_team_message(+ ticket,+ {**properties, "message_content": (message_content or "")[:1000]},+ author,+ "$conversation_message_sent",+ )+ _produce_team_reply_internal_event(ticket, properties, author)def capture_private_message_sent(@@ -666,7 +698,9 @@ def capture_private_message_sent(The note body is deliberately omitted. Analytics events are queryable by anyproject member, so including it would bypass ticket-level access controls."""- _capture_team_message(ticket, message_id, None, author, "$conversation_private_message_sent")+ _capture_team_message(+ ticket, _team_message_properties(ticket, message_id, author), author, "$conversation_private_message_sent"+ )def capture_message_received(diff --git a/products/conversations/frontend/scenes/settings/NotificationsSection.tsx b/products/conversations/frontend/scenes/settings/NotificationsSection.tsxindex e855a4f869cb..caf2d1bbc5ec 100644--- a/products/conversations/frontend/scenes/settings/NotificationsSection.tsx+++ b/products/conversations/frontend/scenes/settings/NotificationsSection.tsx@@ -1,4 +1,5 @@import { useActions, useValues } from 'kea'+import { combineUrl } from 'kea-router'import { LemonButton, LemonCard, LemonDivider, Link } from '@posthog/lemon-ui'@@ -11,6 +12,8 @@ import { BrowserNotificationsSection } from './BrowserNotificationsSection'import { supportSettingsLogic } from './supportSettingsLogic'interface WorkflowTemplate {+ // Matches the global template ID in products/workflows/backend/templates/+ id: stringtitle: stringdescription: stringtrigger: string@@ -18,41 +21,18 @@ interface WorkflowTemplate {const WORKFLOW_TEMPLATES: WorkflowTemplate[] = [{- title: 'New ticket → Slack channel',- description: 'Post a message to a chosen Slack channel whenever a customer opens a new ticket.',- trigger: '$conversation_ticket_created',- },- {- title: 'Team reply → email customer',+ id: '019ce1f1-5d12-0000-e318-4b3ebd4b2aea',+ title: 'New ticket → Slack or email',description:- 'When a team member replies on a ticket, email the customer so they receive the response in their inbox.',- trigger: '$conversation_message_sent',- },- {- title: 'Customer message → notify team',- description: 'When a customer sends a message on a ticket, notify the assigned teammate by email or Slack.',- trigger: '$conversation_message_received',- },- {- title: 'SLA: no response in 4h → escalate',- description: 'If a ticket sits without a team reply for 4 hours, reassign to a lead and email the team.',+ 'Post a message to a chosen Slack channel or email your support team whenever a customer opens a new ticket.',trigger: '$conversation_ticket_created',},{- title: 'First team reply → mark Pending',- description: 'When a team member sends the first reply, automatically move the ticket to Pending.',+ id: 'a638999a-bf53-4fde-af36-c85ad9827076',+ title: 'Team reply → email customer',+ description: 'When a team member replies on a ticket, email the customer to let them know a reply is waiting.',trigger: '$conversation_message_sent',},- {- title: 'Resolved → CSAT email',- description: 'When a ticket is resolved, wait an hour and email the customer a 1-question CSAT survey.',- trigger: '$conversation_ticket_status_changed',- },- {- title: 'VIP cohort → high priority + auto-assign',- description: 'Tickets from your VIP cohort get bumped to high priority and routed to the on-call lead.',- trigger: '$conversation_ticket_created',- },]export function NotificationsSection(): JSX.Element {@@ -94,12 +74,16 @@ export function NotificationsSection(): JSX.Element {><div className="grid grid-cols-1 md:grid-cols-2 gap-3 max-w-[800px]">{WORKFLOW_TEMPLATES.map((template) => (- <LemonCard key={template.title} hoverEffect={false} className="flex flex-col gap-2 px-4 py-3">+ <LemonCard key={template.id} hoverEffect={false} className="flex flex-col gap-2 px-4 py-3"><h4 className="font-semibold mb-0">{template.title}</h4><p className="text-xs text-muted-alt mb-1 flex-1">{template.description}</p><div className="flex items-center justify-between gap-2 mt-1"><code className="text-xs text-muted-alt truncate">{template.trigger}</code>- <LemonButton type="secondary" size="small" to={urls.workflowNew()}>+ <LemonButton+ type="secondary"+ size="small"+ to={combineUrl(urls.workflowNew(), { templateId: template.id }).url}+ >Create workflow</LemonButton></div>diff --git a/products/workflows/backend/models/hog_flow/hog_flow.py b/products/workflows/backend/models/hog_flow/hog_flow.pyindex 453b45903303..f2ad18f4afb5 100644--- a/products/workflows/backend/models/hog_flow/hog_flow.py+++ b/products/workflows/backend/models/hog_flow/hog_flow.py@@ -80,7 +80,14 @@ COHORT_TRIGGER_TRANSITIONS: Final[tuple[str, ...]] = ("entered", "left")# allowlist keeps that gap closed by default, so adding a trigger means answering the# authorization question for that event. Pair a new entry with a tile in# products/workflows/frontend/Workflows/hogflows/registry/triggers/.-WORKFLOW_SAFE_INTERNAL_EVENTS: Final[frozenset[str]] = frozenset({"$slack_message_received", "$github_event_received"})+WORKFLOW_SAFE_INTERNAL_EVENTS: Final[frozenset[str]] = frozenset(+ {+ "$slack_message_received",+ "$github_event_received",+ # A public support reply. Its payload omits the reply body and matches the analytics event.+ "$conversation_message_sent",+ }+)# Billable action types that are subject to rate limiting and quota tracking# These action types incur costs and are counted against customer quotasdiff --git a/products/workflows/backend/templates/__init__.py b/products/workflows/backend/templates/__init__.pyindex 2dbea0c3dfa0..9fb52933026d 100644--- a/products/workflows/backend/templates/__init__.py+++ b/products/workflows/backend/templates/__init__.py@@ -11,6 +11,7 @@ logger = structlog.get_logger(__name__)TEMPLATE_FILES = ["welcome_email_sequence_template.json","support-ticket-notification.json",+ "support-reply-customer-email.json","negative-survey-response.json","convert-trials-to-paid.json","abandoned-checkout-recovery.json",diff --git a/products/workflows/backend/templates/support-reply-customer-email.json b/products/workflows/backend/templates/support-reply-customer-email.jsonnew file mode 100644index 000000000000..9f65c3611d39--- /dev/null+++ b/products/workflows/backend/templates/support-reply-customer-email.json@@ -0,0 +1,151 @@+{+ "id": "a638999a-bf53-4fde-af36-c85ad9827076",+ "name": "Support reply notification",+ "description": "Email the customer when your support team replies to their ticket, so they never miss an answer.",+ "version": 1,+ "created_at": "2026-10-27T00:00:00Z",+ "created_by": null,+ "updated_at": "2026-10-27T00:00:00Z",+ "trigger": {+ "type": "internal-event",+ "filters": {+ "source": "internal-events",+ "events": [+ {+ "id": "$conversation_message_sent",+ "name": "Ticket message sent",+ "type": "events"+ }+ ],+ "properties": [+ {+ "key": "customer_email_verified",+ "value": ["true"],+ "operator": "exact",+ "type": "event"+ },+ {+ "key": "channel_source",+ "value": ["email"],+ "operator": "is_not",+ "type": "event"+ }+ ]+ }+ },+ "trigger_masking": null,+ "conversion": {+ "filters": [],+ "bytecode": [],+ "window_minutes": null+ },+ "exit_condition": "exit_only_at_end",+ "edges": [+ {+ "to": "action_function_email_6254cf7c-c5de-42ba-b54e-3782bd102208",+ "from": "trigger_node",+ "type": "continue"+ },+ {+ "to": "exit_node",+ "from": "action_function_email_6254cf7c-c5de-42ba-b54e-3782bd102208",+ "type": "continue"+ }+ ],+ "actions": [+ {+ "id": "trigger_node",+ "name": "Support team replies on a ticket",+ "description": "A teammate has replied to a customer on a support ticket. Runs only when the customer's email is verified, and skips email tickets because those replies already go out by email.",+ "on_error": null,+ "created_at": 0,+ "updated_at": 0,+ "filters": null,+ "type": "trigger",+ "config": {+ "type": "internal-event",+ "filters": {+ "source": "internal-events",+ "events": [+ {+ "id": "$conversation_message_sent",+ "name": "Ticket message sent",+ "type": "events"+ }+ ],+ "properties": [+ {+ "key": "customer_email_verified",+ "value": ["true"],+ "operator": "exact",+ "type": "event"+ },+ {+ "key": "channel_source",+ "value": ["email"],+ "operator": "is_not",+ "type": "event"+ }+ ]+ }+ },+ "output_variable": null+ },+ {+ "id": "action_function_email_6254cf7c-c5de-42ba-b54e-3782bd102208",+ "name": "Email the customer",+ "description": "Write the email that tells the customer your support team replied to their ticket.",+ "on_error": null,+ "created_at": 1793059200000,+ "updated_at": 1793059200000,+ "filters": null,+ "type": "function_email",+ "output_variable": null,+ "config": {+ "template_id": "template-email",+ "inputs": {+ "email": {+ "value": {+ "to": {+ "name": "{{ event.properties.customer_name }}",+ "email": "{{ event.properties.customer_email }}"+ },+ "from": {+ "name": "",+ "email": ""+ },+ "html": "",+ "text": "",+ "design": null,+ "replyTo": "",+ "subject": "",+ "preheader": ""+ },+ "templating": "liquid"+ }+ },+ "message_category_type": "transactional"+ }+ },+ {+ "id": "exit_node",+ "name": "Exit",+ "description": "User moved through the workflow without errors.",+ "on_error": null,+ "created_at": 0,+ "updated_at": 0,+ "filters": null,+ "type": "exit",+ "config": {+ "reason": "Default exit"+ },+ "output_variable": null+ }+ ],+ "abort_action": null,+ "variables": [],+ "billable_action_types": ["function_email"],+ "image_url": "https://res.cloudinary.com/dmukukwp6/image/upload/Template_cover_9_cc52152691.jpg",+ "tags": ["email", "support ticket", "support"],+ "scope": "global"+}diff --git a/products/workflows/backend/templates/support-ticket-notification.json b/products/workflows/backend/templates/support-ticket-notification.jsonindex 7c5e913c9ee4..cdf212dc9b5b 100644--- a/products/workflows/backend/templates/support-ticket-notification.json+++ b/products/workflows/backend/templates/support-ticket-notification.json@@ -1,7 +1,7 @@{"id": "019ce1f1-5d12-0000-e318-4b3ebd4b2aea","name": "New support ticket notification",- "description": "Notify your support team in Slack as soon as a new ticket comes in.",+ "description": "Notify your support team in Slack or by email as soon as a new ticket comes in.","version": 1,"created_at": "2026-03-12T12:06:57.554838Z","created_by": {@@ -15,7 +15,7 @@"hedgehog_config": null,"role_at_organization": null},- "updated_at": "2026-03-12T12:07:27.301356Z",+ "updated_at": "2026-10-27T00:00:00Z","trigger": {"type": "event","filters": {@@ -44,9 +44,14 @@"type": "continue"},{- "to": "exit_node",+ "to": "action_function_email_826ffd05-91e4-4647-a7b2-d8ce81376b87","from": "action_function_431166ee-1322-4d35-8186-958120346fc2","type": "continue"+ },+ {+ "to": "exit_node",+ "from": "action_function_email_826ffd05-91e4-4647-a7b2-d8ce81376b87",+ "type": "continue"}],"actions": [@@ -78,7 +83,7 @@{"id": "action_function_431166ee-1322-4d35-8186-958120346fc2","name": "Message in Slack channel",- "description": "Connect the right Slack channel and notify your support team.",+ "description": "Connect the right Slack channel and write the message for your support team. Delete this step if you only want email.","on_error": null,"created_at": 1773317149872,"updated_at": 1773317149872,@@ -101,40 +106,11 @@"templating": "hog"},"blocks": {- "value": [- {- "text": {- "text": "🎫 *New support ticket created*\n\n*User:* {person.name}\n*Email:* {person.email}\n\nA user has submitted a new support request.",- "type": "mrkdwn"- },- "type": "section"- },- {- "type": "actions",- "elements": [- {- "url": "{person.url}",- "text": {- "text": "View user in PostHog",- "type": "plain_text"- },- "type": "button"- },- {- "url": "{source.url}",- "text": {- "text": "Open ticket",- "type": "plain_text"- },- "type": "button"- }- ]- }- ],+ "value": [],"templating": "hog"},"text": {- "value": "*{person.name}* created a ticket: '{event.event}'",+ "value": "","templating": "hog"}},@@ -142,6 +118,42 @@},"output_variable": null},+ {+ "id": "action_function_email_826ffd05-91e4-4647-a7b2-d8ce81376b87",+ "name": "Email your support team",+ "description": "Add your support inbox as the recipient and write the email. Delete this step if you only want Slack.",+ "on_error": null,+ "created_at": 1793059200000,+ "updated_at": 1793059200000,+ "filters": null,+ "type": "function_email",+ "output_variable": null,+ "config": {+ "template_id": "template-email",+ "inputs": {+ "email": {+ "value": {+ "to": {+ "name": "",+ "email": ""+ },+ "from": {+ "name": "",+ "email": ""+ },+ "html": "",+ "text": "",+ "design": null,+ "replyTo": "",+ "subject": "",+ "preheader": ""+ },+ "templating": "liquid"+ }+ },+ "message_category_type": "transactional"+ }+ },{"id": "exit_node","name": "Exit",@@ -159,8 +171,8 @@],"abort_action": null,"variables": [],- "billable_action_types": ["function"],+ "billable_action_types": ["function", "function_email"],"image_url": "https://res.cloudinary.com/dmukukwp6/image/upload/Template_cover_9_cc52152691.jpg",- "tags": ["slack", "support ticket", "support"],+ "tags": ["slack", "email", "support ticket", "support"],"scope": "global"}diff --git a/products/workflows/backend/tests/api/test_hog_flow_template.py b/products/workflows/backend/tests/api/test_hog_flow_template.pyindex 7313bc5d56a7..626cf0cf14fb 100644--- a/products/workflows/backend/tests/api/test_hog_flow_template.py+++ b/products/workflows/backend/tests/api/test_hog_flow_template.py@@ -264,6 +264,20 @@ class TestHogFlowTemplateAPI(APIBaseTest):},201,),+ (+ "support_reply",+ {+ "type": "internal-event",+ "filters": {+ "source": "internal-events",+ "events": [{"id": "$conversation_message_sent", "type": "events"}],+ "properties": [+ {"key": "customer_email_verified", "value": ["true"], "operator": "exact", "type": "event"}+ ],+ },+ },+ 201,+ ),("disallowed_internal_event",{diff --git a/products/workflows/frontend/Workflows/hogflows/registry/triggers/conversations.tsx b/products/workflows/frontend/Workflows/hogflows/registry/triggers/conversations.tsxindex 79b2712743df..ebf3ee24b9d3 100644--- a/products/workflows/frontend/Workflows/hogflows/registry/triggers/conversations.tsx+++ b/products/workflows/frontend/Workflows/hogflows/registry/triggers/conversations.tsx@@ -20,6 +20,11 @@ function getEventId(config: EventTriggerConfig): string | null {return typeof firstEvent?.id === 'string' ? firstEvent.id : null}+// The support reply template triggers on the server-only internal copy of a reply, which public capture cannot forge.+function isInternalEventConfig(config: unknown): boolean {+ return (config as { type?: unknown } | null)?.type === 'internal-event'+}+function isSupportStatusValue(value: unknown): value is SupportStatusValue {return typeof value === 'string' && SUPPORT_STATUS_VALUES.includes(value as SupportStatusValue)}@@ -100,6 +105,7 @@ const SUPPORT_TRIGGER_META: Record<string, { name: string; description: string }function StepTriggerConfigurationSupportFilters({ node }: { node: any }): JSX.Element {const { setWorkflowActionConfig } = useActions(workflowLogic)const config = node.data.config as EventTriggerConfig+ const isInternalEvent = isInternalEventConfig(node.data.config)const eventId = getEventId(config) ?? '$conversation_message_received'const meta = SUPPORT_TRIGGER_META[eventId] ?? SUPPORT_TRIGGER_META['$conversation_message_received']@@ -113,15 +119,15 @@ function StepTriggerConfigurationSupportFilters({ node }: { node: any }): JSX.El<HogFlowPropertyFiltersfiltersKey={`support-trigger-${node.data.id}`}filters={config.filters ?? {}}- setFilters={(filters) =>- setWorkflowActionConfig(node.data.id, {- type: 'event',- filters: {- ...filters,- events: [{ id: eventId, type: 'events', name: meta.name }],- },- })- }+ setFilters={(filters) => {+ const nextFilters = { ...filters, events: [{ id: eventId, type: 'events', name: meta.name }] }+ setWorkflowActionConfig(+ node.data.id,+ isInternalEvent+ ? { type: 'internal-event', filters: { ...nextFilters, source: 'internal-events' } }+ : { type: 'event', filters: nextFilters }+ )+ }}typeKey={`support-trigger-${node.data.id}`}/></LemonField.Pure>@@ -180,7 +186,9 @@ registerTriggerType({icon: <IconBolt />,description: 'Trigger when a teammate replies on a ticket',group: 'Support',- matchConfig: (config) => config.type === 'event' && getEventId(config) === '$conversation_message_sent',+ matchConfig: (config) =>+ (config.type === 'event' || isInternalEventConfig(config)) &&+ getEventId(config) === '$conversation_message_sent',buildConfig: () => ({type: 'event',filters: {diff --git a/tach.toml b/tach.tomlindex f793c13e55e7..49f73cde1ae8 100644--- a/tach.toml+++ b/tach.toml@@ -281,7 +281,7 @@ layer = "modules"path = "products.conversations"depends_on = ["ee",- "posthog", "products.tasks", "products.business_knowledge", "products.warehouse_sources", "products.customer_analytics", "products.access_control",+ "posthog", "products.cdp", "products.tasks", "products.business_knowledge", "products.warehouse_sources", "products.customer_analytics", "products.access_control",# Facade-only: the deleted-ticket purge retracts the ticket's signal embeddings. products.signals# depends on products.conversations in turn, so keep this direction on the facade."products.signals",