Skip to content

Commit 7b679dc

Browse files
committed
feat: add webhook event type
1 parent 7b71963 commit 7b679dc

5 files changed

Lines changed: 31 additions & 12 deletions

File tree

examples/receiving_email.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import os
22

33
import resend
4-
54
# Type imports
65
from resend import AttachmentsReceiving, EmailsReceiving
76

examples/webhooks.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
from typing import List
33

44
import resend
5+
from resend.webhooks import WebhookEvent
56

67
if not os.environ["RESEND_API_KEY"]:
78
raise EnvironmentError("RESEND_API_KEY is missing")
89

10+
events: List[WebhookEvent] = ["email.sent", "email.delivered", "email.bounced"]
911

1012
create_params: resend.Webhooks.CreateParams = {
1113
"endpoint": "https://webhook.example.com/handler",
12-
"events": ["email.sent", "email.delivered", "email.bounced"],
14+
"events": events,
1315
}
1416
webhook: resend.Webhooks.CreateWebhookResponse = resend.Webhooks.create(
1517
params=create_params

resend/webhooks/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from resend.webhooks._webhook import Webhook
1+
from resend.webhooks._webhook import Webhook, WebhookEvent, WebhookStatus
22
from resend.webhooks._webhooks import Webhooks
33

4-
__all__ = ["Webhook", "Webhooks"]
4+
__all__ = ["Webhook", "WebhookEvent", "WebhookStatus", "Webhooks"]

resend/webhooks/_webhook.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,27 @@
44

55
WebhookStatus = Literal["enabled", "disabled"]
66

7+
WebhookEvent = Literal[
8+
# Email events
9+
"email.sent",
10+
"email.delivered",
11+
"email.delivery_delayed",
12+
"email.complained",
13+
"email.bounced",
14+
"email.opened",
15+
"email.clicked",
16+
"email.received",
17+
"email.failed",
18+
# Contact events
19+
"contact.created",
20+
"contact.updated",
21+
"contact.deleted",
22+
# Domain events
23+
"domain.created",
24+
"domain.updated",
25+
"domain.deleted",
26+
]
27+
728

829
class Webhook(TypedDict):
930
"""
@@ -39,7 +60,7 @@ class Webhook(TypedDict):
3960
"""
4061
The URL where webhook events will be sent
4162
"""
42-
events: List[str]
63+
events: List[WebhookEvent]
4364
"""
4465
Array of event types to subscribe to
4566
"""

resend/webhooks/_webhooks.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from resend import request
66
from resend.pagination_helper import PaginationHelper
7-
from resend.webhooks._webhook import Webhook, WebhookStatus
7+
from resend.webhooks._webhook import Webhook, WebhookEvent, WebhookStatus
88

99

1010
class Webhooks:
@@ -78,7 +78,7 @@ class CreateParams(TypedDict):
7878
"""
7979
The URL where webhook events will be sent.
8080
"""
81-
events: List[str]
81+
events: List[WebhookEvent]
8282
"""
8383
Array of event types to subscribe to.
8484
See https://resend.com/docs/dashboard/webhooks/event-types for available options.
@@ -93,7 +93,7 @@ class UpdateParams(TypedDict):
9393
"""
9494
The URL where webhook events will be sent.
9595
"""
96-
events: NotRequired[List[str]]
96+
events: NotRequired[List[WebhookEvent]]
9797
"""
9898
Array of event types to subscribe to.
9999
"""
@@ -200,11 +200,8 @@ def update(cls, params: UpdateParams) -> UpdateWebhookResponse:
200200
webhook_id = params["webhook_id"]
201201
path = f"/webhooks/{webhook_id}"
202202

203-
# Remove webhook_id from params before sending to API
204-
update_payload = {k: v for k, v in params.items() if k != "webhook_id"}
205-
206203
resp = request.Request[Webhooks.UpdateWebhookResponse](
207-
path=path, params=cast(Dict[Any, Any], update_payload), verb="patch"
204+
path=path, params=cast(Dict[Any, Any], params), verb="patch"
208205
).perform_with_content()
209206
return resp
210207

0 commit comments

Comments
 (0)