0

I am running node.js (v5.10.1) on an ubuntu server (14.04.4 LTS). And the npm (@kikinteractive/kik) has been installed. (https://www.npmjs.com/package/@kikinteractive/kik)

Here is the server.js file I have written:

'use strict';

const util = require('util');
const http = require('http');
const Bot  = require('@kikinteractive/kik');

const port = 80;

let bot = new Bot({
    username: 'botnamehere',
    apiKey: 'blablabla-1001-0110-1001-2112blablabla'
});

bot.onTextMessage((message)=>{
    message.reply(message.body);
});


var server = http.createServer(bot.incoming());
server.on('request', function (request, response) {
    bot.incoming();
    // I added this to write the request 
    //   so that I could verify my server was receiving from kik
    console.log(request.method);
    console.log(request.headers);
    console.log(request.url);
    var fs = require('fs');
    fs.writeFile("./logfile.log", JSON.stringify(request.headers), function(err) {
        if(err) {
            return console.log(err);
        }
        console.log("The kik request was saved!");
    }); 

});

server.listen(port);

Note: An IP address was used for the kik configuration webhook, and the server is listening on port 80.

I know that my kik configuration seems to be correct as the text messages from the kik app result in POST requests at my server, shown here (key data has been replaced for this posted question):

{ "host": "ipaddressofhost", "x-kik-signature": "8EEBLA44C3BB9769BLAE56E7E9CBLA2BA4179445", "content-type": "application/json", "x-kik-username": "botname", "x-cloud-trace-context": "272c0f7616d6189bla9540d1e47668f5/5407793903926111947", "content-length": "307", "connection": "Keep-alive", "user-agent": "AppEngine-Google; (+http://code.google.com/appengine; appid: s~bot-dashboard)", "accept-encoding": "gzip,deflate,br" }

And I know that my server can send messages to kik, as I have tested the following and confirmed the message received in the kik app:

bot.send(Bot.Message.text('What!'), 'username');

So the question is: If my configuration seems correct, in that I am able to verify a POST at my server, and the kik npm is installed correctly as I am able to send messages from my server to kik, why is bot.incoming() and bot.onTextMessage just sitting there rendering my server a big, dumb, expensive brick? What am I missing?

Any help is greatly appreciated.

Thank you.

4

3 に答える 3

0

Webhook に IP アドレスを使用すると述べました。その IP がローカルの場合、Kik API はサーバーにメッセージを送信できません。

https://ngrok.com/のようなサービスを使用して、開発中にサーバーを Kik に公開することをお勧めします。端末で実行するだけngrok start 8080で、すべてをローカル マシンの 8080 ポートにリダイレクトする URL を取得できます。

于 2016-04-14T22:08:43.660 に答える
0
let server = http
    .createServer(bot.incoming())
    .listen(process.env.PORT || 8080);

Does this work?

I'm not sure what the exact issue is but if that should definitely work.

于 2016-04-13T15:23:59.720 に答える