如何配置仅对 public 频道具有只读访问权限的 Slack API OAuth 令牌?

How to configure a Slack API OAuth Token which has read-only access to public channels only?

(松弛 API n00b 此处)

我正在尝试使用 Slack API 在我们的一些 public slack 频道(我们组织内部)中搜索消息。

我正在通过 Python SDK 使用 https://www.slack.com/api/search.messages API,这意味着我正在执行以下操作:

import logging
from slack_sdk import WebClient
from pprint import pprint
    
    
def main():
    logging.basicConfig(level=logging.INFO)

    # TOKEN:
    t = 'xoxp-***'

    print("Getting client")
    c = WebClient(token=t)
    response = c.search_messages(query='in:#some_public_channel some-search-string')
    print("Response Code: {}".format(response.status_code))
    print("Found {} messages.".format(len(response.data['messages']['matches'])))
    
if __name__ == '__main__':
    main()

如果我使用“用户 OAuth 令牌”,我只能让上面的代码工作,不幸的是,这个令牌也可以访问与该用户相关的所有私人消息.

我想要一个只能通过 public 渠道搜索的 OAuth 令牌(只读)。这样,它就可以在同一个团队的成员之间共享(例如)。

有什么解决办法的建议吗?

背景资料:

  1. 如果我尝试使用“Bot User Auth Token”,我会收到 not_allowed_token_type 错误。
DEBUG:slack_sdk.web.slack_response: Received the following response - 
status: 200, 
headers: {...}, 
body: {'ok': False, 'error': 'not_allowed_token_type'}
  1. 我使用的令牌是通过我专门为此目的创建的“应用程序”生成的:

仅用户可以访问 search.messages API,机器人不能访问。我建议的最佳解决方法是 -