0

I have a nodejs bot and a method which helps me send client a request for their location using a special Meta Whatsapp body as prescribed in the section Location Request Messages of Sending Interactive Messages Doc:

Doc prescription below:

{
    "type": "location_request_message",
    "body": {
        "type": "text",
        "text": "<TEXT>"
    },
    "action": {
        "name": "send_location" 
    }
}

Wrapping component of the code above according to the doc (doc says you have to add the above code inside of the interactive property of the blow code):

{
    "recipient_type": "individual",
    "to" : "whatsapp-id", // WhatsApp ID of your recipient
    "type": "interactive",
    "interactive":{
        // Your interactive object  
    }
}

My own code is below (I combined the 2 above codes in one as prescribed by the doc):

  const body = {
      recipient_type: "individual",
      to: "mobile_number", // WhatsApp ID of your recipient
      type: "interactive",
      interactive:{
         // Your interactive object  
         type: "location_request_message",
         body: {
             type: "text",
             text: "Finally"
             // text: "Good day"
         },
         action: {
             name: "send_location" 
         }
      }
  }

And i send it with axios with my promise:

return new Promise((next) => {
    var headers = {
        "Content-Type": "application/json",
        Authorization: `Bearer ${token}`,
    };

    AxiosService.post(
      `https://graph.facebook.com/${VERSION}/${JC_PHONE_ID}/messages`,
       body,
       headers
    )
    .then((response) => {
        // console.log("THIS RESPONSE IS REALLY BIG: ", response)
        if (response.status == 200) {
            console.log(response.status)
            next({ success: true, status: 200 });
        } else {
            console.log(response.status)
            console.log("Heehehehe....")
            next({ success: false, status: 400 });
        }
    })
    .catch((err) => {
        next({ success: false, status: 400 });
    });
});

Finally sending a request for it using my webhook link:

https://0852-154-72-160-109.ngrok-free.app/webhook/

At the end i get a 400 error:

I am pretty sure it is because facebook does not accept the way i set the body.

Can anyone help me on how to set the above json body properly?

TylerH
  • 20,799
  • 66
  • 75
  • 101
vially
  • 187
  • 1
  • 10
  • have you tried Is it working in Postman? – turivishal May 29 '23 at 05:39
  • It is actually on postman i try all my requests before anywhere else. The rest of the json bodies on that documentation work well on postman i receive a response as message on whatsapp...but this particular one is a not working. I do not know how exactly i have to arrange it for it to work. And that is why i am putting it out there for anyone to help. – vially May 29 '23 at 06:24
  • This is only available for on-premises API, make sure you are using that. – turivishal May 29 '23 at 06:36
  • I am not sure i get the full understanding of what you said...kindly explain further please. – vially May 29 '23 at 11:24
  • @vially did you get a way around ? – Shei Jul 24 '23 at 11:28

1 Answers1

1

If you are aware there are 2 types of setups,

  • cloud API

The Cloud API allows you to send and receive messages to and from customers using cloud-based servers owned by Meta. Since we host the API, you avoid the cost of hosting your own servers and can easily scale your business messaging.

  • on-premises API

The On-Premises API allow you to send and receive messages to and from customers using your own servers.

You can read more differences here.

As I can see your request goes to the cloud API's host:

https://graph.facebook.com/${VERSION}/${JC_PHONE_ID}/messages

And you are checking in on-premises API documentation:

Location Request Messages of Sending Interactive Messages Doc

You need to refer to the cloud API documentation for the interactive type message, and there is no mention of location type in interactive, it is just supported in on-premises API setup, https://developers.facebook.com/docs/whatsapp/cloud-api/guides/send-messages#interactive-messages https://developers.facebook.com/docs/whatsapp/cloud-api/reference/messages#interactive-object

turivishal
  • 34,368
  • 7
  • 36
  • 59
  • 1
    The insight you shared are totally valid. I will surely look into the On-Premise Option, deeper. Many Thanks – vially May 31 '23 at 14:03