Search code examples
webhooksfacebook-appsfacebook-messenger

How to add heroku callback URL to Facebook dashboard?


I am really confused about how to get messenger set-up in my facebook dashboard. I have set-up a node.js app on Heroku to communicate with the facebook API and tried to connect to the following callback URL:

https://ancient-dawn-XXXXX.herokuapp.com/webhook/

However I am getting the following error:

The URL couldn't be validated. Callback verification failed with the following errors: HTTP Status Code = 403; HTTP Message = Forbidden

My app's app.js file includes the following code:

var express = require("express");
var request = require("request");
var bodyParser = require("body-parser");

var app = express();
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.listen((process.env.PORT || 5000));

// Server index page
app.get("/", function (req, res) {
  res.send("Deployed!");
});

// Facebook Webhook
// Used for verification
app.get("/webhook/", function (req, res) {
  if (req.query["hub.verify_token"] === "process.env.VERIFICATION_TOKEN") {
    console.log("Verified webhook");
    res.status(200).send(req.query["hub.challenge"]);
  } else {
    console.error("Verification failed. The tokens do not match.");
    res.sendStatus(403);
  }
});

When I try to access the URL https://murmuring-temple-XXXXX.herokuapp.com/webhook/ I also receive a FORBIDDEN response.

What is missing?


Solution

  • You are comparing req.query["hub.verify_token"] to the string "process.env.VERIFICATION_TOKEN" rather than the value process.env.VERIFICATION_TOKEN.

    Also, make sure the value of process.env.VERIFICATION_TOKEN matches the verification token you provided when you set up your webhook.