8
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

slackからQiitaAPI経由でQiita投稿するhubot-script

Last updated at Posted at 2014-12-31

初めに

Qiita:Teamを使うほどじゃないけどQiitaにドキュメントを残したいって需要が小さなチームにはあると思います。
今回は普段のミーティングの議事録をSlackで書いて、Qiitaに投稿するHubotスクリプトを書いてみました。

手前味噌ですが、QiitaAPIでNode.jsからの投稿はこちらを参考にしましょう。
http://qiita.com/n0bisuke/items/336be188fb37b69f6112

準備

Qiita_TOKENという環境変数にアクセストークンをセットしておきます。

herokuの場合は

$ heroku config:add QIITA_TOKEN=**************

で設定できます。

ソースコード

// Description:
//   Messing around with the qiita API.
// Commands:
//   hubot qiji-post 'contents'  - Return post title and so on.

var moment = require('moment');
var m = moment();
var Qiita = require('qiita-js');
var TOKEN = process.env.QIITA_TOKEN;

var options = {
    "body": "",
    "coediting": false,
    "gist": false,
    "private": true,
    "tags": [
        {
            "name": "議事録"
        }
    ],
    "title": "",
    "tweet": false
};

//コマンド実行
module.exports = function(robot) {
    robot.respond(/qiji-post (.+)$/i, function(msg){
        //引数チェック
        if(!msg.match[1]) msg.send('?! 引数が足りません');
        options.title = '議事録' + m.format("YYYY年MM月DD日 HH:mm:ss");
        options.body = msg.match[1];
        Qiita.Resources.Item.create_item(options).then(function(res){
            var output = res.title + 'を投稿しました。' + res.url;
            return msg.send(output);
        });
    });
};

実行

こんなイメージです。

アカウントはチームで一つBOT用に作成しておき、アクセストークンなどはチーム共有にするイメージです。

議事録といいつつ、slackからは記事作成だけして、詳細はコメント欄でやるのがいいかなと思ってます。

8
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?