Skip to content

Commit 5365f6a

Browse files
kraju3AaronDDM
andauthored
Add webhook triggers to bypass ValueErrors (#406)
* Add webhook triggers to bypass ValueErrors * Add deserialization test for all triggers --------- Co-authored-by: Aaron de Mello <314152+AaronDDM@users.noreply.github.com>
1 parent e5e109d commit 5365f6a

File tree

2 files changed

+78
-1
lines changed

2 files changed

+78
-1
lines changed

nylas/models/webhooks.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,16 @@
1111

1212
class WebhookTriggers(str, Enum):
1313
"""Enum representing the available webhook triggers."""
14-
14+
BOOKING_CREATED = "booking.created"
15+
BOOKING_PENDING = "booking.pending"
16+
BOOKING_RESCHEDULED = "booking.rescheduled"
17+
BOOKING_CANCELLED = "booking.cancelled"
18+
BOOKING_REMINDER = "booking.reminder"
1519
CALENDAR_CREATED = "calendar.created"
1620
CALENDAR_UPDATED = "calendar.updated"
1721
CALENDAR_DELETED = "calendar.deleted"
22+
CONTACT_UPDATED = "contact.updated"
23+
CONTACT_DELETED = "contact.deleted"
1824
EVENT_CREATED = "event.created"
1925
EVENT_UPDATED = "event.updated"
2026
EVENT_DELETED = "event.deleted"
@@ -29,7 +35,13 @@ class WebhookTriggers(str, Enum):
2935
MESSAGE_UPDATED = "message.updated"
3036
MESSAGE_OPENED = "message.opened"
3137
MESSAGE_LINK_CLICKED = "message.link_clicked"
38+
MESSAGE_OPENED_LEGACY = "message.opened.legacy"
39+
MESSAGE_LINK_CLICKED_LEGACY = "message.link_clicked.legacy"
40+
MESSAGE_INTELLIGENCE_ORDER = "message.intelligence.order"
41+
MESSAGE_INTELLIGENCE_TRACKING = "message.intelligence.tracking"
42+
MESSAGE_INTELLIGENCE_RETURN = "message.intelligence.return"
3243
THREAD_REPLIED = "thread.replied"
44+
THREAD_REPLIED_LEGACY = "thread.replied.legacy"
3345
FOLDER_CREATED = "folder.created"
3446
FOLDER_UPDATED = "folder.updated"
3547
FOLDER_DELETED = "folder.deleted"

tests/resources/test_webhooks.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,71 @@ def test_webhook_deserialization(self, http_client):
3333
assert webhook.created_at == 1234567890
3434
assert webhook.updated_at == 1234567890
3535

36+
def test_webhook_deserialization_all(self, http_client):
37+
trigger_types = [
38+
"booking.created",
39+
"booking.pending",
40+
"booking.rescheduled",
41+
"booking.cancelled",
42+
"booking.reminder",
43+
"calendar.created",
44+
"calendar.updated",
45+
"calendar.deleted",
46+
"contact.updated",
47+
"contact.deleted",
48+
"event.created",
49+
"event.updated",
50+
"event.deleted",
51+
"grant.created",
52+
"grant.updated",
53+
"grant.deleted",
54+
"grant.expired",
55+
"message.send_success",
56+
"message.send_failed",
57+
"message.bounce_detected",
58+
"message.created",
59+
"message.updated",
60+
"message.opened",
61+
"message.link_clicked",
62+
"message.opened.legacy",
63+
"message.link_clicked.legacy",
64+
"message.intelligence.order",
65+
"message.intelligence.tracking",
66+
"message.intelligence.return",
67+
"thread.replied",
68+
"thread.replied.legacy",
69+
"folder.created",
70+
"folder.updated",
71+
"folder.deleted"
72+
]
73+
74+
webhook_json = {
75+
"id": "UMWjAjMeWQ4D8gYF2moonK4486",
76+
"description": "Production webhook destination",
77+
"trigger_types": trigger_types,
78+
"webhook_url": "https://example.com/webhooks",
79+
"status": "active",
80+
"notification_email_addresses": ["jane@example.com", "joe@example.com"],
81+
"status_updated_at": 1234567890,
82+
"created_at": 1234567890,
83+
"updated_at": 1234567890,
84+
}
85+
86+
webhook = Webhook.from_dict(webhook_json)
87+
88+
assert webhook.id == "UMWjAjMeWQ4D8gYF2moonK4486"
89+
assert webhook.description == "Production webhook destination"
90+
assert webhook.trigger_types == trigger_types
91+
assert webhook.webhook_url == "https://example.com/webhooks"
92+
assert webhook.status == "active"
93+
assert webhook.notification_email_addresses == [
94+
"jane@example.com",
95+
"joe@example.com",
96+
]
97+
assert webhook.status_updated_at == 1234567890
98+
assert webhook.created_at == 1234567890
99+
assert webhook.updated_at == 1234567890
100+
36101
def test_list_webhooks(self, http_client_list_response):
37102
webhooks = Webhooks(http_client_list_response)
38103

0 commit comments

Comments
 (0)