Fixed parameters transfer, added queue assist scripts.

git-svn-id: http://yate.null.ro/svn/yate/trunk@1707 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2008-01-30 19:46:09 +00:00
parent f3d771bb0f
commit 21485588d6
4 changed files with 246 additions and 13 deletions

View File

@ -21,18 +21,20 @@
; length: int: Maximum queue length, will declare congestion if grows larger
; greeting: string: Resource to be played initially as greeting
; onhold: string: Resource to be played while waiting in queue
; maxcall: int: How much to call the operator, in milliseconds
; prompt: string: Resource to play to the operator when it answers
;queue=
; avail: string: Query to fetch operators to which calls can be distributed
; Relevant substitutions:
; ${queue}: string: Name of this queue
; ${required}: int: Number of operators required to handle incoming calls
; ${waiting}: int: Total number of calls waiting in this queue
; Relevant returned params:
; callto: string: Resource where the operator is located
; ${waiting}: int: Total number of calls waiting in this queue (assigned or not)
; Mandatory returned params:
; location: string: Resource where the operator is located
; username: string: User name of the operator
; Relevant returned params:
; timeout: int: How much to call the operator, in seconds
; maxcall: int: How much to call the operator, in milliseconds
; prompt: string: Resource to play to the operator when it answers
;avail=

View File

@ -287,14 +287,10 @@ void CallsQueue::startACD()
Array* res = static_cast<Array*>(msg.userObject("Array"));
if (!res || (msg.getIntValue("rows") < 1))
return;
int timeout = getIntValue("timeout");
String prompt = getValue("prompt");
if (prompt && (prompt.find('/') < 0))
prompt = "wave/play/sounds/" + prompt;
for (int i = 1; i < res->getRows(); i++) {
NamedList params("");
copyArrayParams(params,res,i);
const char* callto = params.getValue("callto");
const char* callto = params.getValue("location");
const char* user = params.getValue("username");
if (!(callto && user))
continue;
@ -312,10 +308,12 @@ void CallsQueue::startACD()
ex->addParam("callto",s_chanOutgoing);
ex->addParam("notify",*call);
ex->addParam("queue",c_str());
if (timeout > 0)
ex->addParam("maxcall",String(timeout*1000));
if (prompt)
msg.setParam("prompt",prompt);
const char* tmp = params.getValue("maxcall",getValue("maxcall"));
if (tmp)
ex->addParam("maxcall",tmp);
tmp = params.getValue("prompt",getValue("prompt"));
if (tmp)
ex->addParam("prompt",tmp);
Engine::enqueue(ex);
}
}

131
share/scripts/queue_in.php Executable file
View File

@ -0,0 +1,131 @@
#!/usr/bin/php -q
<?
/*
* Queue inbound calls (waiting in queue)
* The queue module should let the call.execute fall through to this script.
* It will optionally play a short greeting and then attach an on-hold source.
*/
require_once("libyate.php");
$ourcallid = "q-in/" . uniqid(rand(),1);
$partycallid = "";
$newsource = "";
$answermode = "";
$override = "";
function SendMsg($msg)
{
global $ourcallid;
global $partycallid;
$m = new Yate($msg);
$m->id = "";
$m->params["id"] = $ourcallid;
$m->params["peerid"] = $partycallid;
$m->params["targetid"] = $partycallid;
$m->params["reason"] = "queued";
$m->Dispatch();
}
/* Always the first action to do */
Yate::Init();
Yate::SetLocal("id",$ourcallid);
Yate::SetLocal("disconnected","true");
/* Install handlers for the wave end and dtmf notify messages */
//Yate::Install("chan.dtmf");
/* The main loop. We pick events and handle them */
for (;;) {
$ev=Yate::GetEvent();
/* If Yate disconnected us then exit cleanly */
if ($ev === false)
break;
/* No need to handle empty events in this application */
if ($ev === true)
continue;
/* If we reached here we should have a valid object */
switch ($ev->type) {
case "incoming":
switch ($ev->name) {
case "call.execute":
$partycallid = $ev->params["id"];
if (array_key_exists("targetid",$ev->params))
$ourcallid = $ev->params["targetid"];
else
$ev->params["targetid"] = $ourcallid;
$answermode = $ev->GetValue("answermode","late");
$ev->handled = true;
/* We must ACK this message before dispatching a call.answered */
$ev->Acknowledge();
if ($ev->GetValue("source") || $ev->GetValue("consumer") || $ev->GetValue("greeting")) {
$m = new Yate("chan.attach");
$m->params["id"] = $ourcallid;
if ($ev->GetValue("consumer"))
$m->params["consumer"] = $ev->GetValue("consumer");
$newsource = $ev->GetValue("source");
if ($ev->GetValue("greeting"))
$m->params["source"] = $ev->GetValue("greeting");
else if ($newsource) {
$m->params["source"] = $newsource;
$newsource = "";
}
if ($newsource) {
$m->params["notify"] = $ourcallid;
Yate::Install("chan.notify");
}
else if ($answermode == "late")
$answermode = "early";
$m->Dispatch();
}
switch ($answermode) {
case "early":
SendMsg("call.answered");
break;
case "late":
case "never":
SendMsg("call.ringing");
break;
}
/* Prevent a warning if trying to ACK this message again */
$ev = false;
break;
case "chan.notify":
if ($ev->GetValue("targetid") == $ourcallid) {
Yate::Uninstall("chan.notify");
$m = new Yate("chan.attach");
$m->params["id"] = $ourcallid;
$m->params["source"] = $newsource;
$m->Dispatch();
$newsource = "";
if ($answermode == "late")
SendMsg("call.answered");
}
break;
}
/* This is extremely important.
We MUST let messages return, handled or not */
if ($ev)
$ev->Acknowledge();
break;
case "answer":
Yate::Output("PHP Answered: " . $ev->name . " id: " . $ev->id);
break;
case "installed":
Yate::Output("PHP Installed: " . $ev->name);
break;
case "uninstalled":
Yate::Output("PHP Uninstalled: " . $ev->name);
break;
default:
Yate::Output("PHP Event: " . $ev->type);
}
}
Yate::Output("PHP: bye!");
/* vi: set ts=8 sw=4 sts=4 noet: */
?>

