【问题标题】:Slack Bot with Bolt for JavaScript and OAuth 2.0 to share the app with other workspacesSlack Bot 与 Bolt for JavaScript 和 OAuth 2.0 与其他工作区共享应用程序
【发布时间】:2020-08-26 01:17:00
【问题描述】:

我使用 Bolt for Javascript 添加了一个带有 Add to 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、Users 和 token

【问题讨论】:

    标签: javascript node.js oauth slack slack-api


    【解决方案1】:

    应该是

    const expressReceiver = new ExpressReceiver({
      signingSecret: process.env.SLACK_SIGNING_SECRET,
      endpoints: "/slack/events"
    });
    

    就我而言。不是:

      endpoints: "/events"
    

    【讨论】:

      猜你喜欢
      • 2021-11-18
      • 1970-01-01
      • 1970-01-01
      • 2017-03-19
      • 1970-01-01
      • 2014-12-19
      • 1970-01-01
      • 1970-01-01
      • 2012-02-25
      相关资源
      最近更新 更多