Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cdp): add microsoft teams template #25652

Merged
merged 37 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
c61f766
add microsoft teams template
MarconLP Oct 17, 2024
2ad2473
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 17, 2024
4316315
only allow teams urls
MarconLP Oct 18, 2024
dec5a2e
fix url check and add tests
MarconLP Oct 18, 2024
ff6d02b
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 18, 2024
7ac919f
fix merge conflict
MarconLP Oct 18, 2024
25814ce
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 18, 2024
0fbf4a2
mention correct format in the error message
MarconLP Oct 21, 2024
b6066ab
fix merge conflict
MarconLP Oct 21, 2024
ada3e19
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 21, 2024
33840cf
fix merge conflict
MarconLP Oct 21, 2024
3f2eb4e
merge master into this branch
MarconLP Oct 21, 2024
c6d7a82
fix test
MarconLP Oct 21, 2024
164e8ce
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 21, 2024
b40cab4
Update query snapshots
github-actions[bot] Oct 21, 2024
25d8f87
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 21, 2024
fd4daea
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 21, 2024
7e68e76
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 21, 2024
d10e5d6
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 21, 2024
31f3531
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 21, 2024
4c949e2
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 21, 2024
bffb293
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 21, 2024
80089df
use new workflows instead
MarconLP Oct 21, 2024
6e88ebb
adjust key in sub templates
MarconLP Oct 21, 2024
529adfd
Update UI snapshots for `chromium` (2)
github-actions[bot] Oct 21, 2024
ecd354c
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 21, 2024
d2a2a3c
Update UI snapshots for `chromium` (2)
github-actions[bot] Oct 21, 2024
6622760
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 21, 2024
bcd2310
Update UI snapshots for `chromium` (2)
github-actions[bot] Oct 21, 2024
7dbea7c
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 21, 2024
c191de4
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 21, 2024
ff14fb9
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 21, 2024
dd389c3
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 21, 2024
fc1c7bc
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 21, 2024
b037bd4
Update UI snapshots for `chromium` (1)
github-actions[bot] Oct 21, 2024
ff8b6da
Merge branch 'master' into add-teams-hog-template
daibhin Oct 21, 2024
e2fda2e
reset snapshots
daibhin Oct 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/services/microsoft-teams.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 @@ -27,6 +27,7 @@
from .activecampaign.template_activecampaign import template as activecampaign
from .google_ads.template_google_ads import template as google_ads
from .attio.template_attio import template as attio
from .microsoft_teams.template_microsoft_teams import template as microsoft_teams
from .google_cloud_storage.template_google_cloud_storage import (
template as google_cloud_storage,
TemplateGoogleCloudStorageMigrator,
Expand Down Expand Up @@ -56,6 +57,7 @@
mailjet_create_contact,
mailjet_update_contact_list,
meta_ads,
microsoft_teams,
posthog,
rudderstack,
salesforce_create,
Expand Down
62 changes: 62 additions & 0 deletions posthog/cdp/templates/microsoft_teams/template_microsoft_teams.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from posthog.cdp.templates.hog_function_template import HogFunctionTemplate, HogFunctionSubTemplate, SUB_TEMPLATE_COMMON

template: HogFunctionTemplate = HogFunctionTemplate(
status="beta",
MarconLP marked this conversation as resolved.
Show resolved Hide resolved
id="template-microsoft-teams",
name="Microsoft Teams",
description="Sends a message to a Microsoft Teams channel",
icon_url="/static/services/microsoft-teams.png",
category=["Customer Success"],
hog="""
let res := fetch(inputs.webhookUrl, {
'body': {
'text': inputs.content
},
'method': 'POST',
'headers': {
'Content-Type': 'application/json'
}
});

if (res.status >= 400) {
throw Error(f'Failed to post message to Microsoft Teams: {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://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook?tabs=newteams%2Cdotnet#create-an-incoming-webhook",
"secret": False,
"required": True,
},
{
"key": "content",
"type": "string",
"label": "Content",
"description": "(see https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook?tabs=newteams%2Cdotnet#example)",
"default": "**{person.name}** triggered event: '{event.event}'",
"secret": False,
"required": True,
},
],
sub_templates=[
HogFunctionSubTemplate(
id="early_access_feature_enrollment",
name="Post to Microsoft Teams on feature enrollment",
description="Posts a message to Microsoft Teams when a user enrolls or un-enrolls in an early access feature",
filters=SUB_TEMPLATE_COMMON["early_access_feature_enrollment"].filters,
inputs={
"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 Microsoft Teams on survey response",
description="Posts a message to Microsoft Teams when a user responds to a survey",
filters=SUB_TEMPLATE_COMMON["survey_response"].filters,
inputs={"content": "**{person.name}** responded to survey **{event.properties.$survey_name}**"},
),
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from inline_snapshot import snapshot
from posthog.cdp.templates.helpers import BaseHogFunctionTemplateTest
from posthog.cdp.templates.microsoft_teams.template_microsoft_teams import template as template_microsoft_teams


class TestTemplateMicrosoftTeams(BaseHogFunctionTemplateTest):
template = template_microsoft_teams

def _inputs(self, **kwargs):
inputs = {
"webhookUrl": "https://max.webhook.office.com/webhookb2/abcdefg@abcdefg/IncomingWebhook/abcdefg/abcdefg",
"content": "**[email protected]** triggered event: '$pageview'",
}
inputs.update(kwargs)
return inputs

def test_function_works(self):
self.run_function(inputs=self._inputs())

assert self.get_mock_fetch_calls()[0] == snapshot(
(
"https://max.webhook.office.com/webhookb2/abcdefg@abcdefg/IncomingWebhook/abcdefg/abcdefg",
{
"method": "POST",
"headers": {
"Content-Type": "application/json",
},
"body": {
"text": "**[email protected]** triggered event: '$pageview'",
},
},
)
)
Loading