webex-bot 1.0.2__tar.gz → 1.0.4__tar.gz

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.
Files changed (35) hide show
  1. {webex_bot-1.0.2/webex_bot.egg-info → webex_bot-1.0.4}/PKG-INFO +8 -2
  2. {webex_bot-1.0.2 → webex_bot-1.0.4}/README.md +7 -1
  3. {webex_bot-1.0.2 → webex_bot-1.0.4}/setup.cfg +1 -1
  4. {webex_bot-1.0.2 → webex_bot-1.0.4}/setup.py +1 -1
  5. {webex_bot-1.0.2 → webex_bot-1.0.4}/webex_bot/__init__.py +1 -1
  6. {webex_bot-1.0.2 → webex_bot-1.0.4}/webex_bot/webex_bot.py +9 -8
  7. {webex_bot-1.0.2 → webex_bot-1.0.4}/webex_bot/websockets/webex_websocket_client.py +43 -18
  8. {webex_bot-1.0.2 → webex_bot-1.0.4/webex_bot.egg-info}/PKG-INFO +8 -2
  9. {webex_bot-1.0.2 → webex_bot-1.0.4}/CONTRIBUTING.rst +0 -0
  10. {webex_bot-1.0.2 → webex_bot-1.0.4}/LICENSE +0 -0
  11. {webex_bot-1.0.2 → webex_bot-1.0.4}/MANIFEST.in +0 -0
  12. {webex_bot-1.0.2 → webex_bot-1.0.4}/docs/Makefile +0 -0
  13. {webex_bot-1.0.2 → webex_bot-1.0.4}/docs/conf.py +0 -0
  14. {webex_bot-1.0.2 → webex_bot-1.0.4}/docs/contributing.rst +0 -0
  15. {webex_bot-1.0.2 → webex_bot-1.0.4}/docs/index.rst +0 -0
  16. {webex_bot-1.0.2 → webex_bot-1.0.4}/docs/installation.rst +0 -0
  17. {webex_bot-1.0.2 → webex_bot-1.0.4}/docs/make.bat +0 -0
  18. {webex_bot-1.0.2 → webex_bot-1.0.4}/docs/usage.rst +0 -0
  19. {webex_bot-1.0.2 → webex_bot-1.0.4}/tests/__init__.py +0 -0
  20. {webex_bot-1.0.2 → webex_bot-1.0.4}/tests/test_webex_bot.py +0 -0
  21. {webex_bot-1.0.2 → webex_bot-1.0.4}/webex_bot/cards/__init__.py +0 -0
  22. {webex_bot-1.0.2 → webex_bot-1.0.4}/webex_bot/commands/__init__.py +0 -0
  23. {webex_bot-1.0.2 → webex_bot-1.0.4}/webex_bot/commands/echo.py +0 -0
  24. {webex_bot-1.0.2 → webex_bot-1.0.4}/webex_bot/commands/help.py +0 -0
  25. {webex_bot-1.0.2 → webex_bot-1.0.4}/webex_bot/exceptions.py +0 -0
  26. {webex_bot-1.0.2 → webex_bot-1.0.4}/webex_bot/formatting.py +0 -0
  27. {webex_bot-1.0.2 → webex_bot-1.0.4}/webex_bot/models/__init__.py +0 -0
  28. {webex_bot-1.0.2 → webex_bot-1.0.4}/webex_bot/models/command.py +0 -0
  29. {webex_bot-1.0.2 → webex_bot-1.0.4}/webex_bot/models/response.py +0 -0
  30. {webex_bot-1.0.2 → webex_bot-1.0.4}/webex_bot/websockets/__init__.py +0 -0
  31. {webex_bot-1.0.2 → webex_bot-1.0.4}/webex_bot.egg-info/SOURCES.txt +0 -0
  32. {webex_bot-1.0.2 → webex_bot-1.0.4}/webex_bot.egg-info/dependency_links.txt +0 -0
  33. {webex_bot-1.0.2 → webex_bot-1.0.4}/webex_bot.egg-info/not-zip-safe +0 -0
  34. {webex_bot-1.0.2 → webex_bot-1.0.4}/webex_bot.egg-info/requires.txt +0 -0
  35. {webex_bot-1.0.2 → webex_bot-1.0.4}/webex_bot.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: webex_bot
