From 549649c9729c665b2101356a43c17b1de15c0172 Mon Sep 17 00:00:00 2001 From: Dylan Duan Date: Tue, 10 Feb 2026 17:41:10 -0500 Subject: [PATCH] feat: add webhook support to streaming parameters --- assemblyai/streaming/v3/models.py | 3 +++ tests/unit/test_streaming.py | 44 +++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/assemblyai/streaming/v3/models.py b/assemblyai/streaming/v3/models.py index 00b0eec..bce64f2 100644 --- a/assemblyai/streaming/v3/models.py +++ b/assemblyai/streaming/v3/models.py @@ -89,6 +89,9 @@ class StreamingParameters(StreamingSessionParameters): speech_model: Optional[SpeechModel] = None language_detection: Optional[bool] = None inactivity_timeout: Optional[int] = None + webhook_url: Optional[str] = None + webhook_auth_header_name: Optional[str] = None + webhook_auth_header_value: Optional[str] = None class UpdateConfiguration(StreamingSessionParameters): diff --git a/tests/unit/test_streaming.py b/tests/unit/test_streaming.py index af04db9..e6a2729 100644 --- a/tests/unit/test_streaming.py +++ b/tests/unit/test_streaming.py @@ -141,6 +141,50 @@ def mocked_websocket_connect( assert actual_open_timeout == 15 +def test_client_connect_with_webhook(mocker: MockFixture): + actual_url = None + actual_additional_headers = None + actual_open_timeout = None + + def mocked_websocket_connect( + url: str, additional_headers: dict, open_timeout: float + ): + nonlocal actual_url, actual_additional_headers, actual_open_timeout + actual_url = url + actual_additional_headers = additional_headers + actual_open_timeout = open_timeout + + mocker.patch( + "assemblyai.streaming.v3.client.websocket_connect", + new=mocked_websocket_connect, + ) + + _disable_rw_threads(mocker) + + options = StreamingClientOptions(api_key="test", api_host="api.example.com") + client = StreamingClient(options) + + params = StreamingParameters( + sample_rate=16000, + webhook_url="https://example.com/webhook", + webhook_auth_header_name="X-Webhook-Secret", + webhook_auth_header_value="secret-value", + ) + + client.connect(params) + + expected_headers = { + "sample_rate": params.sample_rate, + "webhook_url": params.webhook_url, + "webhook_auth_header_name": params.webhook_auth_header_name, + "webhook_auth_header_value": params.webhook_auth_header_value, + } + + assert actual_url == f"wss://api.example.com/v3/ws?{urlencode(expected_headers)}" + assert actual_additional_headers["Authorization"] == "test" + assert actual_open_timeout == 15 + + def test_client_send_audio(mocker: MockFixture): actual_url = None actual_additional_headers = None