Skip to content

Commit

Permalink
remove migrator
Browse files Browse the repository at this point in the history
  • Loading branch information
MarconLP committed Jan 2, 2025
1 parent 0909084 commit cdf0c30
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 131 deletions.
48 changes: 1 addition & 47 deletions posthog/cdp/templates/intercom/template_intercom.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from copy import deepcopy
import dataclasses
from posthog.cdp.templates.hog_function_template import HogFunctionTemplate, HogFunctionTemplateMigrator
from posthog.cdp.templates.hog_function_template import HogFunctionTemplate

template: HogFunctionTemplate = HogFunctionTemplate(
status="beta",
Expand Down Expand Up @@ -287,47 +285,3 @@
"filter_test_accounts": True,
},
)


class TemplateIntercomMigrator(HogFunctionTemplateMigrator):
plugin_url = "https://github.com/PostHog/posthog-intercom-plugin"

@classmethod
def migrate(cls, obj):
hf = deepcopy(dataclasses.asdict(template))

useEuropeanDataStorage = obj.config.get("useEuropeanDataStorage", "No")
intercomApiKey = obj.config.get("intercomApiKey", "")
triggeringEvents = obj.config.get("triggeringEvents", "$identify")
ignoredEmailDomains = obj.config.get("ignoredEmailDomains", "")

hf["filters"] = {}

events_to_filter = [event.strip() for event in triggeringEvents.split(",") if event.strip()]
domains_to_filter = [domain.strip() for domain in ignoredEmailDomains.split(",") if domain.strip()]

if domains_to_filter:
hf["filters"]["properties"] = [
{
"key": "email",
"value": domain,
"operator": "not_icontains",
"type": "person",
}
for domain in domains_to_filter
]

if events_to_filter:
hf["filters"]["events"] = [
{"id": event, "name": event, "type": "events", "order": 0} for event in events_to_filter
]

hf["inputs"] = {
"access_token": {"value": intercomApiKey},
"host": {"value": "api.eu.intercom.com"}
if useEuropeanDataStorage == "Yes"
else {"value": "api.intercom.io"},
"email": {"value": "{person.properties.email}"},
}

return hf
85 changes: 1 addition & 84 deletions posthog/cdp/templates/intercom/test_template_intercom.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import pytest
from inline_snapshot import snapshot
from posthog.cdp.templates.helpers import BaseHogFunctionTemplateTest
from posthog.cdp.templates.intercom.template_intercom import template as template_intercom, TemplateIntercomMigrator
from posthog.models.plugin import PluginConfig
from posthog.test.base import BaseTest
from posthog.cdp.templates.intercom.template_intercom import template as template_intercom


class TestTemplateIntercom(BaseHogFunctionTemplateTest):
Expand Down Expand Up @@ -76,83 +73,3 @@ def test_logs_other_errors(self):
e.value.message # type: ignore[attr-defined]
== "Error from intercom api (status 400): {'type': 'error.list', 'request_id': '001dh0h1qb205el244gg', 'errors': [{'code': 'error', 'message': 'Other error'}]}"
)


class TestTemplateMigration(BaseTest):
def get_plugin_config(self, config: dict):
_config = {
"intercomApiKey": "INTERCOM_API_KEY",
"triggeringEvents": "$identify",
"ignoredEmailDomains": "",
"useEuropeanDataStorage": "No",
}

_config.update(config)
return PluginConfig(enabled=True, order=0, config=_config)

def test_full_function(self):
obj = self.get_plugin_config({})

template = TemplateIntercomMigrator.migrate(obj)
assert template["inputs"] == snapshot(
{
"access_token": {"value": "INTERCOM_API_KEY"},
"host": {"value": "api.intercom.io"},
"email": {"value": "{person.properties.email}"},
}
)
assert template["filters"] == snapshot(
{"events": [{"id": "$identify", "name": "$identify", "type": "events", "order": 0}]}
)

def test_eu_host(self):
obj = self.get_plugin_config(
{
"useEuropeanDataStorage": "Yes",
}
)

template = TemplateIntercomMigrator.migrate(obj)
assert template["inputs"] == snapshot(
{
"access_token": {"value": "INTERCOM_API_KEY"},
"host": {"value": "api.eu.intercom.com"},
"email": {"value": "{person.properties.email}"},
}
)

def test_triggering_events(self):
obj = self.get_plugin_config(
{
"triggeringEvents": "$identify,$pageview, custom event, ",
}
)

template = TemplateIntercomMigrator.migrate(obj)
assert template["filters"] == snapshot(
{
"events": [
{"id": "$identify", "name": "$identify", "type": "events", "order": 0},
{"id": "$pageview", "name": "$pageview", "type": "events", "order": 0},
{"id": "custom event", "name": "custom event", "type": "events", "order": 0},
]
}
)

def test_ignore_domains(self):
obj = self.get_plugin_config(
{
"ignoredEmailDomains": "test.com, other.com, ",
}
)

template = TemplateIntercomMigrator.migrate(obj)
assert template["filters"] == snapshot(
{
"properties": [
{"key": "email", "value": "test.com", "operator": "not_icontains", "type": "person"},
{"key": "email", "value": "other.com", "operator": "not_icontains", "type": "person"},
],
"events": [{"id": "$identify", "name": "$identify", "type": "events", "order": 0}],
}
)

0 comments on commit cdf0c30

Please sign in to comment.