welcome-message.ts 1.6 KB

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