如何使用 Bolt for JavaScript(Node.JS) 获取 Slack 机器人的当前用户电子邮件地址

How to get the current user email address for Slack bot using Bolt for JavaScript(Node.JS)

就上下文而言,我正在使用 Bolt for JavaScript 框架来开发 Slack 机器人。我有一个工作区,我是唯一的成员。

在应用主页中,我需要检索当前用户的电子邮件地址,但我不知道该怎么做。

WebAPI methods for users例如users.profile.get和users.identity,需要用户令牌,我想我需要获取当前用户的用户令牌。

关于如何从后端检索用户令牌有什么想法吗?将不胜感激。

我建议使用机器人令牌来调用 users.info (https://api.slack.com/methods/users.info). You will need to request the users:read and the users:read.email scopes in order for the email to be returned in the API call. When you install your app on your Workspace your bot token will appear in the OAuth & Permissions page of your Developer Config site (https://api.slack.com/apps),而不是用户令牌。您的应用程序应该正在侦听 app_home_opened 事件。当用户打开 App Home 时,user_id 将在事件负载中返回。然后,您可以使用 user_id 调用 users.info 并获取用户电子邮件。