Răsfoiți Sursa

Merge branch 'feat/growi-bot' into imprv/gw5283-show-next-10-results

# Conflicts:
#	src/server/service/bolt.js
Kaori Tokashiki 5 ani în urmă
părinte
comite
f4da976dec
2 a modificat fișierele cu 14 adăugiri și 19 ștergeri
  1. 6 8
      src/server/routes/apiv3/slack-bot.js
  2. 8 11
      src/server/service/bolt.js

+ 6 - 8
src/server/routes/apiv3/slack-bot.js

@@ -2,7 +2,6 @@
 const express = require('express');
 
 const router = express.Router();
-const ErrorV3 = require('../../models/vo/error-apiv3');
 
 module.exports = (crowi) => {
   this.app = crowi.express;
@@ -15,13 +14,12 @@ module.exports = (crowi) => {
       res.send(req.body);
       return;
     }
-    try {
-      const response = await requestHandler(req.body) || null;
-      res.send(response);
-    }
-    catch (err) {
-      return res.apiv3Err(new ErrorV3(`Error:Slack-Bot:${err}`), 500);
-    }
+
+    // Send response immediately to avoid opelation_timeout error
+    // See https://api.slack.com/apis/connections/events-api#the-events-api__responding-to-events
+    res.send();
+
+    await requestHandler(req.body);
   });
 
   return router;

+ 8 - 11
src/server/service/bolt.js

@@ -27,7 +27,7 @@ class BoltReciever {
       body: reqBody,
       ack: (response) => {
         if (ackCalled) {
-          return null;
+          return;
         }
 
         ackCalled = true;
@@ -36,13 +36,7 @@ class BoltReciever {
           const message = response.message || 'Error occurred';
           throw new Error(message);
         }
-        else if (!response) {
-          return null;
-        }
-        else {
-          return response;
-        }
-
+        return;
       },
     };
 
@@ -153,7 +147,7 @@ class BoltService {
         this.generateMarkdownSectionBlock('*No command.*\n Hint\n `/growi [command] [keyword]`'),
       ],
     });
-    throw new Error('/growi command: Invalid first argument');
+    return;
   }
 
   showNextResults = (command, args, offset) => {
@@ -171,7 +165,7 @@ class BoltService {
           this.generateMarkdownSectionBlock('*Input keywords.*\n Hint\n `/growi search [keyword]`'),
         ],
       });
-      throw new Error('/growi command:search: Invalid keyword');
+      return;
     }
 
     // removing 'search' from the head in the array.
@@ -228,6 +222,9 @@ class BoltService {
       resultPaths, offset, keywords,
     } = await this.getSearchResultPaths(command, args, offsettt);
 
+    if (resultPaths == null) {
+      return;
+    }
     const base = this.crowi.appService.getSiteUrl();
 
     const urls = resultPaths.map((path) => {
@@ -349,7 +346,7 @@ class BoltService {
         channel: command.channel_id,
         user: command.user_id,
         blocks: [
-          this.generateMarkdownSectionBlock('*Failed to create new page.*\n Hint\n `/growi create`'),
+          this.generateMarkdownSectionBlock(`*Failed to create new page.*\n ${err}`),
         ],
       });
       throw err;