Flyingdiver
Flyingdiver

Reputation: 2142

Slack API Socket Mode and asyncio

I'm writing some middle-ware in Python that uses Socket Mode. Non-async testing works fine. But the connect() call fails:

app_token='xapp-XXX'
bot_token='xoxb-XXX'

web_client = AsyncWebClient(bot_token)
sm_client = SocketModeClient(app_token=app_token, web_client=web_client)

sm_client.connect()

Returns:

Traceback (most recent call last):
  File "wrapper.py", line 57, in <module>
    sm_client.connect()
  File "/Library/Python/3.8/site-packages/slack_sdk/socket_mode/builtin/client.py", line 132, in connect
    self.wss_uri = self.issue_new_wss_url()
  File "/Library/Python/3.8/site-packages/slack_sdk/socket_mode/client.py", line 48, in issue_new_wss_url
    return response["url"]
TypeError: 'coroutine' object is not subscriptable
sys:1: RuntimeWarning: coroutine 'AsyncWebClient.apps_connections_open' was never awaited

I can't find anything in the API or SDK documentation about how to use AsyncWebClient in a Socket Mode application. Is this possible?

Upvotes: 0

Views: 1205

Answers (1)

Casey
Casey

Reputation: 429

In your traceback, it is referencing the builtin client, aka the concurrent client. You're probably importing this:

from slack_sdk.socket_mode import SocketModeClient

You need to use the async client if you're using the AsyncWebClient:

from slack_sdk.socket_mode.aiohttp import SocketModeClient

Upvotes: 1

Related Questions