Skip to content

Commit 1e33cf0

Browse files
authored
Hotfix -- Stop using deprecated asyncio loop logic (#135)
aiohttp dropped support for the deprecated in Python 3.12 method [`get_event_loop()`](https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.get_event_loop): aio-libs/aiohttp#8555 In this PR I am adapting the logic to these changes.
1 parent d09b983 commit 1e33cf0

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

sam/__main__.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,9 @@ def run(verbose):
4040
@run.command()
4141
def slack():
4242
"""Run the Slack bot demon."""
43-
from slack_bolt.adapter.socket_mode.async_handler import AsyncSocketModeHandler
43+
from .slack import run_slack
4444

45-
from .slack import get_app
46-
47-
loop = asyncio.get_event_loop()
48-
49-
loop.run_until_complete(
50-
AsyncSocketModeHandler(get_app(), config.SLACK_APP_TOKEN).start_async()
51-
)
45+
asyncio.run(run_slack())
5246

5347

5448
@cli.group(chain=True)

sam/slack.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from datetime import datetime
1111
from typing import Any
1212

13+
from slack_bolt.adapter.socket_mode.async_handler import AsyncSocketModeHandler
1314
from slack_bolt.async_app import AsyncSay
1415
from slack_sdk import errors
1516
from slack_sdk.web.async_client import AsyncWebClient
@@ -203,11 +204,16 @@ def get_app(): # pragma: no cover
203204
return app
204205

205206

207+
async def run_slack():
208+
handler = AsyncSocketModeHandler(get_app(), config.SLACK_APP_TOKEN)
209+
await handler.start_async()
210+
211+
206212
def fetch_coworker_contacts(_context=None) -> str:
207213
"""Fetch profile data about your coworkers from Slack.
208214
209215
The profiles include:
210-
- first & last name
216+
- first a last name
211217
- email address
212218
- status
213219
- pronouns

0 commit comments

Comments
 (0)