Block Call List Function that can be used for multiple flows

110 Views Asked by At

I'm trying to create a blocked call list function, then use this function with multiple twilio flows for all of my numbers.

I'm using this doc:

https://support.twilio.com/hc/en-us/articles/360034788313-Reject-Incoming-Calls-with-a-Phone-Number-Block-List

The issue is that if the number is not blocked, the function redirects to one URL. I need the function to redirect back to the flow being used with the number being called.

So I found this which seems like it would solve the problem by using the empty jquery:

Twilio Virtual Block List

However, I can't get the suggested function to work. If I call using a blocked number, I am still connected to the flow and get sent to voicemail. I need a blocked number to be immediately rejected and receive a "no longer in service" message.

I would continue that stack overflow thread, but I don't have enough reputation to comment.

How can I get this to work?

Here is my fucntion:

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 || [ "+19709892022", "+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, {});
  }
};

And here is my flow:

Studio Flow using Blocked Caller List Function

---- Edit 1A ---

tcbeaton suggested I use a split to direct the call, so I've edited the function and flow as follows. This sends the blocked number to "hello" when it should be going to "goodbye".

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 blocked = true;
  if (numberBlock.length > 0) {
    if (numberBlock.indexOf(event.From) === -1) {
      blocked = false;
    }
  }
  if (blocked) {
    callback(null, "blocked");
  }
  else {
    callback(null, "accepted");
  }
};

enter image description here

1

There are 1 best solutions below

3
tcbeaton On

When you call your BlockList function, it will always return to the Studio Flow. You need to check the returned value using the "Split Based On" widget to either continue to the say/play widget or exit the flow.

If you need more help, I can provide more details later (in a meeting now).