A Twiml with the following content:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial>
<Number
statusCallbackEvent="answered"
statusCallback="https://crimson-hawk-9615.twil.io/update-status"
statusCallbackMethod="POST"
>
(786) 528-8304
(785) 528-8303
(784) 528-8302
</Number>
</Dial>
</Response>
And two functions:
One for the redirect SMS:
exports.handler = function(context, event, callback) {
const twiml = new Twilio.twiml.MessagingResponse();
twiml.message("At this time, MLH is only able to receive calls on this number. Please try calling the number or emailing [email protected]");
callback(null, twiml);
};
And another for updating the other numbers that are also on call for one specific incident response number:
exports.handler = function(context, event, callback) {
const attendant = event.To;
const twilioNumber = event.ForwardedFrom
const caller = event.Caller
const phoneNumbers = [
'+17865288304',
'+17565288303',
'+17465288302',
]
const filteredNumbers = phoneNumbers.filter((phoneNumber) => {
return !attendant.endsWith(phoneNumber)
});
const twilioClient = context.getTwilioClient();
filteredNumbers.forEach((phoneNumber) => {
twilioClient.messages.create({
from: twilioNumber,
to: phoneNumber,
body: `Call from ${caller} answered by ${attendant}`,
}, function(err, result) {
callback();
});
})
};