itizawa 4 лет назад
Родитель
Сommit
293b926f86

+ 9 - 8
packages/slackbot-proxy/src/controllers/slack.ts

@@ -18,6 +18,7 @@ import { OrderRepository } from '~/repositories/order';
 import { AddSigningSecretToReq } from '~/middlewares/slack-to-growi/add-signing-secret-to-req';
 import { AuthorizeCommandMiddleware, AuthorizeInteractionMiddleware } from '~/middlewares/slack-to-growi/authorizer';
 import { InstallerService } from '~/services/InstallerService';
+import { SelectRequestService } from '~/services/SelectRequestService';
 import { RegisterService } from '~/services/RegisterService';
 import { UnregisterService } from '~/services/UnregisterService';
 import { InvalidUrlError } from '../models/errors';
@@ -43,6 +44,9 @@ export class SlackCtrl {
   @Inject()
   orderRepository: OrderRepository;
 
+  @Inject()
+  selectRequestService: SelectRequestService;
+
   @Inject()
   registerService: RegisterService;
 
@@ -130,18 +134,15 @@ export class SlackCtrl {
       });
     }
 
-    if (singlePostCommands.includes(growiCommand.growiCommandType)) {
-      return res.json({
-        blocks: [
-          generateMarkdownSectionBlock('*singlePostCommands*'),
-        ],
-      });
-    }
-
     // 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();
 
+    if (singlePostCommands.includes(growiCommand.growiCommandType)) {
+      body.growiUris = relations.map(relation => relation.growiUri);
+      return this.selectRequestService.process(growiCommand, authorizeResult, body);
+    }
+
     /*
      * forward to GROWI server
      */

+ 63 - 0
packages/slackbot-proxy/src/services/SelectRequestService.ts

@@ -0,0 +1,63 @@
+import { Service } from '@tsed/di';
+import { WebClient, LogLevel } from '@slack/web-api';
+import { GrowiCommand } from '@growi/slack';
+import { AuthorizeResult } from '@slack/oauth';
+import { GrowiCommandProcessor } from '~/interfaces/slack-to-growi/growi-command-processor';
+
+
+const isProduction = process.env.NODE_ENV === 'production';
+
+@Service()
+export class SelectRequestService implements GrowiCommandProcessor {
+
+  async process(growiCommand: GrowiCommand, authorizeResult: AuthorizeResult, body: {[key:string]:string } & {growiUris:string[]}): Promise<void> {
+    const { botToken } = authorizeResult;
+
+    const client = new WebClient(botToken, { logLevel: isProduction ? LogLevel.DEBUG : LogLevel.INFO });
+    await client.views.open({
+      trigger_id: body.trigger_id,
+      view: {
+        type: 'modal',
+        callback_id: 'register',
+        title: {
+          type: 'plain_text',
+          text: 'Slect Growi url',
+        },
+        submit: {
+          type: 'plain_text',
+          text: 'Submit',
+        },
+        close: {
+          type: 'plain_text',
+          text: 'Close',
+        },
+        private_metadata: JSON.stringify({ channel: body.channel_name }),
+
+        blocks: [
+          {
+            type: 'input',
+            block_id: 'select_growi',
+            label: {
+              type: 'plain_text',
+              text: 'GROWI App',
+            },
+            element: {
+              type: 'static_select',
+              action_id: 'growi_app',
+              options: body.growiUris.map((growiUri) => {
+                return ({
+                  text: {
+                    type: 'plain_text',
+                    text: growiUri,
+                  },
+                  value: growiUri,
+                });
+              }),
+            },
+          },
+        ],
+      },
+    });
+  }
+
+}