//native
type Brevo = {
apiKey: string;
};
/**
* Send a WhatsApp message
* This endpoint is used to send a WhatsApp message. (**The first message you send using the API must contain a Template ID. You must create a template on WhatsApp on the Brevo platform to fetch the Template ID.**)
*/
export async function main(
auth: Brevo,
body:
| {
templateId: number;
senderNumber: string;
params?: {};
contactNumbers: string[];
}
| { senderNumber: string; text: string; contactNumbers: string[] },
) {
const url = new URL(`https://api.brevo.com/v3/whatsapp/sendMessage`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
"api-key": auth.apiKey,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 428 days ago