3
- Version: 1.0.2
3
+ Version: 1.0.4
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
@@ -447,9 +447,15 @@ bot = WebexBot(teams_bot_token=os.getenv("WEBEX_ACCESS_TOKEN")
447
447
 
448
448
  * Fix for [issue #48][i48] - Fix for `Commands not being received` issue.
449
449
 
450
- ### 1.0.2 (2025-Jun-04)
450
+ ### 1.0.3 (2025-Jun-04)
451
451
 
452
452
  * Add connection headers to requests.
453
+ * Only call me people API once per run.
454
+
455
+ ### 1.0.4 (2025-Jul-01)
456
+
457
+ * Add retry mechanism with backoff for websocket 404 errors
458
+ *
453
459
 
454
460
  [1]: https://github.com/aaugustin/websockets
455
461
 
@@ -407,9 +407,15 @@ bot = WebexBot(teams_bot_token=os.getenv("WEBEX_ACCESS_TOKEN")
407
407
 
408
408
  * Fix for [issue #48][i48] - Fix for `Commands not being received` issue.
409
409
 
410
- ### 1.0.2 (2025-Jun-04)
410
+ ### 1.0.3 (2025-Jun-04)
411
411
 
412
412
  * Add connection headers to requests.
413
+ * Only call me people API once per run.
414
+
415
+ ### 1.0.4 (2025-Jul-01)
416
+
417
+ * Add retry mechanism with backoff for websocket 404 errors
418
+ *
413
419
 
414
420
  [1]: https://github.com/aaugustin/websockets
415
421
 
@@ -1,5 +1,5 @@
1
1
  [bumpversion]
2
- current_version = 1.0.2
2
+ current_version = 1.0.4
3
3
  commit = True
4
4
  tag = True
5
5
 
@@ -45,6 +45,6 @@ setup(
45
45
  test_suite='tests',
46
46
  tests_require=test_requirements,
47
47
  url='https://github.com/fbradyirl/webex_bot',
48
- version='1.0.2',
48
+ version='1.0.4',
49
49
  zip_safe=False,
50
50
  )
@@ -1,4 +1,4 @@
1
1
  """Top-level package for Webex Bot."""
2
2
 
3
3
  __author__ = """Finbarr Brady"""
4
- __version__ = '1.0.2'
4
+ __version__ = '1.0.4'
@@ -23,9 +23,9 @@ class WebexBot(WebexWebsocketClient):
23
23
 
24
24
  def __init__(self,
25
25
  teams_bot_token,
26
- approved_users=[],
27
- approved_domains=[],
28
- approved_rooms=[],
26
+ approved_users=None,
27
+ approved_domains=None,
28
+ approved_rooms=None,
29
29
  include_demo_commands=False,
30
30
  bot_name="Webex Bot",
31
31
  bot_help_subtitle="Here are my available commands. Click one to begin.",
@@ -61,11 +61,12 @@ class WebexBot(WebexWebsocketClient):
61
61
  on_card_action=self.process_incoming_card_action,
62
62
  proxies=proxies)
63
63
 
64
+ me = self.get_me_info()
64
65
  if help_command is None:
65
66
  self.help_command = HelpCommand(
66
67
  bot_name=bot_name,
67
68
  bot_help_subtitle=bot_help_subtitle,
68
- bot_help_image=self.teams.people.me().avatar)
69
+ bot_help_image=me.avatar)
69
70
  else:
70
71
  self.help_command = help_command
71
72
 
@@ -83,12 +84,11 @@ class WebexBot(WebexWebsocketClient):
83
84
  self.help_command.commands = self.commands
84
85
 
85
86
  self.card_callback_commands = {}
86
- self.approved_users = approved_users
87
- self.approved_domains = approved_domains
88
- self.approved_rooms = approved_rooms
87
+ self.approved_users = approved_users if approved_users is not None else []
88
+ self.approved_domains = approved_domains if approved_domains is not None else []
89
+ self.approved_rooms = approved_rooms if approved_rooms is not None else []
89
90
  self.approval_parameters_check()
90
91
  self.bot_display_name = ""
91
- self.get_me_info()
92
92
  self.threads = threads
93
93
 
94
94
  @backoff.on_exception(backoff.expo, requests.exceptions.ConnectionError)
@@ -100,6 +100,7 @@ class WebexBot(WebexWebsocketClient):
100
100
  self.bot_display_name = me.displayName
101
101
  log.info(f"Running as {me.type} '{me.displayName}' with email {me.emails}")
102
102
  log.debug(f"Running as bot '{me}'")
103
+ return me
103
104
 
104
105
  def add_command(self, command_class: Command):
105
106
  """
@@ -276,22 +276,47 @@ class WebexWebsocketClient(object):
276
276
  while True:
277
277
  await _websocket_recv()
278
278
 
279
- try:
280
- asyncio.get_event_loop().run_until_complete(_connect_and_listen())
281
- except InvalidStatusCode as e:
282
- logger.error(f"WebSocket handshake to {ws_url} failed with status {e.status_code}")
283
- if e.status_code == 404:
284
- logger.info("Refreshing WDM device info and retrying...")
285
- self._get_device_info(check_existing=False)
286
- # update ws_url before retry
287
- ws_url = self.device_info.get('webSocketUrl')
279
+ # Track the number of consecutive 404 errors to prevent infinite loops
280
+ max_404_retries = 3
281
+ current_404_retries = 0
282
+
283
+ while True:
284
+ try:
288
285
  asyncio.get_event_loop().run_until_complete(_connect_and_listen())
289
- else:
290
- raise
291
- except Exception as runException:
292
- logger.error(f"runException: {runException}")
293
- if self._get_device_info(check_existing=False) is None:
294
- logger.error('could not create device info')
295
- raise Exception("No WDM device info")
296
- # trigger re-connect
297
- asyncio.get_event_loop().run_until_complete(_connect_and_listen())
286
+ # If we get here, the connection was successful, so break out of the loop
287
+ break
288
+ except InvalidStatusCode as e:
289
+ logger.error(f"WebSocket handshake to {ws_url} failed with status {e.status_code}")
290
+
291
+ if e.status_code == 404:
292
+ current_404_retries += 1
293
+ if current_404_retries >= max_404_retries:
294
+ logger.error(f"Reached maximum retries ({max_404_retries}) for 404 errors. Giving up.")
295
+ raise Exception(f"Unable to connect to WebSocket after {max_404_retries} attempts. Device registration may be invalid.")
296
+
297
+ logger.info(f"Refreshing WDM device info and retrying... (Attempt {current_404_retries} of {max_404_retries})")
298
+ # Force a new device registration
299
+ self._get_device_info(check_existing=False)
300
+ # Update ws_url with the new device info
301
+ ws_url = self.device_info.get('webSocketUrl')
302
+
303
+ # Add a delay before retrying to avoid hammering the server
304
+ logger.info(f"Waiting 5 seconds before retry attempt {current_404_retries}...")
305
+ asyncio.get_event_loop().run_until_complete(asyncio.sleep(5))
306
+ else:
307
+ # For non-404 errors, just raise the exception
308
+ raise
309
+ except Exception as runException:
310
+ logger.error(f"runException: {runException}")
311
+
312
+ # Check if we can get device info
313
+ if self._get_device_info(check_existing=False) is None:
314
+ logger.error('could not create device info')
315
+ raise Exception("No WDM device info")
316
+
317
+ # Update the URL in case it changed
318
+ ws_url = self.device_info.get('webSocketUrl')
319
+
320
+ # Wait a bit before reconnecting
321
+ logger.info("Waiting 5 seconds before attempting to reconnect...")
322
+ asyncio.get_event_loop().run_until_complete(asyncio.sleep(5))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: webex_bot
3
- Version: 1.0.2
3
+ Version: 1.0.4
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
@@ -447,9 +447,15 @@ bot = WebexBot(teams_bot_token=os.getenv("WEBEX_ACCESS_TOKEN")
447
447
 
448
448
  * Fix for [issue #48][i48] - Fix for `Commands not being received` issue.
449
449
 
450
- ### 1.0.2 (2025-Jun-04)
450
+ ### 1.0.3 (2025-Jun-04)
451
451
 
452
452
  * Add connection headers to requests.
453
+ * Only call me people API once per run.
454
+
455
+ ### 1.0.4 (2025-Jul-01)
456
+
457
+ * Add retry mechanism with backoff for websocket 404 errors
458
+ *
453
459
 
454
460
  [1]: https://github.com/aaugustin/websockets
455
461
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes