Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assemblyai/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.50.0"
__version__ = "0.51.0"
3 changes: 3 additions & 0 deletions assemblyai/streaming/v3/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
44 changes: 44 additions & 0 deletions tests/unit/test_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -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