如何找到工作区名称?
How to find workspace name?
如何使用 Python 的 Slack 机器人从消息中找到工作区名称?我可以使用以下方法找到用户名:
username = message.channel._client.users[message.body['user']]['id']
但我不知道如何找到工作区名称。
一种方法是使用相应团队 ID 的令牌调用 auth.test
。
它将 return team
属性 中令牌/团队 ID 的工作区名称。
示例输出:
{
"ok": true,
"url": "https://subarachnoid.slack.com/",
"team": "Subarachnoid Workspace",
"user": "grace",
"team_id": "T12345678",
"user_id": "W12345678"
}
Python 3.6+ / slackClient 2.1 的示例代码:
import slack
client = slack.WebClient(token='YOUR_TOKEN')
response = client.auth_test()
print(response['team'])
示例代码 Python < 3.6 / slackClient v1
from slackclient import SlackClient
response = self.sc.api_call('auth.test')
if not response['ok']:
raise RuntimeError("...")
else:
print response['team']
实际上我正在试验上述解决方案并决定探索返回的字典:
username = message.channel._client.users[message.body['user']]
像这样使用 Slack 机器人可以更轻松地获取团队 ID(解决方案一直显而易见):
username = message.channel._client.users[message.body['user']]['team_id']
但是谢谢你的帮助,@Erik! :)
如何使用 Python 的 Slack 机器人从消息中找到工作区名称?我可以使用以下方法找到用户名:
username = message.channel._client.users[message.body['user']]['id']
但我不知道如何找到工作区名称。
一种方法是使用相应团队 ID 的令牌调用 auth.test
。
它将 return team
属性 中令牌/团队 ID 的工作区名称。
示例输出:
{
"ok": true,
"url": "https://subarachnoid.slack.com/",
"team": "Subarachnoid Workspace",
"user": "grace",
"team_id": "T12345678",
"user_id": "W12345678"
}
Python 3.6+ / slackClient 2.1 的示例代码:
import slack
client = slack.WebClient(token='YOUR_TOKEN')
response = client.auth_test()
print(response['team'])
示例代码 Python < 3.6 / slackClient v1
from slackclient import SlackClient
response = self.sc.api_call('auth.test')
if not response['ok']:
raise RuntimeError("...")
else:
print response['team']
实际上我正在试验上述解决方案并决定探索返回的字典:
username = message.channel._client.users[message.body['user']]
像这样使用 Slack 机器人可以更轻松地获取团队 ID(解决方案一直显而易见):
username = message.channel._client.users[message.body['user']]['team_id']
但是谢谢你的帮助,@Erik! :)