Skip to content

Commit

Permalink
Merge pull request #31 from fixie-ai/ben-add-webhooks
Browse files Browse the repository at this point in the history
Ben add webhooks
  • Loading branch information
benlower authored Oct 17, 2024
2 parents 71789c1 + 17afc92 commit 6eaf2f5
Show file tree
Hide file tree
Showing 2 changed files with 513 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/src/content/codesnippets/webhooks-security.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import datetime
import hmac

request_timestamp = request.headers["X-Ultravox-Webhook-Timestamp"]
if datetime.datetime.now() - datetime.dateimte.fromisoformat(request_timestamp) > datetime.timedelta(minutes=1):
raise RuntimeError("Expired message")
expected_signature = hmac.new(WEBHOOK_SECRET.encode(), request.content + request_timestamp.encode(), "sha256").hexdigest()
for signature in request.headers["X-Ultravox-Webhook-Signature"].split(","):
if hmac.compare_digest(signature, expected_signature):
break # Valid signature
else:
raise RuntimeError("Message or timestamp was tampered with")
Loading

0 comments on commit 6eaf2f5

Please sign in to comment.