php examples

This commit is contained in:
Raymond Chandler 2012-01-06 03:48:40 -05:00
parent 743dbbf992
commit 93ce1e641f
4 changed files with 317 additions and 0 deletions

View File

@ -0,0 +1,42 @@
<?php
$xml = new XMLWriter();
$xml->openMemory();
$xml->setIndent(1);
$xml->startDocument();
if ( $_REQUEST['exiting'] ) {
header('Content-Type: text/plain');
print "OK";
exit();
}
header('Content-Type: text/xml');
$xml->startElement('document');
$xml->writeAttribute('type', 'xml/freeswitch-httapi');
$xml->startElement('work');
$xml->startElement('pause');
$xml->writeAttribute('milliseconds', '1500');
$xml->endElement(); // </pause>
$xml->startElement('playback');
$xml->writeAttribute('name', 'digits');
$xml->writeAttribute('file', 'http://sidious.freeswitch.org/sounds/exten.wav');
$xml->writeAttribute('error-file', 'http://sidious.freeswitch.org/sounds/invalid.wav');
$xml->writeAttribute('input-timeout', '5000');
$xml->writeAttribute('action', 'dial:default:XML');
$xml->startElement("bind");
$xml->writeAttribute('strip',"#");
$xml->text("~\\d+\#");
$xml->endElement(); // </bind>
$xml->endElement(); // </playback>
$xml->endElement(); // </work>
$xml->endElement(); // </document>
print $xml->outputMemory();

View File

@ -0,0 +1,111 @@
<?php
if ( array_key_exists( 'session_id', $_REQUEST ) ) {
session_id( $_REQUEST['session_id'] );
}
session_start();
$xml = new XMLWriter();
$xml->openMemory();
$xml->setIndent(1);
$xml->startDocument();
if ( array_key_exists( 'exten', $_REQUEST ) ) {
$exten = $_REQUEST['exten'];
} elseif ( array_key_exists( 'exten', $_SESSION ) ) {
$exten = $_SESSION['exten'];
} else {
$exten = '';
}
if ( array_key_exists( 'pin', $_REQUEST ) ) {
$pin = $_REQUEST['pin'];
} elseif ( array_key_exists( 'pin', $_SESSION ) ) {
$pin = $_SESSION['pin'];
} else {
$pin = '';
}
if ( array_key_exists( 'exiting', $_REQUEST ) ) {
$exiting = $_REQUEST['exiting'];
} elseif ( array_key_exists( 'exiting', $_SESSION ) ) {
$exiting = $_SESSION['exiting'];
} else {
$exiting = '';
}
if ( $exiting ) {
header('Content-Type: text/plain');
print "OK";
exit();
}
header('Content-Type: text/xml');
$xml->startElement('document');
$xml->writeAttribute('type', 'xml/freeswitch-httapi');
if ( $exten && $pin ) {
$xml->startElement('work');
$xml->writeElement("playback", "http://sidious.freeswitch.org/sounds/ext_num.wav");
$xml->startElement("say");
$xml->writeAttribute('language', "en");
$xml->writeAttribute('type', "name_spelled");
$xml->writeAttribute('method', "pronounced");
$xml->text($exten);
$xml->endElement(); // </say>
$xml->startElement('pause');
$xml->writeAttribute('milliseconds', "1500");
$xml->endElement(); // </pause>
$xml->startElement("say");
$xml->writeAttribute('language', "en");
$xml->writeAttribute('type', "name_spelled");
$xml->writeAttribute('method', "pronounced");
$xml->text($pin);
$xml->endElement(); // </say>
$xml->writeElement('hangup');
$xml->endElement(); // </work>
} elseif ( $exten ) {
$_SESSION['exten'] = $exten;
$xml->startElement('work');
$xml->startElement('playback');
$xml->writeAttribute('name', "pin");
$xml->writeAttribute('file', "http://sidious.freeswitch.org/sounds/pin.wav");
$xml->writeAttribute('error-file', "http://sidious.freeswitch.org/sounds/bad-pin.wav");
$xml->writeAttribute('input-timeout', "5000");
$xml->startElement("bind");
$xml->writeAttribute('strip', "#");
$xml->text("~\\d+\#");
$xml->endElement(); // </bind>
$xml->endElement(); // </playback>
$xml->endElement(); // </work>
} else {
$xml->startElement('work');
$xml->startElement('playback');
$xml->writeAttribute('name', "exten");
$xml->writeAttribute('file', "http://sidious.freeswitch.org/sounds/exten.wav");
$xml->writeAttribute('loops', "3");
$xml->writeAttribute('error-file', "http://sidious.freeswitch.org/sounds/invalid.wav");
$xml->writeAttribute('input-timeout', "5000");
$xml->startElement("bind");
$xml->writeAttribute('strip', "#");
$xml->text("~\\d+\#");
$xml->endElement(); // </bind>
$xml->endElement(); // </playback>
$xml->endElement(); // </work>
}
$xml->endElement(); // </document>
print $xml->outputMemory();

