Intercept DTMF event with AJAM

My AJAM application need to send DTMF tone and make other actions in a connected call…for example during a call throug a SIP/trunk and a Local/Extension, need to send a DTMF tone to the trunk an then hangup.
I’m using jquery ajax functions and Shift8 library to connect to AMI.

es. send a DTMF tone to the trunk line then disconnect the call

// array with the sequence of actions


execMacro(m,‘SIP/trunk_on’); //function that run the macro

function execMacro(macroArray,channel){
//ricorsive function that run the sequence of actions
if (macroArray.length<=0) return false;
var elem=macroArray.shift(); //get the first element from array
var macro=elem[‘action_code’];
var param=elem[‘parameter’];
‘url’: ‘function/manager.php’,
‘data’: ‘func=’+macro+’&channel=’+channel+’&parameter=’+param,
‘type’: ‘POST’,
‘dataType’: ‘json’,
‘async’: false,
‘cache’: false,
‘success’: function(d) {
// wait the end of the action
execMacro(macroArray,channel); //exec the next action

…// first connect to manager server

… // then execute the actions using shift8 library

switch ($_POST[‘func’])
case “playDTMF”:
echo json_encode($response);
case “hangup”:
echo json_encode($response);


the problem is :
the system exec the actions but the response from server is too quick… in this case the call is closed before the DTMF sent.

I try to get the “DTMF” event from manager poller but it starts only if one of the telephone connected press a DTMF tone, it doesnt starts if the manager send the DTMF… why???
any ideas?

Add a delay.

Yes adding a no-op delay

function usleep(microseconds) {
// Delay for a given number of micro seconds
var start = new Date().getTime();
while (new Date() < (start + microseconds/1000));
return true;

             'success': function(d) {
		// attende il termine della chiamata per eseguire la funzione successiva

with the right delay it works but it’s not an elegant solution… i’d like to get an event when the action is effectively terminated