Tuesday, August 7, 2012

Reject calls in Twilio OpenVBX (Code Modification)

Every week I get an automated call from some number to my Twilio number. It is very annoying and I don't want to pay (even a penny) every time this caller tries to dial my number.

Solution (Kind of):
When talking to Twilio support and suggesting that they allow you the control to deny numbers from ever reaching your numbers (block list) and therefore reducing harassment and saving precious pennies, they said such a system is not in place. One support rep noticed I was using the OpenVBX and shot me some PHP to reject this number.

I think this will only prevent the number from getting routed through your system, but you will still have to pay for each time these people call. (I'm fairly certain here, but I will verify and correct myself if found otherwise).

In order to block a number in OpenVBX you would need to modify this OpenVBX source file:
// block calls
$caller = normalize_phone_to_E164(isset($_REQUEST['From'])? $ci->input->get_post('From') : '');

$response = new TwimlResponse;

// Update this list of numbers
$block_list = array('+16146526398');
if (in_array($caller, $block_list)){
        $response->reject(array('reason' => 'rejected'));
        $next = AppletInstance::getDropZoneUrl('next');
        if (!empty($next)) {



Luther said...

The Twilio guys forwarded your post here to me as a possible way to reject the 40+ spam calls we're getting.

I can't get it to work... it, in fact, causes the entire VBX system to just error out and give me a message to call the admin.

Any ideas of something has changed in the last few releases that would've broken your code?

JR_Rant said...


Tried copy/paste of your code, then adjust number in the array. However, when uploading file to server and testing on working number a message is received by caller that an application error has occurred.

Nothing more than that message, then it hangs up.

Any ideas what might be the cause?

Michael Corrigan said...

@Luther, I'm currently running OpenVBX v1.2.9 r75 and (which is slightly out of date) it's been working without any issues. I haven't tried the newest version v1.2.12. Have you checked your PHP logs? Let me know if I can help further. Good luck!

Michael Corrigan said...

@JR_Rant, that sounds really strange I wonder if it has anything to do with @Luther's issue. Are you on the latest version? Also, have you checked the PHP error log?

JR_Rant said...

Version number i'm running is: OpenVBX • v1.2.12 r79

checked logs and it seems to be chocking on this file:

line 227

Luther said...

I'm running 1.2.12 r79 as well, actually.

My error log is blank... but might have just reset.

The message I get is exactly the same as @JR_Rant.

Looking at the openvbx.php file at line 227, I have the $ci command cache lines. Considering my poor knowledge of PHP, I have no clue what this does. I understand what the rest of the code is doing, but not this one part.

Any thoughts, other than downgrading to an older version?

Michael Corrigan said...

@JR_Rant, it looks like maybe CodeIgniter can't load the model "vbx_settings" into memory at that point. Possibly that model has a syntactical error or a configuration is not set properly. I would mention your issue to the OpenVBX guys and see if they have a solution. Also, try restoring the modified file to its original form to ensure that is the in fact related to the problem. I will try to look into it more when I have some time. Good luck!

Michael Corrigan said...

@Luther, is line 227 the model loading or the cache object, I looked it up on Github and it looked like it was the model loading, but that file also could be different from the stable one release in v1.2.12.

Luther said...

Here's the section of code as well as I can find:

* Returns the version of the database schema
* @static
* @return int
public static function schemaVersion()
if (empty(self::$schemaVersion))
$ci =& get_instance();
if ($ci->db)
if (!$cache && $ci->cache->enabled())
$reenable_cache = true;
self::$schemaVersion = $ci->vbx_settings->get('schema-version', VBX_PARENT_TENANT);
if ($reenable_cache)
return self::$schemaVersion;

I'll also email the VBX contact and see what I can figure out with them.

If you have any more insight, let me know.