/** * This method is called internally to keep the module running. * It processes the events and returns if a notification is received, * a specific tone comes in or a number of tones are collected. */ static function RunEvents() { global $chan_instance; if ($chan_instance->exiting) { return; } $loop = true; while ($loop) { $ev = Yate::GetEvent(); if ($ev === true) { continue; } if ($ev === false) { $chan_instance->exiting = true; break; } if ($ev->type == "incoming") { if ($ev->name == "call.execute") { $chan_instance->targetid = $ev->params["id"]; $ev->params["targetid"] = $chan_instance->localid; $ev->handled = true; $ev->Acknowledge(); break; } if ($ev->params["targetid"] == $chan_instance->localid) { switch ($ev->name) { case "chan.notify": $loop = false; break; case "chan.dtmf": $t = $ev->params["text"]; $chan_instance->collect .= $t; if ($chan_instance->maxtones > 0 && strlen($chan_instance->collect) >= $chan_instance->maxtones) { $loop = false; } else { for ($i = 0; $i < strlen($t); $i++) { if (strstr($chan_instance->breaktones, $t[$i])) { $loop = false; break; } } } break; } $ev->handled = true; } $ev->Acknowledge(); } } }
/* 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(); /* Install a handler for the engine generated timer message */ //Yate::Install("engine.timer",10); Yate::Install("user.auth", 10); /* 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) { // Yate::Output("PHP event: empty"); continue; } /* If we reached here we should have a valid object */ switch ($ev->type) { case "incoming": $conn = pg_connect("host=127.0.0.1 dbname=yate user=postgres password="******"SELECT username,password FROM yatet");
/** * 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(); } }