View File

@ -0,0 +1,71 @@
<?php
if ( array_key_exists( 'session_id', $_REQUEST ) ) {
session_id( $_REQUEST['session_id'] );
}
session_start();
$xml = new XMLWriter();
$xml->openMemory();
$xml->setIndent(1);
$xml->startDocument();
if ( array_key_exists( 'exiting', $_REQUEST ) ) {
$exiting = $_REQUEST['exiting'];
} elseif ( array_key_exists( 'exiting', $_SESSION ) ) {
$exiting = $_SESSION['exiting'];
} else {
$exiting = '';
}
if ( $_FILES && array_key_exists( 'recorded_file', $_FILES ) ) {
move_uploaded_file($_FILES['recorded_file']['tmp_name'], '/tmp/' . $_FILES['recorded_file']['name']);
trigger_error( print_r( $_FILES, true ) );
header('Content-Type: text/plain');
print "OK\n";
exit();
}
if ( $exiting ) {
header('Content-Type: text/plain');
print "OK";
exit();
}
header('Content-Type: text/xml');
$xml->startElement('document');
$xml->writeAttribute('type', 'xml/freeswitch-httapi');
$xml->startElement('work');
$xml->startElement('pause');
$xml->writeAttribute('milliseconds', "1500");
$xml->endElement();
$xml->startElement('playback');
$xml->writeAttribute('file', "http://sidious.freeswitch.org/eg/ivr-say_name.wav");
$xml->endElement();
$xml->startElement('record');
$xml->writeAttribute('name', "recorded_file");
$xml->writeAttribute('file', $_REQUEST['session_id'] . ".wav");
$xml->writeAttribute('error-file', "http://sidious.freeswitch.org/sounds/invalid.wav");
$xml->writeAttribute('input-timeout', "5000");
$xml->writeAttribute('beep-file', "tone_stream://%(1000,0,460)");
$xml->endElement();
$xml->startElement("bind");
$xml->writeAttribute('strip', "#");
$xml->text("~\\d+\#");
$xml->endElement();
$xml->endElement(); // </work>
$xml->endElement(); // </document>
print $xml->outputMemory();

View File

@ -0,0 +1,93 @@
<?php
if ( array_key_exists( 'session_id', $_REQUEST ) ) {
session_id( $_REQUEST['session_id'] );
}
session_start();
$xml = new XMLWriter();
$xml->openMemory();
$xml->setIndent(1);
$xml->startDocument();
if ( array_key_exists( 'exiting', $_REQUEST ) ) {
$exiting = $_REQUEST['exiting'];
} elseif ( array_key_exists( 'exiting', $_SESSION ) ) {
$exiting = $_SESSION['exiting'];
} else {
$exiting = '';
}
if ( array_key_exists( 'result', $_REQUEST ) ) {
$result = $_REQUEST['result'];
} elseif ( array_key_exists( 'result', $_SESSION ) ) {
$result = $_SESSION['result'];
} else {
$result = '';
}
if ( array_key_exists( 'input_type', $_REQUEST ) ) {
$input_type = $_REQUEST['input_type'];
} elseif ( array_key_exists( 'input_type', $_SESSION ) ) {
$input_type = $_SESSION['input_type'];
} else {
$input_type = '';
}
if ( $exiting ) {
header('Content-Type: text/plain');
print "OK";
exit();
}
header('Content-Type: text/xml');
$xml->startElement('document');
$xml->writeAttribute('type', 'xml/freeswitch-httapi');
if ($result) {
$xml->startElement('work');
if ($type == "dtmf") {
$xml->startElement("say");
$xml->writeAttribute('language', "en");
$xml->writeAttribute('type', "name_spelled");
$xml->writeAttribute('method', "pronounced");
$xml->text( $result );
}
$xml->startElement("log");
$xml->writeAttribute('level', "crit");
$xml->text($result);
$xml->endElement();
$xml->writeElement('hangup');
$xml->endElement();
} else {
$xml->startElement('work');
$xml->startElement('pause');
$xml->writeAttribute('milliseconds', "1500");
$xml->endElement();
$xml->startElement('playback');
$xml->writeAttribute('name', "result");
$xml->writeAttribute('asr-engine', "pocketsphinx");
$xml->writeAttribute('asr-grammar', "pizza_yesno");
$xml->writeAttribute('file', "http://sidious.freeswitch.org/sounds/ConfirmDelivery.wav");
$xml->writeAttribute('error-file', "http://sidious.freeswitch.org/sounds/invalid.wav");
$xml->startElement("bind");
$xml->writeAttribute('strip', "#");
$xml->text("~\\d+\#");
$xml->endElement();
$xml->endElement();
$xml->endElement();
}
$xml->endElement(); // </document>
print $xml->outputMemory();