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:
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?
If you are aware there are 2 types of setups,
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.
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