Browse Source

customized notification

sou 7 years ago
parent
commit
d80f23208d
2 changed files with 18 additions and 4 deletions
  1. 1 1
      lib/routes/comment.js
  2. 17 3
      lib/util/slack.js

+ 1 - 1
lib/routes/comment.js

@@ -79,7 +79,7 @@ module.exports = function(crowi, app) {
     //slack notification
     //slack notification
     const slackNotify = new slack(crowi);
     const slackNotify = new slack(crowi);
     const user = await User.findUserByUsername(req.user.username);
     const user = await User.findUserByUsername(req.user.username);
-    await slackNotify.post(page, user, 'general', 'comment', null);
+    await slackNotify.post(page, user, 'general', 'comment', null, createdComment);
 
 
     return res.json(ApiResponse.success({comment: createdComment}));
     return res.json(ApiResponse.success({comment: createdComment}));
   };
   };

+ 17 - 3
lib/util/slack.js

@@ -88,7 +88,7 @@ module.exports = function(crowi) {
     };
     };
   };
   };
 
 
-  const prepareSlackMessage = function(page, user, channel, updateType, previousRevision) {
+  const prepareSlackMessage = function(page, user, channel, updateType, previousRevision, comment) {
     var url = config.crowi['app:url'] || '';
     var url = config.crowi['app:url'] || '';
     var body = page.revision.body;
     var body = page.revision.body;
 
 
@@ -112,6 +112,20 @@ module.exports = function(crowi) {
       text: body,
       text: body,
       mrkdwn_in: ['text'],
       mrkdwn_in: ['text'],
     };
     };
+
+    if (updateType == 'comment') {
+      attachment = {
+        color: '#263a3c',
+        author_name: '@' + user.username,
+        author_link: url + '/user/' + user.username,
+        author_icon: user.image,
+        title: comment.comment,
+        title_link: url + '/' + page._id,
+        text: body,
+        mrkdwn_in: ['text'],
+      };
+    }
+
     if (user.image) {
     if (user.image) {
       attachment.author_icon = user.image;
       attachment.author_icon = user.image;
     }
     }
@@ -145,8 +159,8 @@ module.exports = function(crowi) {
   };
   };
 
 
   // slack.post = function (channel, message, opts) {
   // slack.post = function (channel, message, opts) {
-  slack.post = (page, user, channel, updateType, previousRevision) => {
-    const messageObj = prepareSlackMessage(page, user, channel, updateType, previousRevision);
+  slack.post = (page, user, channel, updateType, previousRevision, comment) => {
+    const messageObj = prepareSlackMessage(page, user, channel, updateType, previousRevision, comment);
 
 
     return new Promise((resolve, reject) => {
     return new Promise((resolve, reject) => {
       // define callback function for Promise
       // define callback function for Promise