welcome-message.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { markdownSectionBlock } from '@growi/slack/dist/utils/block-kit-builder';
  2. import { ChatPostMessageResponse, WebClient } from '@slack/web-api';
  3. export const postWelcomeMessageOnce = async(client: WebClient, channel: string): Promise<void|ChatPostMessageResponse> => {
  4. const history = await client.conversations.history({
  5. channel,
  6. limit: 1,
  7. });
  8. // skip posting on the second time or later
  9. if (history.messages != null && history.messages.length > 0) {
  10. return;
  11. }
  12. return client.chat.postMessage({
  13. channel,
  14. blocks: [
  15. markdownSectionBlock('Hi! This is GROWI bot.\n'
  16. + 'You can invoke any feature with `/growi [command]` in any channel. Type `/growi help` to check the available features.'),
  17. markdownSectionBlock('Looking for additional help? '
  18. // eslint-disable-next-line max-len
  19. + 'See <https://docs.growi.org/en/admin-guide/management-cookbook/slack-integration/official-bot-settings.html#official-bot-settings | Docs>.'),
  20. ],
  21. });
  22. };
  23. export const postInstallSuccessMessage = async(client: WebClient, userId: string): Promise<ChatPostMessageResponse> => {
  24. return client.chat.postMessage({
  25. channel: userId,
  26. blocks: [
  27. markdownSectionBlock(':tada: You have successfully installed GROWI bot on this Slack workspace.\n'
  28. + 'At first you do `/growi register` in the channel that you want to use.'),
  29. markdownSectionBlock('Looking for additional help? '
  30. // eslint-disable-next-line max-len
  31. + 'See <https://docs.growi.org/en/admin-guide/management-cookbook/slack-integration/official-bot-settings.html#official-bot-settings | Docs>.'),
  32. ],
  33. });
  34. };