|
@@ -1,10 +1,12 @@
|
|
|
import type { IUser } from '@growi/core/dist/interfaces';
|
|
import type { IUser } from '@growi/core/dist/interfaces';
|
|
|
import { pagePathUtils } from '@growi/core/dist/utils';
|
|
import { pagePathUtils } from '@growi/core/dist/utils';
|
|
|
|
|
+import type { ChatPostMessageArguments } from '@slack/web-api';
|
|
|
import urljoin from 'url-join';
|
|
import urljoin from 'url-join';
|
|
|
|
|
|
|
|
import type Crowi from '~/server/crowi';
|
|
import type Crowi from '~/server/crowi';
|
|
|
import {
|
|
import {
|
|
|
GlobalNotificationSettingEvent,
|
|
GlobalNotificationSettingEvent,
|
|
|
|
|
+ type GlobalNotificationSettingModel,
|
|
|
GlobalNotificationSettingType,
|
|
GlobalNotificationSettingType,
|
|
|
} from '~/server/models/GlobalNotificationSetting';
|
|
} from '~/server/models/GlobalNotificationSetting';
|
|
|
import loggerFactory from '~/utils/logger';
|
|
import loggerFactory from '~/utils/logger';
|
|
@@ -17,10 +19,6 @@ const _logger = loggerFactory('growi:service:GlobalNotificationSlackService');
|
|
|
|
|
|
|
|
const { encodeSpaces } = pagePathUtils;
|
|
const { encodeSpaces } = pagePathUtils;
|
|
|
|
|
|
|
|
-interface GlobalNotificationSlackSetting {
|
|
|
|
|
- slackChannels: string;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* sub service class of GlobalNotificationSetting
|
|
* sub service class of GlobalNotificationSetting
|
|
|
*/
|
|
*/
|
|
@@ -53,14 +51,14 @@ class GlobalNotificationSlackService {
|
|
|
): Promise<void> {
|
|
): Promise<void> {
|
|
|
const { appService, slackIntegrationService } = this.crowi;
|
|
const { appService, slackIntegrationService } = this.crowi;
|
|
|
|
|
|
|
|
- const { GlobalNotificationSetting } = this.crowi.models;
|
|
|
|
|
- const notifications = (
|
|
|
|
|
- GlobalNotificationSetting as any
|
|
|
|
|
- ).findSettingByPathAndEvent(
|
|
|
|
|
- event,
|
|
|
|
|
- path,
|
|
|
|
|
- GlobalNotificationSettingType.SLACK,
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ const GlobalNotificationSetting = this.crowi.models
|
|
|
|
|
+ .GlobalNotificationSetting as GlobalNotificationSettingModel;
|
|
|
|
|
+ const notifications =
|
|
|
|
|
+ await GlobalNotificationSetting.findSettingByPathAndEvent(
|
|
|
|
|
+ event,
|
|
|
|
|
+ path,
|
|
|
|
|
+ GlobalNotificationSettingType.SLACK,
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
const messageBody = this.generateMessageBody(
|
|
const messageBody = this.generateMessageBody(
|
|
|
event,
|
|
event,
|
|
@@ -80,15 +78,16 @@ class GlobalNotificationSlackService {
|
|
|
const appTitle = appService.getAppTitle();
|
|
const appTitle = appService.getAppTitle();
|
|
|
|
|
|
|
|
await Promise.all(
|
|
await Promise.all(
|
|
|
- notifications.map((notification: GlobalNotificationSlackSetting) => {
|
|
|
|
|
|
|
+ notifications.map((notification) => {
|
|
|
const messageObj = prepareSlackMessageForGlobalNotification(
|
|
const messageObj = prepareSlackMessageForGlobalNotification(
|
|
|
messageBody,
|
|
messageBody,
|
|
|
attachmentBody,
|
|
attachmentBody,
|
|
|
appTitle,
|
|
appTitle,
|
|
|
notification.slackChannels,
|
|
notification.slackChannels,
|
|
|
);
|
|
);
|
|
|
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
|
- return slackIntegrationService.postMessage(messageObj as any);
|
|
|
|
|
|
|
+ return slackIntegrationService.postMessage(
|
|
|
|
|
+ messageObj as unknown as ChatPostMessageArguments,
|
|
|
|
|
+ );
|
|
|
}),
|
|
}),
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
@@ -106,6 +105,7 @@ class GlobalNotificationSlackService {
|
|
|
*
|
|
*
|
|
|
* @return slack message body
|
|
* @return slack message body
|
|
|
*/
|
|
*/
|
|
|
|
|
+ // biome-ignore lint/nursery/useMaxParams: event vars needed for different notification types
|
|
|
generateMessageBody(
|
|
generateMessageBody(
|
|
|
event: string,
|
|
event: string,
|
|
|
id: string,
|
|
id: string,
|
|
@@ -170,6 +170,7 @@ class GlobalNotificationSlackService {
|
|
|
*
|
|
*
|
|
|
* @return slack attachment body
|
|
* @return slack attachment body
|
|
|
*/
|
|
*/
|
|
|
|
|
+ // biome-ignore lint/nursery/useMaxParams: event vars needed for different notification types
|
|
|
generateAttachmentBody(
|
|
generateAttachmentBody(
|
|
|
_event: string,
|
|
_event: string,
|
|
|
_id: string,
|
|
_id: string,
|
|
@@ -203,4 +204,4 @@ class GlobalNotificationSlackService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export default GlobalNotificationSlackService;
|
|
|
|
|
|
|
+export { GlobalNotificationSlackService };
|