Added sample script that allows picking up a call ringing on an extension.

git-svn-id: http://yate.null.ro/svn/yate/trunk@2409 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2008-12-19 20:56:46 +00:00
parent b6cd6401d6
commit 67178500d9
1 changed files with 87 additions and 0 deletions

87
share/scripts/pickup.php Executable file
View File

@ -0,0 +1,87 @@
#!/usr/bin/php -q
<?
/* Call pickup script for the Yate PHP interface
Add in extmodule.conf
[scripts]
pickup.php=PREFIX
where PREFIX is whatever you need to dial in front of the number to pick
*/
require_once("libyate.php");
Yate::Init();
//Yate::Debug(true);
function doRoute(&$ev)
{
global $prefix, $calls;
$called = $ev->GetValue("called");
// Check if called number starts with prefix
$len = strlen($prefix);
if (substr($called,0,$len) != $prefix)
return;
// Get rid of prefix and search the active calls
$called = substr($called,$len);
if ($called == "")
return;
// Have to search, cannot use number as array key because it's not unique
$chan = array_search($called,$calls);
Yate::Debug("For picking up '$called' found channel '$chan'");
if ($chan == "")
return;
// Found! Route to it and signal success
$ev->retval = "pickup/$chan";
$ev->handled = true;
}
function doCdr($ev)
{
global $calls;
$chan = $ev->GetValue("chan");
if ($chan == "")
return;
switch ($ev->GetValue("operation")) {
case "initialize":
// Remember the called number for this call leg
$calls[$chan] = $ev->GetValue("called");
break;
case "finalize":
// Forget about the call leg that got hung up
unset($calls[$chan]);
break;
}
}
$calls = array();
$prefix = Yate::Arg();
if ($prefix == "") {
// Hope this is a sensible default - else set a prefix from extmodule.conf
$prefix = "#8";
Yate::Output("Pickup prefix not set, using default '$prefix'");
}
Yate::Install("call.route",35);
Yate::Install("call.cdr",110,"direction","outgoing");
Yate::SetLocal("restart",true);
for (;;) {
$ev=Yate::GetEvent();
if ($ev === false)
break;
if ($ev === true)
continue;
if ($ev->type == "incoming") {
switch ($ev->name) {
case "call.route":
doRoute($ev);
break;
case "call.cdr":
doCdr($ev);
break;
}
$ev->Acknowledge();
}
}
/* vi: set ts=8 sw=4 sts=4 noet: */
?>