I have created a facebook webhook using node.js to pick messages sent to my account. However, I am unable to receive the test post requests on my server. I thought the problem was with my code, but sending the same json post requests from the Postman platform works perfectly. The server receives the requests. Why don't the facebook test requests get sent to my server.
I have been working on this for a really long time for such a small project that it's embarrassing. Any help would be highly appreciated.
I have tried most of the suggestions on this platform, as well as others, to no avail.
I have tried removing the subscription and validating the callback url over and over, so that's not the problem. The get requests to validate are sent successfully.
I also have both GET and POST methods in my code, and i think i have routed them correctly. Here is the code for my post method in case there is something wrong with it though:
app.post('/webhook', (req, res) => {
console.log(`Received a ${req.method} request for ${req.url}`);
console.log(`Request body: ${JSON.stringify(req.body)}`);
if (!req.body || Object.keys(req.body).length === 0) {
console.log('Received an empty request body');
res.status(400).send('Bad Request: Request body is empty');
return;
}
let body = req.body;
if (body.object === 'page') {
body.entry.forEach(function(entry) {
let webhook_event = entry.messaging[0];
console.log(webhook_event);
});
res.status(200).send('EVENT_RECEIVED');
}
else {
res.sendStatus(404);
}
});
Facebook side also seems to be working fine, and says that the requests have been sent to my server successfully. I am still in development mode and I am only trying to get the test updates sent to my server and not any live production data. After sending the message test requests