const axios = require("axios");
const apiKey = "your_api_key";
async function sendSMS(to, from) {
try {
const response = await axios.post(
"https://api.telnyx.com/v2/messages",
{
from: from,
to: to,
text: "Hello World",
},
{
headers: {
"Authorization": `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
},
);
console.log(`Message sent with ID: ${response.data.data.id}`);
} catch (error) {
console.error(`Failed to send message: ${error.response ? error.response.data : error.message}`);
}
}
sendSMS("+1234567890", "+0987654321");