webex-bot 1.0.2__py2.py3-none-any.whl → 1.0.4__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 +1 -1
- webex_bot/webex_bot.py +9 -8
- webex_bot/websockets/webex_websocket_client.py +43 -18
- {webex_bot-1.0.2.dist-info → webex_bot-1.0.4.dist-info}/METADATA +8 -2
- {webex_bot-1.0.2.dist-info → webex_bot-1.0.4.dist-info}/RECORD +8 -8
- {webex_bot-1.0.2.dist-info → webex_bot-1.0.4.dist-info}/WHEEL +0 -0
- {webex_bot-1.0.2.dist-info → webex_bot-1.0.4.dist-info}/licenses/LICENSE +0 -0
- {webex_bot-1.0.2.dist-info → webex_bot-1.0.4.dist-info}/top_level.txt +0 -0
webex_bot/__init__.py
CHANGED
webex_bot/webex_bot.py
CHANGED
|
@@ -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=
|
|
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
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
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
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
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.
|
|
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.
|
|
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
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
webex_bot/__init__.py,sha256=
|
|
1
|
+
webex_bot/__init__.py,sha256=Tzm9k-JrR1ZSrXQY5OyBg6ljQWMbUK_6TZJCUgCGfBU,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=
|
|
4
|
+
webex_bot/webex_bot.py,sha256=QRia8QBXnWNt6iwj1kfpcWgPi7RT_DoQfqtdUUbsUTo,21278
|
|
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=STY-MikBRjUteDK-g8G4GPB0V-Yi7siPN1DRMXrT-QU,3399
|
|
@@ -10,9 +10,9 @@ webex_bot/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,
|
|
|
10
10
|
webex_bot/models/command.py,sha256=MyThlDaEkGlj1fDE_i_wr79O3QboakimRme8yI744yo,5327
|
|
11
11
|
webex_bot/models/response.py,sha256=d4k2ohR5SUVzvuQzcnm7jQQVTMB0gH9Kz9y09vkoAaU,2545
|
|
12
12
|
webex_bot/websockets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
|
-
webex_bot/websockets/webex_websocket_client.py,sha256=
|
|
14
|
-
webex_bot-1.0.
|
|
15
|
-
webex_bot-1.0.
|
|
16
|
-
webex_bot-1.0.
|
|
17
|
-
webex_bot-1.0.
|
|
18
|
-
webex_bot-1.0.
|
|
13
|
+
webex_bot/websockets/webex_websocket_client.py,sha256=qVbYquh_FJ-rDZeWspcDydBJOw96U3UcYZSX2XfYYoY,13964
|
|
14
|
+
webex_bot-1.0.4.dist-info/licenses/LICENSE,sha256=93eGb10xmgkBP2Fh_n0E9YDXe0c0oz-FsnAimXG0S4Y,1072
|
|
15
|
+
webex_bot-1.0.4.dist-info/METADATA,sha256=Ni8h1xfMT6ijtlWsucOGK9yqTM2S0GbN3Jw1CAbZFjw,14782
|
|
16
|
+
webex_bot-1.0.4.dist-info/WHEEL,sha256=JNWh1Fm1UdwIQV075glCn4MVuCRs0sotJIq-J6rbxCU,109
|
|
17
|
+
webex_bot-1.0.4.dist-info/top_level.txt,sha256=q1Y0RtYYinR7oXSwL93cK59c2KN_CbMVca8MLWeF63M,10
|
|
18
|
+
webex_bot-1.0.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|