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: 8 additions & 10 deletions docs/reference/adapter/asgi/base_handler.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,13 @@ <h2 class="section-title" id="header-classes">Classes</h2>
return AsgiHttpResponse(status=bolt_response.status, headers=bolt_response.headers, body=bolt_response.body)
return AsgiHttpResponse(status=404, headers={&#34;content-type&#34;: [&#34;text/plain;charset=utf-8&#34;]}, body=&#34;Not Found&#34;)

async def _handle_lifespan(self, receive: Callable) -&gt; Dict[str, str]:
while True:
lifespan = await receive()
if lifespan[&#34;type&#34;] == &#34;lifespan.startup&#34;:
&#34;&#34;&#34;Do something before startup&#34;&#34;&#34;
return {&#34;type&#34;: &#34;lifespan.startup.complete&#34;}
if lifespan[&#34;type&#34;] == &#34;lifespan.shutdown&#34;:
&#34;&#34;&#34;Do something before shutdown&#34;&#34;&#34;
return {&#34;type&#34;: &#34;lifespan.shutdown.complete&#34;}
async def _handle_lifespan(self, receive: Callable, send: Callable) -&gt; None:
message = await receive()
if message[&#34;type&#34;] == &#34;lifespan.startup&#34;:
await send({&#34;type&#34;: &#34;lifespan.startup.complete&#34;})
message = await receive()
if message[&#34;type&#34;] == &#34;lifespan.shutdown&#34;:
await send({&#34;type&#34;: &#34;lifespan.shutdown.complete&#34;})

async def __call__(self, scope: scope_type, receive: Callable, send: Callable) -&gt; None:
if scope[&#34;type&#34;] == &#34;http&#34;:
Expand All @@ -107,7 +105,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
await send(response.get_response_body())
return
if scope[&#34;type&#34;] == &#34;lifespan&#34;:
await send(await self._handle_lifespan(receive))
await self._handle_lifespan(receive, send)
return
raise TypeError(f&#34;Unsupported scope type: {scope[&#39;type&#39;]!r}&#34;)</code></pre>
</details>
Expand Down
44 changes: 28 additions & 16 deletions docs/reference/adapter/asgi/http_response.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,14 @@ <h2 class="section-title" id="header-classes">Classes</h2>

def __init__(self, status: int, headers: Dict[str, Sequence[str]] = {}, body: str = &#34;&#34;):
self.status: int = status
self.raw_headers: List[Tuple[bytes, bytes]] = [
(bytes(key, ENCODING), bytes(value[0], ENCODING)) for key, value in headers.items()
]
self.raw_headers.append((b&#34;content-length&#34;, bytes(str(len(body)), ENCODING)))
self.body: bytes = bytes(body, ENCODING)
self.raw_headers: List[Tuple[bytes, bytes]] = []
for key, values in headers.items():
if key.lower() == &#34;content-length&#34;:
continue
for v in values:
self.raw_headers.append((bytes(key, ENCODING), bytes(v, ENCODING)))
self.raw_headers.append((b&#34;content-length&#34;, bytes(str(len(self.body)), ENCODING)))

def get_response_start(self) -&gt; Dict[str, Union[str, int, Iterable[Tuple[bytes, bytes]]]]:
return {
Expand Down Expand Up @@ -94,11 +97,14 @@ <h3>Instance variables</h3>

def __init__(self, status: int, headers: Dict[str, Sequence[str]] = {}, body: str = &#34;&#34;):
self.status: int = status
self.raw_headers: List[Tuple[bytes, bytes]] = [
(bytes(key, ENCODING), bytes(value[0], ENCODING)) for key, value in headers.items()
]
self.raw_headers.append((b&#34;content-length&#34;, bytes(str(len(body)), ENCODING)))
self.body: bytes = bytes(body, ENCODING)
self.raw_headers: List[Tuple[bytes, bytes]] = []
for key, values in headers.items():
if key.lower() == &#34;content-length&#34;:
continue
for v in values:
self.raw_headers.append((bytes(key, ENCODING), bytes(v, ENCODING)))
self.raw_headers.append((b&#34;content-length&#34;, bytes(str(len(self.body)), ENCODING)))

def get_response_start(self) -&gt; Dict[str, Union[str, int, Iterable[Tuple[bytes, bytes]]]]:
return {
Expand Down Expand Up @@ -127,11 +133,14 @@ <h3>Instance variables</h3>

def __init__(self, status: int, headers: Dict[str, Sequence[str]] = {}, body: str = &#34;&#34;):
self.status: int = status
self.raw_headers: List[Tuple[bytes, bytes]] = [
(bytes(key, ENCODING), bytes(value[0], ENCODING)) for key, value in headers.items()
]
self.raw_headers.append((b&#34;content-length&#34;, bytes(str(len(body)), ENCODING)))
self.body: bytes = bytes(body, ENCODING)
self.raw_headers: List[Tuple[bytes, bytes]] = []
for key, values in headers.items():
if key.lower() == &#34;content-length&#34;:
continue
for v in values:
self.raw_headers.append((bytes(key, ENCODING), bytes(v, ENCODING)))
self.raw_headers.append((b&#34;content-length&#34;, bytes(str(len(self.body)), ENCODING)))

def get_response_start(self) -&gt; Dict[str, Union[str, int, Iterable[Tuple[bytes, bytes]]]]:
return {
Expand Down Expand Up @@ -160,11 +169,14 @@ <h3>Instance variables</h3>

def __init__(self, status: int, headers: Dict[str, Sequence[str]] = {}, body: str = &#34;&#34;):
self.status: int = status
self.raw_headers: List[Tuple[bytes, bytes]] = [
(bytes(key, ENCODING), bytes(value[0], ENCODING)) for key, value in headers.items()
]
self.raw_headers.append((b&#34;content-length&#34;, bytes(str(len(body)), ENCODING)))
self.body: bytes = bytes(body, ENCODING)
self.raw_headers: List[Tuple[bytes, bytes]] = []
for key, values in headers.items():
if key.lower() == &#34;content-length&#34;:
continue
for v in values:
self.raw_headers.append((bytes(key, ENCODING), bytes(v, ENCODING)))
self.raw_headers.append((b&#34;content-length&#34;, bytes(str(len(self.body)), ENCODING)))

def get_response_start(self) -&gt; Dict[str, Union[str, int, Iterable[Tuple[bytes, bytes]]]]:
return {
Expand Down
12 changes: 6 additions & 6 deletions docs/reference/adapter/falcon/async_resource.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ <h2 class="section-title" id="header-classes">Classes</h2>
await self._write_response(bolt_resp, resp)
return

resp.status = &#34;404&#34;
# Falcon 4.x w/ mypy fails to correctly infer the str type here
resp.body = &#34;The page is not found...&#34;
resp.status = HTTPStatus.NOT_FOUND
resp.content_type = MEDIA_TEXT
resp.text = &#34;The page is not found...&#34;

async def on_post(self, req: Request, resp: Response):
bolt_req = await self._to_bolt_request(req)
Expand Down Expand Up @@ -149,9 +149,9 @@ <h3>Methods</h3>
await self._write_response(bolt_resp, resp)
return

resp.status = &#34;404&#34;
# Falcon 4.x w/ mypy fails to correctly infer the str type here
resp.body = &#34;The page is not found...&#34;</code></pre>
resp.status = HTTPStatus.NOT_FOUND
resp.content_type = MEDIA_TEXT
resp.text = &#34;The page is not found...&#34;</code></pre>
</details>
<div class="desc"></div>
</dd>
Expand Down
12 changes: 6 additions & 6 deletions docs/reference/adapter/falcon/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ <h2 class="section-title" id="header-classes">Classes</h2>
self._write_response(bolt_resp, resp)
return

resp.status = &#34;404&#34;
# Falcon 4.x w/ mypy fails to correctly infer the str type here
resp.body = &#34;The page is not found...&#34;
resp.status = HTTPStatus.NOT_FOUND
resp.content_type = MEDIA_TEXT
resp.text = &#34;The page is not found...&#34;

def on_post(self, req: Request, resp: Response):
bolt_req = self._to_bolt_request(req)
Expand Down Expand Up @@ -159,9 +159,9 @@ <h3>Methods</h3>
self._write_response(bolt_resp, resp)
return

resp.status = &#34;404&#34;
# Falcon 4.x w/ mypy fails to correctly infer the str type here
resp.body = &#34;The page is not found...&#34;</code></pre>
resp.status = HTTPStatus.NOT_FOUND
resp.content_type = MEDIA_TEXT
resp.text = &#34;The page is not found...&#34;</code></pre>
</details>
<div class="desc"></div>
</dd>
Expand Down
12 changes: 6 additions & 6 deletions docs/reference/adapter/falcon/resource.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ <h2 class="section-title" id="header-classes">Classes</h2>
self._write_response(bolt_resp, resp)
return

resp.status = &#34;404&#34;
# Falcon 4.x w/ mypy fails to correctly infer the str type here
resp.body = &#34;The page is not found...&#34;
resp.status = HTTPStatus.NOT_FOUND
resp.content_type = MEDIA_TEXT
resp.text = &#34;The page is not found...&#34;

def on_post(self, req: Request, resp: Response):
bolt_req = self._to_bolt_request(req)
Expand Down Expand Up @@ -148,9 +148,9 @@ <h3>Methods</h3>
self._write_response(bolt_resp, resp)
return

resp.status = &#34;404&#34;
# Falcon 4.x w/ mypy fails to correctly infer the str type here
resp.body = &#34;The page is not found...&#34;</code></pre>
resp.status = HTTPStatus.NOT_FOUND
resp.content_type = MEDIA_TEXT
resp.text = &#34;The page is not found...&#34;</code></pre>
</details>
<div class="desc"></div>
</dd>
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/adapter/socket_mode/async_internals.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
<span>Expand source code</span>
</summary>
<pre><code class="python">async def run_async_bolt_app(app: AsyncApp, req: SocketModeRequest):
bolt_req: AsyncBoltRequest = AsyncBoltRequest(mode=&#34;socket_mode&#34;, body=req.payload)
bolt_req: AsyncBoltRequest = AsyncBoltRequest(mode=&#34;socket_mode&#34;, body=req.payload, headers=build_headers(req))
bolt_resp: BoltResponse = await app.async_dispatch(bolt_req)
return bolt_resp</code></pre>
</details>
Expand Down
22 changes: 21 additions & 1 deletion docs/reference/adapter/socket_mode/internals.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,25 @@ <h1 class="title">Module <code>slack_bolt.adapter.socket_mode.internals</code></
<section>
<h2 class="section-title" id="header-functions">Functions</h2>
<dl>
<dt id="slack_bolt.adapter.socket_mode.internals.build_headers"><code class="name flex">
<span>def <span class="ident">build_headers</span></span>(<span>req:ย slack_sdk.socket_mode.request.SocketModeRequest) โ€‘>ย Dict[str,ย strย |ย Sequence[str]]ย |ย None</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def build_headers(req: SocketModeRequest) -&gt; Optional[Dict[str, Union[str, Sequence[str]]]]:
# Mirror the HTTP mode retry headers so middleware/listeners can detect Events API retries
headers: Dict[str, Union[str, Sequence[str]]] = {}
if req.retry_attempt is not None:
headers[&#34;x-slack-retry-num&#34;] = str(req.retry_attempt)
if req.retry_reason is not None:
headers[&#34;x-slack-retry-reason&#34;] = req.retry_reason
return headers or None</code></pre>
</details>
<div class="desc"></div>
</dd>
<dt id="slack_bolt.adapter.socket_mode.internals.run_bolt_app"><code class="name flex">
<span>def <span class="ident">run_bolt_app</span></span>(<span>app:ย <a title="slack_bolt.app.app.App" href="../../app/app.html#slack_bolt.app.app.App">App</a>,<br>req:ย slack_sdk.socket_mode.request.SocketModeRequest)</span>
</code></dt>
Expand All @@ -54,7 +73,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
<span>Expand source code</span>
</summary>
<pre><code class="python">def run_bolt_app(app: App, req: SocketModeRequest):
bolt_req: BoltRequest = BoltRequest(mode=&#34;socket_mode&#34;, body=req.payload)
bolt_req: BoltRequest = BoltRequest(mode=&#34;socket_mode&#34;, body=req.payload, headers=build_headers(req))
bolt_resp: BoltResponse = app.dispatch(bolt_req)
return bolt_resp</code></pre>
</details>
Expand Down Expand Up @@ -111,6 +130,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
</li>
<li><h3><a href="#header-functions">Functions</a></h3>
<ul class="">
<li><code><a title="slack_bolt.adapter.socket_mode.internals.build_headers" href="#slack_bolt.adapter.socket_mode.internals.build_headers">build_headers</a></code></li>
<li><code><a title="slack_bolt.adapter.socket_mode.internals.run_bolt_app" href="#slack_bolt.adapter.socket_mode.internals.run_bolt_app">run_bolt_app</a></code></li>
<li><code><a title="slack_bolt.adapter.socket_mode.internals.send_response" href="#slack_bolt.adapter.socket_mode.internals.send_response">send_response</a></code></li>
</ul>
Expand Down
15 changes: 9 additions & 6 deletions docs/reference/adapter/wsgi/handler.html
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,20 @@ <h2 class="section-title" id="header-classes">Classes</h2>

def __call__(
self,
environ: Dict[str, Any],
start_response: Callable[[str, List[Tuple[str, str]]], None],
environ: &#34;WSGIEnvironment&#34;,
start_response: &#34;StartResponse&#34;,
) -&gt; Iterable[bytes]:
request = WsgiHttpRequest(environ)
if &#34;HTTP&#34; in request.protocol:
if request.protocol.startswith(&#34;HTTP&#34;):
response: WsgiHttpResponse = self._get_http_response(
request=request,
)
start_response(response.status, response.get_headers())
return response.get_body()
raise TypeError(f&#34;Unsupported SERVER_PROTOCOL: {request.protocol}&#34;)</code></pre>
else:
response = WsgiHttpResponse(
status=400, headers={&#34;content-type&#34;: [&#34;text/plain;charset=utf-8&#34;]}, body=&#34;Bad Request&#34;
)
start_response(response.status, response.get_headers())
return response.get_body()</code></pre>
</details>
<div class="desc"><p>Setup Bolt as a WSGI web framework, this will make your application compatible with WSGI web servers.
This can be used for production deployments.</p>
Expand Down
Loading