docs/reference/middleware/async_custom_middleware.html
class AsyncCustomMiddleware (*,app_name: str,func: Callable[..., Awaitable[Any]],base_logger: logging.Logger | None = None)#Expand source code
class AsyncCustomMiddleware(AsyncMiddleware):
app_name: str
func: Callable[..., Awaitable[Any]]
arg_names: MutableSequence[str]
logger: Logger
def __init__ (
self,
*,
app_name: str,
func: Callable[..., Awaitable[Any]],
base_logger: Optional[Logger] = None,
):
self.app_name = app_name
if is_callable_coroutine(func):
self.func = func
else:
raise ValueError("Async middleware function must be an async function")
self.arg_names = get_arg_names_of_callable(func)
self.logger = get_bolt_app_logger(self.app_name, self.func, base_logger)
async def async_process(
self,
*,
req: AsyncBoltRequest,
resp: BoltResponse,
# As this method is not supposed to be invoked by bolt-python users,
# the naming conflict with the built-in one affects
# only the internals of this method
next: Callable[[], Awaitable[BoltResponse]],
) -> BoltResponse:
return await self.func(
**build_async_required_kwargs(
logger=self.logger,
required_arg_names=self.arg_names,
request=req,
response=resp,
next_func=next, # type: ignore[arg-type]
this_func=self.func,
)
)
@property
def name(self) -> str:
return f"AsyncCustomMiddleware(func={get_name_for_callable(self.func)})"
A middleware can process request data before other middleware and listener functions.
var app_name : str
The type of the None singleton.
var arg_names : MutableSequence[str]
The type of the None singleton.
var func : Callable[..., Awaitable[Any]]
The type of the None singleton.
var logger : logging.Logger
The type of the None singleton.
AsyncMiddleware:
async_processname