I'm starting to integrate Twilio into our service. Is it possible to take an incoming SMS and routed between 2 (possibly more) HTTP URLs based on data from the SMS (From, Message, etc)?
I see this happening with Functions, but I couldn't find an example of a Function that takes an incoming SMS and using data from the SMS, the chooses between multiple HTTP URLs/Endpoints to forward the original SMS without modifying it.
So far I've got the following Twilio function:
exports.handler = function(context, event, callback) {
const response = new Twilio.Response();
let message = event.body
if(PhoneNumberInTestCloud(event.From, context))
{
console.log("data content: " + response)
console.log("forwarded to: " + context.TestCloudURL)
response.appendHeader('Location', context.TestCloudURL);
callback(null, response);
}
else
{
console.log("data content: " + response)
console.log("forwarded to: " + context.MATestCloudURL)
response.appendHeader('Location', context.MATestCloudURL);
callback(null, response);
}
};
function PhoneNumberInTestCloud(phoneNumber, context) {
if(phoneNumber == context.DevPhone1)
{
return true;
}
else if (phoneNumber == context.QAPhone)
{
return true;
}
return false;
}
Note that TestCloudURL, MATestCloudURL, DevPhone1, and QAPhone are Environmental Variables.
Thanks for your help.