|
@@ -1,5 +1,5 @@
|
|
|
import {
|
|
import {
|
|
|
- BodyParams, Controller, Get, Inject, Next, Post, Req, Res, UseBefore,
|
|
|
|
|
|
|
+ BodyParams, Controller, Get, Inject, Post, Req, Res, UseBefore,
|
|
|
} from '@tsed/common';
|
|
} from '@tsed/common';
|
|
|
|
|
|
|
|
import axios from 'axios';
|
|
import axios from 'axios';
|
|
@@ -7,7 +7,7 @@ import axios from 'axios';
|
|
|
import { WebAPICallResult } from '@slack/web-api';
|
|
import { WebAPICallResult } from '@slack/web-api';
|
|
|
|
|
|
|
|
import {
|
|
import {
|
|
|
- generateMarkdownSectionBlock, parseSlashCommand, postEphemeralErrors, RequestFromSlack, verifySlackRequest,
|
|
|
|
|
|
|
+ generateMarkdownSectionBlock, parseSlashCommand, postEphemeralErrors, verifySlackRequest,
|
|
|
} from '@growi/slack';
|
|
} from '@growi/slack';
|
|
|
|
|
|
|
|
import { Relation } from '~/entities/relation';
|
|
import { Relation } from '~/entities/relation';
|
|
@@ -15,6 +15,7 @@ import { AuthedReq } from '~/interfaces/authorized-req';
|
|
|
import { InstallationRepository } from '~/repositories/installation';
|
|
import { InstallationRepository } from '~/repositories/installation';
|
|
|
import { RelationRepository } from '~/repositories/relation';
|
|
import { RelationRepository } from '~/repositories/relation';
|
|
|
import { OrderRepository } from '~/repositories/order';
|
|
import { OrderRepository } from '~/repositories/order';
|
|
|
|
|
+import { AddSigningSecretToReq } from '~/middlewares/add-signing-secret-to-req';
|
|
|
import { AuthorizeCommandMiddleware, AuthorizeInteractionMiddleware } from '~/middlewares/authorizer';
|
|
import { AuthorizeCommandMiddleware, AuthorizeInteractionMiddleware } from '~/middlewares/authorizer';
|
|
|
import { InstallerService } from '~/services/InstallerService';
|
|
import { InstallerService } from '~/services/InstallerService';
|
|
|
import { RegisterService } from '~/services/RegisterService';
|
|
import { RegisterService } from '~/services/RegisterService';
|
|
@@ -24,17 +25,6 @@ import loggerFactory from '~/utils/logger';
|
|
|
const logger = loggerFactory('slackbot-proxy:controllers:slack');
|
|
const logger = loggerFactory('slackbot-proxy:controllers:slack');
|
|
|
|
|
|
|
|
|
|
|
|
|
-/**
|
|
|
|
|
- * Middleware to pass verifySlackRequest
|
|
|
|
|
- * @param req
|
|
|
|
|
- * @param res
|
|
|
|
|
- * @param next
|
|
|
|
|
- */
|
|
|
|
|
-const addSigningSecretToReq = (req: Req & RequestFromSlack, res: Res, next: Next): void => {
|
|
|
|
|
- req.slackSigningSecret = process.env.SLACK_SIGNING_SECRET;
|
|
|
|
|
- next();
|
|
|
|
|
-};
|
|
|
|
|
-
|
|
|
|
|
@Controller('/slack')
|
|
@Controller('/slack')
|
|
|
export class SlackCtrl {
|
|
export class SlackCtrl {
|
|
|
|
|
|
|
@@ -74,7 +64,7 @@ export class SlackCtrl {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Post('/commands')
|
|
@Post('/commands')
|
|
|
- @UseBefore(addSigningSecretToReq, verifySlackRequest, AuthorizeCommandMiddleware)
|
|
|
|
|
|
|
+ @UseBefore(AddSigningSecretToReq, verifySlackRequest, AuthorizeCommandMiddleware)
|
|
|
async handleCommand(@Req() req: AuthedReq, @Res() res: Res): Promise<void|string|Res|WebAPICallResult> {
|
|
async handleCommand(@Req() req: AuthedReq, @Res() res: Res): Promise<void|string|Res|WebAPICallResult> {
|
|
|
const { body, authorizeResult } = req;
|
|
const { body, authorizeResult } = req;
|
|
|
|
|
|