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
我使用 Bolt 为 Javascript 添加了一个带有添加到 Slack 按钮的应用程序。 Slack 命令还不起作用,因为我还没有带有授权令牌的数据库。我计划实现它,但意识到我从未看到控制台日志。
所以根据我的理解 console.log("authorizeFn") 应该有效
const { App, ExpressReceiver } = require("@slack/bolt");;
const expressReceiver = new ExpressReceiver({
signingSecret: process.env.SLACK_SIGNING_SECRET,
endpoints: "/events"
});
const authorizeFn = async ({ teamId }) => {
//Implement query of database looking for teamId, getting auth token...
console.log("authorizeFn") //This one never logs???
};
const app = new App({
authorize: authorizeFn,
receiver: expressReceiver
});
const app_express = expressReceiver.app;
如果用户被授权,它应该检查每个事件,对吗?
代码就是这样
/* Page with add button, can be implemented in website instead */
app_express.get("/auth/add", (req, res, next) => {
res.write(
'<a href="https:/...'
);
res.end();
});
app_express.get("/auth/direct", (req, res, next) => {
res.redirect(
"https://slack...."
);
res.end();
});
/* Thanks for installing! */
app_express.get("/auth/thanks", (req, res, next) => {
res.write("Thanks for installing!");
res.end();
});
/* oauth callback function */
app_express.get("/auth/callback", (req, res, next) => {
let code = req.query.code;
let state = req.query.state;
return app.client.oauth.v2
.access({
client_id: process.env.SLACK_CLIENT_ID,
client_secret: process.env.SLACK_CLIENT_SECRET,
code: code
})
.then(async result => {
console.log(result);
// save result of oauth.access call somewhere, like in a database.
res.redirect(process.env.BASE_DOMAIN + "/auth/thanks");
res.end();
})
.catch(error => {
throw error;
});
});
console.log(结果);记录一些有用的东西,看起来像 teamIds、用户和令牌
必须是
const expressReceiver = new ExpressReceiver({
signingSecret: process.env.SLACK_SIGNING_SECRET,
endpoints: "/slack/events"
});
就我而言。不是:
endpoints: "/events"
我使用 Bolt 为 Javascript 添加了一个带有添加到 Slack 按钮的应用程序。 Slack 命令还不起作用,因为我还没有带有授权令牌的数据库。我计划实现它,但意识到我从未看到控制台日志。
所以根据我的理解 console.log("authorizeFn") 应该有效
const { App, ExpressReceiver } = require("@slack/bolt");;
const expressReceiver = new ExpressReceiver({
signingSecret: process.env.SLACK_SIGNING_SECRET,
endpoints: "/events"
});
const authorizeFn = async ({ teamId }) => {
//Implement query of database looking for teamId, getting auth token...
console.log("authorizeFn") //This one never logs???
};
const app = new App({
authorize: authorizeFn,
receiver: expressReceiver
});
const app_express = expressReceiver.app;
如果用户被授权,它应该检查每个事件,对吗?
代码就是这样
/* Page with add button, can be implemented in website instead */
app_express.get("/auth/add", (req, res, next) => {
res.write(
'<a href="https:/...'
);
res.end();
});
app_express.get("/auth/direct", (req, res, next) => {
res.redirect(
"https://slack...."
);
res.end();
});
/* Thanks for installing! */
app_express.get("/auth/thanks", (req, res, next) => {
res.write("Thanks for installing!");
res.end();
});
/* oauth callback function */
app_express.get("/auth/callback", (req, res, next) => {
let code = req.query.code;
let state = req.query.state;
return app.client.oauth.v2
.access({
client_id: process.env.SLACK_CLIENT_ID,
client_secret: process.env.SLACK_CLIENT_SECRET,
code: code
})
.then(async result => {
console.log(result);
// save result of oauth.access call somewhere, like in a database.
res.redirect(process.env.BASE_DOMAIN + "/auth/thanks");
res.end();
})
.catch(error => {
throw error;
});
});
console.log(结果);记录一些有用的东西,看起来像 teamIds、用户和令牌
必须是
const expressReceiver = new ExpressReceiver({
signingSecret: process.env.SLACK_SIGNING_SECRET,
endpoints: "/slack/events"
});
就我而言。不是:
endpoints: "/events"