mirror of
https://github.com/PostHog/posthog.git
synced 2024-11-24 18:07:17 +01:00
Support all event properties in webhook message (#3629)
This commit is contained in:
parent
bf2c4429b5
commit
37b11ac20b
@ -90,16 +90,18 @@ class TestWebhookMessage(BaseTest):
|
||||
|
||||
def test_get_formatted_message(self) -> None:
|
||||
self.team.slack_incoming_webhook = "https://hooks.slack.com/services/"
|
||||
event1 = Event.objects.create(team=self.team, distinct_id="2", properties={"$browser": "Chrome"})
|
||||
event1 = Event.objects.create(
|
||||
team=self.team, distinct_id="2", properties={"$browser": "Chrome", "page_title": "Pricing"}
|
||||
)
|
||||
action1 = Action.objects.create(
|
||||
team=self.team,
|
||||
name="action1",
|
||||
id=1,
|
||||
slack_message_format="[user.name] did action from browser [user.browser]",
|
||||
slack_message_format="[user.name] from [user.browser] on [event.properties.page_title] page with [event.properties.fruit]",
|
||||
)
|
||||
|
||||
text, markdown = get_formatted_message(action1, event1, "https://localhost:8000")
|
||||
self.assertEqual(text, "2 did action from browser Chrome")
|
||||
self.assertEqual(text, "2 from Chrome on Pricing page with undefined")
|
||||
|
||||
def test_get_formatted_message_default(self) -> None:
|
||||
"""
|
||||
|
@ -1,3 +1,4 @@
|
||||
import json
|
||||
import re
|
||||
from typing import Tuple
|
||||
|
||||
@ -57,6 +58,14 @@ def get_value_of_token(action: Action, event: Event, site_url: str, token_parts:
|
||||
elif token_parts[0] == "event":
|
||||
if token_parts[1] == "name":
|
||||
text = markdown = event.event
|
||||
elif token_parts[1] == "properties" and len(token_parts) > 2:
|
||||
property_name = token_parts[2]
|
||||
if property_name in event.properties:
|
||||
property = event.properties[property_name]
|
||||
text = markdown = property if isinstance(property, str) else json.dumps(property)
|
||||
else:
|
||||
text = markdown = "undefined"
|
||||
|
||||
else:
|
||||
raise ValueError
|
||||
return text, markdown
|
||||
|
Loading…
Reference in New Issue
Block a user