Sotaro KARASAWA 8 سال پیش
والد
کامیت
7ceb9d6459
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'),
     Config = crowi.model('Config'),
     SlackWebClient = require('@slack/client').WebClient,
     SlackWebClient = require('@slack/client').WebClient,
     sprintf = require('sprintf'),
     sprintf = require('sprintf'),
+    pageEvent = crowi.event('page'),
     slack = {};
     slack = {};
 
 
   slack.client = undefined;
   slack.client = undefined;
 
 
+  // get client with access token,
+  // if access token is not fetched, return undefiend
   slack.getClient = function() {
   slack.getClient = function() {
     // alreay created
     // alreay created
     if (slack.client) {
     if (slack.client) {
@@ -32,7 +35,7 @@ module.exports = function(crowi) {
     return slack.client;
     return slack.client;
   };
   };
 
 
-  // hmmm
+  // this is called to generate redirect_uri
   slack.getSlackAuthCallbackUrl = function()
   slack.getSlackAuthCallbackUrl = function()
   {
   {
     var config = crowi.getConfig();
     var config = crowi.getConfig();
@@ -41,6 +44,7 @@ module.exports = function(crowi) {
     return (config.crowi['app:url'] || '') + '/admin/notification/slackAuth';
     return (config.crowi['app:url'] || '') + '/admin/notification/slackAuth';
   }
   }
 
 
+  // this is called to get the url for oauth screen
   slack.getAuthorizeURL = function () {
   slack.getAuthorizeURL = function () {
     const config = crowi.getConfig();
     const config = crowi.getConfig();
     if (Config.hasSlackConfig(config)) {
     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) {
   slack.getOauthAccessToken = function(code) {
 
 
     const client = new SlackWebClient();
     const client = new SlackWebClient();
@@ -161,23 +166,23 @@ module.exports = function(crowi) {
     var message = {
     var message = {
       channel: '#' + channel,
       channel: '#' + channel,
       username: 'Crowi',
       username: 'Crowi',
-      text: this.getSlackMessageText(page.path, user, updateType),
+      text: this.getSlackMessageText(page, user, updateType),
       attachments: [attachment],
       attachments: [attachment],
     };
     };
 
 
     return message;
     return message;
   };
   };
 
 
-  slack.getSlackMessageText = function(path, user, updateType) {
+  slack.getSlackMessageText = function(page, user, updateType) {
     let text;
     let text;
     const config = crowi.getConfig();
     const config = crowi.getConfig();
     const url = config.crowi['app:url'] || '';
     const url = config.crowi['app:url'] || '';
 
 
-    const pageUrl = `<${url}${path}|${path}>`;
+    const pageLink = `<${url}/${page._id}|${page.path}>`;
     if (updateType == 'create') {
     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 {
     } else {
-      text = sprintf(':up: %s updated %s', user.username, pageUrl);
+      text = sprintf(':up: %s updated %s', user.username, pageLink);
     }
     }
 
 
     return text;
     return text;