Yuki Takei il y a 4 ans
Parent
commit
adfeb445d2

+ 4 - 2
packages/slackbot-proxy/src/controllers/slack.ts

@@ -4,6 +4,8 @@ import {
 
 import axios from 'axios';
 
+import { WebAPICallResult } from '@slack/web-api';
+
 import {
   generateMarkdownSectionBlock, parseSlashCommand, postEphemeralErrors, RequestFromSlack, verifySlackRequest,
 } from '@growi/slack';
@@ -73,7 +75,7 @@ export class SlackCtrl {
 
   @Post('/commands')
   @UseBefore(addSigningSecretToReq, verifySlackRequest, AuthorizeCommandMiddleware)
-  async handleCommand(@Req() req: AuthedReq, @Res() res: Res): Promise<void|string|Res> {
+  async handleCommand(@Req() req: AuthedReq, @Res() res: Res): Promise<void|string|Res|WebAPICallResult> {
     const { body, authorizeResult } = req;
 
     if (body.text == null) {
@@ -129,7 +131,7 @@ export class SlackCtrl {
 
     try {
       // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-      postEphemeralErrors(rejectedResults, body.channel_id, body.user_id, botToken!);
+      return postEphemeralErrors(rejectedResults, body.channel_id, body.user_id, botToken!);
     }
     catch (err) {
       logger.error(err);

+ 10 - 1
src/server/routes/apiv3/slack-integration.js

@@ -37,11 +37,20 @@ module.exports = (crowi) => {
   };
 
   async function handleCommands(req, res) {
+    const { body } = req;
+
+    if (body.text == null) {
+      return 'No text.';
+    }
+
+    /*
+     * TODO: use parseSlashCommand
+     */
+
     // 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();
 
-    const { body } = req;
     const args = body.text.split(' ');
     const command = args[0];