Skip to content

Commit f1340f2

Browse files
authored
chore: sync sdk code with DeepLearning repo (#167)
1 parent b4a08fb commit f1340f2

3 files changed

Lines changed: 48 additions & 1 deletion

File tree

assemblyai/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.50.0"
1+
__version__ = "0.51.0"

assemblyai/streaming/v3/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ class StreamingParameters(StreamingSessionParameters):
8989
speech_model: Optional[SpeechModel] = None
9090
language_detection: Optional[bool] = None
9191
inactivity_timeout: Optional[int] = None
92+
webhook_url: Optional[str] = None
93+
webhook_auth_header_name: Optional[str] = None
94+
webhook_auth_header_value: Optional[str] = None
9295

9396

9497
class UpdateConfiguration(StreamingSessionParameters):

tests/unit/test_streaming.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,47 @@ def mocked_websocket_connect(
170170

171171
assert client._write_queue.qsize() == 1
172172
assert isinstance(client._write_queue.get(timeout=1), bytes)
173+
174+
175+
def test_client_connect_with_webhook(mocker: MockFixture):
176+
actual_url = None
177+
actual_additional_headers = None
178+
actual_open_timeout = None
179+
180+
def mocked_websocket_connect(
181+
url: str, additional_headers: dict, open_timeout: float
182+
):
183+
nonlocal actual_url, actual_additional_headers, actual_open_timeout
184+
actual_url = url
185+
actual_additional_headers = additional_headers
186+
actual_open_timeout = open_timeout
187+
188+
mocker.patch(
189+
"assemblyai.streaming.v3.client.websocket_connect",
190+
new=mocked_websocket_connect,
191+
)
192+
193+
_disable_rw_threads(mocker)
194+
195+
options = StreamingClientOptions(api_key="test", api_host="api.example.com")
196+
client = StreamingClient(options)
197+
198+
params = StreamingParameters(
199+
sample_rate=16000,
200+
webhook_url="https://example.com/webhook",
201+
webhook_auth_header_name="X-Webhook-Secret",
202+
webhook_auth_header_value="my-secret",
203+
)
204+
205+
client.connect(params)
206+
207+
expected_params = {
208+
"sample_rate": params.sample_rate,
209+
"webhook_url": params.webhook_url,
210+
"webhook_auth_header_name": params.webhook_auth_header_name,
211+
"webhook_auth_header_value": params.webhook_auth_header_value,
212+
}
213+
214+
assert actual_url == f"wss://api.example.com/v3/ws?{urlencode(expected_params)}"
215+
assert actual_additional_headers["Authorization"] == "test"
216+
assert actual_open_timeout == 15

0 commit comments

Comments
 (0)