SMS integration with Twilio
Last updated
Was this helpful?
Was this helpful?
exports.handler = async function (context, event, callback) {
const client = context.getTwilioClient();
// Your mobile number and Twilio phone number
const yourMobileNumber = '+1234567890'; // Replace with your mobile number
const twilioNumber = '+1987654321'; // Replace with your Twilio number
try {
// Log the incoming webhook data
console.log('Received webhook:', event);
// Forward the message to your mobile number
const message = await client.messages.create({
body: `IoT Alert: ${event.text || 'No message received'}`,
from: twilioNumber,
to: yourMobileNumber,
});
console.log(`Message sent: ${message.sid}`);
callback(null, 'Message forwarded successfully!');
} catch (error) {
console.error('Error forwarding message:', error);
callback(error);
}
}; const yourMobileNumber = '+972542205056'; // Replace with your mobile number const twilioNumber = '+12405234667'; // Replace with your Twilio number