Skip to content

Commit

Permalink
add discord template
Browse files Browse the repository at this point in the history
  • Loading branch information
MarconLP committed Oct 17, 2024
1 parent cb1b316 commit 4c0ba1b
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
Binary file added frontend/public/services/discord.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions posthog/cdp/templates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -43,6 +44,7 @@
braze,
clearbit,
customerio,
discord,
engage,
gleap,
google_ads,
Expand Down
64 changes: 64 additions & 0 deletions posthog/cdp/templates/discord/template_discord.py
Original file line number Diff line number Diff line change
@@ -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}**"},
},
),
],
)

0 comments on commit 4c0ba1b

Please sign in to comment.