$ev->Acknowledge(); } break; case "answer": Yate::Debug("PHP Answered: " . $ev->name . " id: " . $ev->id); if (!$ev->handled) { if ($ev->name == "call.execute") { // call leg to operator didn't even start Yate::Output("Failed to start queue '{$queue}' call leg to: " . $ev->GetValue("callto")); $m = new Yate("chan.hangup"); $m->id = ""; $m->params["notify"] = $partycallid; $m->params["queue"] = $queue; $m->params["cdrtrack"] = "false"; $m->Dispatch(); } else { if ($ev->name == "chan.locate") { // caller hung up before we installed the hangup handler Yate::Output("Call {$partycallid} from '{$caller}' exited early from '{$queue}'"); Yate::SetLocal("reason", "nocall"); exit; } } } break; default: Yate::Debug("PHP Event: " . $ev->type); } } Yate::Debug("PHP: bye!"); /* vi: set ts=8 sw=4 sts=4 noet: */
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->params["cdrcreate"] = "false"; $m->Dispatch(); } /* Always the first action to do */ Yate::Init(); /* Uncomment next line to get debugging messages */ //Yate::Debug(true); Yate::SetLocal("trackparam", "queue_in.php"); Yate::SetLocal("id", $ourcallid); /* 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) {
* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ /* Simple player/recorder for the Yate PHP interface To test add in regexroute.conf ^NNN$=external/nodata/playrec.php where NNN is the number you want to assign */ require_once "libyate.php"; /* Always the first action to do */ Yate::Init(); /* Set tracking name for all installed handlers */ Yate::SetLocal("trackparam", "playrec.php"); /* Install handlers for the DTMF and wave EOF messages */ Yate::Install("chan.dtmf"); Yate::Install("chan.notify"); $ourcallid = "playrec/" . uniqid(rand(), 1); $partycallid = ""; $state = "call"; $dir = "/tmp"; function setState($newstate) { global $ourcallid; global $partycallid; global $state; global $dir; // are we exiting? if ($state == "") {
set_time_limit(600); function debug($msg) { Yate::Debug('send_mail.php: ' . $msg); } if (!isset($incoming_trunks)) { $incoming_trunks = array(); } $sql_time = "SELECT value FROM ntn_settings WHERE param = 'time_zone_hour'"; $res_time = query_to_array($sql_time); $time_zone_hour = $res_time[0]['value'] ? $res_time[0]['value'] : 3; // Always the first action to do Yate::Init(); Yate::Install('call.cdr', 120); // Ask Yate to restart this script if it dies unexpectedly Yate::SetLocal('restart', true); Yate::Debug(true); // The main loop. We pick events and handle them for (;;) { $ev = Yate::GetEvent(); if ($ev === false) { break; } if ($ev === true) { continue; } // We are sure it's the timer message if ($ev->type == 'incoming') { switch ($ev->name) { case 'call.cdr': $ev->Acknowledge();
// Install handler for the wave end notify messages Yate::Watch("engine.timer"); Yate::Install("user.register"); Yate::Install("user.unregister"); Yate::Install("user.auth"); Yate::Install("call.route"); Yate::Install("call.cdr"); Yate::Install("call.answered", 50); Yate::Install("chan.disconnected", 50); Yate::Install("chan.hangup"); Yate::Install("user.notify"); Yate::Install("engine.status"); Yate::Install("engine.command"); Yate::Install("engine.debug"); // Ask to be restarted if dying unexpectedly Yate::SetLocal("restart", "true"); $query = "SELECT enabled, protocol, username, description, 'interval', formats, authname, password, server, domain, outbound , localaddress, modified, gateway as account, gateway_id, status, 1 AS gw, ip_transport FROM gateways WHERE enabled = 1 AND gateway IS NOT NULL AND username IS NOT NULL ORDER BY gateway"; $res = query_to_array($query); for ($i = 0; $i < count($res); $i++) { $m = new Yate("user.login"); $m->params = $res[$i]; $m->Dispatch(); } set_caller_id(); set_moh(); set_prefixes(); // The main loop. We pick events and handle them for (;;) { $ev = Yate::GetEvent(); // If Yate disconnected us then exit cleanly if ($ev === false) {
$calls[$key]--; if ($calls[$key] <= 0) { sendTones($key, $tones[$key]); // sendTones() might change the counter if ($calls[$key] <= 0) { setupCall($key, false); } } } } Yate::Watch("call.answered"); Yate::Watch("chan.replaced"); Yate::Install("chan.hangup"); Yate::Install("engine.timer"); // Restart if terminated Yate::SetLocal("restart", true); Yate::Debug($param . ": Starting"); /* The main loop. We pick events and handle them */ for (;;) { $ev = Yate::GetEvent(); /* If Yate disconnected us then exit cleanly */ if ($ev === false) { break; } /* Empty events are normal in non-blocking operation. This is an opportunity to do idle tasks and check timers */ if ($ev === true) { Yate::Debug($param . ": empty event"); continue; } switch ($ev->type) {
Yate::Init(); /* Install a handler for the engine generated timer message */ Yate::Install("engine.timer", 10); /* Create and dispatch an initial test message */ $m = new Yate("test"); $m->params["param1"] = "val1"; $m->retval = "ret_value"; $m->Dispatch(); Yate::GetLocal("engine.version"); Yate::GetLocal("engine.nodename"); Yate::GetLocal("engine.nosuch"); Yate::SetLocal("engine.nodename", "error because is readonly"); Yate::GetLocal("config.nosuch"); Yate::GetLocal("config.localsym"); Yate::GetLocal("config.localsym.h323chan.yate"); Yate::SetLocal("config.localsym.h323chan.yate", "r/o error too"); /* The main loop. We pick events and handle them */ for (;;) { $ev = Yate::GetEvent(); /* If Yate disconnected us then exit cleanly */ if ($ev === false) { break; } /* Empty events are normal in non-blocking operation. This is an opportunity to do idle tasks and check timers */ if ($ev === true) { Yate::Output("PHP event: empty"); continue; } /* If we reached here we should have a valid object */ switch ($ev->type) {
/** * Asynchronously retrieve a local module parameter * @param $name Name of the parameter to read */ static function GetLocal($name) { Yate::SetLocal($name, ""); }
function onFax($id) { Yate::Output("Fax call detected on {$id}"); $m = new Yate("chan.masquerade"); $m->id = ""; // don't notify about message result $m->params["message"] = "call.execute"; $m->params["id"] = $id; // FIXME: generate an unique name for each call $m->params["callto"] = "fax/receive/spool/fax-rx.tif"; $m->params["reason"] = "fax"; $m->Dispatch(); } /* Always the first action to do */ Yate::Init(); Yate::SetLocal("trackparam", "detector.php"); Yate::Install("engine.command", 85); Yate::Install("engine.help", 125); Yate::Install("call.execute", 25); Yate::Install("call.fax", 25); /* Create and dispatch an initial test message */ /* The main loop. We pick events and handle them */ for (;;) { $ev = Yate::GetEvent(); /* If Yate disconnected us then exit cleanly */ if ($ev === false) { break; } /* Empty events are normal in non-blocking operation. This is an opportunity to do idle tasks and check timers */ if ($ev === true) {
function endRoute($callto, $ok, $err, $params) { global $partycallid; global $collect; global $final; global $queue; global $routeOnly; global $state; if ($ok && $callto != "-" && $callto != "error") { Yate::Output("Overlapped got route: '{$callto}' for '{$collect}'"); $m = new Yate("chan.masquerade"); $m->params = $params; $m->params["message"] = "call.execute"; $m->params["complete_minimal"] = true; $m->params["id"] = $partycallid; $m->params["callto"] = $callto; $m->Dispatch(); if (strlen($queue)) { // Masquerade the remaining digits // TODO: wait for call.execute to be processed to do that? $d = new Yate("chan.masquerade"); $d->params["message"] = "chan.dtmf"; $d->params["id"] = $partycallid; $d->params["tone"] = $queue; $d->Dispatch(); } return; } if ($final) { Yate::Output("Overlapped got final error '{$err}' for '{$collect}'"); Yate::SetLocal("reason", $err); setState(""); } else { if ($err != "incomplete") { Yate::Output("Overlapped got error '{$err}' for '{$collect}'"); Yate::SetLocal("reason", $err); setState(""); $final = true; } else { Yate::Debug("Overlapped still incomplete: '{$collect}'"); if ($routeOnly) { setState("noroute"); } else { // Don't use setState: we don't want to change the prompt $state = "prompt"; } // Check if got some other digits if ($queue != "") { gotDTMF(""); } } } }
global $done; Yate::Debug("callAnswered"); if ($prompt != "") { $m = new Yate("chan.attach"); $m->id = ""; $m->SetParam("id", $ourcallid); $m->SetParam("source", $prompt); $m->SetParam("single", true); $m->SetParam("notify", $ourcallid); $m->Dispatch(); } else { $done = true; } } Yate::SetLocal("id", $ourcallid); Yate::SetLocal("disconnected", "true"); Yate::Install("chan.disconnected", 90, "id", $ourcallid); // The main loop. We pick events and handle them while ($running) { $ev = Yate::GetEvent(); if ($ev === false) { break; } if ($ev === true) { continue; } switch ($ev->type) { case "incoming": switch ($ev->name) { case "call.execute": $caller = $ev->GetValue("caller");
/** * Run the IVR system * @param $ivrname Name of the initial IVR to start */ static function Run($ivrname) { global $yate_ivr_target; global $yate_ivr_current; if (IVR::Jump($ivrname)) { $init_id = true; while ($yate_ivr_current !== null) { $ev = Yate::GetEvent(); if ($ev === true) { continue; } if ($ev === false) { break; } if ($ev->type == "incoming" && $ev->name == "call.execute") { $yate_ivr_target = $ev->GetValue("id"); IVR::SetChannelID($ev->GetValue("ivrchanid")); } IVR::EventIVR($ev); if ($init_id && $yate_ivr_current !== null) { $init_id = false; Yate::SetLocal("id", IVR::ChannelID()); Yate::Install("chan.dtmf", 100, "targetid", IVR::ChannelID()); Yate::Install("chan.notify", 100, "targetid", IVR::ChannelID()); } if ($ev && $ev->type == "incoming") { if ($ev->handled && $ev->name == "call.execute") { $ev->SetParam("targetid", IVR::ChannelID()); } $ev->Acknowledge(); } } IVR::CleanupIVR(); } }
* but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ /* Test script for the Yate PHP interface To test add in extmodule.conf [scripts] test.php= */ require_once "libyate.php"; /* Always the first action to do */ Yate::Init(); /* Comment the next line to get output only in logs, not in rmanager */ Yate::Output(true); /* Set tracking name for all installed handlers */ Yate::SetLocal("trackparam", "route.php"); /* Install a handler for the call routing message */ Yate::Install("call.route", 80); /* The main loop. We pick events and handle them */ for (;;) { $ev = Yate::GetEvent(); /* If Yate disconnected us then exit cleanly */ if ($ev === false) { break; } /* Empty events are normal in non-blocking operation. This is an opportunity to do idle tasks and check timers */ if ($ev === true) { // Yate::Output("PHP event: empty"); continue; }