-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsms.js
35 lines (32 loc) · 976 Bytes
/
sms.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function sendSMS(message) {
// URL for Twilio SMS API
const apiUrl =
"https://api.twilio.com/2010-04-01/Accounts/AC64a6c99ef0352b5944d417f4dafb3513/Messages.json";
// SMS data
const smsData = {
To: config.callTo, //Duncan
//To: "+14036148363", // John
From: "+19496823519",
Body: message,
};
// Create a form-urlencoded string from the SMS data
const formData = new URLSearchParams(smsData).toString();
// Make the Twilio API request using fetch
fetch(apiUrl, {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Authorization: `Basic ${btoa(
`${config.accountSid}:${config.authToken}`
)}`, // Base64 encoded credentials
},
body: formData,
})
.then((response) => response.json())
.then((data) => {
console.log("Twilio SMS sent successfully:", data);
})
.catch((error) => {
console.error("Error sending Twilio SMS:", error);
});
}