create.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. const { markdownSectionBlock, inputSectionBlock } = require('@growi/slack');
  2. const logger = require('@alias/logger')('growi:service:SlackCommandHandler:create');
  3. module.exports = () => {
  4. const BaseSlackCommandHandler = require('./slack-command-handler');
  5. const handler = new BaseSlackCommandHandler();
  6. handler.handleCommand = async(client, body) => {
  7. try {
  8. await client.views.open({
  9. trigger_id: body.trigger_id,
  10. view: {
  11. type: 'modal',
  12. callback_id: 'createPage',
  13. title: {
  14. type: 'plain_text',
  15. text: 'Create Page',
  16. },
  17. submit: {
  18. type: 'plain_text',
  19. text: 'Submit',
  20. },
  21. close: {
  22. type: 'plain_text',
  23. text: 'Cancel',
  24. },
  25. blocks: [
  26. markdownSectionBlock('Create new page.'),
  27. inputSectionBlock('path', 'Path', 'path_input', false, '/path'),
  28. inputSectionBlock('contents', 'Contents', 'contents_input', true, 'Input with Markdown...'),
  29. ],
  30. private_metadata: JSON.stringify({ channelId: body.channel_id }),
  31. },
  32. });
  33. }
  34. catch (err) {
  35. logger.error('Failed to create a page.');
  36. await client.chat.postEphemeral({
  37. channel: body.channel_id,
  38. user: body.user_id,
  39. text: 'Failed To Create',
  40. blocks: [
  41. markdownSectionBlock(`*Failed to create new page.*\n ${err}`),
  42. ],
  43. });
  44. throw err;
  45. }
  46. };
  47. return handler;
  48. };