Asterisk IVR dialer: Inbound Calling is Easy; Outbound Calling is Hard

Whether it’s a regular election or the Prime Minister of Japan calls for a snap election. To capitalize on an electoral opportunity or decide on some pressing social issue. Polling gives political candidates a picture of where they stand with the electorate.

Voter opinions shift from week to week, even day to day, as the candidates battle it out. Socio Diversity Co., Ltd. conducts telephone based data collection efforts to paint this picture.

Socio partnered with INVITE Communications Co., Ltd. to provide the communications platform, infrastructure, and development of an Asterisk based telephone survey system.

Building a static dialplan to create a basic Interactive Voice Response (IVR) application on Asterisk is straightforward and easy. After placing the audio in an Asterisk support format on the system, the BackGround() command can be used to play the audio file while waiting for digits, and the Asterisk Gateway Interface (AGI) can call a phpagi script to store the inputed digits in a database along with other channel variables.

 exten => s,1,Wait(0.3)
  same => n,Set(TIMEOUT(absolute)=60)

  same => n,Background(audio_file_q1)
  same => n,Background(silence/silence)
  same => n,Background(silence/silence)
  same => n,Background(silence/silence)
 exten => 1,1,agi(myagi.php,'Gender','Male')
  same => n,Goto('question-two',s,1)

 exten => 2,1,agi(myagi.php,'Gender','Female')
  same => n,Goto('question-two',s,1)

 ;~ Invalid Option
 exten => i,1,NoOp()
  same => n,Goto('question-one',s,1)
 ;~ Timeout
 exten => t,1,NoOp()
  same => n,Hangup()
#!/usr/bin/php -q
require "/var/lib/asterisk/agi-bin/phpagi.php";
$agi = new AGI();

// Available Channel Variables
$agi_request = $agi->request['agi_request'];
$agi_channel = $agi->request['agi_channel'];
$agi_language = $agi->request['agi_language'];
$agi_type = $agi->request['agi_type'];
$agi_uniqueid = $agi->request['agi_uniqueid'];
$agi_version = $agi->request['agi_version'];
$agi_callerid = $agi->request['agi_callerid'];
$agi_calleridname = $agi->request['agi_calleridname'];
$agi_callingpres = $agi->request['agi_callingpres'];
$agi_callingani2 = $agi->request['agi_callingani2'];
$agi_callington = $agi->request['agi_callington'];
$agi_callingtns = $agi->request['agi_callingtns'];
$agi_dnid = $agi->request['agi_dnid'];
$agi_rdnis = $agi->request['agi_rdnis'];
$agi_context = $agi->request['agi_context'];
$agi_extension = $agi->request['agi_extension'];
$agi_priority = $agi->request['agi_priority'];
$agi_enhanced = $agi->request['agi_enhanced'];
$agi_accountcode = $agi->request['agi_accountcode'];
$agi_threadid = $agi->request['agi_threadid'];

// Assign Arguments
$question = $argv[1];
$answer = $argv[2];

//DB connect
$servername = "localhost";
$username = "user";
$password = "pass";
$database = "table";

$mysqli = new mysqli($servername, $username, $password, $database);

