Skip to content

Commit 57fdb45

Browse files
committed
Add Japanese version of Basic Concepts documents
1 parent cddcc95 commit 57fdb45

27 files changed

+875
-19
lines changed

docs/_advanced/async.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Using async
2+
title: Using async (asyncio)
33
lang: en
44
slug: async
55
order: 2

docs/_basic/authenticating_oauth.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ order: 15
77

88
<div class="section-content">
99

10-
Slack apps installed on multiple workspaces will need to implement OAuth, then store installation information (like access tokens) securely. By providing `client_id`, `client_secret`, `scopes`, `installation_store`, and `state_store` when initializing App, Bolt for Python will handle the work of setting up OAuth routes and verifying state. If youre implementing a custom adapter, you can make use of our [OAuth library](https://slack.dev/python-slack-sdk/oauth/), which is what Bolt for Python uses under the hood.
10+
Slack apps installed on multiple workspaces will need to implement OAuth, then store installation information (like access tokens) securely. By providing `client_id`, `client_secret`, `scopes`, `installation_store`, and `state_store` when initializing App, Bolt for Python will handle the work of setting up OAuth routes and verifying state. If you're implementing a custom adapter, you can make use of our [OAuth library](https://slack.dev/python-slack-sdk/oauth/), which is what Bolt for Python uses under the hood.
1111

12-
Bolt for Python will create a **Redirect URL** `slack/oauth_redirect`, which Slack uses to redirect users after they complete your apps installation flow. You will need to add this **Redirect URL** in your app configuration settings under **OAuth and Permissions**. This path can be configured in the `OAuthSettings` argument described below.
12+
Bolt for Python will create a **Redirect URL** `slack/oauth_redirect`, which Slack uses to redirect users after they complete your app's installation flow. You will need to add this **Redirect URL** in your app configuration settings under **OAuth and Permissions**. This path can be configured in the `OAuthSettings` argument described below.
1313

1414
Bolt for Python will also create a `slack/install` route, where you can find an **Add to Slack** button for your app to perform direct installs of your app. If you need any additional authorizations (user tokens) from users inside a team when your app is already installed or a reason to dynamically generate an install URL, you can pass your own custom URL generator to `oauth_settings` as `authorize_url_generator`.
1515

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: イベントの確認
3+
lang: ja-jp
4+
slug: acknowledge
5+
order: 7
6+
---
7+
8+
<div class="section-content">
9+
10+
アクション(action)、コマンド(command)、およびオプション(options)の各イベントは、**必ず** `ack()` 関数を使って確認を行う必要があります。これによってイベントが受信されたことが Slack に認識され、Slack のユーザーインターフェイスが適切に更新されます。
11+
12+
イベントの種類によっては、確認で通知方法が異なる場合があります。例えば、外部データソースを使用する選択メニューのオプションのリクエストに対する確認では、適切な[オプション](https://api.slack.com/reference/block-kit/composition-objects#option)のリストとともに `ack()` を呼び出します。
13+
14+
確認までの猶予は 3 秒しかないため、新しいメッセージの送信や、データベースからの情報の取得は、`ack()` を呼び出した後で行うことをおすすめします。
15+
16+
</div>
17+
18+
```python
19+
# 外部データを使用する選択メニューオプションに応答するサンプル
20+
@app.options("menu_selection")
21+
def show_menu_options(ack):
22+
options = [
23+
{
24+
"text": {"type": "plain_text", "text":"Option 1"},
25+
"value":"1-1",
26+
},
27+
{
28+
"text": {"type": "plain_text", "text":"Option 2"},
29+
"value":"1-2",
30+
},
31+
]
32+
ack(options=options)
33+
```
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---
2+
title: OAuth を使った認証
3+
lang: ja-jp
4+
slug: authenticating-oauth
5+
order: 15
6+
---
7+
8+
<div class="section-content">
9+
10+
Slack アプリを複数のワークスペースにインストールできるようにするためには、OAuth フローを実装した上で、アクセストークンなどのインストールに関する情報をセキュアな方法で保存する必要があります。アプリを初期化する際に `client_id``client_secret``scopes``installation_store``state_store` を指定することで、OAuth のエンドポイントのルート情報や stateパラメーターの検証をBolt for Python にハンドリングさせることができます。カスタムのアダプターを実装する場合は、SDK が提供する組み込みの[OAuth ライブラリ](https://slack.dev/python-slack-sdk/oauth/)を利用するのが便利です。これは Slack が開発したモジュールで、Bolt for Python 内部でも利用しています。
11+
12+
Bolt for Python によって `slack/oauth_redirect` という**リダイレクト URL** が生成されます。Slack はアプリのインストールフローを完了させたユーザーをこの URL にリダイレクトします。この**リダイレクト URL** は、アプリの設定の「**OAuth and Permissions**」であらかじめ追加しておく必要があります。この URL は、後ほど説明するように `OAuthSettings` というコンストラクタの引数で指定することもできます。
13+
14+
Bolt for Python は `slack/install` というルートも生成します。これはアプリを直接インストールするための「**Add to Slack**」ボタンを表示するために使われます。すでにワークスペースへのアプリのインストールが済んでいる場合に追加で各ユーザーのユーザートークンなどの情報を取得する場合や、カスタムのインストール用の URL を動的に生成したい場合などは、`oauth_settings``authorize_url_generator` でカスタムの URL ジェネレーターを指定することができます。
15+
16+
バージョン 1.1.0 以降の Bolt for Python では、[OrG 全体へのインストール](https://api.slack.com/enterprise/apps)がデフォルトでサポートされています。OrG 全体へのインストールは、アプリの設定の「**Org Level Apps**」で有効化できます。
17+
18+
Slack での OAuth を使ったインストールフローについて詳しくは、[API ドキュメントを参照してください](https://api.slack.com/authentication/oauth-v2)
19+
20+
</div>
21+
22+
```python
23+
import os
24+
from slack_bolt import App
25+
from slack_bolt.oauth.oauth_settings import OAuthSettings
26+
from slack_sdk.oauth.installation_store import FileInstallationStore
27+
from slack_sdk.oauth.state_store import FileOAuthStateStore
28+
29+
oauth_settings = OAuthSettings(
30+
client_id=os.environ["SLACK_CLIENT_ID"],
31+
client_secret=os.environ["SLACK_CLIENT_SECRET"],
32+
scopes=["channels:read", "groups:read", "chat:write"],
33+
installation_store=FileInstallationStore(base_dir="./data"),
34+
state_store=FileOAuthStateStore(expiration_seconds=600, base_dir="./data")
35+
)
36+
37+
app = App(
38+
signing_secret=os.environ["SIGNING_SECRET"],
39+
oauth_settings=oauth_settings
40+
)
41+
```
42+
43+
<details class="secondary-wrapper">
44+
<summary class="section-head" markdown="0">
45+
<h4 class="section-head">OAuth デフォルト設定をカスタマイズ</h4>
46+
</summary>
47+
48+
<div class="secondary-content" markdown="0">
49+
`oauth_settings` を使って OAuth モジュールのデフォルト設定を上書きすることができます。このカスタマイズされた設定は App の初期化時に渡します。以下の情報を変更可能です:
50+
51+
- `install_path` : 「Add to Slack」ボタンのデフォルトのパスを上書きするために使用
52+
- `redirect_uri` : リダイレクト URL のデフォルトのパスを上書きするために使用
53+
- `callback_options` : OAuth フローの最後に表示するカスタムの成功ページと失敗ページの表示処理を提供するために使用
54+
- `state_store` : 組み込みの `FileOAuthStateStore` に代わる、カスタムの stateに関するデータストアを指定するために使用
55+
- `installation_store` : 組み込みの `FileInstallationStore` に代わる、カスタムのデータストアを指定するために使用
56+
57+
</div>
58+
59+
```python
60+
from slack_bolt.oauth.callback_options import CallbackOptions, SuccessArgs, FailureArgs
61+
from slack_bolt.response import BoltResponse
62+
63+
def success(args:SuccessArgs) -> BoltResponse:
64+
assert args.request is not None
65+
return BoltResponse(
66+
status=200, # ユーザーをリダイレクトすることも可能
67+
body="Your own response to end-users here"
68+
)
69+
70+
def failure(args:FailureArgs) -> BoltResponse:
71+
assert args.request is not None
72+
assert args.reason is not None
73+
return BoltResponse(
74+
status=args.suggested_status_code,
75+
body="Your own response to end-users here"
76+
)
77+
78+
callback_options = CallbackOptions(success=success, failure=failure)
79+
80+
import os
81+
from slack_bolt import App
82+
from slack_bolt.oauth.oauth_settings import OAuthSettings
83+
from slack_sdk.oauth.installation_store import FileInstallationStore
84+
from slack_sdk.oauth.state_store import FileOAuthStateStore
85+
86+
app = App(
87+
signing_secret=os.environ.get("SLACK_SIGNING_SECRET"),
88+
installation_store=FileInstallationStore(base_dir="./data"),
89+
oauth_settings=OAuthSettings(
90+
client_id=os.environ.get("SLACK_CLIENT_ID"),
91+
client_secret=os.environ.get("SLACK_CLIENT_SECRET"),
92+
scopes=["app_mentions:read", "channels:history", "im:history", "chat:write"],
93+
user_scopes=[],
94+
redirect_uri=None,
95+
install_path="/slack/install",
96+
redirect_uri_path="/slack/oauth_redirect",
97+
state_store=FileOAuthStateStore(expiration_seconds=600, base_dir="./data"),
98+
callback_options=callback_options,
99+
),
100+
)
101+
```
102+
103+
</details>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
title: アクションのリスニング
3+
lang: ja-jp
4+
slug: action-listening
5+
order: 5
6+
---
7+
8+
<div class="section-content">
9+
Bolt アプリは `action` メソッドを用いて、ボタンのクリック、メニューの選択、メッセージショートカットなどのユーザーのアクションをリッスンすることができます。
10+
11+
アクションは `str` 型または `re.Pattern` 型の `action_id` でフィルタリングできます。`action_id` は、Slack プラットフォーム上のインタラクティブコンポーネントを区別する一意の識別子として機能します。
12+
13+
`action()` を使ったすべての例で `ack()` が使用されていることに注目してください。アクションのリスナー内では、Slack からのイベントを受信したことを確認するために、`ack()` 関数を呼び出す必要があります。これについては、[イベントの確認](#acknowledge)セクションで説明しています。
14+
15+
</div>
16+
17+
```python
18+
# 'approve_button' という action_id のブロックエレメントがトリガーされるたびに、このリスナーが呼び出させれる
19+
@app.action("approve_button")
20+
def update_message(ack):
21+
ack()
22+
# アクションへの反応としてメッセージを更新
23+
```
24+
25+
<details class="secondary-wrapper">
26+
<summary class="section-head" markdown="0">
27+
<h4 class="section-head">制約付きオブジェクトを使用したアクションのリスニング</h4>
28+
</summary>
29+
30+
<div class="secondary-content" markdown="0">
31+
32+
制約付きのオブジェクトを使用すると、`callback_id``block_id`、および `action_id` をそれぞれ、または任意に組み合わせてリッスンできます。オブジェクト内の制約は、`str` 型または `re.Pattern` 型で指定できます。
33+
34+
</div>
35+
36+
```python
37+
# この関数は、block_id が 'assign_ticket' に一致し
38+
# かつ action_id が 'select_user' に一致する場合にのみ呼び出される
39+
@app.action({
40+
"block_id": "assign_ticket",
41+
"action_id": "select_user"
42+
})
43+
def update_message(ack, body, client):
44+
ack()
45+
46+
if "container" in body and "message_ts" in body["container"]:
47+
client.reactions_add(
48+
name="white_check_mark",
49+
channel=body["channel"]["id"],
50+
timestamp=body["container"]["message_ts"],
51+
)
52+
```
53+
54+
</details>

docs/_basic/ja_listening_events.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
title: イベントのリスニング
3+
lang: ja-jp
4+
slug: event-listening
5+
order: 3
6+
---
7+
8+
<div class="section-content">
9+
10+
`event()` メソッドを使うと、[Events API](https://api.slack.com/events) の任意のイベントをリッスンできます。リッスンするイベントは、アプリの設定であらかじめサブスクライブしておく必要があります。これを利用することで、アプリがインストールされたワークスペースで何らかのイベント(例:ユーザーがメッセージにリアクションをつけた、ユーザーがチャンネルに参加した)が発生したときに、アプリに何らかのアクションを実行させることができます。
11+
12+
`event()` メソッドには `str` 型の `eventType` を指定する必要があります。
13+
14+
</div>
15+
16+
```python
17+
# ユーザーがワークスペースに参加した際に、自己紹介を促すメッセージを指定のチャンネルに送信
18+
@app.event("team_join")
19+
def ask_for_introduction(event, say):
20+
welcome_channel_id = "C12345"
21+
user_id = event["user"]
22+
text = f"Welcome to the team, <@{user_id}>! 🎉 You can introduce yourself in this channel."
23+
say(text=text, channel=welcome_channel_id)
24+
```
25+
26+
<details class="secondary-wrapper" >
27+
28+
<summary class="section-head" markdown="0">
29+
<h4 class="section-head">メッセージのサブタイプのフィルタリング</h4>
30+
</summary>
31+
32+
<div class="secondary-content" markdown="0">
33+
`message()` リスナーは `event("message")` と等価の機能を提供します。
34+
35+
`subtype` という追加のキーを指定して、イベントのサブタイプでフィルタリングすることもできます。よく使われるサブタイプには、`bot_message``message_replied` があります。詳しくは[メッセージイベントページ](https://api.slack.com/events/message#message_subtypes)を参照してください。
36+
37+
</div>
38+
39+
```python
40+
# 変更されたすべてのメッセージに一致
41+
@app.event({
42+
"type": "message",
43+
"subtype": "message_changed"
44+
})
45+
def log_message_change(logger, event):
46+
user, text = event["user"], event["text"]
47+
logger.info(f"The user {user} changed the message to {text}")
48+
```
49+
</details>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
title: メッセージのリスニング
3+
lang: ja-jp
4+
slug: message-listening
5+
order: 1
6+
---
7+
8+
<div class="section-content">
9+
10+
[あなたのアプリがアクセス権限を持つ](https://api.slack.com/messaging/retrieving#permissions)メッセージの投稿イベントをリッスンするには `message()` メソッドを利用します。このメソッドは `type``message` ではないイベントを処理対象から除外します。
11+
12+
`message()` の引数には `str` 型または `re.Pattern` オブジェクトを指定できます。この条件のパターンに一致しないメッセージは除外されます。
13+
14+
</div>
15+
16+
```python
17+
# '👋' が含まれるすべてのメッセージに一致
18+
@app.message(":wave:")
19+
def say_hello(message, say):
20+
user = message['user']
21+
say(f"Hi there, <@{user}>!")
22+
```
23+
24+
<details class="secondary-wrapper">
25+
<summary markdown="0">
26+
<h4 class="secondary-header">正規表現パターンの使用</h4>
27+
</summary>
28+
29+
<div class="secondary-content" markdown="0">
30+
31+
文字列の代わりに `re.compile()` メソッドを使用すれば、より細やかな条件指定ができます。
32+
33+
</div>
34+
35+
```python
36+
import re
37+
38+
@app.message(re.compile("(hi|hello|hey)"))
39+
def say_hello_regex(say, context):
40+
# 正規表現のマッチ結果は context.matches に設定される
41+
greeting = context['matches'][0]
42+
say(f"{greeting}, how are you?")
43+
```
44+
45+
</details>

docs/_basic/ja_listening_modals.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: モーダルの送信のリスニング
3+
lang: ja-jp
4+
slug: view_submissions
5+
order: 12
6+
---
7+
8+
<div class="section-content">
9+
10+
<a href="https://api.slack.com/reference/block-kit/views">モーダルのペイロード</a>に input ブロックを含める場合、その入力値を受け取るために`view_submission` イベントをリッスンする必要があります。`view_submission` イベントのリッスンには、組み込みの`view()` メソッドを利用することができます。`view()` の引数には、`str` 型または `re.Pattern` 型の `callback_id` を指定します。
11+
12+
`input` ブロックの値にアクセスするには `state` オブジェクトを参照します。`state` 内には `values` というオブジェクトがあり、`block_id` と一意の `action_id` に紐づける形で入力値を保持しています。
13+
14+
モーダルの送信について詳しくは、<a href="https://api.slack.com/surfaces/modals/using#interactions">API ドキュメント</a>を参照してください。
15+
16+
</div>
17+
18+
```python
19+
# view_submission イベントを処理
20+
@app.view("view_1")
21+
def handle_submission(ack, body, client, view):
22+
# `block_c`という block_id に `dreamy_input` を持つ input ブロックがある場合
23+
hopes_and_dreams = view["state"]["values"]["block_c"]["dreamy_input"]
24+
user = body["user"]["id"]
25+
# 入力値を検証
26+
errors = {}
27+
if hopes_and_dreams is not None and len(hopes_and_dreams) <= 5:
28+
errors["block_c"] = "The value must be longer than 5 characters"
29+
if len(errors) > 0:
30+
ack(response_action="errors", errors=errors)
31+
return
32+
# view_submission イベントの確認を行い、モーダルを閉じる
33+
ack()
34+
# 入力されたデータを使った処理を実行。このサンプルでは DB に保存する処理を行う
35+
# そして入力値の検証結果をユーザーに送信
36+
37+
# ユーザーに送信するメッセージ
38+
msg = ""
39+
try:
40+
# DB に保存
41+
msg = f"Your submission of {hopes_and_dreams} was successful"
42+
except Exception as e:
43+
# エラーをハンドリング
44+
msg = "There was an error with your submission"
45+
finally:
46+
# ユーザーにメッセージを送信
47+
client.chat_postMessage(channel=user, text=msg)
48+
```
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: コマンドのリスニングと応答
3+
lang: ja-jp
4+
slug: commands
5+
order: 9
6+
---
7+
8+
<div class="section-content">
9+
10+
スラッシュコマンドが実行されたイベントをリッスンするには、`command()` メソッドを使用します。このメソッドでは `str` 型の `command_name` の指定が必要です。
11+
12+
コマンドイベントをアプリが受信し確認したことを Slack に通知するため、`ack()` を呼び出す必要があります。
13+
14+
スラッシュコマンドに応答する方法は 2 つあります。1 つ目は `say()` を使う方法で、文字列または JSON のペイロードを渡すことができます。2 つ目は `respond()` を使う方法です。これは `response_url` がある場合に活躍します。これらの方法は[アクションへの応答](#action-respond)セクションで詳しく説明しています。
15+
16+
アプリの設定でコマンドを登録するときは、リクエスト URL の末尾に `/slack/events` をつけます。
17+
18+
</div>
19+
20+
```python
21+
# echoコマンドは受け取ったコマンドをそのまま返す
22+
@app.command("/echo")
23+
def repeat_text(ack, say, command):
24+
# command リクエストを確認
25+
ack()
26+
say(f"{command['text']}")
27+
```

0 commit comments

Comments
 (0)