use*_*628 6 email channel slack-api slack
鉴于松弛频道的名称,有没有办法检索该频道中所有成员的电子邮件列表?我试着查看松弛的api文档,但找不到我需要的方法来实现这一点(https://api.slack.com/methods).
如果您具有必要的范围,则可以检索从频道名称开始的频道的所有成员的电子邮件,如下所示:
请注意,这也适用于使用私人频道groups.list和groups.info,但前提是对访问令牌的用户或BOT是私人频道中的一员.
小智 5
这是一个使用最新 API 与 Python 2 或 3 配合使用的版本。
import os
import requests
SLACK_API_TOKEN='xoxb-TOKENID' # Your token here
CHANNEL_NAME='general' # Your channel here
channel_list = requests.get('https://slack.com/api/conversations.list?token=%s&types=%s' % (SLACK_API_TOKEN, 'public_channel,private_channel,im,mpim')).json()['channels']
for c in channel_list:
if 'name' in c and c['name'] == CHANNEL_NAME:
channel = c
members = requests.get('https://slack.com/api/conversations.members?token=%s&channel=%s' % (SLACK_API_TOKEN, channel['id'])).json()['members']
users_list = requests.get('https://slack.com/api/users.list?token=%s' % SLACK_API_TOKEN).json()['members']
for user in users_list:
if "email" in user['profile'] and user['id'] in members:
print(user['profile']['email'])
Run Code Online (Sandbox Code Playgroud)
请注意,您需要使用 OAuth API 令牌和以下授权范围创建一个 Slack 应用程序,以适用于所有各种类型的对话:
channels:read
groups:read
im:read
mpim:read
users:read
users:read.email
Run Code Online (Sandbox Code Playgroud)
此外,要从私人频道或聊天中阅读,您需要将您的应用添加到工作区,并为您感兴趣的每个频道添加“/invite appname”。