LoginSignup
11
12

More than 5 years have passed since last update.

ユーザーローカルの人工知能Bot APIを使ってみた

Last updated at Posted at 2016-06-20

ユーザーローカルが提供を開始した人工知能Bot APIでちょっと使ってみました。
http://ai.userlocal.jp/

Facebook MessengerBot
Nodejs

Messengerから入力された文字列を言われた通りエンコードして、投げて、帰って来た結果を表示するだけという全くひねりのないBotをつくってみました。

パラメータは下記の通り

Screen Shot 2016-06-20 at 4.25.28 PM.png

Demoビデオ

作りかけの Botのコードを部分的に持ってきたので、アレですが。
一応、載せておきます。

FacebookのBotの作り方についてはこちらに詳しい説明があります。
http://qiita.com/pochi-sato/items/f3f5598e36c1fa92d840


router.post('/', function (req, res, next) {
    var messaging_events = req.body.entry[0].messaging,
        replayMessages = [];
    var baseURL = "";
    for (i = 0; i < messaging_events.length; i++) {
        event = req.body.entry[0].messaging[i];
        sender = event.sender.id;
        if (event.message && event.message.text) {
            var typedCommand = event.message.text;
            console.log("typed: ", typedCommand);
            var msg = encodeURIComponent(typedCommand);
            baseURL = "https://chatbot-api.userlocal.jp/api/chat?message="+msg+"&key="+aiKey;
            heyAI(baseURL);
        }
    }
    res.sendStatus(200);
});

function heyAI(url) {
    console.log("heyAI function started!");
    console.log("url",url);
    var options = {
        uri: url,
        gzip: false,
        json: true
    };

    request(options, function (err, response, body) {
        if (err || response.statusCode != 200) {
            console.log("Error/エラーですよ", err);
            return;
        }
        var items = body;
        var apiStatus = items.status;
        var text ="";
        text = items.result;
        text = "Something wrong man!!!!";
        sendTextMessage(sender, text.substring(0,320));
    });
}

二期の募集も始まったみたいです。
http://ai.userlocal.jp/#download

11
12
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
11
12