Sotaro KARASAWA 8 лет назад
Родитель
Сommit
2636931683
1 измененных файлов с 11 добавлено и 6 удалено
  1. 11 6
      lib/util/slack.js

+ 11 - 6
lib/util/slack.js

@@ -11,10 +11,13 @@ module.exports = function(crowi) {
     Config = crowi.model('Config'),
     SlackWebClient = require('@slack/client').WebClient,
     sprintf = require('sprintf'),
+    pageEvent = crowi.event('page'),
     slack = {};
 
   slack.client = undefined;
 
+  // get client with access token,
+  // if access token is not fetched, return undefiend
   slack.getClient = function() {
     // alreay created
     if (slack.client) {
@@ -32,7 +35,7 @@ module.exports = function(crowi) {
     return slack.client;
   };
 
-  // hmmm
+  // this is called to generate redirect_uri
   slack.getSlackAuthCallbackUrl = function()
   {
     var config = crowi.getConfig();
@@ -41,6 +44,7 @@ module.exports = function(crowi) {
     return (config.crowi['app:url'] || '') + '/admin/notification/slackAuth';
   }
 
+  // this is called to get the url for oauth screen
   slack.getAuthorizeURL = function () {
     const config = crowi.getConfig();
     if (Config.hasSlackConfig(config)) {
@@ -54,6 +58,7 @@ module.exports = function(crowi) {
     }
   }
 
+  // this is called to get access token with code (oauth process)
   slack.getOauthAccessToken = function(code) {
 
     const client = new SlackWebClient();
@@ -161,23 +166,23 @@ module.exports = function(crowi) {
     var message = {
       channel: '#' + channel,
       username: 'Crowi',
-      text: this.getSlackMessageText(page.path, user, updateType),
+      text: this.getSlackMessageText(page, user, updateType),
       attachments: [attachment],
     };
 
     return message;
   };
 
-  slack.getSlackMessageText = function(path, user, updateType) {
+  slack.getSlackMessageText = function(page, user, updateType) {
     let text;
     const config = crowi.getConfig();
     const url = config.crowi['app:url'] || '';
 
-    const pageUrl = `<${url}${path}|${path}>`;
+    const pageLink = `<${url}/${page._id}|${page.path}>`;
     if (updateType == 'create') {
-      text = sprintf(':white_check_mark: %s created a new page! %s', user.username, pageUrl);
+      text = sprintf(':white_check_mark: %s created a new page! %s', user.username, pageLink);
     } else {
-      text = sprintf(':up: %s updated %s', user.username, pageUrl);
+      text = sprintf(':up: %s updated %s', user.username, pageLink);
     }
 
     return text;