How to do routing using javascript: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 4: | Line 4: | ||
routing=example.js | routing=example.js | ||
The example.js for outside routing requires to configure [[Accfile|accfile.conf]]: | |||
// First display calling and called party numbers | |||
Engine.output("Got call from '" + message.caller + "' to '" + message.called + "'"); | |||
//message.autoprogress = true; | |||
//Channel.callTo("wave/play//var/spool/sounds/hello.au"); | |||
//Channel.callTo("sip/sip:090@192.168.168.1"); | |||
if (message.called.substr(0,2)=="19") { | |||
// route calls starting with 09 to 192.168.168.1 | |||
// 5060 is the default sip port. When using the default port you don't need to specify it | |||
Channel.callJust("sip/sip:" + message.called + "@192.168.168.1:5060"); | |||
} else if (message.called.substr(0,2)=="00" && message.called.length>10) | |||
routeOutside(); | |||
else if (message.called.match("^60")) | |||
Channel.callJust("h323/"+message.called+"@192.168.168.1:1720"); | |||
else if (message.caller=="209") { | |||
Channel.callJust("iax/user_iax@192.168.168.1:4569/"+message.called."@iaxcontext"); | |||
} else { | |||
Channel.callJust("wave/play//var/spool/ymmii/hello.au"); | |||
} | |||
function routeOutside() | |||
{ | |||
// rewrite caller number for all calls that will be routed to this account | |||
message.caller = "+40211231234"; | |||
// rewrite called number: strip 00 and add +_in front of the number | |||
message.called = "+" + message.called.substr(2); | |||
// send all calls starting with +40 to line "gwout" defined in accfile | |||
message.line = "gwout"; | |||
Channel.callJust("line/"+message.called); | |||
} | |||
Revision as of 09:09, 5 October 2012
To configure a script for Javascript routing it must be listed in the javascript.conf file:
[general] routing=example.js
The example.js for outside routing requires to configure accfile.conf:
// First display calling and called party numbers
Engine.output("Got call from '" + message.caller + "' to '" + message.called + "'");
//message.autoprogress = true;
//Channel.callTo("wave/play//var/spool/sounds/hello.au");
//Channel.callTo("sip/sip:090@192.168.168.1");
if (message.called.substr(0,2)=="19") {
// route calls starting with 09 to 192.168.168.1
// 5060 is the default sip port. When using the default port you don't need to specify it
Channel.callJust("sip/sip:" + message.called + "@192.168.168.1:5060");
} else if (message.called.substr(0,2)=="00" && message.called.length>10)
routeOutside();
else if (message.called.match("^60"))
Channel.callJust("h323/"+message.called+"@192.168.168.1:1720");
else if (message.caller=="209") {
Channel.callJust("iax/user_iax@192.168.168.1:4569/"+message.called."@iaxcontext");
} else {
Channel.callJust("wave/play//var/spool/ymmii/hello.au");
}
function routeOutside()
{
// rewrite caller number for all calls that will be routed to this account
message.caller = "+40211231234";
// rewrite called number: strip 00 and add +_in front of the number
message.called = "+" + message.called.substr(2);
// send all calls starting with +40 to line "gwout" defined in accfile
message.line = "gwout";
Channel.callJust("line/"+message.called);
}