itizawa 5 лет назад
Родитель
Сommit
30d95a7398
2 измененных файлов с 28 добавлено и 30 удалено
  1. 28 12
      src/server/routes/apiv3/slack-bot.js
  2. 0 18
      src/server/service/bolt.js

+ 28 - 12
src/server/routes/apiv3/slack-bot.js

@@ -1,14 +1,11 @@
 
 const express = require('express');
-const { createMessageAdapter } = require('@slack/interactive-messages');
 
 const router = express.Router();
 
 module.exports = (crowi) => {
   this.app = crowi.express;
 
-  const signingSecret = crowi.configManager.getConfig('crowi', 'slackbot:signingSecret');
-  const slackInteractions = createMessageAdapter(signingSecret);
 
   // Check if the access token is correct
   // function verificationAccessToken(req, res, next) {
@@ -22,12 +19,6 @@ module.exports = (crowi) => {
   //   return next();
   // }
 
-  slackInteractions.viewSubmission('view_submission', (payload) => {
-    // Log the input elements from the view submission.
-    console.log(payload.view.state);
-  });
-
-
   function verificationRequestUrl(req, res, next) {
     // for verification request URL on Event Subscriptions
     if (req.body.type === 'url_verification') {
@@ -62,19 +53,44 @@ module.exports = (crowi) => {
 
   });
 
+  const handleBlockActions = async(payload) => {
+    const { action_id: actionId } = payload.actions[0];
+
+    switch (actionId) {
+      case 'shareSearchResults': {
+        console.log(payload);
+        break;
+      }
+      case 'showNextResults': {
+        const parsedValue = JSON.parse(payload.actions[0].value);
+
+        const { body, args, offset } = parsedValue;
+        const newOffset = offset + 10;
+        await crowi.boltService.showEphemeralSearchResults(body, args, newOffset);
+        break;
+      }
+      default:
+        break;
+    }
+  };
+
   router.post('/interactive', verificationRequestUrl, async(req, res) => {
 
     // 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();
-    console.log(req.body);
+
     const payload = JSON.parse(req.body.payload);
     const { type } = payload;
+    // const { callback_id: callbackId } = payload.view;
 
     switch (type) {
-      case 'view_submission':
-        await crowi.boltService.createPageInGrowi(payload);
+      case 'block_actions':
+        handleBlockActions(payload);
         break;
+      // case 'block_actions':
+      //   await crowi.boltService.createPageInGrowi(payload);
+      //   break;
       default:
         break;
     }

+ 0 - 18
src/server/service/bolt.js

@@ -79,24 +79,6 @@ class BoltService extends S2sMessageHandlable {
     }
   }
 
-
-  // this.bolt.action('showNextResults', async({
-
-  //   const command = parsedValue.command;
-  //   const args = parsedValue.args;
-  //   const offset = parsedValue.offset;
-
-  //   const newOffset = offset + 10;
-  //   this.showEphemeralSearchResults(command, args, newOffset);
-  // });
-
-  // this.bolt.action('shareSearchResults', async({
-  //   body, ack, say, action,
-  // }) => {
-  //   await ack();
-  //   await say(action.value);
-  // });
-
   notCommand(body) {
     logger.error('Invalid first argument');
     this.client.chat.postEphemeral({