SelectRequestService.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { Service } from '@tsed/di';
  2. import { WebClient, LogLevel } from '@slack/web-api';
  3. import { GrowiCommand } from '@growi/slack';
  4. import { AuthorizeResult } from '@slack/oauth';
  5. import { GrowiCommandProcessor } from '~/interfaces/slack-to-growi/growi-command-processor';
  6. const isProduction = process.env.NODE_ENV === 'production';
  7. @Service()
  8. export class SelectRequestService implements GrowiCommandProcessor {
  9. async process(growiCommand: GrowiCommand, authorizeResult: AuthorizeResult, body: {[key:string]:string } & {growiUris:string[]}): Promise<void> {
  10. const { botToken } = authorizeResult;
  11. const client = new WebClient(botToken, { logLevel: isProduction ? LogLevel.DEBUG : LogLevel.INFO });
  12. await client.views.open({
  13. trigger_id: body.trigger_id,
  14. view: {
  15. type: 'modal',
  16. callback_id: 'register',
  17. title: {
  18. type: 'plain_text',
  19. text: 'Slect Growi url',
  20. },
  21. submit: {
  22. type: 'plain_text',
  23. text: 'Submit',
  24. },
  25. close: {
  26. type: 'plain_text',
  27. text: 'Close',
  28. },
  29. private_metadata: JSON.stringify({ channel: body.channel_name }),
  30. blocks: [
  31. {
  32. type: 'input',
  33. block_id: 'select_growi',
  34. label: {
  35. type: 'plain_text',
  36. text: 'GROWI App',
  37. },
  38. element: {
  39. type: 'static_select',
  40. action_id: 'growi_app',
  41. options: body.growiUris.map((growiUri) => {
  42. return ({
  43. text: {
  44. type: 'plain_text',
  45. text: growiUri,
  46. },
  47. value: growiUri,
  48. });
  49. }),
  50. },
  51. },
  52. ],
  53. },
  54. });
  55. }
  56. }