77
88
99class AsyncSlackAppServer :
10+ port : int
11+ path : str
12+ bolt_app : "AsyncApp"
13+ web_app : web .Application
14+
1015 def __init__ (
11- self , port : int , path : str , app , # AsyncApp
16+ self , port : int , path : str , app : " AsyncApp" ,
1217 ):
1318 """Standalone AIOHTTP Web Server
1419
1520 Refer to AIOHTTP documents for details.
1621 https://docs.aiohttp.org/en/stable/web.html
1722 """
18- self ._port = port
19- self ._endpoint_path = path
20- self ._bolt_app : "AsyncApp" = app
21-
23+ self .port = port
24+ self .path = path
25+ self .bolt_app : "AsyncApp" = app
2226 self .web_app = web .Application ()
23- self ._bolt_oauth_flow = self ._bolt_app .oauth_flow
27+ self ._bolt_oauth_flow = self .bolt_app .oauth_flow
2428 if self ._bolt_oauth_flow :
2529 self .web_app .add_routes (
2630 [
@@ -31,13 +35,11 @@ def __init__(
3135 self ._bolt_oauth_flow .redirect_uri_path ,
3236 self .handle_get_requests ,
3337 ),
34- web .post (self ._endpoint_path , self .handle_post_requests ),
38+ web .post (self .path , self .handle_post_requests ),
3539 ]
3640 )
3741 else :
38- self .web_app .add_routes (
39- [web .post (self ._endpoint_path , self .handle_post_requests )]
40- )
42+ self .web_app .add_routes ([web .post (self .path , self .handle_post_requests )])
4143
4244 async def handle_get_requests (self , request : web .Request ) -> web .Response :
4345 oauth_flow = self ._bolt_oauth_flow
@@ -56,21 +58,21 @@ async def handle_get_requests(self, request: web.Request) -> web.Response:
5658 return web .Response (status = 404 )
5759
5860 async def handle_post_requests (self , request : web .Request ) -> web .Response :
59- if self ._endpoint_path != request .path :
61+ if self .path != request .path :
6062 return web .Response (status = 404 )
6163
6264 bolt_req = await to_bolt_request (request )
63- bolt_resp : BoltResponse = await self ._bolt_app .async_dispatch (bolt_req )
65+ bolt_resp : BoltResponse = await self .bolt_app .async_dispatch (bolt_req )
6466 return await to_aiohttp_response (bolt_resp )
6567
6668 def start (self ) -> None :
6769 """ Starts a new web server process.
6870
6971 :return: None
7072 """
71- if self ._bolt_app .logger .level > logging .INFO :
73+ if self .bolt_app .logger .level > logging .INFO :
7274 print ("⚡️ Bolt app is running!" )
7375 else :
74- self ._bolt_app .logger .info ("⚡️ Bolt app is running!" )
76+ self .bolt_app .logger .info ("⚡️ Bolt app is running!" )
7577
76- web .run_app (self .web_app , host = "0.0.0.0" , port = self ._port )
78+ web .run_app (self .web_app , host = "0.0.0.0" , port = self .port )
0 commit comments