-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrigger_webhook.py
More file actions
37 lines (30 loc) · 1.09 KB
/
Copy pathtrigger_webhook.py
File metadata and controls
37 lines (30 loc) · 1.09 KB
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
import urllib.parse
from uuid import uuid4
import os, json, hmac, hashlib, httpx, asyncio
from dotenv import load_dotenv
load_dotenv(".env")
# Must match test user exactly
sender_id = "3b691c11-2fb8-431b-85d3-b58092f3b932"
message_id = str(uuid4())
payload = {
"sender_id": sender_id,
"message_id": message_id,
"text": "Find me the latest email that mentions Apple",
"history": []
}
body_bytes = json.dumps(payload, separators=(',', ':')).encode('utf-8')
secret = os.environ.get("WEBHOOK_SECRET", "").encode('utf-8')
signature = hmac.new(secret, body_bytes, hashlib.sha256).hexdigest()
print(f"Sending webhook with signature: {signature}")
# Send the request natively to avoid bash escaping issues
# Using httpx since we know it's installed
async def main():
async with httpx.AsyncClient() as client:
resp = await client.post(
"http://localhost:5001/webhook",
json=payload,
headers={"x-agent-signature": signature, "x-user-id": sender_id}
)
print(f"Status: {resp.status_code}")
print(f"Body: {resp.text}")
asyncio.run(main())