Browse Source

implement value

itizawa 4 years ago
parent
commit
7159de271f

+ 4 - 1
packages/slack/src/utils/block-kit-builder.ts

@@ -67,7 +67,9 @@ export function inputBlock(
  * Button element
  * https://api.slack.com/reference/block-kit/block-elements#button
  */
-export function buttonElement(text: string, actionId: string, style?: string): Button {
+export function buttonElement({
+  text, actionId, style, value,
+}:{text: string, actionId: string, style?: string, value?:string}): Button {
   const button: Button = {
     type: 'button',
     text: {
@@ -75,6 +77,7 @@ export function buttonElement(text: string, actionId: string, style?: string): B
       text,
     },
     action_id: actionId,
+    value,
   };
   if (style === 'primary' || style === 'danger') {
     button.style = style;

+ 6 - 9
src/server/routes/apiv3/slack-integration.js

@@ -149,7 +149,12 @@ module.exports = (crowi) => {
         break;
       }
       case 'togetterShowMore': {
-        console.log('Show more here');
+        const parsedValue = JSON.parse(payload.actions[0].value);
+        const togetterHandler = require('../../service/slack-command-handler/togetter')(crowi);
+
+        const { body, args, limit } = parsedValue;
+        const newLimit = limit + 1;
+        await togetterHandler.handleCommand(client, body, args, newLimit);
         break;
       }
       case 'togetterCreatePage': {
@@ -160,14 +165,6 @@ module.exports = (crowi) => {
         console.log('Cancel here');
         break;
       }
-      case 'showMoreTogetterResults': {
-        const parsedValue = JSON.parse(payload.actions[0].value);
-
-        const { body, args, limit } = parsedValue;
-        const newLimit = limit + 10;
-        await crowi.slackBotService.togetterCommand(client, body, args, newLimit);
-        break;
-      }
       default:
         break;
     }

+ 7 - 5
src/server/service/slack-command-handler/togetter.js

@@ -18,18 +18,20 @@ module.exports = () => {
       channel: body.channel_id,
       user: body.user_id,
       text: 'Select messages to use.',
-      delete_original: true,
-      blocks: this.togetterMessageBlocks(result.messages),
+      blocks: this.togetterMessageBlocks(result.messages, body, args, limit),
     });
     return;
   };
 
-  handler.togetterMessageBlocks = function(messages) {
+  handler.togetterMessageBlocks = function(messages, body, args, limit) {
     return [
       inputBlock(this.togetterCheckboxesElement(messages), 'selected_messages', 'Select massages to use.'),
-      actionsBlock(buttonElement('Show more', 'togetterShowMore')),
+      actionsBlock(buttonElement({ text: 'Show more', actionId: 'togetterShowMore', value: JSON.stringify({ body, args, limit }) })),
       inputBlock(this.togetterInputBlockElement('page_path', '/'), 'page_path', 'Page path'),
-      actionsBlock(buttonElement('Cancel', 'togetterCancelPageCreation'), buttonElement('Create page', 'togetterCreatePage', 'primary')),
+      actionsBlock(
+        buttonElement({ text: 'Cancel', actionId: 'togetterCancelPageCreation' }),
+        buttonElement({ text: 'Create page', actionId: 'togetterCreatePage', color: 'primary' }),
+      ),
     ];
   };