import { BodyParams, Controller, Get, Inject, Post, Req, Res, } from '@tsed/common'; import { supportedGrowiCommandsMappings } from '@growi/slack/src/index'; import { Installation } from '~/entities/installation'; import { InstallationRepository } from '~/repositories/installation'; import { InstallerService } from '~/services/InstallerService'; import { registerService } from '~/services/RegisterService'; @Controller('/slack') export class SlackCtrl { @Inject() installationRepository: InstallationRepository; // eslint-disable-next-line no-useless-constructor constructor(private readonly installerService: InstallerService) { } @Get('/testsave') testsave(): void { const installation = new Installation(); installation.data = { team: undefined, enterprise: undefined, user: { id: '', token: undefined, scopes: undefined, }, }; this.installationRepository.save(installation); } @Get('/install') async install(): Promise { const url = await this.installerService.installer.generateInstallUrl({ // Add the scopes your app needs scopes: [ 'channels:history', 'commands', 'groups:history', 'im:history', 'mpim:history', 'chat:write', ], }); return `` // eslint-disable-next-line max-len + 'Add to Slack' + ''; } @Post('/events') handleEvent(@BodyParams() body:{[key:string]:string}, @Res() res: Res): string { // Send response immediately to avoid opelation_timeout error // See https://api.slack.com/apis/connections/events-api#the-events-api__responding-to-events const method = supportedGrowiCommandsMappings[body.text]; const modulePath = `../services/${method}Service`; const targetModule = require(modulePath); console.log('hoge', targetModule); targetModule(); // const slackInput = this.receiveService.receiveContentsFromSlack(body); // console.log('Controller/events', slackInput); res.send(); console.log('body', body); return 'This action will be handled by bolt service.'; } @Get('/oauth_redirect') async handleOauthRedirect(@Req() req: Req, @Res() res: Res): Promise { // illegal state // TODO: https://youtrack.weseek.co.jp/issue/GW-5543 if (req.query.state === '') { throw new Error('illegal state'); } return this.installerService.installer.handleCallback(req, res); // TODO: https://youtrack.weseek.co.jp/issue/GW-5543 // this.installer.handleCallback(req, res, { // success: (installation, metadata, req, res) => {}, // failure: (error, installOptions, req, res) => {}, // }); } }