LoginSignup
31
26

More than 3 years have passed since last update.

SlackAPIを使うまでのメモ

Last updated at Posted at 2019-04-25

はじめに

SlackAPIを初めて使う方向けの、
SlackAPIの権限設定からデバッグまでのメモです。

おおまかな流れは、
1.Token(特定のSlackチャンネルにアクセスするキー情報)の発行
2.APIデバッグ用のページで実際に使用できるかのテスト
3.実装

以上。

1.Tokenの発行方法

https://api.slack.com/apps
1)ログイン(ワークスペースの選択)
2)Tokenの目的設定
3)ワークスペースのインストール

たったこれだけ。

Slack API 推奨Tokenについて @ykhiraoさん
https://qiita.com/ykhirao/items/3b19ee6a1458cfb4ba21
でとてもわかり易くまとめられています。

image.png

2.Tokenのスコープ

わからないところはサクッと(使うことがあれば追記していきます。)

Incoming Webhooks

メッセージ受信

Interactive Components

メッセージ送信

Slash Commands

コマンド実行

OAuth & Permissions

APIの許可権限設定
迷ったらこれ
例)Access information about user’s public channels
  channels:read
  ユーザーの公開チャンネルに関する情報にアクセスする
  チャンネル:読み込み権限

image.png

Event Subscriptions

通知機能

Bot Users

BOTユーザ作成

User ID Translation

グローバルIDをローカルユーザIDに変換する。

3.SlackAPIの種類について

4.テスト方法

入力例
image.png

失敗

{
    "ok":"false",
    "error":"not_allowed_token_type"
}

Tokenのスコープ設定を見直して、
OAuth & Permissionsに権限を追加。
変更するとトークンを再インストール(関連付け)する必要があるので実行する。

成功(Jsonファイルが取得できる)

{
    "ok":"true",
    "channels":[
        {
            "id":"XXXXXXXXX"
            "name":"test"
            (省略)
        }
    ]
}

あとはAPIをスクリプトで実行すればよいだけ。

トラブルシューティング

1)missing_scope(権限が足りないよ)

[19-04-25 17:41:20:665 JST] {needed=chat:write:user, provided=identify,channels:read,files:read,files:write:user, ok=false, error=missing_scope}

needed:
chat:write:user,
provided=identify,
channels:read,
files:read,
files:write:user

この権限が必要です
chat:write:user,
provided=identify,
channels:read,
files:read,
files:write:user

ok=false

だめでした

error=missing_scope

権限が足りないよ

image.png

さくっと追加して。成功。

31
26
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
31
26