: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(conversations): attribute Teams support replies to the agent (#72832)
Luke Beltonf657ce9bd68a
diff --git a/products/conversations/backend/api/tests/test_teams_formatting.py b/products/conversations/backend/api/tests/test_teams_formatting.pyindex 8c45ecee6f6c..5081cbcf92f6 100644--- a/products/conversations/backend/api/tests/test_teams_formatting.py+++ b/products/conversations/backend/api/tests/test_teams_formatting.py@@ -3,6 +3,8 @@ from django.test import SimpleTestCasefrom parameterized import parameterizedfrom products.conversations.backend.teams_formatting import (+ append_teams_attribution,+ build_teams_reply_html,rich_content_to_teams_html,teams_html_to_content_and_rich_content,)@@ -264,3 +266,34 @@ class TestRichContentToTeamsHtml(SimpleTestCase):}result = rich_content_to_teams_html(rich)assert result == "<p><i><b>wow</b></i></p>"+++class TestAppendTeamsAttribution(SimpleTestCase):+ def test_appends_italic_footer(self):+ assert append_teams_attribution("<p>Hello</p>", "Max Hedgehog") == (+ "<p>Hello</p><p><i>Max Hedgehog via SupportHog</i></p>"+ )++ def test_no_author_leaves_reply_untouched(self):+ assert append_teams_attribution("<p>Hello</p>", "") == "<p>Hello</p>"++ def test_escapes_author_name(self):+ result = append_teams_attribution("<p>Hello</p>", "<script>alert(1)</script>")+ assert "<script>" not in result+ assert "<script>" in result+++class TestBuildTeamsReplyHtml(SimpleTestCase):+ def test_renders_rich_content_then_footer(self):+ rich = {+ "type": "doc",+ "content": [{"type": "paragraph", "content": [{"type": "text", "text": "All fixed now."}]}],+ }+ assert build_teams_reply_html(rich, "All fixed now.", "Max Hedgehog") == (+ "<p>All fixed now.</p><p><i>Max Hedgehog via SupportHog</i></p>"+ )++ def test_falls_back_to_plain_content_with_footer(self):+ assert build_teams_reply_html(None, "All fixed now.", "Max Hedgehog") == (+ "All fixed now.<p><i>Max Hedgehog via SupportHog</i></p>"+ )diff --git a/products/conversations/backend/tasks.py b/products/conversations/backend/tasks.pyindex 517b03ff4da3..653c0e89c7eb 100644--- a/products/conversations/backend/tasks.py+++ b/products/conversations/backend/tasks.py@@ -97,7 +97,7 @@ from products.conversations.backend.teams import (post_teams_channel_message_via_graph,)from products.conversations.backend.teams_attachments import extract_teams_graph_images-from products.conversations.backend.teams_formatting import rich_content_to_teams_html+from products.conversations.backend.teams_formatting import build_teams_reply_htmlfrom .support_slack import SUPPORT_SLACK_ALLOWED_HOST_SUFFIXES@@ -1000,7 +1000,7 @@ def post_reply_to_teams(logger.warning("teams_reply_no_bot_token", team_id=team_id)return- reply_html = rich_content_to_teams_html(rich_content, content)+ reply_html = build_teams_reply_html(rich_content, content, author_name)display_text = f"{author_name}: {content[:200]}" if author_name else content[:200]payload: dict[str, Any] = {@@ -1069,9 +1069,7 @@ def post_reply_to_teams_via_graph(logger.warning("teams_graph_reply_team_not_found", team_id=team_id)return- reply_html = rich_content_to_teams_html(rich_content, content)- if author_name:- reply_html = f"<p><b>{html_mod.escape(author_name)}</b></p>{reply_html}"+ reply_html = build_teams_reply_html(rich_content, content, author_name)status, _message_id = post_teams_channel_message_via_graph(team=team,diff --git a/products/conversations/backend/teams_formatting.py b/products/conversations/backend/teams_formatting.pyindex c7098e18afec..cdbf3b610740 100644--- a/products/conversations/backend/teams_formatting.py+++ b/products/conversations/backend/teams_formatting.py@@ -86,6 +86,32 @@ def rich_content_to_teams_html(rich_content: JSON | None, fallback_content: strreturn "".join(parts) or html_mod.escape(fallback_content)+def build_teams_reply_html(rich_content: JSON | None, content: str, author_name: str) -> str:+ """Render a support agent's reply to Teams-ready HTML, with the attribution footer.++ Single entry point shared by both outbound reply paths (bot connector and Graph)+ so their formatting can't drift.+ """+ reply_html = rich_content_to_teams_html(rich_content, content)+ return append_teams_attribution(reply_html, author_name)+++def append_teams_attribution(reply_html: str, author_name: str) -> str:+ """Append a subtle "{name} via SupportHog" footer to an outbound Teams reply.++ A Teams bot's display name is fixed in the app manifest, so every reply otherwise+ shows up from a nameless "SupportHog" and customers can't tell which agent answered.+ The footer makes the sender clear. Both outbound paths (bot connector and Graph)+ render the common inline HTML tags, so the same italic markup works for each.++ Keep the footer markup here only -- it's the single place to restyle attribution.+ """+ if not author_name:+ return reply_html+ footer = f"<p><i>{html_mod.escape(author_name)} via SupportHog</i></p>"+ return f"{reply_html}{footer}"++def _render_node(node: JSON) -> str:node_type = node.get("type", "")