Explorar o código

fresh install

Steven Fukase %!s(int64=4) %!d(string=hai) anos
pai
achega
e442e537b3
Modificáronse 4 ficheiros con 26 adicións e 17 borrados
  1. 1 0
      package.json
  2. 0 3
      src/server/service/user-notification/index.js
  3. 11 14
      src/server/util/slack.js
  4. 14 0
      yarn.lock

+ 1 - 0
package.json

@@ -80,6 +80,7 @@
     "@promster/express": "^5.0.1",
     "@promster/server": "^6.0.0",
     "@slack/web-api": "^6.2.3",
+    "@slack/webhook": "^6.0.0",
     "JSONStream": "^1.3.5",
     "archiver": "^3.1.1",
     "array.prototype.flatmap": "^1.2.2",

+ 0 - 3
src/server/service/user-notification/index.js

@@ -46,9 +46,6 @@ class UserNotificationService {
       else {
         res = await slack.postPage(page, user, chan, mode, previousRevision);
       }
-      if (res.status !== 'ok') {
-        throw new Error(`fail to send slack notification to #${chan} channel`);
-      }
       return res;
     });
 

+ 11 - 14
src/server/util/slack.js

@@ -8,25 +8,22 @@ const urljoin = require('url-join');
 /* eslint-disable no-use-before-define */
 
 module.exports = function(crowi) {
-  const Slack = require('slack-node');
+  const { IncomingWebhook } = require('@slack/webhook');
   const { WebClient } = require('@slack/web-api');
   const { configManager } = crowi;
 
   const slack = {};
 
-  const postWithIwh = function(messageObj) {
-    return new Promise((resolve, reject) => {
-      const client = new Slack();
-      client.setWebhook(configManager.getConfig('notification', 'slack:incomingWebhookUrl'));
-      client.webhook(messageObj, (err, res) => {
-        if (err) {
-          debug('Post error', err, res);
-          debug('Sent data to slack is:', messageObj);
-          return reject(err);
-        }
-        resolve(res);
-      });
-    });
+  const postWithIwh = async(messageObj) => {
+    const webhook = new IncomingWebhook(configManager.getConfig('notification', 'slack:incomingWebhookUrl'));
+    try {
+      await webhook.send(messageObj);
+    }
+    catch (error) {
+      debug('Post error', error);
+      debug('Sent data to slack is:', messageObj);
+      throw error;
+    }
   };
 
   const postWithWebApi = async(messageObj) => {

+ 14 - 0
yarn.lock

@@ -1831,6 +1831,11 @@
   dependencies:
     "@types/node" ">=12.0.0"
 
+"@slack/types@^1.2.1":
+  version "1.10.0"
+  resolved "https://registry.yarnpkg.com/@slack/types/-/types-1.10.0.tgz#cbf7d83e1027f4cbfd13d6b429f120c7fb09127a"
+  integrity sha512-tA7GG7Tj479vojfV3AoxbckalA48aK6giGjNtgH6ihpLwTyHE3fIgRrvt8TWfLwW8X8dyu7vgmAsGLRG7hWWOg==
+
 "@slack/types@^2.0.0":
   version "2.0.0"
   resolved "https://registry.yarnpkg.com/@slack/types/-/types-2.0.0.tgz#7b938ab576cd1d6c9ff9ad67a96f8058d101af10"
@@ -1853,6 +1858,15 @@
     p-queue "^6.6.1"
     p-retry "^4.0.0"
 
+"@slack/webhook@^6.0.0":
+  version "6.0.0"
+  resolved "https://registry.yarnpkg.com/@slack/webhook/-/webhook-6.0.0.tgz#844593c1e864a966e549f60bb640586628f3c1c4"
+  integrity sha512-2fohfhLI9lkAmOSWt1R457JBsB3iFNqahu4GqdFZRtcp/bT+xeG/kPn/hQa78JS74poRjWTt5G/qJjNaWMGOEQ==
+  dependencies:
+    "@slack/types" "^1.2.1"
+    "@types/node" ">=12.0.0"
+    axios "^0.21.1"
+
 "@types/babel__core@^7.1.0":
   version "7.1.2"
   resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.2.tgz#608c74f55928033fce18b99b213c16be4b3d114f"