Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(user-interviews): look up access token under call.assistantOverrides.metadata too (#58771)

Paul D'Ambra73519c317fe6
diff --git a/products/user_interviews/backend/test_interview_sharing.py b/products/user_interviews/backend/test_interview_sharing.py
index 5ee9cc547c37..8e85430f9aaa 100644
--- a/products/user_interviews/backend/test_interview_sharing.py
+++ b/products/user_interviews/backend/test_interview_sharing.py
@@ -568,15 +568,28 @@ class TestVapiWebhook(APIBaseTest):
)
return SharingConfiguration.objects.create(team=self.team, interviewee_context=ic, enabled=True)
- def _end_of_call_payload(self, access_token: str | None, call_id: str = "call_abc") -> dict:
+ def _end_of_call_payload(
+ self, access_token: str | None, call_id: str = "call_abc", metadata_path: str = "top"
+ ) -> dict:
+ # Vapi can surface our `assistant_overrides.metadata` either at `call.metadata`
+ # (top-level) or `call.assistantOverrides.metadata` (nested). The handler must
+ # find it in either path; parameterised tests cover both.
+ if metadata_path == "nested":
+ call: dict[str, Any] = {
+ "id": call_id,
+ "assistantOverrides": {"metadata": {"sharing_access_token": access_token}},
+ "duration": 120,
+ }
+ else:
+ call = {
+ "id": call_id,
+ "metadata": {"sharing_access_token": access_token},
+ "duration": 120,
+ }
return {
"message": {
"type": "end-of-call-report",
- "call": {
- "id": call_id,
- "metadata": {"sharing_access_token": access_token},
- "duration": 120,
- },
+ "call": call,
"transcript": "Hi! ...",
"summary": "User talked about replay.",
"recording": {"url": "https://vapi.example/recording.mp3"},
@@ -593,11 +606,15 @@ class TestVapiWebhook(APIBaseTest):
HTTP_X_VAPI_SIGNATURE=signature,
)
+ @parameterized.expand([("top",), ("nested",)])
@override_settings(VAPI_WEBHOOK_SECRET="topsecret")
- def test_webhook_creates_user_interview(self):
+ def test_webhook_creates_user_interview(self, metadata_path: str):
share = self._create_share()
self.client.logout()
- response = self._signed_post("topsecret", self._end_of_call_payload(share.access_token))
+ response = self._signed_post(
+ "topsecret",
+ self._end_of_call_payload(share.access_token, metadata_path=metadata_path),
+ )
self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.content)
interview = UserInterview.objects.get(team=self.team)
assert share.interviewee_context is not None
diff --git a/products/user_interviews/backend/webhooks.py b/products/user_interviews/backend/webhooks.py
index 6a8de04d5a07..96fe8f63c7f8 100644
--- a/products/user_interviews/backend/webhooks.py
+++ b/products/user_interviews/backend/webhooks.py
@@ -329,8 +329,18 @@ def vapi_webhook(request: Request) -> Response:
message: dict[str, Any] = payload.get("message", {})
message_type = message.get("type")
call: dict[str, Any] = message.get("call", {}) or {}
- metadata: dict[str, Any] = call.get("metadata", {}) or {}
- access_token = metadata.get("sharing_access_token") or metadata.get("access_token")
+ # Vapi can surface our `assistant_overrides.metadata` (set in `start_call`) in two
+ # places on the Call object: `call.metadata` for some message types, and nested under
+ # `call.assistantOverrides.metadata` on others. Empirically end-of-call-report comes
+ # through with the nested form, so try both.
+ overrides_metadata: dict[str, Any] = (call.get("assistantOverrides") or {}).get("metadata") or {}
+ top_metadata: dict[str, Any] = call.get("metadata") or {}
+ access_token = (
+ top_metadata.get("sharing_access_token")
+ or top_metadata.get("access_token")
+ or overrides_metadata.get("sharing_access_token")
+ or overrides_metadata.get("access_token")
+ )
call_id = call.get("id")
if message_type == "status-update":