102
share/scripts/queue_out.php Executable file
View File

@ -0,0 +1,102 @@
#!/usr/bin/php -q
<?
/*
* Queue outbound calls (distributed to operators)
* The queue module will create one instance every time it tries to send a
* call from queue to an available operator.
*/
require_once("libyate.php");
$ourcallid = "q-out/" . uniqid(rand(),1);
$partycallid = "";
$prompt = "";
$queue = "";
/* Always the first action to do */
Yate::Init();
Yate::SetLocal("id",$ourcallid);
Yate::SetLocal("disconnected","true");
Yate::Install("call.answered",50);
Yate::Install("chan.hangup");
Yate::Install("chan.disconnected",20);
/* The main loop. We pick events and handle them */
for (;;) {
$ev=Yate::GetEvent();
/* If Yate disconnected us then exit cleanly */
if ($ev === false)
break;
/* No need to handle empty events in this application */
if ($ev === true)
continue;
/* If we reached here we should have a valid object */
switch ($ev->type) {
case "incoming":
switch ($ev->name) {
case "call.execute":
$partycallid = $ev->GetValue("notify");
$prompt = $ev->GetValue("prompt");
$queue = $ev->GetValue("queue");
$ev->handled=true;
$m = new Yate("call.execute");
$m->params["id"] = $ourcallid;
$m->params["caller"] = $ev->GetValue("caller");
$m->params["called"] = $ev->GetValue("called");
$m->params["callto"] = $ev->GetValue("direct");
$m->params["maxcall"] = $ev->GetValue("maxcall");
$m->params["cdrtrack"] = "false";
$m->Dispatch();
break;
case "call.answered":
if ($ev->GetValue("targetid") == $ourcallid) {
$ev->params["targetid"] = $partycallid;
$ev->Acknowledge();
$m = new Yate("chan.connect");
$m->params["id"] = $ev->GetValue("id");
$m->params["targetid"] = $partycallid;
$ev = false;
$m->Dispatch();
}
break;
case "chan.notify":
if ($ev->GetValue("targetid") == $ourcallid) {
Yate::Uninstall("chan.notify");
}
break;
case "chan.disconnected":
if (($ev->GetValue("id") == $ourcallid) && $ev->GetValue("reason")) {
$ev->name = "chan.hangup";
$ev->params["notify"] = $partycallid;
$ev->params["queue"] = $queue;
$ev->params["cdrtrack"] = "false";
}
break;
case "chan.hangup":
if ($ev->GetValue("id") == $partycallid)
exit();
}
/* This is extremely important.
We MUST let messages return, handled or not */
if ($ev)
$ev->Acknowledge();
break;
case "answer":
Yate::Output("PHP Answered: " . $ev->name . " id: " . $ev->id);
break;
case "installed":
Yate::Output("PHP Installed: " . $ev->name);
break;
case "uninstalled":
Yate::Output("PHP Uninstalled: " . $ev->name);
break;
default:
Yate::Output("PHP Event: " . $ev->type);
}
}
Yate::Output("PHP: bye!");
/* vi: set ts=8 sw=4 sts=4 noet: */
?>