import axios from 'axios';
export const sendWhatsAppTemplateMessage = async (to: string, templateName: string, languageCode: string, variables: string[]): Promise => {
try {
const url = https://graph.facebook.com/v19.0/${process.env.NUMBER_ID}/messages
;
const data = {
messaging_product: "whatsapp",
to: to,
type: "template",
template: {
name: templateName,
language: {
code: languageCode,
},
components: [
{
type: "body",
parameters: variables.map(variable => ({
type: "text",
text: variable
}))
}
]
}
};
const headers = {
'Content-Type': 'application/json',
'Authorization': Bearer ${process.env.JWT_TOKEN}
,
};
await axios.post(url, data, { headers });
} catch (error) {
console.error("Error al enviar el mensaje de plantilla de WhatsApp:", error);
}
};
Rescato la información envio una plantilla aprobada por meta no funciona necesito ayuda