if (mysqli_connect_errno()) {
    $agi->verbose("Connection failed: " . mysqli_connect_error(),0);
} else {

    $mysqli->query("SET NAMES utf8");

    $myquery = "INSERT INTO answers VALUES (NULL, NULL, '$agi_uniqueid', '$agi_callerid', '$agi_context', '$agi_extension', '$agi_accountcode', '$question', '$answer')";

    if ($mysqli->query($myquery)) {
        $agi->verbose("New record created successfully",4);
    } else {
        $agi->verbose("Error: " . $myquery . ": " . $mysqli->error,2);



After placing numerous inbound calls and performing rigorous tests, the IVR was ready for outbound calls. With INVITE providing hundreds of channels of calling capacity on their Multi-Carrier Aggregate Trunking (MCAT) platform, there was only one thing missing. An efficient way to handle the outbound calling.

There are many ways to originate calls with Asterisk, but there isn’t an easy way to control the flow of outbound calling. Sending thousands of simultaneous dial requests can bog down the system, exceed the channel capacity, and even trigger toll-fraud blocking of some carriers.

Attempting to slow down the flow of outbound calling brings it’s own set of challenges. Smaller blocks of numbers from a list requires regular manual input. Synchronously processing numbers in a list can waste available channel resources. Stopping outbound calls may involve shutting down Asterisk, dropping active calls, and the need to manually rebuild the list before restarting.

Creating a simple predictive dialer application that uses the AGI or the Asterisk Manager Interface (AMI) creates a whole litany of other problems that need to be solved. Rescheduling busy or unanswered calls, setting timeouts, monitoring the call progress, limiting calling to a specific time period, just to name a few.

WombatDialer solves all these problem and many more!

Instead of using in-house resources to develop a basic predictive dialer application with a few simple features. WombatDialer is a ready-to-use predictive dialer with a broad range of features.

The free 30-day 100-channel trial offered by Loway allowed INVITE to quickly implement an outbound calling solution with Asterisk. Allowing INVITE to focus on improving the IVR.

INVITE developed a web-based interface that allows clients to create their own customized IVR, define the DTMF input options, upload the audio files, and populate a list of numbers to call. With these details stored in a database backend, the static IVR dialplan was converted to use the Asterisk RealTime Architecture (ARA), dynamically generating the dialplan for the IVR.


    uuid() AS `id`,
    'realtime' AS `context`,
    `extension` AS `exten`,
    1 AS `priority`,
    'NoOp' AS `app`,
    `ivr_id` AS `appdata` 

    uuid() AS `id`,
    'realtime' AS `context`,
    `extension` AS `exten`,
    2 AS `priority`,
    'Set' AS `app`,
    concat('AMD=',`amd_enabled`) AS `appdata` 
    uuid() AS `id`,
    'realtime' AS `context`,
    `extension` AS `exten`,
    3 AS `priority`,
    'AGI' AS `app`,
    concat('path/to/',',',`ivr_id`) AS `appdata` 
    uuid() AS `id`,
    'realtime' AS `context`,
    `extension` AS `exten`,
    4 AS `priority`,
    'Hangup' AS `app`,
    '' AS `appdata` 

AGI script improvements were also made to handle the audio, wait for responses, and capture the data. With the addition of Answering Machine Detect (AMD) and skip logic, creating a custom path through the IVR that varies based on the respondent’s answers. Even an Automatic Speech Recognition (ASR) proof-of-concept was tested, converting audio to text using the Google Cloud Speech API.

WombatDialer also generates standard Asterisk channel variables that can be passed to an AGI script when a call ends. Allowing the WombatDialer data for each calling attempt to be captured. The final results are downloaded by INVITE clients using a web-based interface.

By manually configuring the WombatDialer, INVITE processed nearly fifty (50) database driven dialing campaigns. The web-based interface was later modified to interact directly with the WombatDialer. Using the PHP cURL Library to interact with the WombatDialer JSON configuration API, over 600 campaigns were created during 2017.

The development and improvement of an in-house predictive dialer isn’t necessary when using WombatDialer. Allowing the development team to concentrate its efforts on the IVR, to focus more on the client facing features and functionality, instead of making outbound calling work properly.

About Socio Diversity

Socio Diversity Co., Ltd. was established to advance information and telecommunications for a network society, in anticipation of a fully digital society. Supporting the implementation of IP-based technology for office environments and call centers. Contributing to society by reducing overhead costs and improving operational efficiency, through the use of full-IP solutions.

About INVITE Communications

INVITE Communications Co., Ltd. is a Tokyo based managed service provider with unique expertise in managing, migrating, and implementing connectivity solutions in Japan. Assisting businesses to move or install voice and data connectivity solutions from the broad range of communication services available from Japanese carriers. The company’s Multi-Carrier Aggregate Trunking (MCAT) delivers flexible capacity carrier-neutral Voice over IP (VoIP) services for contact centers, hosted business services, and unified communications.

About WombatDialer

WombatDialer predictive dialer software is highly scalable, multi-server and works with your existing Asterisk PBX. With easy to use campaign management tools it boosts agents productivity and improves your call center campaigns with automatic dialing, queue recalls functions, call forwarding options, and different dialing modes including direct, reverse, preview, manual and predictive.
If you are a new user and would like to test all the new features and benefits offered by WombatDialer feel free to request a 30 days trial with 100 channels at

Permalink - Back to home