Skip to content

Commit

Permalink
Update Japanese document about shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
seratch committed Mar 25, 2020
1 parent a8abaf9 commit 37bfd07
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 70 deletions.
7 changes: 3 additions & 4 deletions docs/_advanced/ja_receiver.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ order: 8
| `start()` | None | `Promise` |
| `stop()` | None | `Promise` |

Bolt アプリでは `init()` が 2 回呼び出されます。
* `await app.processEvent(event)` は、解析されたすべての着信リクエストを `onIncomingEvent()` にルーティングする必要があります。これは、Bolt アプリでは `this.receiver.on('message', message => this.onIncomingEvent(message))` として呼び出されます。
* `await app.handleError` は、エラーをグローバルエラーハンドラーにルーティングする必要があります。これは、Bolt アプリでは `this.receiver.on('error', error => this.onGlobalError(error))` として呼び出されます。
Bolt アプリでは `init()` が 2 回呼び出されます。このメソッドはレシーバーに `App` の参照を付与するため、これにより以下の呼び出しが可能になります。
* `await app.processEvent(event)` は Slack から送信されてくるイベントを受け取るたびに呼び出されます。ハンドリングされなかったエラーが発生した場合はそれを throw します。

Bolt アプリを初期化するときにカスタムレシーバーをコンストラクタに渡すことで、そのカスタムレシーバーを使用できます。ここで紹介するのは、基本的なカスタムレシーバーです。

レシーバーについて詳しくは、[組み込み Express レシーバーのソースコード](https://github.com/slackapi/bolt/blob/master/src/ExpressReceiver.ts)をお読みください。
レシーバーについて詳しくは、[組み込み `ExpressReceiver` のソースコード](https://github.com/slackapi/bolt/blob/master/src/ExpressReceiver.ts)をお読みください。
</div>

```javascript
Expand Down
65 changes: 0 additions & 65 deletions docs/_basic/ja_ listening_responding_shortcuts.md

This file was deleted.

133 changes: 133 additions & 0 deletions docs/_basic/ja_listening_responding_shortcuts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
---
title: ショートカットのリスニング
lang: ja-jp
slug: shortcuts
order: 8
---

<div class="section-content">
`shortcut()` メソッドは、[グローバルショートカット](https://api.slack.com/interactivity/shortcuts/using#global_shortcuts)[メッセージショートカット](https://api.slack.com/interactivity/shortcuts/using#message_shortcuts)の両方をサポートします。

ショートカットは、テキスト入力エリアや検索バーから起動できる Slack クライアント内の UI エレメントです。グローバルショートカットは、コンポーザーメニューまたは検索メニューから呼び出すことができます。メッセージショートカットは、メッセージのコンテキストメニュー内にあります。`shortcut()` メソッドを使って、これらのショートカットのイベントをリスニングすることができます。このメソッドには `callback_id` を文字列または正規表現のデータ型で設定します。

グローバルショートカットのイベントは Slack へイベントを受信したことを知らせるために `ack()` メソッドで確認する必要があります。

グローバルショートカットのペイロードは、ユーザーの実行アクションの確認のために[モーダルを開く](#creating-modals)などの用途に使用できる `trigger_id` を含んでいます。

⚠️ グローバルショートカットのペイロードは **チャンネル ID は含んでいない** ことに注意してください。もしあなたのアプリがチャンネル ID を知る必要があれば、モーダル内で [`conversations_select`](https://api.slack.com/reference/block-kit/block-elements#conversation_select) エレメントを使用できます。
メッセージショートカットのペイロードはチャンネル ID を含みます。
</div>

```javascript
// open_modal というグローバルショートカットはシンプルなモーダルを開く
app.shortcut('open_modal', async ({ shortcut, ack, context }) => {
// グローバルショートカットリクエストの確認
ack();

try {
// 組み込みの WebClient を使って views.open API メソッドを呼び出す
const result = await app.client.views.open({
// `context` オブジェクトに保持されたトークンを使用
token: context.botToken,
trigger_id: shortcut.trigger_id,
view: {
"type": "modal",
"title": {
"type": "plain_text",
"text": "My App"
},
"close": {
"type": "plain_text",
"text": "Close"
},
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "About the simplest modal you could conceive of :smile:\n\nMaybe <https://api.slack.com/reference/block-kit/interactive-components|*make the modal interactive*> or <https://api.slack.com/surfaces/modals/using#modifying|*learn more advanced modal use cases*>."
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "Psssst this modal was designed using <https://api.slack.com/tools/block-kit-builder|*Block Kit Builder*>"
}
]
}
]
}
});

console.log(result);
}
catch (error) {
console.error(error);
}
});
```

<details class="secondary-wrapper">
<summary class="section-head" markdown="0">
<h4 class="section-head">制約付きオブジェクトを使用したショートカットのリスニング</h4>
</summary>

<div class="secondary-content" markdown="0">
制約付きオブジェクトを使って `callback_id``type` によるリスニングをすることができます。オブジェクト内の制約は文字列型または RegExp オブジェクトを使用できます。

</div>

```javascript
// callback_id が 'open_modal' と一致し type が 'message_action' と一致する場合のみミドルウェアが呼び出される
app.shortcut({ callback_id: 'open_modal', type: 'message_action' }, async ({ shortcut, ack, context, client }) => {
try {
// ショートカットリクエストの確認
await ack();

// 組み込みの WebClient を使って views.open API メソッドを呼び出す
const result = await app.client.views.open({
// `context` オブジェクトに保持されたトークンを使用
token: context.botToken,
trigger_id: shortcut.trigger_id,
view: {
type: "modal",
title: {
type: "plain_text",
text: "My App"
},
close: {
type: "plain_text",
text: "Close"
},
blocks: [
{
type: "section",
text: {
type: "mrkdwn",
text: "About the simplest modal you could conceive of :smile:\n\nMaybe <https://api.slack.com/reference/block-kit/interactive-components|*make the modal interactive*> or <https://api.slack.com/surfaces/modals/using#modifying|*learn more advanced modal use cases*>."
}
},
{
type: "context",
elements: [
{
type: "mrkdwn",
text: "Psssst this modal was designed using <https://api.slack.com/tools/block-kit-builder|*Block Kit Builder*>"
}
]
}
]
}
});

console.log(result);
}
catch (error) {
console.error(error);
}
});
```

</details>
2 changes: 1 addition & 1 deletion docs/_tutorials/ja_getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ app.message('hello', async ({ message, say }) => {

### アクションの送信と応答

ボタン、選択メニュー、日付ピッカー、ダイアログ、メッセージショートカットなどの機能を使用するには、インタラクティブ性を有効にする必要があります。イベントと同様に、Slack の URL を指定してアクション ( 「ボタン・クリック」など) を送信する必要があります。
ボタン、選択メニュー、日付ピッカー、ダイアログなどの機能を使用するには、インタラクティブ性を有効にする必要があります。イベントと同様に、Slack の URL を指定してアクション ( 「ボタン・クリック」など) を送信する必要があります。

アプリ設定ページに戻り、左側の **Interactive Components** をクリックします。**Request URL** ボックスがもう 1 つあることがわかります。

Expand Down

0 comments on commit 37bfd07

Please sign in to comment.