我使用Bolt for Javascript添加了一个带有Add to Slack Button的应用程序。Slack命令还不能用,因为我还没有一个带有auth tokens的数据库。我计划实现这一点,但意识到我从来没有看到控制台日志。
所以根据我的理解,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(result); 记录一些有用的东西,看起来像teamIds,Users和一个token。
它必须是
const expressReceiver = new ExpressReceiver({
signingSecret: process.env.SLACK_SIGNING_SECRET,
endpoints: "/slack/events"
});
在我看来。没有
endpoints: "/events"