0

I have a studio flow that I am attempting to handle multiple different languages. I have a widget that starts the call and then passes it over to my function. However, after making the call and moving to the function, the call instantly ends. Am I doing something incorrect? From what I understand, I can send the call to a function to continue it. Is something wrong with my function? See my function code below.


exports.handler = function(context, event, callback) {
    let twiml = new Twilio.twiml.VoiceResponse();
  const gatherOptions = { Numdigit:"1", Timeout:"5"};
  let sayOptions = { Voice:"Alice", Language: event.Language };

  if(!event.Retries){
    event.Retries = 0;
  }
  console.log(event.Language);
  console.log(event.Body);
  if (event.Digits) {
    if(event.Digits === '9' && event.Retries < 3) {
      event.Retries += 1;
      twiml.gather(gatherOptions).say(sayOptions, event.Body);
    } else if(event.Digits === '3' || event.Digits === '5'){
      return callback(null, twiml);
    }else {
      twiml.say("sorry, I didnt get that.");
      event.Digits = '9';
    }
  } else {
    twiml.gather(gatherOptions).say(sayOptions, event.Body);
  }
  callback(null, twiml);
};

Nemean
  • 21
  • 2
  • Hi Nemean, welcome to SO! Are there any error messages in the [Twilio Debugger](https://www.twilio.com/console/debugger) when executing this? What are you trying to do with this function? – yvesonline Jan 27 '21 at 17:42
  • There were a few errors (in the options) and i have cleared them up and started getting some voice. now I am attempting to get back the response. I am attempting to use a function to be able to do the following: 1. Allow for multiple languages with only 1 widget 2. Gather and send responses back to my studio flow. (9 repeats the message, 3 or 5 are accepted answers, anything else is a repeat) – Nemean Jan 27 '21 at 20:39

1 Answers1

0

Outside of your Twilio Function code, anytime you jump out of Studio and return TwiML and then want to return to the Studio flow, you must use the TwiML Redirect Widget (which you can use to call the Twilio Function).

Your gatherOptions keys should be camelCase (i.e. numDigits, timeout).

This may be useful to carry state across Functions.

How to Share Information Between Your Applications

Alan
  • 10,465
  • 2
  • 8
  • 9