LoginSignup
3
3

More than 5 years have passed since last update.

特定のSlackチャンネルに参加しているユーザーのメールアドレス一覧を取得する

Last updated at Posted at 2016-09-14

特定のプロジェクト参加者(チャンネルにjoinしている)を対象にメールアドレスをキーに外部システムへimport/exportをしたかった。
外部システムと共通なのはメールアドレスぐらいなのでSlack APIからサっと取得しようとしたら、意外とめんどうだったのでスクリプトを書いた。

#!/usr/bin/env node

// https://github.com/slackhq/node-slack-sdk
const WebClient = require('@slack/client').WebClient;
const web = new WebClient(process.env.SLACK_API_TOKEN);
const SLACK_CHANNEL_ID = process.env.SLACK_CHANNEL_ID;

web.channels.info(SLACK_CHANNEL_ID)
      .then((channel) => {
        web.users.list().then((users) => {
          for (var m of users.members) {
            if (channel.channel.members.includes(m.id)) {
              console.log(m.profile.email); // HERE
            }
          }
        })
      });

SLACK_CHANNEL_ID はチャンネル名じゃなくてID文字列。
https://api.slack.com/methods/channels.list/test から探して……

3
3
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
3
3