hakumizuki 4 лет назад
Родитель
Сommit
7a02bd61cb

+ 4 - 4
src/server/routes/apiv3/slack-integration.js

@@ -9,7 +9,7 @@ const { verifySlackRequest, generateWebClient } = require('@growi/slack');
 const logger = loggerFactory('growi:routes:apiv3:slack-integration');
 const logger = loggerFactory('growi:routes:apiv3:slack-integration');
 const router = express.Router();
 const router = express.Router();
 const SlackAppIntegration = mongoose.model('SlackAppIntegration');
 const SlackAppIntegration = mongoose.model('SlackAppIntegration');
-const { slackbotResponse } = require('../../service/slack-command-handler/slackbot-response');
+const { respondIfSlackbotError } = require('../../service/slack-command-handler/slackbot-response');
 
 
 module.exports = (crowi) => {
 module.exports = (crowi) => {
   this.app = crowi.express;
   this.app = crowi.express;
@@ -108,7 +108,7 @@ module.exports = (crowi) => {
       await crowi.slackBotService.handleCommandRequest(command, client, body, args);
       await crowi.slackBotService.handleCommandRequest(command, client, body, args);
     }
     }
     catch (err) {
     catch (err) {
-      await slackbotResponse(client, body, err);
+      await respondIfSlackbotError(client, body, err);
     }
     }
 
 
   }
   }
@@ -157,7 +157,7 @@ module.exports = (crowi) => {
             await crowi.slackBotService.handleBlockActionsRequest(client, payload);
             await crowi.slackBotService.handleBlockActionsRequest(client, payload);
           }
           }
           catch (err) {
           catch (err) {
-            await slackbotResponse(client, req.body, err);
+            await respondIfSlackbotError(client, req.body, err);
           }
           }
           break;
           break;
         case 'view_submission':
         case 'view_submission':
@@ -165,7 +165,7 @@ module.exports = (crowi) => {
             await crowi.slackBotService.handleViewSubmissionRequest(client, payload);
             await crowi.slackBotService.handleViewSubmissionRequest(client, payload);
           }
           }
           catch (err) {
           catch (err) {
-            await slackbotResponse(client, req.body, err);
+            await respondIfSlackbotError(client, req.body, err);
           }
           }
           break;
           break;
         default:
         default:

+ 0 - 64
src/server/service/slack-command-handler/slackbot-response.js

@@ -1,64 +0,0 @@
-const logger = require('@alias/logger')('growi:service:SlackCommandHandler:slack-bot-response');
-const { markdownSectionBlock } = require('@growi/slack');
-const SlackbotError = require('../../models/vo/slackbot-error');
-
-async function slackbotResponse(client, body, err) {
-  // check if the request is to /commands OR /interactions
-  const isInteraction = !body.channel_id;
-
-  // throw non-SlackbotError
-  if (!SlackbotError.isSlackbotError(err)) {
-    logger.error(`A non-SlackbotError error occured.\n${err.toString()}`);
-    throw err;
-  }
-
-  // for both postMessage and postEphemeral
-  let toChannel;
-  // for only postEphemeral
-  let toUser;
-  // decide which channel to send to
-  switch (err.to) {
-    case 'dm':
-      toChannel = isInteraction ? JSON.parse(body.payload).user.id : body.user_id;
-      toUser = toChannel;
-      break;
-    case 'channel':
-      toChannel = isInteraction ? JSON.parse(body.payload).channel.id : body.channel_id;
-      toUser = isInteraction ? JSON.parse(body.payload).user.id : body.user_id;
-      break;
-    default:
-      logger.error('The "to" property of SlackbotError must be "dm" or "channel".');
-      break;
-  }
-
-  // argumentObj object to pass to postMessage OR postEphemeral
-  let argumentsObj = {};
-  switch (err.method) {
-    case 'postMessage':
-      argumentsObj = {
-        channel: toChannel,
-        text: err.popupMessage,
-        blocks: [
-          markdownSectionBlock(err.mainMessage),
-        ],
-      };
-      break;
-    case 'postEphemeral':
-      argumentsObj = {
-        channel: toChannel,
-        user: toUser,
-        text: err.popupMessage,
-        blocks: [
-          markdownSectionBlock(err.mainMessage),
-        ],
-      };
-      break;
-    default:
-      logger.error('The "method" property of SlackbotError must be "postMessage" or "postEphemeral".');
-      break;
-  }
-
-  await client.chat[err.method](argumentsObj);
-}
-
-module.exports = { slackbotResponse };