Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
2
Help us understand the problem. What is going on with this article?
@chilitreat

Hubot+Heroku+node.js+雑談API

More than 3 years have passed since last update.

完全にメモ

nodejs2週間目の人が書きました.動作保証しません.

Coffeescriptが書けなかった

環境

Hubot
node.js 6.9.~
Heroku
Docomo雑談API

ソース

app.js
var request = require('request');
var apiURL = 'https://api.apigw.smt.docomo.ne.jp/dialogue/v1/dialogue?APIKEY=';
var apiKEY = 環境変数にしよう;
var context;

module.exports = function (robot) {
    //なんでもいい時の正規表現
    robot.hear(/(.*)$/i, function(msg) {

        var status = {
            //自分が打ったメッセージを正規表現から持ってくる
            "utt": msg.match[1],
            "context": context,
            "mode": "dialog"
        };

        const options = {
            url: apiURL + apiKEY,
            headers: {
                'Content-Type': 'application/json; charset=UTF-8'
            },
            body: status,
            json: true
        }

        request.post(options, function(err, res, data) {
            //前の会話から続けて会話する時に前のメッセージのコンテクストを入れておく
            context = data.context;
            //第3引数のuttにメッセージが入ってる
            msg.send(data.utt);
        });
    })
};

動作

スクリーンショット 2017-01-28 12.03.35.png

詰まったところ

herokuにプッシュする時,package.jsonのdependenceにrequestモジュールを書かないと動かない.
npm i --save大事

2
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
chilitreat
GitHub: https://github.com/chilitreat
iwate-pu
岩手県滝沢市にある公立大学です。Qiitaではソフトウェア情報学部生や出身の人が多いです。

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
2
Help us understand the problem. What is going on with this article?