diff --git a/frontend/public/services/discord.png b/frontend/public/services/discord.png new file mode 100644 index 0000000000000..d21ba297b0d9c Binary files /dev/null and b/frontend/public/services/discord.png differ diff --git a/posthog/cdp/templates/__init__.py b/posthog/cdp/templates/__init__.py index 1d982a7fdd199..915c4d119530f 100644 --- a/posthog/cdp/templates/__init__.py +++ b/posthog/cdp/templates/__init__.py @@ -8,6 +8,7 @@ from .clearbit.template_clearbit import template as clearbit from .posthog.template_posthog import template as posthog, TemplatePostHogMigrator from .aws_kinesis.template_aws_kinesis import template as aws_kinesis +from .discord.template_discord import template as discord from .salesforce.template_salesforce import template_create as salesforce_create, template_update as salesforce_update from .mailjet.template_mailjet import ( template_create_contact as mailjet_create_contact, @@ -43,6 +44,7 @@ braze, clearbit, customerio, + discord, engage, gleap, google_ads, diff --git a/posthog/cdp/templates/discord/template_discord.py b/posthog/cdp/templates/discord/template_discord.py new file mode 100644 index 0000000000000..576324ef21e4a --- /dev/null +++ b/posthog/cdp/templates/discord/template_discord.py @@ -0,0 +1,64 @@ +from posthog.cdp.templates.hog_function_template import HogFunctionTemplate, HogFunctionSubTemplate, SUB_TEMPLATE_COMMON + +template: HogFunctionTemplate = HogFunctionTemplate( + status="beta", + id="template-discord", + name="Discord", + description="Sends a message to a discord channel", + icon_url="/static/services/discord.png", + category=["Customer Success"], + hog=""" +let res := fetch(inputs.webhookUrl, { + 'body': inputs.content, + 'method': 'POST', + 'headers': { + 'Content-Type': 'application/json' + } +}); + +if (res.status != 200 or not res.body.ok) { + throw Error(f'Failed to post message to Discord: {res.status}: {res.body}'); +} +""".strip(), + inputs_schema=[ + { + "key": "webhookUrl", + "type": "string", + "label": "Webhook URL", + "description": "See this page on how to generate a Webhook URL: https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks", + "secret": False, + "required": True, + }, + { + "key": "content", + "type": "json", + "label": "Content", + "description": "(see https://support.discord.com/hc/en-us/articles/210298617-Markdown-Text-101-Chat-Formatting-Bold-Italic-Underline)", + "default": {"content": "**{person.name}** triggered event: '{event.event}'"}, + "secret": False, + "required": True, + }, + ], + sub_templates=[ + HogFunctionSubTemplate( + id="early_access_feature_enrollment", + name="Post to Discord on feature enrollment", + description="Posts a message to Discord when a user enrolls or un-enrolls in an early access feature", + filters=SUB_TEMPLATE_COMMON["early_access_feature_enrollment"].filters, + inputs={ + "content": { + "content": "**{person.name}** {event.properties.$feature_enrollment ? 'enrolled in' : 'un-enrolled from'} the early access feature for '{event.properties.$feature_flag}'" + }, + }, + ), + HogFunctionSubTemplate( + id="survey_response", + name="Post to Discord on survey response", + description="Posts a message to Discord when a user responds to a survey", + filters=SUB_TEMPLATE_COMMON["survey_response"].filters, + inputs={ + "content": {"content": "**{person.name}** responded to survey **{event.properties.$survey_name}**"}, + }, + ), + ], +)