我试图在Facebook上制作一些bot messenger,但是当我尝试设置webhook时,它总是失败,有什么建议吗?
这是我的代码,我在设置中做错了什么?
const express = require('express');
const bodyParser = require('body-parser');
const request = require('request');
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
const APP_SECRET = "";
const VALID_TOKEN = "semarangbot";
const SERVER_URL = "https://b915e9f8.ngrok.io";
const ACCESS_TOKEN = "";
const server = app.listen(process.env.PORT || 5000, () => {
console.log('Express server listening on port %d in %s mode', server.address().port, app.settings.env);
})
app.get('/', (req, res) => {
console.log('Server Ok!');
res.sendStatus(200);
});
app.get('/webhook', (req, res) => {
if (req.query['hub.mode'] && req.query['hub.verify_token'] === VALID_TOKEN) {
res.status(200).send(req.query['hub.challenge']);
} else {
res.status(403).end();
}
});
答案 0 :(得分:1)
您需要将/webhook
添加到'回拨网址中的网址'领域。这是您已设置验证的端点。现在,您告诉Messenger平台致电/
进行验证,该验证仅返回200OK
。