我在ubuntu服务器(14.04.4 LTS)上运行node.js(v5.10.1)。 已安装npm(@ kikinteractive/kik)。 (https://www.npmjs.com/package/@kikinteractive/kik)kik bot服务器接收POST但bot.onTextMessage(...)没有响应
这是我写的server.js文件:
'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);
注:被用于KIK配置网络挂接一个IP地址,服务器侦听端口80
我知道我的KIK配置似乎是正确的,因为从KIK应用结果在我的服务器,这里显示POST请求的文本消息(关键数据已被替换为这个贴出的问题):
{“主机” :“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“}并确认在KIK应用程序收到消息:
bot.send(Bot.Message.text( '什么!'), '用户名');
所以,问题是:如果我的配置似乎是正确的,因为我能够在我的服务器上验证POST,并且kik npm已正确安装,因为我可以将消息从我的服务器发送到kik,为什么bot.incoming()和bot.onTextMessage只是坐在那里呈现我的服务器一个大的,笨的,昂贵的砖块?我错过了什么?
任何帮助,非常感谢。
谢谢。
澄清指定:无论我在onTextMessage处理器都试过了,使用Kik的文档提供的所有例子,任何我在其他地方发现的,没有的server.js示例在我的服务器上按预期工作;但是当我添加console.log(请求。头文件),我可以看到我的服务器确实收到了来自Kik的POST。什么? – tbmac3