|
|
@@ -0,0 +1,44 @@
|
|
|
+import { Service } from '@tsed/di';
|
|
|
+import { WebClient, LogLevel } from '@slack/web-api';
|
|
|
+import { generateInputSectionBlock, GrowiCommand, generateMarkdownSectionBlock } from '@growi/slack';
|
|
|
+import { AuthorizeResult } from '@slack/oauth';
|
|
|
+import { GrowiCommandProcessor } from '~/interfaces/slack-to-growi/growi-command-processor';
|
|
|
+import { Relation } from '~/entities/relation';
|
|
|
+
|
|
|
+const isProduction = process.env.NODE_ENV === 'production';
|
|
|
+
|
|
|
+@Service()
|
|
|
+export class UnregisterService implements GrowiCommandProcessor {
|
|
|
+
|
|
|
+ async process(growiCommand: GrowiCommand, authorizeResult: AuthorizeResult, body: {[key:string]:string}): Promise<void> {
|
|
|
+ const { botToken } = authorizeResult;
|
|
|
+ const client = new WebClient(botToken, { logLevel: isProduction ? LogLevel.DEBUG : LogLevel.INFO });
|
|
|
+
|
|
|
+ await client.views.open({
|
|
|
+ trigger_id: body.trigger_id,
|
|
|
+ view: {
|
|
|
+ type: 'modal',
|
|
|
+ callback_id: 'unregister',
|
|
|
+ title: {
|
|
|
+ type: 'plain_text',
|
|
|
+ text: 'Unregister Credentials',
|
|
|
+ },
|
|
|
+ submit: {
|
|
|
+ type: 'plain_text',
|
|
|
+ text: 'Submit',
|
|
|
+ },
|
|
|
+ close: {
|
|
|
+ type: 'plain_text',
|
|
|
+ text: 'Close',
|
|
|
+ },
|
|
|
+ private_metadata: JSON.stringify({ channel: body.channel_name }),
|
|
|
+
|
|
|
+ blocks: [
|
|
|
+ ...growiCommand.growiCommandArgs.map(growiCommandArg => generateMarkdownSectionBlock(`GROWI url: ${growiCommandArg}.`)),
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|