# discourse-chat-integration プラグインを使用した Slack 通知の設定

**URL:** https://meta.discourse.org/t/set-up-slack-notifications-using-the-discourse-chat-integration-plugin/66730
**Category:** Integrations
**Tags:** chat-integration, how-to
**Created:** [2017 年 7 月 24 日午後 4:45 UTC](https://meta.discourse.org/t/set-up-slack-notifications-using-the-discourse-chat-integration-plugin/66730 "2017-07-24T16:45:28Z")
**Posts on this page:** 1
**Showing post:** 1

<div class="post-metadata">

### Author: ![Discourse](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/discourse/32/148734_2.png) [@Discourse](https://meta.discourse.org/u/Discourse)
#### Post date: [2017 年 7 月 24 日午後 4:45 UTC](https://meta.discourse.org/t/set-up-slack-notifications-using-the-discourse-chat-integration-plugin/66730/1 "2017-07-24T16:45:28Z")

</div>

この #howto では、`discourse-chat-integration` に含まれる Slack プロバイダーの設定方法を説明します。

これにより、Slack に通知を投稿したり、スラッシュコマンドを使用してルールを管理したり、トランスクリプトを Discourse に投稿したりできます。スラッシュコマンドの手順は、`/discourse help` と入力することで確認できます。トランスクリプトは、Slack の投稿のコンテキストメニューを使用して作成できます。

# インストール

まだの場合、[discourse-chat-integration](https://meta.discourse.org/t/chatroom-integration-plugin-discourse-chat-integration/66522) プラグインをインストールし、サイト設定の `chat integration enabled` で有効になっていることを確認してください。

# Slack の設定

1. [Slack API: Applications | Slack](https://api.slack.com/apps) に移動し、新しいアプリを作成します。まだログインしていない場合は、ログインを求められます。（ログイン後にリダイレクトされないようなので、このリンクをもう一度クリックする必要があるかもしれません ☹ ）

2. Create New App をクリックします

3. 名前を付け（任意）、参加させたい Slack チームを選択します  

4. 左側のメニューの「Features」の下にある「OAuth & Permissions」をクリックします。

5. 「Scopes / Bot Token Scopes」までスクロールダウンし、プラグインが Slack ワークスペースにメッセージを投稿できるように、これらすべてを追加します。

> [@](#):
>
> ### スラッシュコマンドとトランスクリプト投稿のため （これらが必要ない場合は、このブロックはスキップしてください）
> 
> 1. 「Scopes / Bot Token Scopes」の下に次のスコープを追加します
> 
> 2. 左側のメニューの「Features」の下にある Slash Commands ページに移動します。Create New Command をクリックします  
> 
> 3. Save
> 
> 4. Interactivity & Shortcuts ページに移動し、Interactivity セクションを On に切り替えて有効にし、「Request URL」の下にこの URL を入力します
> 
> 5. Save Changes
> 
> 6. Interactivity & Shortcuts ページに移動し、Create new Shortcut をクリックし、「On messages」を選択し、Next をクリックします。次の詳細を入力します。

1. 設定 \> Install App ページに移動し、`Install to Workspace` をクリックして、アプリをチームに認証させます。

2. `Bot User OAuth Token` をコピーし、Discourse サイト設定の `chat_integration_slack_access_token` に貼り付けます。

3. Basic Information ページに移動し、`Verification Token` をコピーし、Discourse サイト設定の `chat_integration_slack_incoming_webhook_token` に貼り付けます。

4. Basic Information ページの最下部で、ボットのアイコン、名前、説明を設定できます。

5. [discourse-chat-integration](https://meta.discourse.org/t/chatroom-integration-plugin-discourse-chat-integration/66522) の手順に従って、チャンネルの「ルール」を設定するか、あるいは、スラッシュコマンドを使用してチャンネル内で設定を開始します。

6. ボットが投稿できるチャンネルに Discourse ボットユーザーを追加します。

> [@](#):
>
> ## 「Granular Scopes」へのアップグレード
> 
> しばらく前に統合を設定した場合、上記のように機能させるには、Slack の「Granular Scopes」にアップグレードする必要があるかもしれません。
> 
> > **手順**
> >
> > 1. [Slack API: Applications | Slack](https://api.slack.com/apps) に移動し、Discourse 統合アプリを選択します。
> > 
> > 2. 左側で、「Update to Granular Scopes」を選択します。  
> > 
> > 3. 「Bot Token Scopes」について、`chat:write` と `chat:write.customize` を選択します。スラッシュコマンドや/またはトランスクリプト投稿を使用している場合は、`users:read`、`channels:history`、`groups:history`、`im:history` も選択します。他のすべてのスコープのチェックを外すことができます。
> > 
> > 4. Next をクリックします。
> > 
> > 5. すべての User Token スコープのチェックを外します - それらは必要ありません。
> > 
> > 6. Next をクリックし、「Yes, Migrate my app」をクリックして移行を完了します。
> > 
> > 7. 左側で、「Install App」を選択し、次に「Reinstall to Workspace」を選択します。
> > 
> > 8. 「Bot User OAuth Token」をコピーし、Discourse の「chat\_integration\_slack\_access\_token」設定に貼り付けます。
> > 
> > 9. Slack サイドバーの「Apps」の下で、Discourse 統合を選択します。
> > 
> > 10. 一番上でその名前をクリックし、「Add this app to a channel」を選択します。
> > 
> > 11. Discourse と統合したいすべてのチャンネルを選択します。
> > 
> > 12. 完了です 🎉

## トラブルシューティング

### /discourse スラッシュコマンドが `dispatch_failed` エラーを返す

**症状**

Slack 統合を設定した後、`/discourse` スラッシュコマンドを試すと、Slack に次のエラーが表示されます。

```plaintext
/discourse failed with the error "dispatch_failed"

```

 ![image](https://global.discourse-cdn.com/meta/original/4X/7/3/f/73f4c84a0615893c2e0c160a4975695849b26a34.png)

**原因**

これは設定エラーが原因である可能性が高いです。 **Request URL** に設定した値が正しいか確認してください。次の形式である必要があります。

```plaintext
\u003cyour-discourse-url\u003e/chat-integration/slack/command

```

**修正**

**Request URL** を更新し、特に次の点に注意してください。

1. 正しいプロトコル（例: `https://`）で始まっていることを確認します。
2. Slack インスタンスではなく、Discourse サイトのドメインを使用していることを確認します。
3. 正しいパス `/chat-integration/slack/command` が含まれていることを確認します。

---

_[View the full topic](https://meta.discourse.org/t/set-up-slack-notifications-using-the-discourse-chat-integration-plugin/66730)._
