[asterisk-users] Ring back when free?
Yehavi Bourvine +972-8-9489444
YEHAVI at VMS.HUJI.AC.IL
Sun Apr 6 02:02:00 CDT 2008
> Has anyone here implemented "Ring back when free" in Asterisk?
Here is what I do; the dialplan enclosed is in AEL2 format, but you can get the
idea.
When a call is originated I save the called and callee numbers in a database.
If the user gets busy he/she hangs up and dial *41. I then retreive the last
number they dialled and place a flag in the database that someone is camping on
it. The H extension checks this flag and if found generates a .call file.
First, I have a macro to save the for each extension who is the last they
called and the last who called them:
// Save the calling and called numbers in To and From and in the database so
// they can be used by *41 and *42. This way the h extension can acecss this
// database for all destinations.
macro Save_From_to ( ) {
// To and From are used in the dialplan, since we might change ${EXTEN}
Set(_To=${MACRO_EXTEN});
Set(_From=${CALLERID(num)});
NoOp("===== ${From} -> ${To});
// Save them in database for later use.
// Save the caller number at the called extension for *42 usage.
Set(DB(${To}/LastCaller)=${From});
// Where we called for *41
Set(DB(${From}/LastCalled)=${To});
};
This macro is called at the beginning of the "normal" dialplan.
Now, the *41 which registers the "camp-on" using the data saved above:
// *41: Camp on the last extension dialled
*41 => {
Set(tmp=${DB(${CALLERID(num)}/LastCalled)});
// Save it so when the other side hangs it will see it and dial us.
Set(DB(${tmp}/CallBack)=${CALLERID(num)});
// Say the number to caller so he can verify...
SayDigits(${tmp});
Hangup();
};
And now the H extension for handling it:
// The Hangup extension which is called when the call is hanged. See whether
// we have some waiting callback waiting on this extension.
h => {
ResetCDR(w); // To make the CDR correct.
NoOp(${From});
// We have to check the two sides of the call: Those who camp on the calling
and
// those who camp on the called.
Set(tmp=${DB(${From}/CallBack)}); // The calling.
if("${tmp}" != "") { // Something is there.
DBdel(${From}/CallBack); // And delete it...
// Create the callfile and then move it to the spool directory to make the
call.
System(echo Channel: SIP/${tmp} >
/tmp/test.tmp${From})
;
System(echo WaitTime: 20 >> /tmp/test.tmp${From});
System(echo Extension: ${From} >>
/tmp/test.tmp${From});
System(echo CallerID: Callback \\\<${tmp}\\\> >>
/tmp/te
st.tmp${From});
System(mv /tmp/test.tmp${From}
/var/spool/asterisk/outgo
ing/);
};
Set(tmp=${DB(${To}/CallBack)}); // The called
if("${tmp}" != "") { // Something is there
DBdel(${To}/CallBack); // And delete it...
// Create the callfile and then move it to the spool directory to make the
call.
System(echo Channel: SIP/${tmp} > /tmp/test.tmp${To});
System(echo WaitTime: 20 >> /tmp/test.tmp${To});
System(echo Extension: ${To} >> /tmp/test.tmp${To});
System(echo CallerID: Callback \\\<${tmp}\\\> >>
/tmp/te
st.tmp${To});
System(mv /tmp/test.tmp${To}
/var/spool/asterisk/outgoin
g/);
};
};
Good luck! __Yehavi:
More information about the asterisk-users
mailing list