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.

fix(conversations): keep comment text when zendesk import has an image (#72438)

HaynesPostHog7f79baa0e8bf
diff --git a/products/conversations/backend/api/tests/test_attachments_service.py b/products/conversations/backend/api/tests/test_attachments_service.py
index 1f1ba3e16056..0cc89e75f9ef 100644
--- a/products/conversations/backend/api/tests/test_attachments_service.py
+++ b/products/conversations/backend/api/tests/test_attachments_service.py
@@ -32,6 +32,32 @@ class TestAttachmentsService(SimpleTestCase):
assert "image" in node_types
assert "paragraph" in node_types
+ def test_build_content_seeds_text_when_no_rich_content(self) -> None:
+ # Guards the Zendesk-import regression: a comment with an image passes rich_content=None,
+ # and the body text must be seeded as a paragraph node or it's dropped from the UI.
+ images = [{"url": "https://app.posthog.com/uploaded_media/img", "name": "shot.png"}]
+ _content, rich_content = build_content_with_images("please see the screenshot", None, images, [])
+
+ assert rich_content is not None
+ text = "".join(
+ c.get("text", "") for n in rich_content["content"] if n["type"] == "paragraph" for c in n.get("content", [])
+ )
+ assert "please see the screenshot" in text
+
+ def test_build_content_seeds_multiline_text_as_separate_paragraphs(self) -> None:
+ # A single text node collapses newlines to spaces in the renderer, so a multi-line
+ # body must become one paragraph per line.
+ images = [{"url": "https://app.posthog.com/uploaded_media/img", "name": "shot.png"}]
+ _content, rich_content = build_content_with_images("first line\n\nsecond line", None, images, [])
+
+ assert rich_content is not None
+ paragraphs = [
+ "".join(c.get("text", "") for c in n.get("content", []))
+ for n in rich_content["content"]
+ if n["type"] == "paragraph"
+ ]
+ assert paragraphs == ["first line", "second line"]
+
def test_build_content_no_attachments_returns_unchanged(self) -> None:
content, rich_content = build_content_with_images("just text", None, [], [])
assert content == "just text"
diff --git a/products/conversations/backend/services/attachments.py b/products/conversations/backend/services/attachments.py
index fc17b107586d..a1bb04ea2cf7 100644
--- a/products/conversations/backend/services/attachments.py
+++ b/products/conversations/backend/services/attachments.py
@@ -126,7 +126,16 @@ def build_content_with_images(
content = "\n\n".join(parts)
if not isinstance(rich_content, dict):
- rich_content = {"type": "doc", "content": []}
+ # Callers without upstream rich_content (e.g. Zendesk import) pass the text here only.
+ # Seed it as paragraph nodes, or the UI — which renders rich_content exclusively — drops it.
+ # Split on newlines so multi-line bodies keep their structure (the renderer collapses \n
+ # within a single text node), matching how the Teams path builds its doc.
+ seeded = [
+ {"type": "paragraph", "content": [{"type": "text", "text": line}]}
+ for raw_line in cleaned_text.split("\n")
+ if (line := raw_line.strip())
+ ]
+ rich_content = {"type": "doc", "content": seeded}
rich_nodes = rich_content.setdefault("content", [])
for img in images:
rich_nodes.append(
diff --git a/products/conversations/backend/temporal/zendesk_import/tests/test_activities.py b/products/conversations/backend/temporal/zendesk_import/tests/test_activities.py
index 991b58d17935..d62765839372 100644
--- a/products/conversations/backend/temporal/zendesk_import/tests/test_activities.py
+++ b/products/conversations/backend/temporal/zendesk_import/tests/test_activities.py
@@ -519,6 +519,14 @@ class TestZendeskImportBatchActivity(BaseTest):
assert rich_content is not None
image_nodes = [n for n in rich_content["content"] if n.get("type") == "image"]
self.assertEqual(image_nodes[0]["attrs"]["src"], "https://media.posthog.test/shot.png")
+ # The comment body must survive alongside the image, not be dropped from rich_content.
+ body_text = "".join(
+ c.get("text", "")
+ for n in rich_content["content"]
+ if n.get("type") == "paragraph"
+ for c in n.get("content", [])
+ )
+ self.assertIn("see image", body_text)
content = stored.content
assert content is not None
self.assertIn("https://media.posthog.test/shot.png", content)