itizawa 5 лет назад
Родитель
Сommit
0922e5cd9f

+ 3 - 3
src/client/js/components/Admin/SlackIntegration/CustomBotWithoutProxySettings.jsx

@@ -22,7 +22,7 @@ const CustomBotWithoutProxySettings = (props) => {
   // eslint-disable-next-line no-unused-vars
   const [siteName, setSiteName] = useState('');
   // eslint-disable-next-line no-unused-vars
-  const [isBoltSetup, setIsBoltSetup] = useState(null);
+  const [isSetupSlackBot, setIsSetupSlackBot] = useState(null);
   const currentBotType = 'custom-bot-without-proxy';
 
   const getSlackWSInWithoutProxy = useCallback(async() => {
@@ -40,14 +40,14 @@ const CustomBotWithoutProxySettings = (props) => {
       await adminAppContainer.retrieveAppSettingsData();
       const res = await appContainer.apiv3.get('/slack-integration/');
       const {
-        slackSigningSecret, slackBotToken, slackSigningSecretEnvVars, slackBotTokenEnvVars, isBoltSetup,
+        slackSigningSecret, slackBotToken, slackSigningSecretEnvVars, slackBotTokenEnvVars, isSetupSlackBot,
       } = res.data.slackBotSettingParams.customBotWithoutProxySettings;
       setSlackSigningSecret(slackSigningSecret);
       setSlackBotToken(slackBotToken);
       setSlackSigningSecretEnv(slackSigningSecretEnvVars);
       setSlackBotTokenEnv(slackBotTokenEnvVars);
       setSiteName(adminAppContainer.state.title);
-      setIsBoltSetup(isBoltSetup);
+      setIsSetupSlackBot(isSetupSlackBot);
     }
     catch (err) {
       toastError(err);

+ 7 - 7
src/server/crowi/index.js

@@ -57,7 +57,7 @@ function Crowi(rootdir) {
   this.syncPageStatusService = null;
   this.cdnResourcesService = new CdnResourcesService();
   this.interceptorManager = new InterceptorManager();
-  this.boltService = null;
+  this.slackService = null;
   this.xss = new Xss();
 
   this.tokens = null;
@@ -118,7 +118,7 @@ Crowi.prototype.init = async function() {
     this.setupImport(),
     this.setupPageService(),
     this.setupSyncPageStatusService(),
-    this.setupBoltService(),
+    this.setupSlackService(),
   ]);
 
   // globalNotification depends on slack and mailer
@@ -670,15 +670,15 @@ Crowi.prototype.setupSyncPageStatusService = async function() {
   }
 };
 
-Crowi.prototype.setupBoltService = async function() {
-  const BoltService = require('../service/bolt');
-  if (this.boltService == null) {
-    this.boltService = new BoltService(this);
+Crowi.prototype.setupSlackService = async function() {
+  const SlackService = require('../service/slack');
+  if (this.slackService == null) {
+    this.slackService = new SlackService(this);
   }
 
   // add as a message handler
   if (this.s2sMessagingService != null) {
-    this.s2sMessagingService.addMessageHandler(this.boltService);
+    this.s2sMessagingService.addMessageHandler(this.slackService);
   }
 };
 

+ 6 - 6
src/server/routes/apiv3/slack-bot.js

@@ -40,13 +40,13 @@ module.exports = (crowi) => {
 
     switch (command) {
       case 'search':
-        await crowi.boltService.showEphemeralSearchResults(body, args);
+        await crowi.slackService.showEphemeralSearchResults(body, args);
         break;
       case 'create':
-        await crowi.boltService.createModal(body);
+        await crowi.slackService.createModal(body);
         break;
       default:
-        await crowi.boltService.notCommand(body);
+        await crowi.slackService.notCommand(body);
         break;
     }
 
@@ -57,7 +57,7 @@ module.exports = (crowi) => {
 
     switch (actionId) {
       case 'shareSearchResults': {
-        await crowi.boltService.shareSearchResults(payload);
+        await crowi.slackService.shareSearchResults(payload);
         break;
       }
       case 'showNextResults': {
@@ -65,7 +65,7 @@ module.exports = (crowi) => {
 
         const { body, args, offset } = parsedValue;
         const newOffset = offset + 10;
-        await crowi.boltService.showEphemeralSearchResults(body, args, newOffset);
+        await crowi.slackService.showEphemeralSearchResults(body, args, newOffset);
         break;
       }
       default:
@@ -78,7 +78,7 @@ module.exports = (crowi) => {
 
     switch (callbackId) {
       case 'createPage':
-        await crowi.boltService.createPageInGrowi(payload);
+        await crowi.slackService.createPageInGrowi(payload);
         break;
       default:
         break;

+ 13 - 13
src/server/routes/apiv3/slack-integration.js

@@ -101,7 +101,7 @@ module.exports = (crowi) => {
         slackBotTokenEnvVars: crowi.configManager.getConfigFromEnvVars('crowi', 'slackbot:token'),
         slackSigningSecret: crowi.configManager.getConfig('crowi', 'slackbot:signingSecret'),
         slackBotToken: crowi.configManager.getConfig('crowi', 'slackbot:token'),
-        isBoltSetup: crowi.boltService.isBoltSetup,
+        isSetupSlackBot: crowi.slackService.isSetupSlackBot,
       },
       // TODO imple when creating with proxy
       customBotWithProxySettings: {
@@ -142,9 +142,9 @@ module.exports = (crowi) => {
       try {
         await updateSlackBotSettings(requestParams);
 
-        // initialize bolt service
-        crowi.boltService.initialize();
-        crowi.boltService.publishUpdatedMessage();
+        // initialize slack service
+        crowi.slackService.initialize();
+        crowi.slackService.publishUpdatedMessage();
 
         const slackIntegrationSettingsParams = {
           currentBotType: crowi.configManager.getConfig('crowi', 'slackbot:currentBotType'),
@@ -190,9 +190,9 @@ module.exports = (crowi) => {
       try {
         await updateSlackBotSettings(requestParams);
 
-        // initialize bolt service
-        crowi.boltService.initialize();
-        crowi.boltService.publishUpdatedMessage();
+        // initialize slack service
+        crowi.slackService.initialize();
+        crowi.slackService.publishUpdatedMessage();
 
         // TODO Impl to delete AccessToken both of Proxy and GROWI when botType changes.
         const customBotWithoutProxySettingParams = {
@@ -262,9 +262,9 @@ module.exports = (crowi) => {
       const accessToken = generateAccessToken(req.user);
       await updateSlackBotSettings({ 'slackbot:access-token': accessToken });
 
-      // initialize bolt service
-      crowi.boltService.initialize();
-      crowi.boltService.publishUpdatedMessage();
+      // initialize slack service
+      crowi.slackService.initialize();
+      crowi.slackService.publishUpdatedMessage();
 
       return res.apiv3({ accessToken });
     }
@@ -293,9 +293,9 @@ module.exports = (crowi) => {
     try {
       await updateSlackBotSettings({ 'slackbot:access-token': null });
 
-      // initialize bolt service
-      crowi.boltService.initialize();
-      crowi.boltService.publishUpdatedMessage();
+      // initialize slack service
+      crowi.slackService.initialize();
+      crowi.slackService.publishUpdatedMessage();
 
       return res.apiv3({});
     }

+ 9 - 10
src/server/service/bolt.js → src/server/service/slack.js

@@ -1,4 +1,4 @@
-const logger = require('@alias/logger')('growi:service:BoltService');
+const logger = require('@alias/logger')('growi:service:SlackService');
 const mongoose = require('mongoose');
 
 const PAGINGLIMIT = 10;
@@ -8,7 +8,7 @@ const { WebClient, LogLevel } = require('@slack/web-api');
 const S2sMessage = require('../models/vo/s2s-message');
 const S2sMessageHandlable = require('./s2s-messaging/handlable');
 
-class BoltService extends S2sMessageHandlable {
+class SlackService extends S2sMessageHandlable {
 
   constructor(crowi) {
     super();
@@ -19,24 +19,23 @@ class BoltService extends S2sMessageHandlable {
     this.client = null;
     this.searchService = null;
 
-    this.isSetup = false;
+    this.isSetupSlackBot = false;
     this.lastLoadedAt = null;
 
     this.initialize();
   }
 
   initialize() {
-    this.isSetup = false;
+    this.isSetupSlackBot = false;
 
     const token = this.crowi.configManager.getConfig('crowi', 'slackbot:token');
-    // const signingSecret = this.crowi.configManager.getConfig('crowi', 'slackbot:signingSecret');
 
     if (token != null) {
       this.client = new WebClient(token, { logLevel: LogLevel.DEBUG });
     }
 
     logger.debug('SlackBot: setup is done');
-    this.isSetup = true;
+    this.isSetupSlackBot = true;
     this.lastLoadedAt = new Date();
   }
 
@@ -45,7 +44,7 @@ class BoltService extends S2sMessageHandlable {
    */
   shouldHandleS2sMessage(s2sMessage) {
     const { eventName, updatedAt } = s2sMessage;
-    if (eventName !== 'boltServiceUpdated' || updatedAt == null) {
+    if (eventName !== 'slackServiceUpdated' || updatedAt == null) {
       return false;
     }
 
@@ -59,7 +58,7 @@ class BoltService extends S2sMessageHandlable {
   async handleS2sMessage() {
     const { configManager } = this.crowi;
 
-    logger.info('Reset bolt by pubsub notification');
+    logger.info('Reset slack bot by pubsub notification');
     await configManager.loadConfigs();
     this.initialize();
   }
@@ -68,7 +67,7 @@ class BoltService extends S2sMessageHandlable {
     const { s2sMessagingService } = this;
 
     if (s2sMessagingService != null) {
-      const s2sMessage = new S2sMessage('boltServiceUpdated', { updatedAt: new Date() });
+      const s2sMessage = new S2sMessage('slackServiceUpdated', { updatedAt: new Date() });
 
       try {
         await s2sMessagingService.publish(s2sMessage);
@@ -359,4 +358,4 @@ class BoltService extends S2sMessageHandlable {
 
 }
 
-module.exports = BoltService;
+module.exports = SlackService;