mod_httapi.c -- HT-TAPI Hypertext Telephony API (Twillio FreeSWITCH style)

This commit is contained in:
Anthony Minessale
2012-01-05 15:17:40 -06:00
parent 8950a78c41
commit bc8cbee1fb
12 changed files with 3405 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
#!/usr/bin/perl
# Object initialization:
use XML::Simple;
use CGI;
use Data::Dumper;
use XML::Writer;
my $q = CGI->new;
my $exiting = $q->param("exiting");
if ($exiting) {
print $q->header(-type => "text/plain");
print "OK";
exit();
}
print $q->header(-type => "text/xml");
my $writer = new XML::Writer(OUTPUT => STDOUT, DATA_MODE => 1);
$writer->startTag('document', type => 'xml/freeswitch-httapi');
$writer->startTag('work');
$writer->emptyTag('pause', milliseconds => "1500");
$writer->startTag('playback',
name => digits,
file => "http://sidious.freeswitch.org/sounds/exten.wav",
'error-file' => "http://sidious.freeswitch.org/sounds/invalid.wav",
'input-timeout' => "5000",
action => "dial:default:XML");
$writer->dataElement("bind", "~\\d+\#", strip => "#");
$writer->endTag('playback');
$writer->endTag('work');
$writer->endTag('document');
$writer->end();
+71
View File
@@ -0,0 +1,71 @@
#!/usr/bin/perl
# Object initialization:
use XML::Simple;
use CGI;
use Data::Dumper;
use XML::Writer;
my $q = CGI->new;
my $exten = $q->param("exten");
my $pin = $q->param("pin");
my $exiting = $q->param("exiting");
if ($exiting) {
print $q->header(-type => "text/plain");
print "OK";
exit();
}
print $q->header(-type => "text/xml");
my $writer = new XML::Writer(OUTPUT => STDOUT, DATA_MODE => 1);
$writer->startTag('document', type => 'xml/freeswitch-httapi');
$writer->startTag('params');
if ($exten) {
$writer->dataElement("exten", $exten);
}
if ($pin) {
$writer->dataElement("exten", $pin);
}
$writer->endTag('params');
if ($exten && $pin) {
$writer->startTag('work');
$writer->dataElement("playback", "http://sidious.freeswitch.org/sounds/ext_num.wav");
$writer->dataElement("say", $exten, language => "en", type => "name_spelled", method => "pronounced");
$writer->emptyTag('pause', milliseconds => "1500");
$writer->dataElement("say", $pin, language => "en", type => "name_spelled", method => "pronounced");
$writer->emptyTag('hangup');
$writer->endTag('work');
} elsif ($exten) {
$writer->startTag('work');
$writer->startTag('playback',
name => "pin",
file => "http://sidious.freeswitch.org/sounds/pin.wav",
'error-file' => "http://sidious.freeswitch.org/sounds/bad-pin.wav",
'input-timeout' => "5000");
$writer->dataElement("bind", "~\\d+\#", strip => "#");
$writer->endTag('playback');
$writer->endTag('work');
} else {
$writer->startTag('work');
$writer->startTag('playback',
name => "exten",
file => "http://sidious.freeswitch.org/sounds/exten.wav",
'error-file' => "http://sidious.freeswitch.org/sounds/invalid.wav",
'input-timeout' => "5000");
$writer->dataElement("bind", "~\\d+\#", strip => "#");
$writer->endTag('playback');
$writer->endTag('work');
}
$writer->endTag('document');
$writer->end();
@@ -0,0 +1,58 @@
#!/usr/bin/perl
# Object initialization:
use XML::Simple;
use CGI;
use Data::Dumper;
use XML::Writer;
my $q = CGI->new;
my $exiting = $q->param("exiting");
my $file = $q->upload("recorded_file");
if ($file) {
open(O, ">/tmp/recording.wav");
while(<$file>) {
print O $_;
}
close O;
print $q->header(-type => "text/plain");
print "OK\n";
exit();
}
if ($exiting) {
print $q->header(-type => "text/plain");
print "OK";
exit();
}
print $q->header(-type => "text/xml");
my $writer = new XML::Writer(OUTPUT => STDOUT, DATA_MODE => 1);
$writer->startTag('document', type => 'xml/freeswitch-httapi');
$writer->startTag('work');
$writer->emptyTag('pause', milliseconds => "1500");
$writer->emptyTag('playback', file => "http://sidious.freeswitch.org/eg/ivr-say_name.wav");
$writer->startTag('record',
name => "recorded_file",
file => "recording.wav",
'error-file' => "http://sidious.freeswitch.org/sounds/invalid.wav",
'input-timeout' => "5000",
'beep-file', => "tone_stream://%(1000,0,460)");
$writer->dataElement("bind", "~\\d+\#", strip => "#");
$writer->endTag('record');
$writer->endTag('work');
$writer->endTag('document');
$writer->end();
+61
View File
@@ -0,0 +1,61 @@
#!/usr/bin/perl
# Object initialization:
use XML::Simple;
use CGI;
use Data::Dumper;
use XML::Writer;
my $q = CGI->new;
my $result = $q->param("result");
my $type = $q->param("input_type");
my $exiting = $q->param("exiting");
if ($exiting) {
print $q->header(-type => "text/plain");
print "OK";
exit();
}
print $q->header(-type => "text/xml");
my $writer = new XML::Writer(OUTPUT => STDOUT, DATA_MODE => 1);
$writer->startTag('document', type => 'xml/freeswitch-httapi');
if ($result) {
$writer->startTag('work');
if ($type eq "dtmf") {
$writer->dataElement("say", $result, language => "en", type => "name_spelled", method => "pronounced");
}
$writer->dataElement("log", $result, level => "crit");
$writer->emptyTag('hangup');
$writer->endTag('work');
} else {
$writer->startTag('work');
$writer->emptyTag('pause', milliseconds => "1500");
$writer->startTag('playback',
name => "result",
'asr-engine' => "pocketsphinx",
'asr-grammar' => "pizza_yesno",
file => "http://sidious.freeswitch.org/sounds/ConfirmDelivery.wav",
'error-file' => "http://sidious.freeswitch.org/sounds/invalid.wav"
);
$writer->dataElement("bind", "~\\d+\#", strip => "#");
#$writer->dataElement("bind", "1");
#$writer->dataElement("bind", "2");
$writer->endTag('playback');
$writer->endTag('work');
}
$writer->endTag('document');
$writer->end();