I'm attempting to set up a Webex bot for my team and I've done my best to follow along with every solution that seems viable, but everything gets stuck at a particular stumbling block; it has to work with our company's proxy.
I've been focusing on this bot by fbradyirl, as it seems like it will be the best for us to work with once we get it working. The problem is, it uses the Python Websockets library, which doesn't support using a proxy. I've looked into alternative libraries and found this Websocket-Client that seems like a good alternative which supports proxy. I've managed to find the specific part of the bot library which I need to change through some testing, but I'm not sure how to create code that performs the same function using Websocket-Client instead of Websockets. Here's the specific code in question [line 154]:(https://github.com/fbradyirl/webex_bot/blob/main/webex_bot/websockets/webex_websocket_client.py)
@backoff.on_exception(backoff.expo, websockets.ConnectionClosedError)
@backoff.on_exception(backoff.expo, websockets.ConnectionClosedOK)
@backoff.on_exception(backoff.expo, websockets.ConnectionClosed)
@backoff.on_exception(backoff.expo, socket.gaierror)
async def _connect_and_listen():
ws_url = self.device_info['webSocketUrl']
logger.info(f"Opening websocket connection to {ws_url}")
async with websockets.connect(ws_url, ssl=ssl_context) as _websocket:
self.websocket = _websocket
logger.info("WebSocket Opened.")
msg = {'id': str(uuid.uuid4()),
'type': 'authorization',
'data': {'token': 'Bearer ' + self.access_token}}
await self.websocket.send(json.dumps(msg))
while True:
await _websocket_recv()
try:
asyncio.get_event_loop().run_until_complete(_connect_and_listen())
except Exception as runException:
logger.error(f"runException: {runException}")
if self._get_device_info(check_existing=False) is None:
logger.error('could not create device info')
raise Exception("No WDM device info")
# trigger re-connect
asyncio.get_event_loop().run_until_complete(_connect_and_listen())
How can I convert the code in _connect_and_listen to use websocket-client instead of websockets? Or is there some other way I can make the Webex bot work with the proxy?