Help us understand the problem. What is going on with this article?

新しいSlackチャンネルに別チャンネルメンバーを丸っと招待する

何を作ったのか?

数百人以上が入っているチャンネルを目的別に分けたかった。元のチャンネルのメンバーを新しいチャンネルにまとめて招待したい。
→手作業無理、/inviteコマンドも1ユーザごとしか使えないのでAPIで実装します。

できたやつ

APP(token)の作成

以下スコープを許可したAPPを作成、token(xoxp-XXXX)を習得しましょう。詳細割愛。

channels:read  #チャンネルに所属しているメンバー一覧を取得するため
channels:write  #チャンネルにインバイトするため

実行

以下XXXXXXにパラメータを入れ込んで実行しましょう。

※ channel_idとはチャンネル名ではなくブラウザで見た時のURLのCXXXXXの部分です。
※ limitはコピー元のユーザ数より大きい値で設定ください。

#!/bin/sh
slacktoken=XXXXXXXXX # set your token
channel_copy_from=XXXXXXXXX # set copy channel_id
channel_copy_to=XXXXXXXXX # set invite channel_id 
limit=700 # set number of members
members=`curl -H 'Content-Type: application/x-www-form-urlencoded' "https://slack.com/api/conversations.members" -d "token=$slacktoken&channel=$channel_copy_from&limit=$limit" | jq -r '.members[]'`
for u in $members; do
  echo Inviting user $u;
  curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' -i "https://slack.com/api/conversations.invite" -d "token=$slacktoken&channel=$channel_copy_to&users=$u";
  sleep 2;
done;

参考にさせていただいたサイト

Invite multiple members to slack channel(slackで複数人まとめてinviteする)

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away