Sotaro KARASAWA 10 лет назад
Родитель
Сommit
1fa7206f16
5 измененных файлов с 63 добавлено и 0 удалено
  1. 58 0
      lib/routes/admin.js
  2. 3 0
      lib/routes/index.js
  3. 0 0
      lib/views/admin/slackauth.html
  4. 1 0
      lib/views/admin/slackauthstart.html
  5. 1 0
      package.json

+ 58 - 0
lib/routes/admin.js

@@ -193,6 +193,64 @@ module.exports = function(crowi, app) {
     });
     });
   };
   };
 
 
+  actions.slackauthstart = function(req, res) {
+    var Botkit = require('botkit');
+    var controller = Botkit.slackbot();
+    controller.configureSlackApp({
+      clientId: '',
+      clientSecret: '',
+      redirectUri: 'http://localhost:3000/slackauth',
+      scopes: ['chat:write:bot']
+    });
+
+    return res.render('admin/slackauthstart', {
+      url: controller.getAuthorizeURL(),
+    });
+  };
+
+  actions.slackauth = function(req, res) {
+    debug(req.query.code);
+    var Botkit = require('botkit');
+    var controller = Botkit.slackbot({debug: true});
+    controller.configureSlackApp({
+      clientId: '',
+      clientSecret: '',
+      redirectUri: 'http://localhost:3000/slackauth',
+      scopes: ['chat:write:bot']
+    });
+
+    var bot = controller.spawn();
+    bot.api.oauth.access({code: req.query.code}, function (err, response) {
+      debug(err, response);
+    });
+    //
+    // access_token: '',
+    // scope: 'identify,chat:write:bot',
+    // team_name: '',
+    // team_id: '' }
+    //var bot = controller.spawn({token: ''});
+    //bot.api.chat.postMessage({
+    //  channel: '#xtest',
+    //  username: 'Crowi',
+    //  text: '/hoge/fuga/piyo is updated.',
+    //  attachments: [
+    //    {
+    //      color: '#263a3c',
+    //      author_name: '@sotarok',
+    //      author_link: 'http://localhost:3000/user/sotarok',
+    //      author_icon: 'https://crowi-strk-dev.s3.amazonaws.com/user/56c9dbf860ab5bc62647d84a.png',
+    //      title: "/hoge/fuga/piyo",
+    //      title_link: "http://localhost:3000/hoge/fuga/piyo",
+    //      text: '*# sotarok*\n\nshellに続き、初心者が頑張って理解していくノート的記事です。\nGitHubが常識と化してきた今日この頃、チャレンジしてみたものの、そもそもGitってなんなのかわからないと使いこなせない、っていうか挫折すると思います。私はしました。\nなので、起き上がってまずGitについて本当に一から理解を試みました。\n\n***\n  \n*## Gitって何?*\n\nGitとは、**[バージョン管理システム](https://ja.wikipedia.org/wiki/%E3%83%90%E3%83%BC%E3%82%B8%E3%83%A7%E3%83%B3%E7%AE%A1%E7%90%86%E3%82%B7%E3%82%B9%E3%83%86%E3%83%A0)**のひとつです。\n        バージョン管理‥? :open_mouth: \nバージョンすなわち変更履歴の管理です。\n\n例えばなにかファイルの書き換えをするとき、元データを失わないためにどのような工夫をするでしょうか。ほとんどの場合、保存用にコピーを作成しておくというのが定番の方法だと思います。\nですが、誰しもこんな経験があるのでは。\n\n - 元データの保管が面倒\n  - \'meeting_3月.txt\'、\'meeting_最新.txt\'といった名前のデータが複数できてしまう\n   - チームで触っていて、最後に書き換えたのが誰なのかわからない\n    - 先輩も同時に編集していたのに、知らずにタッチの差で上書きしてしまった\n     - 書き換えたよ~と言われても(あるいは自分でも)、どこを換えたかわからない\n      - 何回か前の更新状態の方が良かった、戻したい…\n      \n      ある~~~!!\n      こんな事態を解消してくれるのが**Gitというバージョン管理システム**です。',
+    //      mrkdwn_in: ["text"],
+    //    },
+    //  ],
+    //});
+
+    //var code = req.query.);
+    res.render('admin/slackauth', {});
+  };
+
   actions.api = {};
   actions.api = {};
   actions.api.appSetting = function(req, res) {
   actions.api.appSetting = function(req, res) {
     var form = req.form.settingForm;
     var form = req.form.settingForm;

+ 3 - 0
lib/routes/index.js

@@ -52,6 +52,9 @@ module.exports = function(crowi, app) {
   app.post('/admin/user/:id/remove'     , loginRequired(crowi, app) , middleware.adminRequired() , admin.user.remove);
   app.post('/admin/user/:id/remove'     , loginRequired(crowi, app) , middleware.adminRequired() , admin.user.remove);
   app.post('/admin/user/:id/removeCompletely' , loginRequired(crowi, app) , middleware.adminRequired() , admin.user.removeCompletely);
   app.post('/admin/user/:id/removeCompletely' , loginRequired(crowi, app) , middleware.adminRequired() , admin.user.removeCompletely);
 
 
+  app.get('/slackauthstart' , loginRequired(crowi, app) , middleware.adminRequired() , admin.slackauthstart);
+  app.get('/slackauth' , loginRequired(crowi, app) , middleware.adminRequired() , admin.slackauth);
+
   app.get('/me'                       , loginRequired(crowi, app) , me.index);
   app.get('/me'                       , loginRequired(crowi, app) , me.index);
   app.get('/me/password'              , loginRequired(crowi, app) , me.password);
   app.get('/me/password'              , loginRequired(crowi, app) , me.password);
   app.get('/me/apiToken'              , loginRequired(crowi, app) , me.apiToken);
   app.get('/me/apiToken'              , loginRequired(crowi, app) , me.apiToken);

+ 0 - 0
lib/views/admin/slackauth.html


+ 1 - 0
lib/views/admin/slackauthstart.html

@@ -0,0 +1 @@
+<a href="{{ url }}">auth</a>

+ 1 - 0
package.json

@@ -34,6 +34,7 @@
     "bluebird": "~3.0.5",
     "bluebird": "~3.0.5",
     "body-parser": "~1.14.1",
     "body-parser": "~1.14.1",
     "bootstrap-sass": "~3.3.6",
     "bootstrap-sass": "~3.3.6",
+    "botkit": "0.0.8",
     "browserify": "~12.0.1",
     "browserify": "~12.0.1",
     "cli": "~0.6.0",
     "cli": "~0.6.0",
     "connect-flash": "~0.1.1",
     "connect-flash": "~0.1.1",