Преглед изворни кода

implementaccessTokenParserForSlackBot

itizawa пре 5 година
родитељ
комит
e04e3bde07
1 измењених фајлова са 15 додато и 1 уклоњено
  1. 15 1
      src/server/routes/apiv3/slack-bot.js

+ 15 - 1
src/server/routes/apiv3/slack-bot.js

@@ -8,7 +8,21 @@ module.exports = (crowi) => {
   const { boltService } = crowi;
   const requestHandler = boltService.receiver.requestHandler.bind(boltService.receiver);
 
-  router.post('/', async(req, res) => {
+  function accessTokenParserForSlackBot(req, res, next) {
+    const slackBotAccessToken = req.body.slack_bot_access_token || null;
+    if (slackBotAccessToken == null) {
+      next();
+    }
+
+    if (slackBotAccessToken === crowi.configManager.getConfig('crowi', 'slackbot:access-token')) {
+      req.body.user = {
+        username: 'slackBot',
+      };
+    }
+    next();
+  }
+
+  router.post('/', accessTokenParserForSlackBot, async(req, res) => {
     // for verification request URL on Event Subscriptions
     if (req.body.type === 'url_verification') {
       res.send(req.body);