Skip to content

Commit

Permalink
support additional headers in external actions requester (#661)
Browse files Browse the repository at this point in the history
* support additional headers in external actions requester

* adds test for headers

* assert headers dont get overwritten
  • Loading branch information
ajar98 authored Jul 24, 2024
1 parent a971ebc commit eaafc1b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/streaming/action/test_external_actions_requester.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,13 @@ async def test_send_request_responses(
JSON_SCHEMA,
base64.b64encode(os.urandom(32)).decode(),
additional_payload_values={"call_id": "call_id"},
additional_headers={"x-vocode-test": "test"},
transport=httpx.AsyncHTTPTransport(retries=3, verify=True),
)

assert httpx_mock.get_request().headers["x-vocode-test"] == "test"
assert "x-vocode-signature" in httpx_mock.get_request().headers

assert response.success is expected_success


Expand Down
2 changes: 2 additions & 0 deletions vocode/streaming/action/external_actions_requester.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ async def send_request(
payload: Dict[str, Any],
signature_secret: str,
additional_payload_values: Dict[str, Any] = {},
additional_headers: Dict[str, str] = {},
transport: httpx.AsyncHTTPTransport = httpx.AsyncHTTPTransport(retries=2),
) -> ExternalActionResponse:
encoded_payload = json.dumps({"payload": payload} | additional_payload_values).encode(
Expand All @@ -62,6 +63,7 @@ async def send_request(
"Accept": "application/json",
"Content-Type": "application/json",
"x-vocode-signature": self._encode_payload(encoded_payload, signature_secret),
**additional_headers,
}

async with httpx.AsyncClient(
Expand Down

0 comments on commit eaafc1b

Please sign in to comment.