Просмотр исходного кода

Merge pull request #3758 from weseek/imprv/gw6009-check-growi-url

Imprv/gw6009 check growi url
Yuki Takei 4 лет назад
Родитель
Сommit
5fa566ff0b

+ 14 - 0
packages/slackbot-proxy/src/controllers/growi-to-slack.ts

@@ -1,6 +1,7 @@
 import {
 import {
   Controller, Get, Inject, Req, Res, UseBefore,
   Controller, Get, Inject, Req, Res, UseBefore,
 } from '@tsed/common';
 } from '@tsed/common';
+import axios from 'axios';
 
 
 import { WebAPICallResult } from '@slack/web-api';
 import { WebAPICallResult } from '@slack/web-api';
 
 
@@ -98,6 +99,19 @@ export class GrowiToSlackCtrl {
       return res.status(400).send({ message: 'order has expired or does not exist.' });
       return res.status(400).send({ message: 'order has expired or does not exist.' });
     }
     }
 
 
+    // Access the GROWI URL saved in the Order record and check if the GtoP token is valid.
+    try {
+      const url = new URL('/_api/v3/slack-integration/proxied/commands', order.growiUrl);
+      await axios.post(url.toString(), {
+        type: 'url_verification',
+        tokenPtoG: order.growiAccessToken,
+        challenge: 'this_is_my_challenge_token',
+      });
+    }
+    catch (err) {
+      logger.error(err);
+    }
+
     logger.debug('order found', order);
     logger.debug('order found', order);
 
 
     const token = order.installation.data.bot?.token;
     const token = order.installation.data.bot?.token;

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

@@ -83,7 +83,7 @@ module.exports = (crowi) => {
     // eslint-disable-next-line max-len
     // 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
     // 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') {
     if (body.type === 'url_verification') {
-      return body.challenge;
+      return res.send({ challenge: body.challenge });
     }
     }
 
 
     return handleCommands(req, res);
     return handleCommands(req, res);