Explorar el Código

support url_verification

Yuki Takei hace 5 años
padre
commit
9d1a1e769e
Se han modificado 1 ficheros con 10 adiciones y 3 borrados
  1. 10 3
      packages/slackbot-proxy/src/controllers/slack.ts

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

@@ -74,8 +74,11 @@ export class SlackCtrl {
 
 
   @Post('/events')
   @Post('/events')
   async handleEvent(@BodyParams() body:{[key:string]:string}, @Res() res: Res): Promise<string> {
   async handleEvent(@BodyParams() body:{[key:string]:string}, @Res() res: Res): Promise<string> {
-    // Send response immediately to avoid opelation_timeout error
-    // See https://api.slack.com/apis/connections/events-api#the-events-api__responding-to-events
+    // eslint-disable-next-line max-len
+    // see: https://api.slack.com/apis/connections/events-api#the-events-api__subscribing-to-event-types__events-api-request-urls__request-url-configuration--verification
+    if (body.type === 'url_verification') {
+      return body.challenge;
+    }
 
 
     if (body.text == null) {
     if (body.text == null) {
       return 'No text.';
       return 'No text.';
@@ -87,9 +90,13 @@ export class SlackCtrl {
     if (executeGrowiCommand == null) {
     if (executeGrowiCommand == null) {
       return 'No executeGrowiCommand';
       return 'No executeGrowiCommand';
     }
     }
-    await executeGrowiCommand(body);
+
+    // 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();
     res.send();
 
 
+    await executeGrowiCommand(body);
+
     const installation = await this.installationRepository.findByID('1');
     const installation = await this.installationRepository.findByID('1');
     if (installation == null) {
     if (installation == null) {
       throw new Error('installation is reqiured');
       throw new Error('installation is reqiured');