Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions slack_bolt/app/async_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,14 +446,18 @@ def process_before_response(self) -> bool:
from .async_server import AsyncSlackAppServer

def server(
self, port: int = 3000, path: str = "/slack/events"
self,
port: int = 3000,
path: str = "/slack/events",
host: Optional[str] = None,
) -> AsyncSlackAppServer:
"""Configure a web server using AIOHTTP.
Refer to https://docs.aiohttp.org/ for more details about AIOHTTP.

Args:
port: The port to listen on (Default: 3000)
path:The path to handle request from Slack (Default: `/slack/events`)
path: The path to handle request from Slack (Default: `/slack/events`)
host: The hostname to serve the web endpoints. (Default: 0.0.0.0)
"""
if (
self._server is None
Expand All @@ -464,6 +468,7 @@ def server(
port=port,
path=path,
app=self,
host=host,
)
return self._server

Expand All @@ -488,15 +493,18 @@ def app_factory():
"""
return self.server(path=path).web_app

def start(self, port: int = 3000, path: str = "/slack/events") -> None:
def start(
self, port: int = 3000, path: str = "/slack/events", host: Optional[str] = None
) -> None:
"""Start a web server using AIOHTTP.
Refer to https://docs.aiohttp.org/ for more details about AIOHTTP.

Args:
port: The port to listen on (Default: 3000)
path:The path to handle request from Slack (Default: `/slack/events`)
path: The path to handle request from Slack (Default: `/slack/events`)
host: The hostname to serve the web endpoints. (Default: 0.0.0.0)
"""
self.server(port=port, path=path).start()
self.server(port=port, path=path, host=host).start()

# -------------------------
# main dispatcher
Expand Down
10 changes: 8 additions & 2 deletions slack_bolt/app/async_server.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from typing import Optional

from aiohttp import web

Expand All @@ -10,6 +11,7 @@
class AsyncSlackAppServer:
port: int
path: str
host: str
bolt_app: "AsyncApp" # type:ignore
web_app: web.Application

Expand All @@ -18,6 +20,7 @@ def __init__( # type:ignore
port: int,
path: str,
app: "AsyncApp", # type:ignore
host: Optional[str] = None,
):
"""Standalone AIOHTTP Web Server.
Refer to https://docs.aiohttp.org/en/stable/web.html for details of AIOHTTP.
Expand All @@ -26,9 +29,11 @@ def __init__( # type:ignore
port: The port to listen on
path: The path to receive incoming requests from Slack
app: The `AsyncApp` instance that is used for processing requests
host: The hostname to serve the web endpoints. (Default: 0.0.0.0)
"""
self.port = port
self.path = path
self.host = host if host is not None else "0.0.0.0"
self.bolt_app: "AsyncApp" = app # type: ignore
self.web_app = web.Application()
self._bolt_oauth_flow = self.bolt_app.oauth_flow
Expand Down Expand Up @@ -72,11 +77,12 @@ async def handle_post_requests(self, request: web.Request) -> web.Response:
bolt_resp: BoltResponse = await self.bolt_app.async_dispatch(bolt_req)
return await to_aiohttp_response(bolt_resp)

def start(self) -> None:
def start(self, host: Optional[str] = None) -> None:
"""Starts a new web server process."""
if self.bolt_app.logger.level > logging.INFO:
print(get_boot_message())
else:
self.bolt_app.logger.info(get_boot_message())

web.run_app(self.web_app, host="0.0.0.0", port=self.port)
_host = host if host is not None else self.host
web.run_app(self.web_app, host=_host, port=self.port)