使用 Slack API 获取所有私人频道的列表

Get a list of all private channels with Slack API

我一直在尝试获取我的 Slack 团队中所有 "groups" 的列表。但是,即使有管理员权限,groups.list 也只提供令牌所有者帐户所属的组。

我在研究中看到的最接近的解决方案是让机器人坐在频道中。 bot 的成员身份允许它在频道上进行报告,但是尽管我们无法以编程方式列出它们,但将 bot 进入每个私人频道存在逻辑问题。

我用来挖掘私人频道列表的代码:

import requests
import json

token = '...'

r = requests.post('https://slack.com/api/groups.list', data={'token': token, 'exclude_archived': 1})
if r.ok:
  privatechannels = { c['id']: c['name'] for c in json.loads(r.text)['groups'] }
  print(privatechannels)

休闲裤privacy policy不支持这个

The most fundamental privacy principle we follow is that by default, anything you post to Slack is private to your team. That is, viewing the messages and files shared within a specific team requires authentication as a member of that team.

The company's upcoming paid Plus plan will include an optional feature called Compliance Exports, which will let administrators access their team's communications, encompassing public and private messages.

这是最接近访问您不属于的私人频道的方法,但需要书面信函...here for more details

如果您确实需要实时监控 Slack 工作区中的所有私人频道(和 DM),还有另一种方法:

  • 确保您 Slack 上的每个用户都为您的应用程序提供令牌。这可以由每个用户 运行 通过应用程序的 OAuath 安装过程完成一次。这将为每个用户创建新的令牌,您的应用程序可以收集这些令牌。
  • 遍历所有活动用户令牌以编译所有的列表 与 conversations.list
  • 的对话(public 频道、私人频道、直接消息......)
  • 遍历所有现有对话 - 使用对该对话有效的令牌 - 收集具有 conversations.history
  • 的所有消息