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:
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:
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:
---- 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");
}
};


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