-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebhook_handler.py
More file actions
37 lines (26 loc) · 980 Bytes
/
webhook_handler.py
File metadata and controls
37 lines (26 loc) · 980 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""FastAPI webhook handler with signature verification."""
from fastapi import FastAPI, HTTPException, Request
from cueapi import verify_webhook
app = FastAPI()
WEBHOOK_SECRET = "whsec_your_secret" # From dashboard.cueapi.ai
@app.post("/webhook")
async def handle_cueapi_webhook(request: Request):
body = await request.body()
signature = request.headers.get("X-CueAPI-Signature", "")
timestamp = request.headers.get("X-CueAPI-Timestamp", "")
if not verify_webhook(
payload=body,
signature=signature,
timestamp=timestamp,
secret=WEBHOOK_SECRET,
):
raise HTTPException(status_code=401, detail="Invalid signature")
data = await request.json()
execution_id = data["execution_id"]
cue_name = data["name"]
payload = data["payload"]
print(f"Received execution {execution_id} for cue {cue_name}")
print(f"Payload: {payload}")
# Your agent logic here
# ...
return {"status": "ok"}