Reputation: 1
Below is my Node Js code,
app.post("/send-confirmation", async (req, res) => {
const { phoneNo, bookingId, name, tripType, origin, destination, bookedDate, bookedTime, carType, distance, estimate } = req.body;
const postData = JSON.stringify({
messaging_product: 'whatsapp',
recipient_type: 'individual',
to: [`91${phoneNo}`], // Phone number of the customer
type: 'template',
template: {
name: 'booking_confirmation',
language: {
code: 'en_US',
},
components: [
{
type: 'header',
parameters: [
{
type: 'image',
image: {
link: 'https://www.examle.com/logo-1.png',
},
},
],
},
{
type: 'body',
parameters: [
{
type: 'text',
text: `${bookingId}`,
},
{
type: 'text',
text: `${name}`,
},
{
type: 'text',
text: `${phoneNo}`,
},
{
type: 'text',
text: `${tripType}`,
},
{
type: 'text',
text: `${origin}`,
},
{
type: 'text',
text: `${destination}`,
},
{
type: 'text',
text: `${bookedDate} ${bookedTime}`,
},
{
type: 'text',
text: `${carType}`,
},
{
type: 'text',
text: `${distance}`,
},
{
type: 'text',
text: `${estimate}`,
},
],
}
],
},
});
try {
const response = await axios({
method: "POST",
url:
"https://graph.facebook.com/v17.0/117505268034839/messages",
data: postData,
headers: {
"Content-Type": "application/json",
'Authorization': `Bearer ${token}`
},
});
console.log(response.data); // or do something with the response data
res.send(response.data);
} catch (error) {
console.error(error);
res.send(error);
}
});
I get this as a response from Meta after the request is made,
{
"messaging_product": "whatsapp",
"contacts": [
{
"input": "[\"917299568568\"]",
"wa_id": "917299568568"
}
],
"messages": [
{
"id": "wamid.HBgMOTE3Mjk5NTY4NTY4FQIAERgSM0MzMkE1NUVENTA2QTNCRUNBAA=="
}
]
}
But, I'm not sure why the message is not getting delivered. Please help what I'm missing here
Upvotes: 0
Views: 87
Reputation: 1
This is very funny, but when you are using the api in development mode, first you have to send a message to the test number, otherwise you will not be able to receive messages
Check this post for a better explanation
Upvotes: 0