webex-bot 0.5.0__py2.py3-none-any.whl → 0.5.1__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
webex_bot/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
1
  """Top-level package for Webex Bot."""
2
2
 
3
3
  __author__ = """Finbarr Brady"""
4
- __version__ = '0.5.0'
4
+ __version__ = '0.5.1'
webex_bot/webex_bot.py CHANGED
@@ -31,7 +31,8 @@ class WebexBot(WebexWebsocketClient):
31
31
  bot_help_subtitle="Here are my available commands. Click one to begin.",
32
32
  threads=True,
33
33
  help_command=None,
34
- log_level="INFO"):
34
+ log_level="INFO",
35
+ proxies=None):
35
36
  """
36
37
  Initialise WebexBot.
37
38
 
@@ -46,7 +47,7 @@ class WebexBot(WebexWebsocketClient):
46
47
  @param threads: If True, respond to msg by creating a thread.
47
48
  @param help_command: If None, use internal HelpCommand, otherwise override.
48
49
  @param log_level: Set loggin level.
49
-
50
+ @param proxies: Dictionary of proxies for connections.
50
51
  """
51
52
 
52
53
  coloredlogs.install(level=os.getenv("LOG_LEVEL", log_level),
@@ -58,7 +59,8 @@ class WebexBot(WebexWebsocketClient):
58
59
  teams_bot_token,
59
60
  on_message=self.process_incoming_message,
60
61
  on_card_action=self.process_incoming_card_action,
61
- device_url=device_url)
62
+ device_url=device_url,
63
+ proxies=proxies)
62
64
 
63
65
  if help_command is None:
64
66
  self.help_command = HelpCommand(
@@ -11,6 +11,12 @@ import requests
11
11
  import websockets
12
12
  from webexteamssdk import WebexTeamsAPI
13
13
 
14
+ try:
15
+ from websockets_proxy import Proxy, proxy_connect
16
+ except ImportError:
17
+ Proxy = None
18
+ proxy_connect = None
19
+
14
20
  logger = logging.getLogger(__name__)
15
21
 
16
22
  DEFAULT_DEVICE_URL = "https://wdm-a.wbx2.com/wdm/api/v1"
@@ -36,16 +42,23 @@ class WebexWebsocketClient(object):
36
42
  access_token,
37
43
  device_url=DEFAULT_DEVICE_URL,
38
44
  on_message=None,
39
- on_card_action=None):
45
+ on_card_action=None,
46
+ proxies=None):
40
47
  self.access_token = access_token
41
- self.teams = WebexTeamsAPI(access_token=access_token)
48
+ self.teams = WebexTeamsAPI(access_token=access_token, proxies=proxies)
42
49
  self.device_url = device_url
43
50
  self.device_info = None
44
51
  self.on_message = on_message
45
52
  self.on_card_action = on_card_action
53
+ self.proxies = proxies
46
54
  self.websocket = None
47
55
  self.share_id = None
48
56
 
57
+ if self.proxies:
58
+ # Connecting through a proxy
59
+ if proxy_connect is None:
60
+ raise ImportError("Failed to load libraries for proxy, maybe forgot [proxy] option during installation.")
61
+
49
62
  def _process_incoming_websocket_message(self, msg):
