Back to Bolt Python

slack_bolt.adapter.socket_mode.base_handler API documentation

docs/reference/adapter/socket_mode/base_handler.html

1.28.04.3 KB
Original Source

The base class of Socket Mode client implementation. If you want to build asyncio-based ones, use AsyncBaseSocketModeHandler instead.

Classes

class BaseSocketModeHandler#Expand source code

class BaseSocketModeHandler:
    app: App
    client: BaseSocketModeClient

    def handle(self, client: BaseSocketModeClient, req: SocketModeRequest) -> None:
        """Handles Socket Mode envelope requests through a WebSocket connection.

        Args:
            client: this Socket Mode client instance
            req: the request data
        """
        raise NotImplementedError()

    def connect(self):
        """Establishes a new connection with the Socket Mode server"""
        self.client.connect()

    def disconnect(self):
        """Disconnects the current WebSocket connection with the Socket Mode server"""
        self.client.disconnect()

    def close(self):
        """Disconnects from the Socket Mode server and cleans the resources this instance holds up"""
        self.client.close()

    def start(self):
        """Establishes a new connection and then blocks the current thread
        to prevent the termination of this process.
        If you don't want to block the current thread, use `#connect()` method instead.
        """
        self.connect()
        if self.app.logger.level > logging.INFO:
            print(get_boot_message())
        else:
            self.app.logger.info(get_boot_message())

        if sys.platform == "win32":
            # Ctrl+C etc does not work on Windows OS
            # see https://bugs.python.org/issue35935 for details
            signal.signal(signal.SIGINT, signal.SIG_DFL)

        Event().wait()

Subclasses

Class variables

var app : App

The type of the None singleton.

var client : slack_sdk.socket_mode.client.BaseSocketModeClient

The type of the None singleton.

Methods

def close(self)#Expand source code

def close(self):
    """Disconnects from the Socket Mode server and cleans the resources this instance holds up"""
    self.client.close()

Disconnects from the Socket Mode server and cleans the resources this instance holds up

def connect(self)#Expand source code

def connect(self):
    """Establishes a new connection with the Socket Mode server"""
    self.client.connect()

Establishes a new connection with the Socket Mode server

def disconnect(self)#Expand source code

def disconnect(self):
    """Disconnects the current WebSocket connection with the Socket Mode server"""
    self.client.disconnect()

Disconnects the current WebSocket connection with the Socket Mode server

def handle(self,client: slack_sdk.socket_mode.client.BaseSocketModeClient,req: slack_sdk.socket_mode.request.SocketModeRequest) ‑> None#Expand source code

def handle(self, client: BaseSocketModeClient, req: SocketModeRequest) -> None:
    """Handles Socket Mode envelope requests through a WebSocket connection.

    Args:
        client: this Socket Mode client instance
        req: the request data
    """
    raise NotImplementedError()

Handles Socket Mode envelope requests through a WebSocket connection.

Args

client this Socket Mode client instance req the request data def start(self)#Expand source code

def start(self):
    """Establishes a new connection and then blocks the current thread
    to prevent the termination of this process.
    If you don't want to block the current thread, use `#connect()` method instead.
    """
    self.connect()
    if self.app.logger.level > logging.INFO:
        print(get_boot_message())
    else:
        self.app.logger.info(get_boot_message())

    if sys.platform == "win32":
        # Ctrl+C etc does not work on Windows OS
        # see https://bugs.python.org/issue35935 for details
        signal.signal(signal.SIGINT, signal.SIG_DFL)

    Event().wait()

Establishes a new connection and then blocks the current thread to prevent the termination of this process. If you don't want to block the current thread, use #connect() method instead.