docs/reference/adapter/socket_mode/websockets/index.html
websockets based implementation / asyncio compatible
class AsyncSocketModeHandler (app: AsyncApp,app_token: str | None = None,logger: logging.Logger | None = None,web_client: slack_sdk.web.async_client.AsyncWebClient | None = None,ping_interval: float = 10)#Expand source code
class AsyncSocketModeHandler(AsyncBaseSocketModeHandler):
app: AsyncApp
app_token: str
client: SocketModeClient
def __init__ (
self,
app: AsyncApp,
app_token: Optional[str] = None,
logger: Optional[Logger] = None,
web_client: Optional[AsyncWebClient] = None,
ping_interval: float = 10,
):
self.app = app
self.app_token = app_token or os.environ["SLACK_APP_TOKEN"]
self.client = SocketModeClient(
app_token=self.app_token,
logger=logger if logger is not None else app.logger,
web_client=web_client if web_client is not None else app.client,
ping_interval=ping_interval,
)
self.client.socket_mode_request_listeners.append(self.handle) # type: ignore[arg-type]
async def handle(self, client: SocketModeClient, req: SocketModeRequest) -> None: # type: ignore[override]
start = time()
bolt_resp: BoltResponse = await run_async_bolt_app(self.app, req)
await send_async_response(client, req, bolt_resp, start)
var app_token : str
The type of the None singleton.
AsyncBaseSocketModeHandler:
appclientclose_asyncconnect_asyncdisconnect_asynchandlestart_asyncclass SocketModeHandler (app: App,app_token: str | None = None,logger: logging.Logger | None = None,web_client: slack_sdk.web.async_client.AsyncWebClient | None = None,ping_interval: float = 10)#Expand source code
class SocketModeHandler(AsyncBaseSocketModeHandler):
app: App
app_token: str
client: SocketModeClient
def __init__ (
self,
app: App,
app_token: Optional[str] = None,
logger: Optional[Logger] = None,
web_client: Optional[AsyncWebClient] = None,
ping_interval: float = 10,
):
"""Socket Mode adapter for Bolt apps.
Please note that this adapter does not support proxy configuration
as the underlying websockets module does not support proxy-wired connections.
If you use proxy, consider using one of the other Socket Mode adapters.
Args:
app: The Bolt app
app_token: App-level token starting with `xapp-`
logger: Custom logger
web_client: custom `slack_sdk.web.WebClient` instance
ping_interval: The ping-pong internal (seconds)
"""
self.app = app
self.app_token = app_token or os.environ["SLACK_APP_TOKEN"]
self.client = SocketModeClient(
app_token=self.app_token,
logger=logger if logger is not None else app.logger,
web_client=web_client if web_client is not None else app.client, # type: ignore[arg-type]
ping_interval=ping_interval,
)
self.client.socket_mode_request_listeners.append(self.handle) # type: ignore[arg-type]
async def handle(self, client: SocketModeClient, req: SocketModeRequest) -> None: # type: ignore[override]
start = time()
bolt_resp: BoltResponse = run_bolt_app(self.app, req)
await send_async_response(client, req, bolt_resp, start)
Socket Mode adapter for Bolt apps.
Please note that this adapter does not support proxy configuration as the underlying websockets module does not support proxy-wired connections. If you use proxy, consider using one of the other Socket Mode adapters.
app The Bolt app app_token App-level token starting with xapp- logger Custom logger web_client custom slack_sdk.web.WebClient instance ping_interval The ping-pong internal (seconds)
var app_token : str
The type of the None singleton.
AsyncBaseSocketModeHandler:
appclientclose_asyncconnect_asyncdisconnect_asynchandlestart_async