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): let compose tag the new ticket (#90745)

posthog[bot]c40b238f0a20
diff --git a/products/conversations/backend/api/tests/test_tickets.py b/products/conversations/backend/api/tests/test_tickets.py
index f9e8ae99cebf..0be34f9ab1ad 100644
--- a/products/conversations/backend/api/tests/test_tickets.py
+++ b/products/conversations/backend/api/tests/test_tickets.py
@@ -15,6 +15,7 @@ from posthog.test.base import (
from unittest.mock import patch
from django.db import transaction
+from django.test import SimpleTestCase
from django.utils import timezone
from parameterized import parameterized
@@ -34,7 +35,7 @@ from posthog.test.persons import create_person
from products.access_control.backend.models.access_control import AccessControl
from products.access_control.backend.models.role import Role
from products.conversations.backend.api.ticket_filters import query_params_to_view_filters
-from products.conversations.backend.api.tickets import TicketReplyRequestSerializer
+from products.conversations.backend.api.tickets import ComposeTicketSerializer, TicketReplyRequestSerializer
from products.conversations.backend.models import EmailChannel, EmailChannelKind, Ticket, TicketAssignment, TicketView
from products.conversations.backend.models.constants import Channel, ChannelDetail, Priority, Status
from products.conversations.backend.person_lookup import PERSON_EMAIL_LOOKUP_QUERY, _get_persons_by_email
@@ -43,6 +44,29 @@ from products.conversations.backend.reply_dedupe import REPLY_IN_PROGRESS_ERROR_
from ee.clickhouse.materialized_columns.columns import get_bloom_filter_lower_index_name
+class TestComposeTicketSerializer(SimpleTestCase):
+ def _payload(self, **overrides):
+ data = {
+ "recipient_email": "[email protected]",
+ "email_config_id": "00000000-0000-0000-0000-000000000000",
+ "message": "Hello!",
+ }
+ data.update(overrides)
+ return data
+
+ def test_rejects_more_than_100_tags(self):
+ # The compose write applies each tag inside the ticket-creation transaction, which
+ # holds a team-row lock. An unbounded list would fan out that work under the lock, so
+ # the field is capped at 100 before any DB work starts.
+ serializer = ComposeTicketSerializer(data=self._payload(tags=[f"t{i}" for i in range(101)]))
+ assert not serializer.is_valid()
+ assert set(serializer.errors) == {"tags"}
+
+ def test_accepts_up_to_100_tags(self):
+ serializer = ComposeTicketSerializer(data=self._payload(tags=[f"t{i}" for i in range(100)]))
+ assert serializer.is_valid(), serializer.errors
+
+
# Patch on_commit to execute immediately in tests
def immediate_on_commit(func):
func()
@@ -1990,6 +2014,23 @@ class TestComposeTicketAPI(APIBaseTest):
assert search.status_code == status.HTTP_200_OK
assert [t["id"] for t in search.json()["results"]] == [str(ticket.id)]
+ def test_compose_applies_tags_to_the_new_ticket(self, mock_on_commit):
+ # Tags let support filter composed tickets by source (e.g. roadmap pitches). If compose
+ # drops the field, the ticket lands untagged and that filtering breaks.
+ response = self._compose(
+ {
+ "recipient_email": "[email protected]",
+ "email_config_id": str(self.email_config.id),
+ "message": "Great idea, we logged it.",
+ "tags": ["roadmap_pitch"],
+ }
+ )
+ assert response.status_code == status.HTTP_201_CREATED
+
+ detail = self.client.get(f"/api/projects/{self.team.id}/conversations/tickets/{response.json()['id']}/")
+ assert detail.status_code == status.HTTP_200_OK
+ assert detail.json()["tags"] == ["roadmap_pitch"]
+
class TestTicketPersonalAPIKeyScopes(APIBaseTest):
def _auth_with_pak(self, scopes: list[str]) -> None:
diff --git a/products/conversations/backend/api/tickets.py b/products/conversations/backend/api/tickets.py
index 46b72b327031..c1248a5fb383 100644
--- a/products/conversations/backend/api/tickets.py
+++ b/products/conversations/backend/api/tickets.py
@@ -35,7 +35,7 @@ from rest_framework.response import Response
from posthog.api.person import get_person_name
from posthog.api.routing import TeamAndOrgViewSetMixin
-from posthog.api.tagged_item import TaggedItemSerializerMixin, TaggedItemViewSetMixin
+from posthog.api.tagged_item import TaggedItemSerializerMixin, TaggedItemViewSetMixin, set_tags_on_object
from posthog.dataclasses import frozen
from posthog.event_usage import report_user_action
from posthog.exceptions_capture import capture_exception
@@ -224,6 +224,13 @@ class ComposeTicketSerializer(serializers.Serializer):
allow_null=True,
help_text="TipTap rich content JSON for formatted messages.",
)
+ tags = serializers.ListField(
+ child=serializers.CharField(max_length=255),
+ required=False,
+ default=list,
+ max_length=100,
+ help_text="Tags to apply to the new ticket, e.g. to mark its source. Each is normalized (lowercased, trimmed). Up to 100.",
+ )
def validate_message(self, value: str) -> str:
if not value or not value.strip():
@@ -1701,6 +1708,9 @@ class TicketViewSet(TaggedItemViewSetMixin, TeamAndOrgViewSetMixin, AccessContro
item_context={"author_type": "human", "is_private": False},
)
+ if data.get("tags"):
+ set_tags_on_object(data["tags"], ticket)
+
try:
report_user_action(
request.user,
diff --git a/products/conversations/frontend/generated/api.schemas.ts b/products/conversations/frontend/generated/api.schemas.ts
index ff8f5ae27f24..69a8535a90fb 100644
--- a/products/conversations/frontend/generated/api.schemas.ts
+++ b/products/conversations/frontend/generated/api.schemas.ts
@@ -533,6 +533,12 @@ export interface ComposeTicketApi {
message: string
/** TipTap rich content JSON for formatted messages. */
rich_content?: unknown
+ /**
+ * Tags to apply to the new ticket, e.g. to mark its source. Each is normalized (lowercased, trimmed). Up to 100.
+ * @maxItems 100
+ * @items.maxLength 255
+ */
+ tags?: string[]
}
export interface ComposeTicketResponseApi {
diff --git a/products/conversations/frontend/generated/api.zod.ts b/products/conversations/frontend/generated/api.zod.ts
index a19766f9b222..4973f9bacdc8 100644
--- a/products/conversations/frontend/generated/api.zod.ts
+++ b/products/conversations/frontend/generated/api.zod.ts
@@ -261,6 +261,10 @@ export const conversationsTicketsComposeCreateBodyEmailSubjectMax = 500
export const conversationsTicketsComposeCreateBodyMessageMax = 5000
+export const conversationsTicketsComposeCreateBodyTagsItemMax = 255
+
+export const conversationsTicketsComposeCreateBodyTagsMax = 100
+
export const ConversationsTicketsComposeCreateBody = /* @__PURE__ */ zod.object({
recipient_email: zod.email().describe('Recipient email address.'),
recipient_distinct_id: zod
@@ -276,6 +280,13 @@ export const ConversationsTicketsComposeCreateBody = /* @__PURE__ */ zod.object(
email_config_id: zod.uuid().describe('ID of the EmailChannel to send from.'),
message: zod.string().max(conversationsTicketsComposeCreateBodyMessageMax).describe('Message content in markdown.'),
rich_content: zod.unknown().optional().describe('TipTap rich content JSON for formatted messages.'),
+ tags: zod
+ .array(zod.string().max(conversationsTicketsComposeCreateBodyTagsItemMax))
+ .max(conversationsTicketsComposeCreateBodyTagsMax)
+ .optional()
+ .describe(
+ 'Tags to apply to the new ticket, e.g. to mark its source. Each is normalized (lowercased, trimmed). Up to 100.'
+ ),
})
export const conversationsViewsCreateBodyNameMax = 400
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 7d3a7191a954..e2b0c4f52757 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -18587,6 +18587,12 @@ export namespace Schemas {
message: string;
/** TipTap rich content JSON for formatted messages. */
rich_content?: unknown;
+ /**
+ * Tags to apply to the new ticket, e.g. to mark its source. Each is normalized (lowercased, trimmed). Up to 100.
+ * @maxItems 100
+ * @items.maxLength 255
+ */
+ tags?: string[];
}
export interface ComposeTicketResponse {