welcome-message.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. // eslint-disable-next-line max-len
  25. 'See <https://docs.growi.org/en/admin-guide/management-cookbook/slack-integration/official-bot-settings.html#official-bot-settings | Docs>.',
  26. ),
  27. ],
  28. });
  29. };
  30. export const postInstallSuccessMessage = async (
  31. client: WebClient,
  32. userId: string,
  33. ): Promise<ChatPostMessageResponse> => {
  34. return client.chat.postMessage({
  35. channel: userId,
  36. blocks: [
  37. markdownSectionBlock(
  38. ':tada: You have successfully installed GROWI bot on this Slack workspace.\n' +
  39. 'At first you do `/growi register` in the channel that you want to use.',
  40. ),
  41. markdownSectionBlock(
  42. 'Looking for additional help? ' +
  43. // eslint-disable-next-line max-len
  44. 'See <https://docs.growi.org/en/admin-guide/management-cookbook/slack-integration/official-bot-settings.html#official-bot-settings | Docs>.',
  45. ),
  46. ],
  47. });
  48. };