Site didn’t respond (WhatsApp Business Platform API)

Hello Dears,
kindly note that im trying to follow the steps to build WhatsApp Business Platform Cloud API, i reached point ( 4. Click Share at the top right to get the Live site URL. Add /webhook at the end of the URL to get your complete callback URL. It will look something like https://<project-name.glitch.me/webhook.) then i stocked the website gave error below:

Site didn’t respond

Something in the code caused it to close the connection before providing a response.
If this is your project please visit us at support.glitch.com for assistance.
https://gwws-whatsapp-business.glitch.me/webhook

Kindly Advise !
Thank you

Hi! We can’t help you because your project seems to have been archived. Can you please check if you can edit the website?
Please note that only the support forum can’t help you if the project is private.
If you want to keep it private (if it is private), please include a piece of code relevant to this case.
Thank you,
Tiago

Hi, Thank you for your reply, actually the project is not private,
This is the link i just thought that the problem from the link so i just update it as below but i did not archived it:

https://gwws-whatsappbusiness.glitch.me/webhook

Also, kindly find code below:

“use strict”;

// Access token for your app
// (copy token from DevX getting started page
// and save it as environment variable into the .env file)
const token = process.env.WHATSAPP_TOKEN;

// Imports dependencies and set up http server
const request = require(“request”),
express = require(“express”),
body_parser = require(“body-parser”),
axios = require(“axios”).default,
app = express().use(body_parser.json()); // creates express http server

// Sets server port and logs message on success
app.listen(process.env.PORT || 1337, () => console.log(“webhook is listening”));

// Accepts POST requests at /webhook endpoint
app.post(“/webhook”, (req, res) => {
// Parse the request body from the POST
let body = req.body;

// Check the Incoming webhook message
console.log(JSON.stringify(req.body, null, 2));

if (req.body.object) {
if (
req.body.entry &&
req.body.entry[0].changes &&
req.body.entry[0].changes[0] &&
req.body.entry[0].changes[0].value.messages &&
req.body.entry[0].changes[0].value.messages[0]
) {
let phone_number_id =
req.body.entry[0].changes[0].value.metadata.phone_number_id;
let from = req.body.entry[0].changes[0].value.messages[0].from; // extract the phone number from the webhook payload
let msg_body = req.body.entry[0].changes[0].value.messages[0].text.body; // extract the message text from the webhook payload
axios({
method: “POST”, // Required, HTTP method, a string, e.g. POST, GET
url:
https://graph.facebook.com/v12.0/” +
phone_number_id +
“/messages?access_token=” +
token,
data: {
messaging_product: “whatsapp”,
to: from,
text: { body: "Ack: " + msg_body },
},
headers: { “Content-Type”: “application/json” },
});
}
res.sendStatus(200);
} else {
// Return a ‘404 Not Found’ if event is not from a WhatsApp API
res.sendStatus(404);
}
});

// Accepts GET requests at the /webhook endpoint. You need this URL to setup webhook initially.

app.get(“/webhook”, (req, res) => {
/**

  • UPDATE YOUR VERIFY TOKEN
    *This will be the Verify Token value when you set up webhook
    **/
    //const verify_token = process.env.VERIFY_TOKEN;
    const verify_token = “hello”;
    // Parse params from the webhook verification request
    let mode = req.query[“hub.mode”];
    let token = req.query[“hub.verify_token”];
    let challenge = req.query[“hub.challenge”];

// Check if a token and mode were sent
if (mode && token) {
// Check the mode and token sent are correct
if (mode === “subscribe” && token === verify_token) {
// Respond with 200 OK and challenge token from the request
console.log(“WEBHOOK_VERIFIED”);
res.status(200).send(challenge);
} else {
// Responds with ‘403 Forbidden’ if verify tokens do not match
res.sendStatus(403);
}
}
});

It’s this thing. It shouldn’t be here.
Replace:

const verify_token = “hello”;

with:

const verify_token = process.env.VERIFY_TOKEN;

and make sure your .env is OK

I’m getting a “Site didn’t respond” error from glitch when I try to open that URL in a browser.

can you try removing code until the http server works? or until there’s so minimal an example that it should be obvious what the problem is

Thank you Tiagorangel2011 for your support, But kindly note that the issue still the same.

@Houssein_Naim Maybe this will help you:

  • Check that your .env file is OK
  • Make sure you have all the necessary credentials
  • Check if your Whatsapp Business account is working
  • Also, try starting your project again from scratch

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.