itizawa 5 лет назад
Родитель
Сommit
d3d65fa98d
1 измененных файлов с 25 добавлено и 13 удалено
  1. 25 13
      src/server/routes/apiv3/slack-bot.js

+ 25 - 13
src/server/routes/apiv3/slack-bot.js

@@ -9,21 +9,18 @@ const router = express.Router();
 
 
 module.exports = (crowi) => {
 module.exports = (crowi) => {
   this.app = crowi.express;
   this.app = crowi.express;
-  const { boltService } = crowi;
-  const requestHandler = boltService.receiver.requestHandler.bind(boltService.receiver);
-
 
 
   // Check if the access token is correct
   // Check if the access token is correct
-  function verificationAccessToken(req, res, next) {
-    const slackBotAccessToken = req.body.slack_bot_access_token || null;
+  // function verificationAccessToken(req, res, next) {
+  //   const slackBotAccessToken = req.body.slack_bot_access_token || null;
 
 
-    if (slackBotAccessToken == null || slackBotAccessToken !== this.crowi.configManager.getConfig('crowi', 'slackbot:access-token')) {
-      logger.error('slack_bot_access_token is invalid.');
-      return res.send('*Access token is inValid*');
-    }
+  //   if (slackBotAccessToken == null || slackBotAccessToken !== this.crowi.configManager.getConfig('crowi', 'slackbot:access-token')) {
+  //     logger.error('slack_bot_access_token is invalid.');
+  //     return res.send('*Access token is inValid*');
+  //   }
 
 
-    return next();
-  }
+  //   return next();
+  // }
 
 
   function verificationRequestUrl(req, res, next) {
   function verificationRequestUrl(req, res, next) {
     // for verification request URL on Event Subscriptions
     // for verification request URL on Event Subscriptions
@@ -34,13 +31,28 @@ module.exports = (crowi) => {
     return next();
     return next();
   }
   }
 
 
-  router.post('/', verificationRequestUrl, verificationAccessToken, async(req, res) => {
+  router.post('/', verificationRequestUrl, async(req, res) => {
 
 
     // Send response immediately to avoid opelation_timeout error
     // Send response immediately to avoid opelation_timeout error
     // See https://api.slack.com/apis/connections/events-api#the-events-api__responding-to-events
     // See https://api.slack.com/apis/connections/events-api#the-events-api__responding-to-events
     res.send();
     res.send();
+    console.log(req.body);
+
+    const { text } = req.body;
+    const args = text.split(' ');
+    const command = args[0];
+
+    switch (command) {
+      case 'search':
+        await crowi.boltService.searchService.search(req.body, args);
+        break;
+
+      default:
+        this.notCommand(command);
+        break;
+    }
+
 
 
-    await requestHandler(req.body);
   });
   });
 
 
   return router;
   return router;