UNPKG

@convex-dev/twilio

Version:

Convex component for sending/receiving SMS messages with Twilio.

22 lines 804 B
export const twilioRequest = async function (path, account_sid, auth_token, body, method = "POST") { const url = `https://api.twilio.com/2010-04-01/Accounts/${account_sid}/${path}`; const auth = btoa(`${account_sid}:${auth_token}`); const request = { method, headers: { Authorization: `Basic ${auth}`, "Content-Type": "application/x-www-form-urlencoded", }, }; if (method === "POST") { request["body"] = new URLSearchParams(body); } const response = await fetch(url, request); if (!response.ok) { console.log(response.status); console.log(await response.text()); throw new Error("Failed to send request to Twilio"); } return await response.json(); }; //# sourceMappingURL=utils.js.map