i tried to make some bot messenger on facebook, but when i try to setup the webhook it is always failed, any suggestion?
and here is my code, what did i do wrong in my setup?
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();
}
});
You need to add /webhook
to the URL in the 'Callback URL' field. That's the endpoint you have setup for verification. Right now, you are telling Messenger Platform to call /
for verification which is only returning a 200OK
.