I'm trying to send a confirmation message to the users using whatsapp could api.
Below is my nodejs code,
app.post("/send-confirmation", async (req, res) => {
const { phoneNo, bookingId, name, tripType, origin, destination, bookedDate, bookedTime, carType, distance, estimate } = req.body;
console.log(phoneNo, bookingId, name, tripType, origin, destination, bookedDate, bookedTime, carType, distance, estimate);
// Prepare the message template with the booking details
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',
},
components: [
{
type: 'body',
parameters: [
{
type: 'text',
text: `Booking ID: ${bookingId}`,
},
{
type: 'text',
text: `Passenger Name: ${name}`,
},
{
type: 'text',
text: `Contact Number: ${phoneNo}`,
},
{
type: 'text',
text: `Journey Type: ${tripType}`,
},
{
type: 'text',
text: `Pickup Location: ${origin}`,
},
{
type: 'text',
text: `Drop-off Location: ${destination}`,
},
{
type: 'text',
text: `Pickup Date and Time: ${bookedDate} ${bookedTime}`,
},
{
type: 'text',
text: `Vehicle Type: ${carType}`,
},
{
type: 'text',
text: `Total Km: ${distance}`,
},
{
type: 'text',
text: `Total Fare: ${estimate} Rs`,
},
],
}
],
},
});
try {
const response = await axios({
method: "POST",
url:
"https://graph.facebook.com/v17.0/" +
'117505268034839' +
"/messages?access_token=" +
token,
data: postData,
headers: { "Content-Type": "application/json" },
});
console.log(response.data); // or do something with the response data
res.sendStatus(200);
} catch (error) {
console.error(error);
res.sendStatus(500);
}
});
My booking_confirmation
is approved by FB. Below is the FB template code
*Booking ID*: {{1}}
*Passenger Name*: {{2}}
*Contact Number*: {{3}}
*Journey Type*: {{4}}
*Pickup Location*: {{5}}
*Drop-off Location*: {{6}}
*Pickup Date and Time*: {{7}}
*Vehicle Type*:{{8}}
*Total Km*: {{9}}
*Total Fare*: {{10}} Rs
Once the API is called, I'm getting the below error
AxiosError: Request failed with status code 400 code: 'ERR_BAD_REQUEST'
Message is not getting delivered, What I'm doing wrong here ? Plz help