|
|
@@ -9,21 +9,18 @@ const router = express.Router();
|
|
|
|
|
|
module.exports = (crowi) => {
|
|
|
this.app = crowi.express;
|
|
|
- const { boltService } = crowi;
|
|
|
- const requestHandler = boltService.receiver.requestHandler.bind(boltService.receiver);
|
|
|
-
|
|
|
|
|
|
// Check if the access token is correct
|
|
|
- function verificationAccessToken(req, res, next) {
|
|
|
- const slackBotAccessToken = req.body.slack_bot_access_token || null;
|
|
|
+ // function verificationAccessToken(req, res, next) {
|
|
|
+ // const slackBotAccessToken = req.body.slack_bot_access_token || null;
|
|
|
|
|
|
- if (slackBotAccessToken == null || slackBotAccessToken !== this.crowi.configManager.getConfig('crowi', 'slackbot:access-token')) {
|
|
|
- logger.error('slack_bot_access_token is invalid.');
|
|
|
- return res.send('*Access token is inValid*');
|
|
|
- }
|
|
|
+ // if (slackBotAccessToken == null || slackBotAccessToken !== this.crowi.configManager.getConfig('crowi', 'slackbot:access-token')) {
|
|
|
+ // logger.error('slack_bot_access_token is invalid.');
|
|
|
+ // return res.send('*Access token is inValid*');
|
|
|
+ // }
|
|
|
|
|
|
- return next();
|
|
|
- }
|
|
|
+ // return next();
|
|
|
+ // }
|
|
|
|
|
|
function verificationRequestUrl(req, res, next) {
|
|
|
// for verification request URL on Event Subscriptions
|
|
|
@@ -34,13 +31,28 @@ module.exports = (crowi) => {
|
|
|
return next();
|
|
|
}
|
|
|
|
|
|
- router.post('/', verificationRequestUrl, verificationAccessToken, async(req, res) => {
|
|
|
+ router.post('/', verificationRequestUrl, async(req, res) => {
|
|
|
|
|
|
// 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();
|
|
|
+ console.log(req.body);
|
|
|
+
|
|
|
+ const { text } = req.body;
|
|
|
+ const args = text.split(' ');
|
|
|
+ const command = args[0];
|
|
|
+
|
|
|
+ switch (command) {
|
|
|
+ case 'search':
|
|
|
+ await crowi.boltService.searchService.search(req.body, args);
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ this.notCommand(command);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
- await requestHandler(req.body);
|
|
|
});
|
|
|
|
|
|
return router;
|