File datacard.php of Package yate-datacard
#!/usr/bin/php -q
<?php
/* Scrtipt to handle SMS/USSD
To test add in extmodule.conf
[scripts]
datacard.php=
*/
require_once("libyate.php");
/* Always the first action to do */
Yate::Init();
Yate::Install("datacard.sms", 100);
Yate::Install("datacard.ussd", 100);
/* 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":
if ($ev->name == "datacard.ussd") {
Yate::Output("[datacard.php] USSD: " . $ev->getValue("text"));
//TODO: Handle USSD
}
if ($ev->name == "datacard.sms") {
Yate::Output("[datacard.php] SMS. Caller: " . $ev->getValue("caller"));
Yate::Output("[datacard.php] SMS. Message: " . $ev->getValue("text"));
//TODO: Handle SMS
}
$ev->handled = true;
$ev->Acknowledge();
break;
default:
Yate::Output("PHP Event: " . $ev->type);
}
}
Yate::Output("PHP: bye!");
/* vi: set ts=4 sw=4 sts=4 noet: */
?>