Handles incoming webhook events from Hume's Empathic Voice Interface.
(request: Request, event: WebhookEvent)
| 23 | |
| 24 | @app.post("/hume-webhook") |
| 25 | async def hume_webhook_handler(request: Request, event: WebhookEvent): |
| 26 | """Handles incoming webhook events from Hume's Empathic Voice Interface.""" |
| 27 | |
| 28 | # Get the raw request body |
| 29 | raw_payload = await request.body() |
| 30 | payload_str = raw_payload.decode("utf-8") |
| 31 | |
| 32 | # Validate HMAC signature and timestamp to ensure request authenticity |
| 33 | try: |
| 34 | validate_webhook_headers(payload_str, request.headers) |
| 35 | except ValueError as e: |
| 36 | raise HTTPException(status_code=401, detail=str(e)) |
| 37 | |
| 38 | if isinstance(event, WebhookEventChatStarted): |
| 39 | print(f"Processing chat_started event: {event.dict()}") |
| 40 | # Add additional chat_started processing logic here |
| 41 | |
| 42 | elif isinstance(event, WebhookEventChatEnded): |
| 43 | print(f"Processing chat_ended event: {event.dict()}") |
| 44 | # Fetch chat events, construct a transcript, and write it to a file |
| 45 | await get_chat_transcript(client, event.chat_id) |
| 46 | # Add additional chat_ended processing logic here |
| 47 | |
| 48 | elif isinstance(event, WebhookEventToolCall): |
| 49 | print(f"Processing tool_call event: {event.dict()}") |
| 50 | # Handle the specific tool call for fetching the current weather |
| 51 | await fetch_weather_tool(client, event.chat_id, event.tool_call_message) |
| 52 | # Add additional tool_call processing logic here |
| 53 | |
| 54 | |
| 55 | # Run the Uvicorn server |
nothing calls this directly
no test coverage detected