Skip to content

Commit

Permalink
FS-492 pass token in request header (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
aksharesh-symbl authored Sep 4, 2024
1 parent 541ba3a commit 24480b4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

setup(
name="symbl",
version="2.0.5",
version="2.0.6",
description="symbl.ai SDK",
author_email="[email protected]",
url="",
Expand Down
2 changes: 1 addition & 1 deletion symbl/configs/configs.py
Original file line number Diff line number Diff line change
@@ -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={}"
SYMBL_STREAMING_API_FORMAT = "wss://api.symbl.ai/v1/realtime/insights/{}?source=python_sdk"
5 changes: 3 additions & 2 deletions symbl/streaming_api/StreamingApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions symbl/streaming_api/StreamingConnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 24480b4

Please sign in to comment.