50
63
  """
51
64
  Handle websocket data.
@@ -124,7 +137,8 @@ class WebexWebsocketClient(object):
124
137
  f"{verb}/{activity_id}")
125
138
  headers = {"Authorization": f"Bearer {self.access_token}"}
126
139
  conversation_message = requests.get(conversation_message_url,
127
- headers=headers).json()
140
+ headers=headers,
141
+ proxies=self.proxies).json()
128
142
  logger.debug(f"conversation_message={conversation_message}")
129
143
  return conversation_message['id']
130
144
 
@@ -197,7 +211,20 @@ class WebexWebsocketClient(object):
197
211
  async def _connect_and_listen():
198
212
  ws_url = self.device_info['webSocketUrl']
199
213
  logger.info(f"Opening websocket connection to {ws_url}")
200
- async with websockets.connect(ws_url, ssl=ssl_context) as _websocket:
214
+
215
+ if self.proxies and "wss" in self.proxies:
216
+ logger.info(f"Using proxy for websocket connection: {self.proxies['wss']}")
217
+ proxy = Proxy.from_url(self.proxies["wss"])
218
+ connect = proxy_connect(ws_url, ssl=ssl_context, proxy=proxy)
219
+ elif self.proxies and "https" in self.proxies:
220
+ logger.info(f"Using proxy for websocket connection: {self.proxies['https']}")
221
+ proxy = Proxy.from_url(self.proxies["https"])
222
+ connect = proxy_connect(ws_url, ssl=ssl_context, proxy=proxy)
223
+ else:
224
+ logger.debug(f"Not using proxy for websocket connection.")
225
+ connect = websockets.connect(ws_url, ssl=ssl_context)
226
+
227
+ async with connect as _websocket:
201
228
  self.websocket = _websocket
202
229
  logger.info("WebSocket Opened.")
203
230
  msg = {'id': str(uuid.uuid4()),
@@ -216,4 +243,4 @@ class WebexWebsocketClient(object):
216
243
  logger.error('could not create device info')
217
244
  raise Exception("No WDM device info")
218
245
  # trigger re-connect
219
- asyncio.get_event_loop().run_until_complete(_connect_and_listen())
246
+ asyncio.get_event_loop().run_until_complete(_connect_and_listen())
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: webex-bot
3
- Version: 0.5.0
3
+ Version: 0.5.1
4
4
  Summary: Python package for a Webex Bot based on websockets.
5
5
  Home-page: https://github.com/fbradyirl/webex_bot
6
6
  Author: Finbarr Brady
@@ -21,6 +21,8 @@ Requires-Dist: webexteamssdk ==1.6.1
21
21
  Requires-Dist: coloredlogs
22
22
  Requires-Dist: websockets ==11.0.3
23
23
  Requires-Dist: backoff
24
+ Provides-Extra: proxy
25
+ Requires-Dist: websockets-proxy >=0.1.1 ; extra == 'proxy'
24
26
 
25
27
  # Introduction
26
28
 
@@ -57,6 +59,10 @@ You can find a sample project, using OpenAI/ChatGPT with this library here: http
57
59
 
58
60
  `pip install webex_bot`
59
61
 
62
+ If you need optional proxy support, use this command instead:
63
+
64
+ `pip install webex_bot[proxy]`
65
+
60
66
  2. On the Webex Developer portal, create a new [bot token][3] and expose it as an environment variable.
61
67
 
62
68
  ```sh
@@ -75,11 +81,19 @@ import os
75
81
  from webex_bot.commands.echo import EchoCommand
76
82
  from webex_bot.webex_bot import WebexBot
77
83
 
84
+ # (Optional) Proxy configuration
85
+ # Supports https or wss proxy, wss prioritized.
86
+ proxies = {
87
+ 'https': 'http://proxy.esl.example.com:80',
88
+ 'wss': 'socks5://proxy.esl.example.com:1080'
89
+ }
90
+
78
91
  # Create a Bot Object
79
92
  bot = WebexBot(teams_bot_token=os.getenv("WEBEX_TEAMS_ACCESS_TOKEN"),
80
93
  approved_rooms=['06586d8d-6aad-4201-9a69-0bf9eeb5766e'],
81
94
  bot_name="My Teams Ops Bot",
82
- include_demo_commands=True)
95
+ include_demo_commands=True,
96
+ proxies=proxies)
83
97
 
84
98
  # Add new commands for the bot to listen out for.
85
99
  bot.add_command(EchoCommand())
@@ -357,13 +371,16 @@ and off you go!
357
371
 
358
372
  ### 0.5.0 (2024-Apr-25)
359
373
 
360
- * Add max backoff time (#55)
361
- * Attached files. Help, threading and log level overrides. (#54)
362
- * add stop() call to gracefully exit the bot (#42)
363
- * feat(20231212): add help image size parameter (#46)
364
- * update websockets to 11.0.3 (#43)
374
+ * Add max backoff time ([#55][pr55])
375
+ * Attached files. Help, threading and log level overrides. ([#54][pr54])
376
+ * add stop() call to gracefully exit the bot ([#42][pr42])
377
+ * feat(20231212): add help image size parameter ([#46][pr46])
378
+ * update websockets to 11.0.3 ([#43][pr43])
365
379
  * Fix for help_command syntax issue
366
380
 
381
+ ### 0.5.1 (2024-Apr-25)
382
+
383
+ * Add Proxy Support. ([#56][pr56])
367
384
 
368
385
  [1]: https://github.com/aaugustin/websockets
369
386
 
@@ -379,6 +396,18 @@ and off you go!
379
396
 
380
397
  [7]: https://eurl.io/#TeBLqZjLs
381
398
 
399
+ [pr43]: https://github.com/fbradyirl/webex_bot/pull/43
400
+
401
+ [pr46]: https://github.com/fbradyirl/webex_bot/pull/46
402
+
403
+ [pr42]: https://github.com/fbradyirl/webex_bot/pull/42
404
+
405
+ [pr54]: https://github.com/fbradyirl/webex_bot/pull/54
406
+
407
+ [pr55]: https://github.com/fbradyirl/webex_bot/pull/55
408
+
409
+ [pr56]: https://github.com/fbradyirl/webex_bot/pull/56
410
+
382
411
  [i1]: https://github.com/fbradyirl/webex_bot/issues/1
383
412
 
384
413
  [i2]: https://github.com/fbradyirl/webex_bot/issues/2
@@ -1,7 +1,7 @@
1
- webex_bot/__init__.py,sha256=o9hxpp3-rpiFtnd86lMQGKVy9tWQAb1JazWjTWECDtA,95
1
+ webex_bot/__init__.py,sha256=fIrggpbtbmnosDI6vwtRg8leUTo8BeJZJZqojDOzZGM,95
2
2
  webex_bot/exceptions.py,sha256=qs9yVitfJtvxwBMC8uCvTDOxUQ_oZjWFf1dU8Oaue14,740
3
3
  webex_bot/formatting.py,sha256=jvPKym-z8CIJygpPVTVbt6vFXQo9_HQHpRDJB-nh-SI,382
4
- webex_bot/webex_bot.py,sha256=Fvga8PUgBtFkdkYirDpNU35uRkfhdIRPUrFj6z6amYo,20325
4
+ webex_bot/webex_bot.py,sha256=f4qJeNfl1x-dvFyAxcBrAWTT0HB-pAq0Kl3gfjrXYe0,20473
5
5
  webex_bot/cards/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  webex_bot/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  webex_bot/commands/echo.py,sha256=YmeRVh56pzsj0_lRHDvgyrv6YqQQdRiusG65dHTh9qU,3397
@@ -10,9 +10,9 @@ webex_bot/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,
10
10
  webex_bot/models/command.py,sha256=Rok661eZM2Mg465CZ4GgctWi1RD-BD5Bruq0FsJ8GDQ,5023
11
11
  webex_bot/models/response.py,sha256=1U0EQv8O5R3-demaumxMExn278DG4AeQHhXP_g4xndk,2544
12
12
  webex_bot/websockets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
- webex_bot/websockets/webex_websocket_client.py,sha256=uBpvpRLmfhgtfDr0Yomg6FNei9CIsCEigNsAEu5c5iY,9427
14
- webex_bot-0.5.0.dist-info/LICENSE,sha256=93eGb10xmgkBP2Fh_n0E9YDXe0c0oz-FsnAimXG0S4Y,1072
15
- webex_bot-0.5.0.dist-info/METADATA,sha256=RqiYq2AdWfRXMD9x0h4DoQIXEh764hWry7rBb7zbc-U,11154
16
- webex_bot-0.5.0.dist-info/WHEEL,sha256=DZajD4pwLWue70CAfc7YaxT1wLUciNBvN_TTcvXpltE,110
17
- webex_bot-0.5.0.dist-info/top_level.txt,sha256=q1Y0RtYYinR7oXSwL93cK59c2KN_CbMVca8MLWeF63M,10
18
- webex_bot-0.5.0.dist-info/RECORD,,
13
+ webex_bot/websockets/webex_websocket_client.py,sha256=QUTQUWgnBYg3bSZ857m_vM49Ns9GWHWT69TYP4U6R9I,10627
14
+ webex_bot-0.5.1.dist-info/LICENSE,sha256=93eGb10xmgkBP2Fh_n0E9YDXe0c0oz-FsnAimXG0S4Y,1072
15
+ webex_bot-0.5.1.dist-info/METADATA,sha256=aSiwp8MqPv55j1njJOpHRCF_FnDiB077O-f_hzKqBhg,11991
16
+ webex_bot-0.5.1.dist-info/WHEEL,sha256=DZajD4pwLWue70CAfc7YaxT1wLUciNBvN_TTcvXpltE,110
17
+ webex_bot-0.5.1.dist-info/top_level.txt,sha256=q1Y0RtYYinR7oXSwL93cK59c2KN_CbMVca8MLWeF63M,10
18
+ webex_bot-0.5.1.dist-info/RECORD,,