Asterisk Support Elastix Support Knowledge Base Technical

Running a Macro on answer for Asterisk queues.

asteriskThe Asterisk Queue application has an option that will run a macro on answer, This can be very useful when integrating with CRM such as Capsule or call centre applications.

This option isnt included in freepbx, Though this can be hand coded it isn’t best to do this when using Elastix, AsteriskNoW or any other freepbx based system.

To add this option We have written a couple of patched versions of the relevant freepbx pages that can be downloaded here , You will also need to add a extra field to the mysql database as follows

  1. Log in to mysql:   mysql -u root -p
  2. Enter password
  3. mysql> use asterisk
  4. mysql> ALTER TABLE `queues_config` ADD `qmacro` VARCHAR( 255 ) NULL;
  5. mysql> describe queues_config;

You should now have something like this:- | qmacro | varchar(255) | YES | | NULL | | as the last line of the table.

Now download the tar file and unpack it. then copy the two files to the /var/www/html/admin/modules/queues directory.

On loading the queue page in freepbx you will now have the “Queue macro on answer” box


In this box you put the macro name you wish to run when a member answers a call.

For example:-

exten => s,1,Noop( capsule crm intergration ${crminfo} ${CALLERID(all)})
exten => s,n,Set(foo=${CURL(${crminfo})})
exten => s,n,Noop(${foo})
exten => s,n,Hangup()

This a simple dialplan that runs a php script to log calls to the capsule crm


$today = date(“F j, Y, g:i a”);
$duedate1 = date(“Y-m-d”);
$duedate2 = date(“H:i:s”);
$number = $_GET[‘strCallid’];
$datetime = $today;
$duedate = “$duedate1″.”T”.”$duedate2″.”Z”;
echo $duedate;
$myxml=”<?xml version=”1.0″ encoding=”UTF-8″?>n
<description>Call recieved from $number at $datetime. Please update and assign this task if required</description>n
<category>incoming call</category>n
// The URL to connect with (note the /api/ that’s needed and note it’s person rather than party)
// SEE:
$capsulepage = “”;
echo $capsulepage;
echo $number;
// Initialise the session and return a cURL handle to pass to other cURL functions.
$ch = curl_init($capsulepage);
// set appropriate options NB these are the minimum necessary to achieve a post with a useful response
// …can and should add more in a real application such as
// and useragent CURLOPT_USERAGENT
$options = array(CURLOPT_USERPWD => “$Token:x”,
CURLOPT_HTTPHEADER => array(‘Content-Type: application/xml’),
curl_setopt_array($ch, $options);
// Do the POST and collect the response for future printing etc then close the session
$response = curl_exec($ch);
$responseInfo = curl_getinfo($ch);
echo $responseInfo;
echo $response;

Have fun


Blog Case Studies Knowledge Base

Simple CRM integration.

CRM’s have changed a lot since the days of ACT and Goldmine costing many thousands of pounds, for example a 3 user licence for Goldmine is $2700 and $430 a year, compare that to a SaaS solution, for example Capsule is $12 a month you can see why users are flocking to reasonably prices web solutions.
Capsule being web based is accessible anywhere you want on PC, Tablet or smartphone, it also integrates with other services such as LinkedIn, Twitter or if you wanted Facebook. It integrates with other SaaS products such as Kashflow and Mailchimp to name but a few allowing accounting direct mailing and contacts to all be linked.

capsule-logo-on-blackSo why did we suddenly show interest in these again. Well we were contacted by business who used another CRM package and wished to migrate to Capsule but wanted to be able to call direct from the application. This feature is not available at the moment with Capsule, But we have previously used a Firefox plugin called greasemonkey that can rewrite pages and convert numbers it recognises into clickable links. On investigation there is a similar product for Chrome called Tampermonkey and they are compatible scriptwise. With minor changes to our CyJax dialer script we got this working on elastix as well as a modified version for users of Gradwell‘s hosted VoIP solution. With this script now installed Capsule allows simple click dialing of contacts from the database.

On Asterisk we have automated the updating of the contacts history notes with details of the Call, The notes are linked to the Case or opportunity that you were working on if you dialled out from case notes. Also we can track incoming calls** so that they show up in Capsule, at the moment they show up as a task as you cannot create a History note with out an owner but this hopefully will change if the Capsule API is extended . This means no more trying to remember when you called someone its all there.

We have recently extended this to now log callback requests from callers who dont want to wait in a queue. This additional feature is important as it lets people keep track of the callback requests dialing them, assigning them to a contact and adding further detail.

** To Track incoming calls required changes to the freepbx module in Elastix so that a macro is called on answer, Details on setting this support and patching Elastix is available  here

The scripts are available for free download at you will see that these are only scripts for your browser, If you want the server script for your ippbx please contact us to discuss this.