: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(cdp): make Discord destination mentions configurable (#72486)
Meikel Ratz8750f4bc5f7b
diff --git a/posthog/cdp/templates/discord/template_discord.py b/posthog/cdp/templates/discord/template_discord.pyindex dc74a4e8d6e3..6efb8e962326 100644--- a/posthog/cdp/templates/discord/template_discord.py+++ b/posthog/cdp/templates/discord/template_discord.py@@ -26,11 +26,18 @@ if (not match(inputs.webhookUrl, '^https://discord.com/api/webhooks/.*')) {throw Error('Invalid URL. The URL should match the format: https://discord.com/api/webhooks/...')}+let allowedParse := [];+if (inputs.allowedMentions == 'roles_users') {+ allowedParse := ['roles', 'users'];+} else if (inputs.allowedMentions == 'everyone') {+ allowedParse := ['everyone', 'roles', 'users'];+}+let res := fetch(inputs.webhookUrl, {'body': {'content': inputs.content,'allowed_mentions': {- 'parse': []+ 'parse': allowedParse}},'method': 'POST',@@ -61,5 +68,28 @@ if (res.status >= 400) {"secret": False,"required": True,},+ {+ "key": "allowedMentions",+ "type": "choice",+ "label": "Allowed mentions",+ "description": "Control which mentions in the message actually ping people. By default mentions are shown as text and nobody is pinged, which avoids accidental pings from event data. Enable roles and users to ping @roles and @users, or allow @everyone / @here too.",+ "choices": [+ {+ "label": "None (mentions shown as text, nobody is pinged)",+ "value": "none",+ },+ {+ "label": "Roles and users (@role and @user mentions ping)",+ "value": "roles_users",+ },+ {+ "label": "Everyone, roles and users (also allows @everyone and @here)",+ "value": "everyone",+ },+ ],+ "default": "none",+ "secret": False,+ "required": True,+ },],)diff --git a/posthog/cdp/templates/discord/test_template_discord.py b/posthog/cdp/templates/discord/test_template_discord.pyindex 62c9929749c3..7b62c4d0a76d 100644--- a/posthog/cdp/templates/discord/test_template_discord.py+++ b/posthog/cdp/templates/discord/test_template_discord.py@@ -1,5 +1,7 @@import pytest+from parameterized import parameterized+from posthog.cdp.templates.discord.template_discord import template as template_discordfrom posthog.cdp.templates.helpers import BaseHogFunctionTemplateTest@@ -32,6 +34,18 @@ class TestTemplateDiscord(BaseHogFunctionTemplateTest):},)+ @parameterized.expand(+ [+ ["none", []],+ ["roles_users", ["roles", "users"]],+ ["everyone", ["everyone", "roles", "users"]],+ ]+ )+ def test_allowed_mentions_maps_to_parse(self, choice, expected_parse):+ self.run_function(inputs=self._inputs(allowedMentions=choice))++ assert self.get_mock_fetch_calls()[0][1]["body"]["allowed_mentions"] == {"parse": expected_parse}+def test_only_allow_teams_url(self):for url, allowed in [["https://discord.com/api/webhooks/abc", True],