简体   繁体   English

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

[英]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:readusers: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.

相关问题 如何使用 Bolt for JS 将图像上传到 Slack Bot? - How to upload an image to a Slack Bot using Bolt for JS? 在使用Node.js的Slack bot tut之后,运行时没有输出? - Following Slack bot tut using Node.js, no output on run? 无法访问 node.js 中的文档名称,设置为来自 fire base 的当前用户电子邮件地址 - unable to access document name in node.js set by as current user email address from fire base 如何在使用GraphQl和Node.js时验证用户电子邮件 - How to verify user email while using GraphQl and Node.js 如何提交结果? Slack bolt-js、JavaScript - How can I submit the results? Slack bolt-js, JavaScript 如何在Windows上使用node.js将图像上传到Slack? - How to upload an image to Slack using node.js on Windows? 如何使JavaScript控制台用户输入工作(node.js)? - How to get JavaScript console user input working (node.js)? 如何通过node.js获取电报bot用户注册日期? - How to get telegram bot user registered date via node.js? Slack Bot with Bolt for JavaScript 和 OAuth 2.0 与其他工作区共享应用程序 - Slack Bot with Bolt for JavaScript and OAuth 2.0 to share the app with other workspaces 使用JavaScript + Node.js向用户发送电子邮件(nodemailer?) - Sending an email to user in JavaScript + Node.js (nodemailer?)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM