Module slack_bolt.listener_matcher

A listener matcher is a simplified version of listener middleware. A listener matcher function returns bool value instead of next() method invocation inside. This interface enables developers to utilize simple predicate functions for additional listener conditions.

Expand source code
"""A listener matcher is a simplified version of listener middleware.
A listener matcher function returns bool value instead of `next()` method invocation inside.
This interface enables developers to utilize simple predicate functions for additional listener conditions.
"""
# Don't add async module imports here
from .custom_listener_matcher import CustomListenerMatcher
from .listener_matcher import ListenerMatcher

builtin_listener_matcher_classes = [
    CustomListenerMatcher,
]
for cls in builtin_listener_matcher_classes:
    ListenerMatcher.register(cls)

__all__ = [
    "CustomListenerMatcher",
    "ListenerMatcher",
    "builtin_listener_matcher_classes",
]

Sub-modules

slack_bolt.listener_matcher.async_builtins
slack_bolt.listener_matcher.async_listener_matcher
slack_bolt.listener_matcher.builtins
slack_bolt.listener_matcher.custom_listener_matcher
slack_bolt.listener_matcher.listener_matcher

Classes

class CustomListenerMatcher (*, app_name: str, func: Callable[..., bool], base_logger: Optional[logging.Logger] = None)
Expand source code
class CustomListenerMatcher(ListenerMatcher):
    app_name: str
    func: Callable[..., bool]
    arg_names: Sequence[str]
    logger: Logger

    def __init__(self, *, app_name: str, func: Callable[..., bool], base_logger: Optional[Logger] = None):
        self.app_name = app_name
        self.func = func
        self.arg_names = get_arg_names_of_callable(func)
        self.logger = get_bolt_app_logger(self.app_name, self.func, base_logger)

    def matches(self, req: BoltRequest, resp: BoltResponse) -> bool:
        return self.func(
            **build_required_kwargs(
                logger=self.logger,
                required_arg_names=self.arg_names,
                request=req,
                response=resp,
                this_func=self.func,
            )
        )

Ancestors

Class variables

var app_name : str
var arg_names : Sequence[str]
var func : Callable[..., bool]
var logger : logging.Logger

Inherited members

class ListenerMatcher
Expand source code
class ListenerMatcher(metaclass=ABCMeta):
    @abstractmethod
    def matches(self, req: BoltRequest, resp: BoltResponse) -> bool:
        """Matches against the request and returns True if matched.

        Args:
            req: The request
            resp: The response

        Returns:
            True if matched.
        """
        raise NotImplementedError()

Subclasses

Methods

def matches(self, req: BoltRequest, resp: BoltResponse) ‑> bool

Matches against the request and returns True if matched.

Args

req
The request
resp
The response

Returns

True if matched.

Expand source code
@abstractmethod
def matches(self, req: BoltRequest, resp: BoltResponse) -> bool:
    """Matches against the request and returns True if matched.

    Args:
        req: The request
        resp: The response

    Returns:
        True if matched.
    """
    raise NotImplementedError()