LoginSignup
2
0

GASでSlackの設定管理【Vol.2 チャンネル一覧取得】

Last updated at Posted at 2023-09-08

背景

Slackを全社導入し、増えてくるユーザ。それと、チャンネルも。。。
そうなってくると必然的に管理しないといけないよね。。。
ページングなしで、一覧でアカウントを見れるものないかな〜

ないなら、どうする? そう! 作っちゃおう!

やったこと

  • GAS(GoogleAppScript)でSlackのチャンネルを取得
  • チャンネル情報の書き出し

GAS(GoogleAppScript)でSlackのチャンネルを取得

対象のエンドポイント/api/conversations.list
※詳しくはこちら

任意のパラメータについて

  • exclude_archived
    • アーカイブ済みのチャンネルを除くか ※デフォルトはfalse
  • limit
    • 1度に取得する件数 ※デフォルトは100
  • types
    • 取得対象を以下の中から設定可能 ※デフォルトはpublic_channel
      • public_channel
      • private_channel
      • mpim
      • im
    • 複数の場合は、カンマ区切りで。
  const token = "{Slackのトークン}";
  let options = {
    "method": "get",
    "contentType": "application/x-www-form-urlencoded",
    "payload": {
      "token": token,
      "limit": 1000,
      "types": types,
      "cursor": cursor
    }
  }
  let url = 'https://slack.com/api/conversations.list';
  let response = UrlFetchApp.fetch(url, options);
  let jsonResponse = JSON.parse(response);
  console.log(jsonResponse);

チャンネル情報の書き出し

以下の情報がレスポンスとして取得可能

    {
            "id": "C012AB3CD",
            "name": "general",
            "is_channel": true,
            "is_group": false,
            "is_im": false,
            "created": 1449252889,
            "creator": "U012A3CDE",
            "is_archived": false,
            "is_general": true,
            "unlinked": 0,
            "name_normalized": "general",
            "is_shared": false,
            "is_ext_shared": false,
            "is_org_shared": false,
            "pending_shared": [],
            "is_pending_ext_shared": false,
            "is_member": true,
            "is_private": false,
            "is_mpim": false,
            "updated": 1678229664302,
            "topic": {
                "value": "Company-wide announcements and work-based matters",
                "creator": "",
                "last_set": 0
            },
            "purpose": {
                "value": "This channel is for team-wide communication and announcements. All team members are in this channel.",
                "creator": "",
                "last_set": 0
            },
            "previous_names": [],
            "num_members": 4
        },

最後に

GASでめんどくさいを自動化してハッピーライフ✨

参考

GASとは
Slackのチャンネル一覧取得

2
0
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
2
0