примерно так
Исходящая маршрутизация
context out {
_X. =>{
Dial(SIP/number@Trunk);
};
h=>{
if ("${CDR(disposition)}"="NO ANSWER") {
&resultat_sql(%${CALLERID(num)}, ${EXTEN}, 0);
};
if ("${CDR(disposition)}" = "BUSY") {
&resultat_sql(%${CALLERID(num)}, ${EXTEN}, 0);
};
};
h=>{
if ("${CDR(disposition)}"="NO ANSWER") {
&resultat_sql(${EXTEN}, status);
};
if ("${CDR(disposition)}" = "BUSY") {
&resultat_sql(${EXTEN}, status);
};
};
};
macro resultat_sql(num_out, num_to, status) {
MYSQL(Connect connid localhost user pass DB);
MYSQL(Query resultid ${connid} INSERT INTO out_call VALUE num_out=${num_out} num_to=${num_to} status=${status});
MYSQL(Clear ${resultid});
MYSQL(Disconnect ${connid});
};
Входящая маршрутизация
context in {
_X. =>{
MYSQL(Connect connid localhost user pass DB)
MYSQL(Query resultid ${connid} select num_out from out_call where num_to LIKE '%${CALLERID(num):2}%' status '0' limit 1)
MYSQL(Fetch fetchid ${resultid} NUMBER_TO_DIAL)
if (${EXIST(${NUMBER_TO_DIAL})}){
Dial(Local/${NUMBER_TO_DIAL});
}
else{
обычное прохождение звонка
};
};
h =>{
MYSQL(Connect connid localhost user pass DB);
MYSQL(Query resultid ${connid} UPDATE out_call SET status='1' where num_to like '%${CALLERID(num):2}%' );
MYSQL(Clear ${resultid});
MYSQL(Disconnect ${connid});
};
};