0

I am trying to develop a virtual block list in Twilio. I was directed to their reject documentation. I set it up as a function in the function area. I'm trying to figure out how to incorporate it into my Studio - Flow. So I have Trigger > VirtualBlockList (Run function) > then inbound call process. I have the number set to A call comes in: Studio > Flow. Not sure how to do the config in the flow:I am completely new to Twilio, i'm just trying to help out our dev team because they are swamped. Any assistance would be helpful! Also, I removed our account SID and flow SID for security so I have the placeholder in there.

ConfigFlowFunction

exports.handler = function(context, event, callback) {
  // List all blocked phone numbers in quotes and E.164 formatting, separated by a comma
  let numberBlock = event.block || [ "+11234567896"" ];  
  let twiml = new Twilio.twiml.VoiceResponse();
  let blocked = true;
  if (numberBlock.length > 0) {
    if (numberBlock.indexOf(event.From) === -1) {
      blocked = false;
    }
  }
  if (blocked) {
    twiml.reject();
  }
  else {
  // if the caller's number is not blocked, redirect to your existing webhook
  twiml.redirect("https://webhooks.twilio.com/v1/Accounts/<account_sid>/Flows/<flow_sid>");
  }
  callback(null, twiml);
};
philnash
  • 70,667
  • 10
  • 60
  • 88

1 Answers1

0

Twilio developer evangelist here.

In this case, returning the <Reject> from the function works for ending the call. But it's better not to return TwiML if you want to continue down the Studio Flow.

exports.handler = function(context, event, callback) {
  // List all blocked phone numbers in quotes and E.164 formatting, separated by a comma
  let numberBlock = event.block || [ "+11234567896" ];  
  let twiml = new Twilio.twiml.VoiceResponse();
  let blocked = true;
  if (numberBlock.length > 0) {
    if (numberBlock.indexOf(event.From) === -1) {
      blocked = false;
    }
  }
  if (blocked) {
    twiml.reject();
    callback(null, twiml);
  }
  else {
    // if the caller's number is not blocked, return an empty JavaScript object
    callback(null, {});
  }
};

Then if you set your flow up to pass through the function after the trigger then if the call is to be rejected the Function will handle that, and if the call can continue, the success transition from the function will lead onto the next interaction.

enter image description here

philnash
  • 70,667
  • 10
  • 60
  • 88
  • I did as you suggested and the reject portion isn't working: It is allowing the call to go through the function without rejecting it – Tayla Belville Oct 20 '21 at 17:02
  • Can you share the code you are using now (it's easiest to read the code if you edit your question) and how you have this section of the Studio Flow set up? – philnash Oct 20 '21 at 22:24