@@ -26,20 +26,30 @@ <h1 class="title">Module <code>slack_bolt.adapter.starlette.async_handler</code>
2626< summary >
2727< span > Expand source code</ span >
2828</ summary >
29- < pre > < code class ="python "> from starlette.requests import Request
29+ < pre > < code class ="python "> from typing import Dict, Any, Optional
30+
31+ from starlette.requests import Request
3032from starlette.responses import Response
3133
3234from slack_bolt import BoltResponse
3335from slack_bolt.async_app import AsyncApp, AsyncBoltRequest
3436from slack_bolt.oauth.async_oauth_flow import AsyncOAuthFlow
3537
3638
37- def to_async_bolt_request(req: Request, body: bytes) -> AsyncBoltRequest:
38- return AsyncBoltRequest(
39+ def to_async_bolt_request(
40+ req: Request,
41+ body: bytes,
42+ addition_context_properties: Optional[Dict[str, Any]] = None,
43+ ) -> AsyncBoltRequest:
44+ request = AsyncBoltRequest(
3945 body=body.decode("utf-8"),
4046 query=req.query_params,
4147 headers=req.headers,
4248 )
49+ if addition_context_properties is not None:
50+ for k, v in addition_context_properties.items():
51+ request.context[k] = v
52+ return request
4353
4454
4555def to_starlette_response(bolt_resp: BoltResponse) -> Response:
@@ -67,23 +77,27 @@ <h1 class="title">Module <code>slack_bolt.adapter.starlette.async_handler</code>
6777 def __init__(self, app: AsyncApp): # type: ignore
6878 self.app = app
6979
70- async def handle(self, req: Request) -> Response:
80+ async def handle(
81+ self, req: Request, addition_context_properties: Optional[Dict[str, Any]] = None
82+ ) -> Response:
7183 body = await req.body()
7284 if req.method == "GET":
7385 if self.app.oauth_flow is not None:
7486 oauth_flow: AsyncOAuthFlow = self.app.oauth_flow
7587 if req.url.path == oauth_flow.install_path:
7688 bolt_resp = await oauth_flow.handle_installation(
77- to_async_bolt_request(req, body)
89+ to_async_bolt_request(req, body, addition_context_properties )
7890 )
7991 return to_starlette_response(bolt_resp)
8092 elif req.url.path == oauth_flow.redirect_uri_path:
8193 bolt_resp = await oauth_flow.handle_callback(
82- to_async_bolt_request(req, body)
94+ to_async_bolt_request(req, body, addition_context_properties )
8395 )
8496 return to_starlette_response(bolt_resp)
8597 elif req.method == "POST":
86- bolt_resp = await self.app.async_dispatch(to_async_bolt_request(req, body))
98+ bolt_resp = await self.app.async_dispatch(
99+ to_async_bolt_request(req, body, addition_context_properties)
100+ )
87101 return to_starlette_response(bolt_resp)
88102
89103 return Response(
@@ -100,20 +114,28 @@ <h1 class="title">Module <code>slack_bolt.adapter.starlette.async_handler</code>
100114< h2 class ="section-title " id ="header-functions "> Functions</ h2 >
101115< dl >
102116< dt id ="slack_bolt.adapter.starlette.async_handler.to_async_bolt_request "> < code class ="name flex ">
103- < span > def < span class ="ident "> to_async_bolt_request</ span > </ span > (< span > req: starlette.requests.Request, body: bytes) ‑> < a title ="slack_bolt.request.async_request.AsyncBoltRequest " href ="../../request/async_request.html#slack_bolt.request.async_request.AsyncBoltRequest "> AsyncBoltRequest</ a > </ span >
117+ < span > def < span class ="ident "> to_async_bolt_request</ span > </ span > (< span > req: starlette.requests.Request, body: bytes, addition_context_properties: Optional[Dict[str, Any]] = None ) ‑> < a title ="slack_bolt.request.async_request.AsyncBoltRequest " href ="../../request/async_request.html#slack_bolt.request.async_request.AsyncBoltRequest "> AsyncBoltRequest</ a > </ span >
104118</ code > </ dt >
105119< dd >
106120< div class ="desc "> </ div >
107121< details class ="source ">
108122< summary >
109123< span > Expand source code</ span >
110124</ summary >
111- < pre > < code class ="python "> def to_async_bolt_request(req: Request, body: bytes) -> AsyncBoltRequest:
112- return AsyncBoltRequest(
125+ < pre > < code class ="python "> def to_async_bolt_request(
126+ req: Request,
127+ body: bytes,
128+ addition_context_properties: Optional[Dict[str, Any]] = None,
129+ ) -> AsyncBoltRequest:
130+ request = AsyncBoltRequest(
113131 body=body.decode("utf-8"),
114132 query=req.query_params,
115133 headers=req.headers,
116- )</ code > </ pre >
134+ )
135+ if addition_context_properties is not None:
136+ for k, v in addition_context_properties.items():
137+ request.context[k] = v
138+ return request</ code > </ pre >
117139</ details >
118140</ dd >
119141< dt id ="slack_bolt.adapter.starlette.async_handler.to_starlette_response "> < code class ="name flex ">
@@ -165,23 +187,27 @@ <h2 class="section-title" id="header-classes">Classes</h2>
165187 def __init__(self, app: AsyncApp): # type: ignore
166188 self.app = app
167189
168- async def handle(self, req: Request) -> Response:
190+ async def handle(
191+ self, req: Request, addition_context_properties: Optional[Dict[str, Any]] = None
192+ ) -> Response:
169193 body = await req.body()
170194 if req.method == "GET":
171195 if self.app.oauth_flow is not None:
172196 oauth_flow: AsyncOAuthFlow = self.app.oauth_flow
173197 if req.url.path == oauth_flow.install_path:
174198 bolt_resp = await oauth_flow.handle_installation(
175- to_async_bolt_request(req, body)
199+ to_async_bolt_request(req, body, addition_context_properties )
176200 )
177201 return to_starlette_response(bolt_resp)
178202 elif req.url.path == oauth_flow.redirect_uri_path:
179203 bolt_resp = await oauth_flow.handle_callback(
180- to_async_bolt_request(req, body)
204+ to_async_bolt_request(req, body, addition_context_properties )
181205 )
182206 return to_starlette_response(bolt_resp)
183207 elif req.method == "POST":
184- bolt_resp = await self.app.async_dispatch(to_async_bolt_request(req, body))
208+ bolt_resp = await self.app.async_dispatch(
209+ to_async_bolt_request(req, body, addition_context_properties)
210+ )
185211 return to_starlette_response(bolt_resp)
186212
187213 return Response(
@@ -192,31 +218,35 @@ <h2 class="section-title" id="header-classes">Classes</h2>
192218< h3 > Methods</ h3 >
193219< dl >
194220< dt id ="slack_bolt.adapter.starlette.async_handler.AsyncSlackRequestHandler.handle "> < code class ="name flex ">
195- < span > async def < span class ="ident "> handle</ span > </ span > (< span > self, req: starlette.requests.Request) ‑> starlette.responses.Response</ span >
221+ < span > async def < span class ="ident "> handle</ span > </ span > (< span > self, req: starlette.requests.Request, addition_context_properties: Optional[Dict[str, Any]] = None ) ‑> starlette.responses.Response</ span >
196222</ code > </ dt >
197223< dd >
198224< div class ="desc "> </ div >
199225< details class ="source ">
200226< summary >
201227< span > Expand source code</ span >
202228</ summary >
203- < pre > < code class ="python "> async def handle(self, req: Request) -> Response:
229+ < pre > < code class ="python "> async def handle(
230+ self, req: Request, addition_context_properties: Optional[Dict[str, Any]] = None
231+ ) -> Response:
204232 body = await req.body()
205233 if req.method == "GET":
206234 if self.app.oauth_flow is not None:
207235 oauth_flow: AsyncOAuthFlow = self.app.oauth_flow
208236 if req.url.path == oauth_flow.install_path:
209237 bolt_resp = await oauth_flow.handle_installation(
210- to_async_bolt_request(req, body)
238+ to_async_bolt_request(req, body, addition_context_properties )
211239 )
212240 return to_starlette_response(bolt_resp)
213241 elif req.url.path == oauth_flow.redirect_uri_path:
214242 bolt_resp = await oauth_flow.handle_callback(
215- to_async_bolt_request(req, body)
243+ to_async_bolt_request(req, body, addition_context_properties )
216244 )
217245 return to_starlette_response(bolt_resp)
218246 elif req.method == "POST":
219- bolt_resp = await self.app.async_dispatch(to_async_bolt_request(req, body))
247+ bolt_resp = await self.app.async_dispatch(
248+ to_async_bolt_request(req, body, addition_context_properties)
249+ )
220250 return to_starlette_response(bolt_resp)
221251
222252 return Response(
0 commit comments