Explorar o código

test parse in slack-proxy

zahmis %!s(int64=5) %!d(string=hai) anos
pai
achega
0ee4734d89

+ 7 - 8
packages/slack/src/utils/slash-command-parser.ts

@@ -1,18 +1,17 @@
-import { SlashCommand } from '@slack/bolt';
+// import { SlashCommand } from '@slack/bolt';
 
-import { GrowiCommand } from '~/interfaces/growi-command';
-import { InvalidGrowiCommandError } from '~/models/errors';
+// import { GrowiCommand } from '~/interfaces/growi-command';
+// import { InvalidGrowiCommandError } from '~/models/errors';
 
-export const parse = (slashCommand: SlashCommand): GrowiCommand => {
+export const parse = (slashCommand) => {
   const splitted = slashCommand.text.split(' ');
-
   if (splitted.length < 2) {
-    throw new InvalidGrowiCommandError('The SlashCommand.text does not specify GrowiCommand type');
+    // throw new InvalidGrowiCommandError('The SlashCommand.text does not specify GrowiCommand type');
   }
 
   return {
     text: slashCommand.text,
-    growiCommandType: splitted[1],
-    growiCommandArgs: splitted.slice(2),
+    growiCommandType: splitted[0],
+    growiCommandArgs: splitted.slice(1),
   };
 };

+ 5 - 5
packages/slackbot-proxy/src/controllers/slack.ts

@@ -6,8 +6,8 @@ import { InstallationRepository } from '~/repositories/installation';
 
 import { InstallerService } from '~/services/InstallerService';
 
-import { supportedSlackCommands } from '../../../slack/src/index';
-import { RegisterService } from '../../../slack/src/services/register';
+// import { supportedSlackCommands } from '../../../slack/src/index';
+import { parse } from '../../../slack/src/utils/slash-command-parser';
 
 @Controller('/slack')
 export class SlackCtrl {
@@ -61,9 +61,9 @@ export class SlackCtrl {
     // 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(supportedSlackCommands);
-    const hoge = new RegisterService();
-    console.log(hoge.hogeFunction(body));
+    // console.log(body.text);
+    const parseBody = parse(body);
+    console.log(parseBody);
     // console.log('body', body);
 
     return 'This action will be handled by bolt service.';