RegisterService.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { Service } from '@tsed/di';
  2. import { WebClient, LogLevel } from '@slack/web-api';
  3. import { generateInputSectionBlock, GrowiCommand } from '@growi/slack';
  4. import { AuthorizeResult } from '@slack/oauth';
  5. import { GrowiCommandProcessor } from '~/interfaces/growi-command-processor';
  6. @Service()
  7. export class RegisterService implements GrowiCommandProcessor {
  8. async process(growiCommand: GrowiCommand, authorizeResult: AuthorizeResult, body: {[key:string]:string}): Promise<void> {
  9. const { botToken } = authorizeResult;
  10. // tmp use process.env
  11. const client = new WebClient(botToken, { logLevel: LogLevel.DEBUG });
  12. await client.views.open({
  13. trigger_id: body.trigger_id,
  14. view: {
  15. type: 'modal',
  16. title: {
  17. type: 'plain_text',
  18. text: 'Register Credentials',
  19. },
  20. submit: {
  21. type: 'plain_text',
  22. text: 'Submit',
  23. },
  24. close: {
  25. type: 'plain_text',
  26. text: 'Close',
  27. },
  28. blocks: [
  29. generateInputSectionBlock('growiDomain', 'GROWI domain', 'contents_input', false, 'https://example.com'),
  30. generateInputSectionBlock('growiAccessToken', 'GROWI ACCESS_TOKEN', 'contents_input', false, 'jBMZvpk.....'),
  31. generateInputSectionBlock('proxyToken', 'PROXY ACCESS_TOKEM', 'contents_input', false, 'jBMZvpk.....'),
  32. ],
  33. },
  34. });
  35. }
  36. }