Skip to content

Commit 66aad21

Browse files
committed
Update docstring and add the api-docs generator script
1 parent 1282934 commit 66aad21

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1719
-384
lines changed

.github/maintainers_guide.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ $ ngrok http 3000 --subdomain {your-domain}
109109

110110
### Releasing
111111

112+
#### Generate API documents
113+
114+
```bash
115+
./scripts/generate_api_docs.sh
116+
```
117+
112118
#### test.pypi.org deployment
113119

114120
##### $HOME/.pypirc

docs/_includes/sidebar.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
<a href="{{ site.url | append: site.baseurl | append: localized_base_url }}/tutorial/getting-started">
2424
<li class="title">{{ site.t[page.lang].start }}</li>
2525
</a>
26+
<a href="{{ site.url | append: site.baseurl | append: localized_base_url }}/api-docs/slack_bolt/" target="_blank">
27+
<li class="title">API Documents</li>
28+
</a>
2629
</ul>
2730

2831
<ul class="sidebar-section">

scripts/generate_api_docs.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
# Generate API documents from the latest source code
3+
4+
script_dir=`dirname $0`
5+
cd ${script_dir}/..
6+
7+
pip install pdoc3
8+
rm -rf docs/api-docs
9+
pdoc slack_bolt --html -o docs/api-docs
10+
open docs/api-docs/slack_bolt/index.html

slack_bolt/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
"""
2+
A Python framework to build Slack apps in a flash with the latest platform features. Read the [getting started guide](https://slack.dev/bolt-python/tutorial/getting-started) and look at our [code examples](https://github.com/slackapi/bolt-python/tree/main/examples) to learn how to build apps using Bolt.
3+
4+
* Website: https://slack.dev/bolt-python/
5+
* GitHub repository: https://github.com/slackapi/bolt-python
6+
* The class representing a Bolt app: `slack_bolt.app.app`
7+
"""
18
# Don't add async module imports here
29
from .app import App # noqa
310
from .context import BoltContext # noqa

slack_bolt/adapter/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"""Adapter modules for running Bolt apps along with Web frameworks or Socket Mode.
2+
"""

slack_bolt/app/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1+
"""Application interface in Bolt.
2+
3+
For most use cases, we recommend using `slack_bolt.app.app`.
4+
If you already have knowledge about asyncio and prefer the programming model,
5+
you can use `slack_bolt.app.async_app` for building async apps.\
6+
"""
7+
18
# Don't add async module imports here
29
from .app import App # type: ignore

slack_bolt/app/app.py

Lines changed: 327 additions & 79 deletions
Large diffs are not rendered by default.

slack_bolt/app/async_app.py

Lines changed: 333 additions & 75 deletions
Large diffs are not rendered by default.

slack_bolt/app/async_server.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ def __init__( # type:ignore
1919
path: str,
2020
app: "AsyncApp", # type:ignore
2121
):
22-
"""Standalone AIOHTTP Web Server
22+
"""Standalone AIOHTTP Web Server.
23+
Refer to https://docs.aiohttp.org/en/stable/web.html for details of AIOHTTP.
2324
24-
Refer to AIOHTTP documents for details.
25-
https://docs.aiohttp.org/en/stable/web.html
25+
Args:
26+
port: The port to listen on
27+
path: The path to receive incoming requests from Slack
28+
app: The `AsyncApp` instance that is used for processing requests
2629
"""
2730
self.port = port
2831
self.path = path
@@ -70,10 +73,7 @@ async def handle_post_requests(self, request: web.Request) -> web.Response:
7073
return await to_aiohttp_response(bolt_resp)
7174

7275
def start(self) -> None:
73-
"""Starts a new web server process.
74-
75-
:return: None
76-
"""
76+
"""Starts a new web server process."""
7777
if self.bolt_app.logger.level > logging.INFO:
7878
print(get_boot_message())
7979
else:

slack_bolt/async_app.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,49 @@
1+
"""Module for creating asyncio based apps
2+
3+
### Creating an async app
4+
5+
If you'd prefer to build your app with [asyncio](https://docs.python.org/3/library/asyncio.html), you can import the [AIOHTTP](https://docs.aiohttp.org/en/stable/) library and call the `AsyncApp` constructor. Within async apps, you can use the async/await pattern.
6+
7+
```bash
8+
# Python 3.6+ required
9+
python -m venv .venv
10+
source .venv/bin/activate
11+
12+
pip install -U pip
13+
# aiohttp is required
14+
pip install slack_bolt aiohttp
15+
```
16+
17+
In async apps, all middleware/listeners must be async functions. When calling utility methods (like `ack` and `say`) within these functions, it's required to use the `await` keyword.
18+
19+
```python
20+
# Import the async app instead of the regular one
21+
from slack_bolt.async_app import AsyncApp
22+
23+
app = AsyncApp()
24+
25+
@app.event("app_mention")
26+
async def event_test(body, say, logger):
27+
logger.info(body)
28+
await say("What's up?")
29+
30+
@app.command("/hello-bolt-python")
31+
async def command(ack, body, respond):
32+
await ack()
33+
await respond(f"Hi <@{body['user_id']}>!")
34+
35+
if __name__ == "__main__":
36+
app.start(3000)
37+
```
38+
39+
If you want to use another async Web framework (e.g., Sanic, FastAPI, Starlette), take a look at the built-in adapters and their examples.
40+
41+
* [The Bolt app examples](https://github.com/slackapi/bolt-python/tree/main/examples)
42+
* [The built-in adapters](https://github.com/slackapi/bolt-python/tree/main/slack_bolt/adapter)
43+
Apps can be run the same way as the synchronous example above. If you'd prefer another async Web framework (e.g., Sanic, FastAPI, Starlette), take a look at [the built-in adapters](https://github.com/slackapi/bolt-python/tree/main/slack_bolt/adapter) and their corresponding [examples](https://github.com/slackapi/bolt-python/tree/main/examples).
44+
45+
Refer to `slack_bolt.app.async_app` for more details.
46+
"""
147
from .app.async_app import AsyncApp # noqa
248
from .context.ack.async_ack import AsyncAck # noqa
349
from .context.async_context import AsyncBoltContext # noqa

0 commit comments

Comments
 (0)