From 176a59a9cf905041e82994a445df03b32e0a5f7b Mon Sep 17 00:00:00 2001 From: aksharesh Date: Wed, 4 Sep 2024 12:40:14 +0530 Subject: [PATCH] FS-492 pass token in request header --- setup.py | 2 +- symbl/configs/configs.py | 2 +- symbl/streaming_api/StreamingApi.py | 5 +++-- symbl/streaming_api/StreamingConnection.py | 5 +++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index 74e4b6a..17bd25b 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ setup( name="symbl", - version="2.0.5", + version="2.0.6", description="symbl.ai SDK", author_email="info@symbl.ai", url="", diff --git a/symbl/configs/configs.py b/symbl/configs/configs.py index 39df36b..996b3d7 100644 --- a/symbl/configs/configs.py +++ b/symbl/configs/configs.py @@ -1,3 +1,3 @@ X_API_KEY_HEADER = "x-api-key" SYMBL_WEBSOCKET_BASE_PATH = "wss://api.symbl.ai/session/subscribe/" -SYMBL_STREAMING_API_FORMAT = "wss://api.symbl.ai/v1/realtime/insights/{}?access_token={}" \ No newline at end of file +SYMBL_STREAMING_API_FORMAT = "wss://api.symbl.ai/v1/realtime/insights/{}?source=python_sdk" \ No newline at end of file diff --git a/symbl/streaming_api/StreamingApi.py b/symbl/streaming_api/StreamingApi.py index 60ed47a..6b2a194 100644 --- a/symbl/streaming_api/StreamingApi.py +++ b/symbl/streaming_api/StreamingApi.py @@ -18,7 +18,8 @@ def __init__(self): def start_connection(self, credentials=None, speaker=None, insight_types=None, config={},trackers=None): randomId = bytes(''.join(random.choices(string.ascii_uppercase +string.digits, k=12)), 'utf-8') id = base64.b64encode(randomId).decode("utf-8") - url = SYMBL_STREAMING_API_FORMAT.format(id, get_access_token(credentials=credentials)) + token = get_access_token(credentials=credentials) + url = SYMBL_STREAMING_API_FORMAT.format(id) if type(config) != dict: raise TypeError("config should be of type dict") @@ -47,7 +48,7 @@ def start_connection(self, credentials=None, speaker=None, insight_types=None, c "config": merged_config } - return StreamingConnection(url= url, connectionId=id, start_request=start_request) + return StreamingConnection(url= url, connectionId=id, start_request=start_request, token=token) def stop_listening(self, url: str): connection = websocket.WebSocketApp(url=url) diff --git a/symbl/streaming_api/StreamingConnection.py b/symbl/streaming_api/StreamingConnection.py index b7370fb..09fcdac 100644 --- a/symbl/streaming_api/StreamingConnection.py +++ b/symbl/streaming_api/StreamingConnection.py @@ -9,20 +9,21 @@ class StreamingConnection(): - def __init__(self, url: str, connectionId: str, start_request: dict): + def __init__(self, url: str, connectionId: str, start_request: dict, token: str): self.conversation = Conversation(None) self.connectionId = connectionId self.url = url self.event_callbacks = {} self.start_request = start_request self.connection = None + self.token = token self.__connect() def __connect(self): if self.connection == None: - self.connection = websocket.WebSocketApp(url=self.url, on_message=lambda this, data: self.__listen_to_events(data), on_error=lambda error: Log.getInstance().error(error)) + self.connection = websocket.WebSocketApp(url=self.url, on_message=lambda this, data: self.__listen_to_events(data), on_error=lambda error: Log.getInstance().error(error), header={'x-api-key': self.token}) Thread.getInstance().start_on_thread(target=self.connection.run_forever) conn_timeout = 5