itizawa 4 лет назад
Родитель
Сommit
08ba629647

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

@@ -159,21 +159,23 @@ export class SlackCtrl {
     // See https://api.slack.com/apis/connections/events-api#the-events-api__responding-to-events
     res.send();
 
-    body.growiUris = [];
-    relations.forEach((relation) => {
-      if (relation.singlePostCommands.includes(growiCommand.growiCommandType)) {
-        body.growiUris.push(relation.growiUri);
-      }
-    });
+    body.growiUrisForSinglePost = relations.filter((relation) => {
+      return relation.singlePostCommands.includes(growiCommand.growiCommandType);
+    }).map(relation => relation.growiUri);
+
 
-    if (body.growiUris != null && body.growiUris.length > 0) {
+    if (body.growiUrisForSinglePost != null && body.growiUrisForSinglePost.length > 0) {
       return this.selectGrowiService.process(growiCommand, authorizeResult, body);
     }
 
+    const relationsForBroadcast = relations.filter((relation) => {
+      return relation.broadcastCommands.includes(growiCommand.growiCommandType);
+    });
+
     /*
      * forward to GROWI server
      */
-    this.sendCommand(growiCommand, relations, body);
+    this.sendCommand(growiCommand, relationsForBroadcast, body);
   }
 
   @Post('/interactions')

+ 2 - 2
packages/slackbot-proxy/src/services/SelectGrowiService.ts

@@ -21,7 +21,7 @@ export class SelectGrowiService implements GrowiCommandProcessor {
   @Inject()
   relationRepository: RelationRepository;
 
-  async process(growiCommand: GrowiCommand, authorizeResult: AuthorizeResult, body: {[key:string]:string } & {growiUris:string[]}): Promise<void> {
+  async process(growiCommand: GrowiCommand, authorizeResult: AuthorizeResult, body: {[key:string]:string } & {growiUrisForSinglePost:string[]}): Promise<void> {
     const { botToken } = authorizeResult;
 
     if (botToken == null) {
@@ -60,7 +60,7 @@ export class SelectGrowiService implements GrowiCommandProcessor {
             element: {
               type: 'static_select',
               action_id: 'growi_app',
-              options: body.growiUris.map((growiUri) => {
+              options: body.growiUrisForSinglePost.map((growiUri) => {
                 return ({
                   text: {
                     type: 'plain_text',