Get a list of all private channels with Slack API

旧巷老猫 提交于 2019-11-30 03:19:10

问题


I've been trying to get a list of all "groups" in my Slack team. However, even with admin privs, groups.list only provides the groups that the token owner's account belongs to.

The closest solution I've seen in my research involves getting a bot to sit in the channel. The bot's membership allows it to report on the channel, but then there's the logistical problem of getting the bot into every private channel, despite the fact that we can't list them programmatically.

The code I've used to dig up private channel listings:

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)

回答1:


slacks privacy policy does not support this.

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.

which is the closest thing to getting access to private channels from which you are not part of, but will require a written letter...here for more details




回答2:


If you really need to monitor all private channels (and DMs) on your Slack workspace in real time there is another approach:

  • Ensure every user on your Slack provides a token to your app. This can be done by each user running through the OAuath installing process for your app once. That will create new token for each user, which you app can collect.
  • Iterate through all active user tokens to compile a list of all conversations (public channels, private channels, direct messages, ..) with conversations.list
  • Iterate through all existing conversations - using a token valid for that conversation - to collect all messages with conversations.history


来源:https://stackoverflow.com/questions/37690761/get-a-list-of-all-private-channels-with-slack-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!