Search code examples
node.jstwiliotwilio-twimltwilio-functionstwilio-programmable-voice

how to send sms from within Twilio programmable voice function


I have a Twilio function which executes whenever someone calls a certain number. I'm trying to have the function send an sms. It's not working, but I'm not getting any error. Any help debugging would be great.

exports.handler = function(context, event, callback) {
  let response = new Twilio.twiml.MessagingResponse();
  response.message({
    to: '+11234567890',
  }, 'new sms from testing');
};

Additionally, If you could let me know how to access the incoming phone number within this function, I would greatly appreciate it. Thanks in advance for any suggestions or insights.


Solution

  • You will not be able to send a messaging response to a voice event, you'll need to create a messaging client and send separately. See docs here: https://www.twilio.com/docs/sms/tutorials/how-to-send-sms-messages-node-js .

    For incoming phone numbers, that is included in the event object. It should be event.From, but you can log the event object to get all the parameters. They should follow the Call object schema: https://www.twilio.com/docs/voice/api/call