我正在一个ubuntu服务器(14.04.4LTS)上运行node.js (v5.10.1)。国家预防机制(@kikinteractive/kik)已经安装。(https://www.npmjs.com/package/@kikinteractive/kik)
下面是我编写的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配置webhook使用了一个IP地址,服务器正在监听端口80。
我知道我的kik配置似乎是正确的,因为kik应用程序的文本消息在我的服务器上产生了POST请求,如下所示(这个发布的问题已经替换了关键数据):
{“主机”:"ipaddressofhost",“x签名”:“8EEBLA44C3B9769BLAE56E7E9CBLA2BA4179445”、“内容-类型”:"application/json“、”x username“:"botname”、“x-cloud-trace”:"272c0f7616d6189bla9540d1e47668f5/5407793903926111947",“内容-长度”:"307“、”连接“:”保持-活动“、”用户-代理“:"AppEngine-Google;(+http://code.google.com/appengine;appid: s~bot-仪表板)“,”接受-编码“:"gzip,deflate,br”}
我知道我的服务器可以向kik发送消息,因为我已经测试了以下内容并确认了在kik应用程序中收到的消息:
Bot.send(Bot.Message.text(‘什么!’),‘用户名’;
所以问题是:如果我的配置看起来是正确的,因为我能够在我的服务器上验证一个帖子,并且kik安装正确,因为我能够从我的服务器发送消息给kik,为什么bot.incoming()和bot.onTextMessage就坐在那里让我的服务器变成了一个巨大的、愚蠢的、昂贵的砖块?我遗漏了什么?
任何帮助都是非常感谢的。
谢谢。
发布于 2016-04-15 14:34:10
检查你是否正确地设置了你的网钩。在您的片段中,您没有指定incomingPath选项,因此它将默认为/incoming,因此请确保将webhook设置为http://1.2.3.5:80/incoming。所有对另一条路径的请求都将被删除。
否则,可以通过以下方式指定
let bot = new Bot({
username: '...',
apiKey: '...',
incomingPath: '/yourincomingpath'
});https://stackoverflow.com/questions/36587692
复制相似问题