Module slack_bolt.adapter.sanic

Expand source code
from .async_handler import AsyncSlackRequestHandler

__all__ = [
    "AsyncSlackRequestHandler",
]

Sub-modules

slack_bolt.adapter.sanic.async_handler

Classes

class AsyncSlackRequestHandler (app: AsyncApp)
Expand source code
class AsyncSlackRequestHandler:
    def __init__(self, app: AsyncApp):  # type: ignore
        self.app = app

    async def handle(self, req: Request) -> HTTPResponse:
        if req.method == "GET":
            if self.app.oauth_flow is not None:
                oauth_flow: AsyncOAuthFlow = self.app.oauth_flow
                if req.path == oauth_flow.install_path:
                    bolt_resp = await oauth_flow.handle_installation(to_async_bolt_request(req))
                    return to_sanic_response(bolt_resp)
                elif req.path == oauth_flow.redirect_uri_path:
                    bolt_resp = await oauth_flow.handle_callback(to_async_bolt_request(req))
                    return to_sanic_response(bolt_resp)

        elif req.method == "POST":
            bolt_resp = await self.app.async_dispatch(to_async_bolt_request(req))
            return to_sanic_response(bolt_resp)

        return HTTPResponse(
            status=404,
            body="Not found",
        )

Methods

async def handle(self, req: sanic.request.Request) ‑> sanic.response.HTTPResponse
Expand source code
async def handle(self, req: Request) -> HTTPResponse:
    if req.method == "GET":
        if self.app.oauth_flow is not None:
            oauth_flow: AsyncOAuthFlow = self.app.oauth_flow
            if req.path == oauth_flow.install_path:
                bolt_resp = await oauth_flow.handle_installation(to_async_bolt_request(req))
                return to_sanic_response(bolt_resp)
            elif req.path == oauth_flow.redirect_uri_path:
                bolt_resp = await oauth_flow.handle_callback(to_async_bolt_request(req))
                return to_sanic_response(bolt_resp)

    elif req.method == "POST":
        bolt_resp = await self.app.async_dispatch(to_async_bolt_request(req))
        return to_sanic_response(bolt_resp)

    return HTTPResponse(
        status=404,
        body="Not found",
    )