feat: return parsed payload from Webhooks.verify#242
Open
mayankbohradev wants to merge 1 commit into
Open
Conversation
Align verify with the documented Node SDK contract and add TypedDicts for webhook event payloads, including message_id on email events.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Webhooks.verifynow returns the parsed webhook event after a successful HMAC check, matching the documented contract and the Node SDK.Also adds TypedDicts for webhook event payloads (
WebhookEventPayloadand per-event types), includingmessage_idon email eventdataper the current webhook docs.Why
Docs say verify should throw on invalid webhooks and otherwise return the parsed payload:
https://resend.com/docs/webhooks/verify-webhooks-requests
The Node SDK already does this (
verify(...): WebhookEventPayload). Python returnedNone, so callers had tojson.loadsthe raw body again (see the previousexamples/webhook_receiver.pyflow).Outbound email webhook docs also include
data.message_id(for example https://resend.com/docs/webhooks/emails/sent). Retrieve/list already exposemessage_idonEmail(#232); webhook payload types did not.Behavior notes
ValueError.ValueError(failed to parse webhook payload), instead of returningNone.bounce.subTypeandclick.ipAddressmatch the API payload shape.Testing
Local gate (same checks CI runs):
tox -e lint— passtox -e mypy— pass (167 source files)tox -e py -- tests/webhooks_test.py— 16 passedtox -e py— 491 passedNew / updated coverage:
email.sentpayload includingmessage_idemail.receivedpayload includingmessage_id/received_forSummary by cubic
Make
Webhooks.verifyreturn the parsed webhook event after signature checks, matching the docs and the Node SDK. Adds TypedDicts for all webhook payloads, includingdata.message_idon email events.New Features
Webhooks.verifyreturnsWebhookEventPayloadon success; raisesValueErrorwhen the body is not valid JSON.WebhookEventPayloadand per-event TypedDicts; exported inresend.examples/webhook_receiver.pyand tests to use the returned payload. TypedDicts mirror API field names (camelCase).Migration
json.loadson the body.ValueErrorfor valid signatures with non-JSON bodies.Written for commit 30e078b. Summary will update on new commits.