|
|
@@ -19,7 +19,7 @@ import S2sMessage from '../models/vo/s2s-message';
|
|
|
import { SlackCommandHandlerError } from '../models/vo/slack-command-handler-error';
|
|
|
import { slackLegacyUtilFactory } from '../util/slack-legacy';
|
|
|
|
|
|
-import type { IConfigManagerForApp } from './config-manager';
|
|
|
+import { configManager } from './config-manager';
|
|
|
import type { S2sMessagingService } from './s2s-messaging/base';
|
|
|
import type { S2sMessageHandlable } from './s2s-messaging/handlable';
|
|
|
import { LinkSharedEventHandler } from './slack-event-handler/link-shared';
|
|
|
@@ -34,8 +34,6 @@ export class SlackIntegrationService implements S2sMessageHandlable {
|
|
|
|
|
|
crowi: Crowi;
|
|
|
|
|
|
- configManager: IConfigManagerForApp;
|
|
|
-
|
|
|
s2sMessagingService!: S2sMessagingService;
|
|
|
|
|
|
lastLoadedAt?: Date;
|
|
|
@@ -44,7 +42,6 @@ export class SlackIntegrationService implements S2sMessageHandlable {
|
|
|
|
|
|
constructor(crowi: Crowi) {
|
|
|
this.crowi = crowi;
|
|
|
- this.configManager = crowi.configManager;
|
|
|
this.s2sMessagingService = crowi.s2sMessagingService;
|
|
|
this.linkSharedHandler = new LinkSharedEventHandler(crowi);
|
|
|
|
|
|
@@ -99,20 +96,20 @@ export class SlackIntegrationService implements S2sMessageHandlable {
|
|
|
}
|
|
|
|
|
|
get isSlackbotConfigured(): boolean {
|
|
|
- const hasSlackbotType = !!this.configManager.getConfig('slackbot:currentBotType');
|
|
|
+ const hasSlackbotType = !!configManager.getConfig('slackbot:currentBotType');
|
|
|
return hasSlackbotType;
|
|
|
}
|
|
|
|
|
|
get isSlackLegacyConfigured(): boolean {
|
|
|
// for legacy util
|
|
|
- const hasSlackToken = !!this.configManager.getConfig('slack:token');
|
|
|
- const hasSlackIwhUrl = !!this.configManager.getConfig('slack:incomingWebhookUrl');
|
|
|
+ const hasSlackToken = !!configManager.getConfig('slack:token');
|
|
|
+ const hasSlackIwhUrl = !!configManager.getConfig('slack:incomingWebhookUrl');
|
|
|
|
|
|
return hasSlackToken || hasSlackIwhUrl;
|
|
|
}
|
|
|
|
|
|
private isCheckTypeValid(): boolean {
|
|
|
- const currentBotType = this.configManager.getConfig('slackbot:currentBotType');
|
|
|
+ const currentBotType = configManager.getConfig('slackbot:currentBotType');
|
|
|
if (currentBotType == null) {
|
|
|
throw new Error('The config \'SLACKBOT_TYPE\'(ns: \'crowi\', key: \'slackbot:currentBotType\') must be set.');
|
|
|
}
|
|
|
@@ -121,7 +118,7 @@ export class SlackIntegrationService implements S2sMessageHandlable {
|
|
|
}
|
|
|
|
|
|
get proxyUriForCurrentType(): string | undefined {
|
|
|
- const currentBotType = this.configManager.getConfig('slackbot:currentBotType');
|
|
|
+ const currentBotType = configManager.getConfig('slackbot:currentBotType');
|
|
|
|
|
|
// TODO assert currentBotType is not null and CUSTOM_WITHOUT_PROXY
|
|
|
|
|
|
@@ -132,7 +129,7 @@ export class SlackIntegrationService implements S2sMessageHandlable {
|
|
|
proxyUri = OFFICIAL_SLACKBOT_PROXY_URI;
|
|
|
break;
|
|
|
default:
|
|
|
- proxyUri = this.configManager.getConfig('slackbot:proxyUri');
|
|
|
+ proxyUri = configManager.getConfig('slackbot:proxyUri');
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
@@ -145,7 +142,7 @@ export class SlackIntegrationService implements S2sMessageHandlable {
|
|
|
async generateClientForCustomBotWithoutProxy(): Promise<WebClient> {
|
|
|
this.isCheckTypeValid();
|
|
|
|
|
|
- const token = this.configManager.getConfig('slackbot:withoutProxy:botToken');
|
|
|
+ const token = configManager.getConfig('slackbot:withoutProxy:botToken');
|
|
|
|
|
|
if (token == null) {
|
|
|
throw new Error('The config \'SLACK_BOT_TOKEN\'(ns: \'crowi\', key: \'slackbot:withoutProxy:botToken\') must be set.');
|
|
|
@@ -179,7 +176,7 @@ export class SlackIntegrationService implements S2sMessageHandlable {
|
|
|
async generateClientForPrimaryWorkspace(): Promise<WebClient> {
|
|
|
this.isCheckTypeValid();
|
|
|
|
|
|
- const currentBotType = this.configManager.getConfig('slackbot:currentBotType');
|
|
|
+ const currentBotType = configManager.getConfig('slackbot:currentBotType');
|
|
|
|
|
|
if (currentBotType === SlackbotType.CUSTOM_WITHOUT_PROXY) {
|
|
|
return this.generateClientForCustomBotWithoutProxy();
|
|
|
@@ -233,7 +230,7 @@ export class SlackIntegrationService implements S2sMessageHandlable {
|
|
|
}
|
|
|
|
|
|
private async postMessageWithLegacyUtil(messageArgs: ChatPostMessageArguments | IncomingWebhookSendArguments): Promise<void> {
|
|
|
- const slackLegacyUtil = slackLegacyUtilFactory(this.configManager);
|
|
|
+ const slackLegacyUtil = slackLegacyUtilFactory(configManager);
|
|
|
|
|
|
try {
|
|
|
await slackLegacyUtil.postMessage(messageArgs);
|