0

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 Answers1

0

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).

tcbeaton
  • 85
  • 7
  • Thank you tcbeaton! The function uses "if blocked, reject" - a rejected call in twilio is disconnected and shouldn't return to the flow, isn't that correct? But ok, I tried to set this up as a "split based on" and changed the values in the function. (see above edits 1A) I'm calling from the blocked number in the function and I'm still going straight to Hello. Do you see a problem with the function or flow? – user2765920 Mar 17 '23 at 09:11
  • Since I can't see into the blocks, some of this might be redundant: (1) In the **BlockList** widget, make sure you are setting a Function Parameter to send the caller's number to the function (i.e., set Key to `caller` and Value to `{{trigger.call.From}}`) (2) In the **blocklist** function, check for `event.caller` (see next comment for revised script) (3) In the **split_1** widget, using revised script is, the value to check is `{{widgets.BlockList.parsed.blocked}}` – tcbeaton Mar 17 '23 at 14:21
  • Here's the corrected code: let numberBlock =["+17171234567"]; let status = {}; status.blocked = true; if (numberBlock.length > 0) { if (numberBlock.indexOf(event.caller) === -1) { status.blocked = false; } } callback(null, status); – tcbeaton Mar 17 '23 at 14:31