diff --git a/assemblyai/__version__.py b/assemblyai/__version__.py index 3a7c7a2..d942e9e 100644 --- a/assemblyai/__version__.py +++ b/assemblyai/__version__.py @@ -1 +1 @@ -__version__ = "0.50.0" +__version__ = "0.51.0" 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..41681a4 100644 --- a/tests/unit/test_streaming.py +++ b/tests/unit/test_streaming.py @@ -170,3 +170,47 @@ def mocked_websocket_connect( assert client._write_queue.qsize() == 1 assert isinstance(client._write_queue.get(timeout=1), bytes) + + +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="my-secret", + ) + + client.connect(params) + + expected_params = { + "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_params)}" + assert actual_additional_headers["Authorization"] == "test" + assert actual_open_timeout == 15