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