Twilio Reject Call not working- Studio Flow


I am trying to get this function to work properly. My set up is as follows:

Phone configuration is set to Studio – Flow – FlowName

The flow itself & function code is below: The Run Function widget is configured like this:

Widget Name: VirtualBlockList
Service: Default
Function URL – Virtual Block List (function name)

When I test this calling from a blocked number listed in the code it’s not rejecting the call. What am I missing?

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 =["+17171234567"];  
  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(reason,'busy');
    callback(null, twiml);
  }
  else {
    // if the caller's number is not blocked, return an empty JavaScript object
    callback(null, {});
  }
};

Source: JavaSript – Stack Overflow

October 20, 2021
Category : News
Tags: javascript | twilio

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.