[英]How to get the current user email address for Slack bot using Bolt for JavaScript(Node.JS)
For context, I'm using the Bolt for JavaScript framework to develop a Slack bot.对于上下文,我使用 Bolt for JavaScript 框架来开发 Slack 机器人。 I have a workspace where I'm the only member.
我有一个工作区,我是唯一的成员。
In the app home, I need to retrieve the current user's email address, but I'm not sure how to do that.在应用主页中,我需要检索当前用户的 email 地址,但我不确定该怎么做。
WebAPI methods for users for example, users.profile.get and users.identity, require a user token, I suppose I need to get the user token of the current user.用户的 WebAPI 方法,例如 users.profile.get 和 users.identity,需要用户令牌,我想我需要获取当前用户的用户令牌。
Any ideas on how to retrieve the user token from the backend?关于如何从后端检索用户令牌的任何想法? Suggestions would be appreciated.
建议将不胜感激。
Instead of a user token, I'd recommend using a bot token to call users.info
( https://api.slack.com/methods/users.info ).我建议使用机器人令牌来调用
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.您需要请求
users:read
和users:read.email
范围,以便在 API 调用中返回 email。 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 ).当您在 Workspace 上安装您的应用程序时,您的机器人令牌将出现在您的开发者配置网站 ( https://api.slack.com/apps ) 的 OAuth 和权限页面中。 Your app should be listening for the
app_home_opened
event.您的应用程序应该正在侦听
app_home_opened
事件。 When a user opens the App Home the user_id
will be returned in the event payload.当用户打开 App Home 时,将在事件负载中返回
user_id
。 You can then use that user_id
to call users.info
and get the user email.然后,您可以使用该
user_id
调用users.info
并获取用户 email。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.