gpt4 book ai didi

email - 松弛 API : Retrieve all member emails from a slack channel

转载 作者:行者123 更新时间:2023-12-04 11:01:57 27 4
gpt4 key购买 nike

给定一个松弛 channel 的名称,有没有办法检索该 channel 中所有成员的电子邮件列表?我尝试查看 slack api 文档,但找不到实现此目的所需的方法 (https://api.slack.com/methods)。

最佳答案

这是python代码:

import requests

SLACK_API_TOKEN = "" # get one from https://api.slack.com/docs/oauth-test-tokens
CHANNEL_NAME = ""

# channel_list = requests.get('https://slack.com/api/channels.list?token=%s' % SLACK_API_TOKEN).json()['channels']
# channel = filter(lambda c: c['name'] == CHANNEL_NAME, channel_list)[0]

# channel_info = requests.get('https://slack.com/api/channels.info?token=%s&channel=%s' % (SLACK_API_TOKEN, channel['id'])).json()['channel']
# members = channel_info['members']

channel_list = requests.get('https://slack.com/api/groups.list?token=%s' % SLACK_API_TOKEN).json()['groups']
channel = filter(lambda c: c['name'] == CHANNEL_NAME, channel_list)[0]

channel_info = requests.get('https://slack.com/api/groups.info?token=%s&channel=%s' % (SLACK_API_TOKEN, channel['id'])).json()['group']
print channel_info
members = channel_info['members']

users_list = requests.get('https://slack.com/api/users.list?token=%s' % SLACK_API_TOKEN).json()['members']
users = filter(lambda u: u['id'] in members, users_list)

for user in users:
first_name, last_name = '', ''

if user['real_name']:
first_name = user['real_name']

if ' ' in user['real_name']:
first_name, last_name = user['real_name'].split()
# print "%s,%s,%s" % (first_name, last_name, user['profile']['email'])
print "%s" % (user['profile']['email'])

关于email - 松弛 API : Retrieve all member emails from a slack channel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41564027/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com