|
|
@@ -79,23 +79,19 @@ export class SlackCtrl {
|
|
|
|
|
|
@Post('/commands')
|
|
|
@UseBefore(AuthorizeCommandMiddleware)
|
|
|
- async handleCommand(@Req() req: AuthedReq, @Res() res: Res): Promise<void|string> {
|
|
|
+ async handleCommand(@Req() req: AuthedReq, @Res() res: Res): Promise<void|string|Res> {
|
|
|
const { body, authorizeResult } = req;
|
|
|
|
|
|
if (body.text == null) {
|
|
|
return 'No text.';
|
|
|
}
|
|
|
|
|
|
- // 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();
|
|
|
-
|
|
|
const growiCommand = parseSlashCommand(body);
|
|
|
|
|
|
// register
|
|
|
if (growiCommand.growiCommandType === 'register') {
|
|
|
await this.registerService.process(growiCommand, authorizeResult, body as {[key:string]:string});
|
|
|
- return;
|
|
|
+ return res.send();
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -106,6 +102,19 @@ export class SlackCtrl {
|
|
|
const installation = await this.installationRepository.findByTeamIdOrEnterpriseId(installationId!);
|
|
|
const relations = await this.relationRepository.find({ installation: installation?.id });
|
|
|
|
|
|
+ if (relations.length === 0) {
|
|
|
+ return res.json({
|
|
|
+ blocks: [
|
|
|
+ generateMarkdownSectionBlock('*No relation found.*'),
|
|
|
+ generateMarkdownSectionBlock('Run `/growi register` first.'),
|
|
|
+ ],
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 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();
|
|
|
+
|
|
|
const promises = relations.map((relation: Relation) => {
|
|
|
// generate API URL
|
|
|
const url = new URL('/_api/v3/slack-bot/commands', relation.growiUri);
|