Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion seam/seam_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,40 @@


class SeamWebhook:
"""
A class to handle Seam webhook verification.

This class provides functionality to verify incoming webhook payloads
using the Svix library.
Comment thread
andrii-balitskyi marked this conversation as resolved.
Outdated
"""

def __init__(self, secret: str):
"""
Initialize the SeamWebhook instance.

Args:
secret (str): The secret key used for webhook verification.
Comment thread
andrii-balitskyi marked this conversation as resolved.
Outdated
"""
self._webhook = Webhook(secret)

def verify(self, payload: str, headers: Dict[str, str]) -> SeamEvent:
res = self._webhook.verify(payload, headers)
"""
Verify the incoming webhook payload and headers.

This method normalizes the headers, verifies the payload using the Svix
Webhook instance, and returns a SeamEvent object.

Args:
payload (str): The webhook payload as a string.
headers (Dict[str, str]): A dictionary of HTTP headers.

Returns:
SeamEvent: An instance of SeamEvent created from the verified payload.

Raises:
Any exceptions raised by the Svix Webhook.verify() method.
"""
normalized_headers = {k.lower(): v for k, v in headers.items()}
res = self._webhook.verify(payload, normalized_headers)

return SeamEvent.from_dict(res)