|
|
@@ -5,7 +5,7 @@ const axios = require('axios');
|
|
|
const urljoin = require('url-join');
|
|
|
const loggerFactory = require('@alias/logger');
|
|
|
|
|
|
-const { getConnectionStatuses } = require('@growi/slack');
|
|
|
+const { getConnectionStatuses, relationTestToSlack } = require('@growi/slack');
|
|
|
|
|
|
const ErrorV3 = require('../../models/vo/error-apiv3');
|
|
|
|
|
|
@@ -55,10 +55,6 @@ module.exports = (crowi) => {
|
|
|
body('currentBotType')
|
|
|
.isIn(['officialBot', 'customBotWithoutProxy', 'customBotWithProxy']),
|
|
|
],
|
|
|
- NotificationTestToSlackWorkSpace: [
|
|
|
- body('channel').trim().not().isEmpty()
|
|
|
- .isString(),
|
|
|
- ],
|
|
|
AccessTokens: [
|
|
|
body('tokenGtoP').trim().not().isEmpty()
|
|
|
.isString()
|
|
|
@@ -70,6 +66,10 @@ module.exports = (crowi) => {
|
|
|
RelationTest: [
|
|
|
body('slackappintegrationsId').isMongoId(),
|
|
|
],
|
|
|
+ SlackChannel: [
|
|
|
+ body('channel').trim().not().isEmpty()
|
|
|
+ .isString(),
|
|
|
+ ],
|
|
|
};
|
|
|
|
|
|
async function resetAllBotSettings() {
|
|
|
@@ -479,5 +479,44 @@ module.exports = (crowi) => {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+ /**
|
|
|
+ * @swagger
|
|
|
+ *
|
|
|
+ * /slack-integration-settings/without-proxy/test:
|
|
|
+ * post:
|
|
|
+ * tags: [botType]
|
|
|
+ * operationId: postTest
|
|
|
+ * summary: test the connection
|
|
|
+ * description: Test the connection with slack work space.
|
|
|
+ * requestBody:
|
|
|
+ * content:
|
|
|
+ * application/json:
|
|
|
+ * schema:
|
|
|
+ * properties:
|
|
|
+ * testChannel:
|
|
|
+ * type: string
|
|
|
+ * responses:
|
|
|
+ * 200:
|
|
|
+ * description: Succeeded to connect to slack work space.
|
|
|
+ */
|
|
|
+ router.post('/without-proxy/test', loginRequiredStrictly, adminRequired, csrf, validator.SlackChannel, apiV3FormValidator, async(req, res) => {
|
|
|
+ const currentBotType = crowi.configManager.getConfig('crowi', 'slackbot:currentBotType');
|
|
|
+ if (currentBotType !== 'customBotWithoutProxy') {
|
|
|
+ const msg = 'Select Without Proxy Type';
|
|
|
+ return res.apiv3Err(new ErrorV3(msg, 'select-not-proxy-type'), 400);
|
|
|
+ }
|
|
|
+ // TODO impl req.body at GW-5998
|
|
|
+ // const { channel } = req.body;
|
|
|
+ const slackBotToken = crowi.configManager.getConfig('crowi', 'slackbot:token');
|
|
|
+ try {
|
|
|
+ await relationTestToSlack(slackBotToken);
|
|
|
+ // TODO impl return response after imple 5996, 6002
|
|
|
+ }
|
|
|
+ catch (error) {
|
|
|
+ logger.error('Error', error);
|
|
|
+ return res.apiv3Err(new ErrorV3(`Error occured while testing. Cause: ${error.message}`, 'test-failed', error.stack));
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
return router;
|
|
|
};
|