0
votes

Trying to modify a SMS message (adding a name based on the from phone number) before forwarding the message to a phone using TWIML. The phone no list is small so I will use a switch statement I am guessing in a function. I am not sure how can I wire this together w/o my own server and just using Twilio hosted stuff (TWIML, function, ?)?

1
maybe better asking on their support? - urlreader

1 Answers

1
votes

Twilio developer evangelist here.

You can absolutely modify the message before forwarding it on.

If you're looking to do so without using your own server, then Twilio Functions is your best bet. Twilio Functions gives you access to a Node.js environment in which you can write functions that respond to webhooks.

To forward a message to a number but add a name based on the incoming number, you can do something like this in a function:

contacts = {
  "number": "name"
}

exports.handler = function(context, event, callback) {
  const name = contacts[event.From];
  if (typeof name !== 'undefined') {
    const message = `${name} said: ${event.Body}`;
    const response = new Twilio.twiml.MessagingResponse();
    response.Message({ to: YOUR_NUMBER, from: YOUR_TWILIO_NUMBER }, message);
    callback(null, response);
  } else {
    // handle not having a name in the contacts
  }
}

Check out this quick start on using Twilio Functions for more detail.