0
我正在试图搭建流星的Facebook Messenger机器人。安装程序包括查找验证令牌,并使用验证GET请求中发送的质询进行响应。在Facebook的(非流星)示例应用程序,下面的代码用于:流星Facebook Messenger Bot webhook
app.get('/webhook', function(req, res) {
if (req.query['hub.mode'] === 'subscribe' &&
req.query['hub.verify_token'] === VALIDATION_TOKEN) {
console.log("Validating webhook");
res.status(200).send(req.query['hub.challenge']);
} else {
console.error("Failed validation. Make sure the validation tokens match.");
res.sendStatus(403);
}
});
当我尝试使用以下的(流星)码,以实现相同的功能,收到以下的误差。
var bodyParser = Meteor.npmRequire('body-parser');
// Add two middleware calls. The first attempting to parse the request body as
// JSON data and the second as URL encoded data.
Picker.middleware(bodyParser.json());
Picker.middleware(bodyParser.urlencoded({ extended: false }));
// ------------------------------------------------------------
// HANDLE THE INITIAL HANDSHAKE WITH FACEBOOK VIA A GET REQUEST
// ------------------------------------------------------------
var getRoutes = Picker.filter(function(req, res) {
// you can write any logic you want.
// but this callback does not run inside a fiber
// at the end, you must return either true or false
return req.method == "GET";
});
getRoutes.route('/webhook', function(params, req, res, next) {
if (params.query['hub.verify_token'] === '78750') {
console.log(params.query['hub.verify_token']);
// res.end();
res.end(params.query['hub.challenge']);
}
}); // end getRoutes
错误:
The URL couldn't be validated. Response does not match challenge, expected value = '1127215706', received='<!DOCTYPE html> <htm...
也许这个问题是由于它是客户端,而不是在服务器上运行?如果是这样,我应该在哪里放置这些代码才能在服务器上运行?
另外,我的浏览器控制台有以下错误12次:
Mixed Content: The page at 'https://pfbe.meteorapp.com/' was loaded over HTTPS, but requested an insecure font 'http://themes.googleusercontent.com/static/fonts/inconsolata/v5/BjAYBlHtW3CJxDcjzrnZCIbN6UDyHWBl620a-IRfuBk.woff'. This request has been blocked; the content must be served over HTTPS.
我能做些什么来解决这个问题?
你是什么意思_ _“它在客户端,而不是在服务器上运行”? Facebook发送请求,所以它是这里的客户端,而你的_server_是它发送给的客户端。 //'received ='<!DOCTYPE html> ...'非常明显 - 您的端点会返回完整的HTML文档(无论是默认模板还是错误文档,都不能从该片段中获知),而不仅仅是挑战它应有的价值。 – CBroe