Voicent Gateway Perl
Interface
The Voicent Perl module contains the following functions.
Since all these functions are implemented as a HTTP client
communicating directly with Voicent Gateway, they can be run on
any machine that has a connection to the host running the gateway.
The perl interface source code is
included at the end of this section.
This Perl interface is developed based on
Voicent Gateway Simple Outbound Call
Interface.
This module can be directly downloaded from CPAN under the user
name 'andrewik'.
Work with Interactive Applications
For many applications, it is desirable to get responses from
callees in addition to deliver a message. The interaction can be
implemented by using the low level gateway VoiceXML interface.
However, using the low level API is a time consuming and error
prone task. A better solution is to utilize Voicent IVR Studio to
create an interactive application, and use the extended Simple
Call Interface to trigger a phone call.
SYNOPSIS
-
call_text <phoneno> <text message> <selfdelete>
DESCRIPTION
- Make a phone call and play the specified text message. The
text message is convert to voice by Voicent Gateway's
text-to-speech engine.
- The options are:
-
<phoneno> |
The phone number to call |
<text message> |
The message for the phone call |
<selfdelete> |
Ask the gateway to automatically delete the
call request after the call is made if it is set to '1'
|
The return value is the call request id <reqId>.
EXAMPLE
-
call_text('123-4567', 'Hello, how are you doing', 1);
Make a call to phone number '123-4567' and say 'Hello, how are
you doing'. Since the
selfdelete
bit is set, the call request record in the gateway will be
removed automatically after the call.
- $reqId =
call_text(123-4567, 'Hello, how are you doing', 0);
- Make a call to phone number '123-4567' and say 'Hello, how
are you doing'. Since the
selfdelete
bit is not set, the call request record in the gateway will not
be removed after the call. You can then use
call_status to get the call status, or use
call_remove to remove the call record.
SYNOPSIS
-
call_audio <phoneno> <audiofile> <selfdelete>
DESCRIPTION
- Make a phone call and play the specified audio message.
- The options are:
-
<phoneno> |
The phone number to call |
<audiofile> |
The audio message for the phone call. The
format must be PCM 16bit, 8KHz, mono wave file. The audio
file must be on the same host as Voicent Gateway.
|
<selfdelete> |
Ask the gateway to automatically delete the
call request after the call is made if it is set to '1'
|
The return value is the call request id <reqId>.
EXAMPLE
-
call_audio('123-4567', 'C:\my audios\hello.wav', 1);
Make a call to phone number '123-4567' and play the hello.wav
file. Since the
selfdelete
bit is set, the call request record in the gateway will be
removed automatically after the call.
- $reqId =
call_audio(123-4567, 'C:\my audios\hello.wav', 0);
- Make a call to phone number '123-4567' and play the
hello.wav file. Since the
selfdelete
bit is not set, the call request record in the gateway will not
be removed after the call. You can then use
call_status to get the call status, or use
call_remove to remove the call record.
-
SYNOPSIS
-
call_status <reqId>
DESCRIPTION
- Check the call status of the call with
<reqId>.
If the call is made, the return value is
'Call Made',
or if the call is failed, the return value is
'Call Failed',
and for any other status, the return value is
''.
Please note that an empty string is returned if the call is
still in progress. You'll need to wait and then poll the status
again.
EXAMPLE
- $status =
call_status('11234035434');
-
SYNOPSIS
-
call_remove <reqId>
DESCRIPTION
- Remove the call record of the call with
<reqId>.
If the call is not made yet, it will be removed also.
EXAMPLE
-
call_remove('11234035434');
-
SYNOPSIS
-
call_till_confirm <vcast prog> <vcast doc> <confirmcode>
<wavfile>
DESCRIPTION
- Keep calling a list of people until anyone enters the
confirmation code. The message is the specified audio file. This
is ideal for using it in a phone notification escalation
process.
To use this feature, Voicent BroadcastByPhone Professional
version has to be installed. This function is similar to the
command line interface BroadcastByPhone has. But since the
command cannot be invoke over a remote machine, this perl
function uses the gateway to schedule an event, which in turn
invokes the command on the gateway host.
The options are:
<vcast prog>
|
The BroadcastByPhone program. It is usually
'C:\Program Files\Voicent\BroadcastByPhone\bin\vcast' on the
gateway host.
|
<vcast doc> |
The BroadcastByPhone call list to use. |
<confirmcode> |
The confirmation code use for the broadcast |
<wavfile> |
The audio file to use for the broadcast |
EXAMPLE
-
call_till_confirm(
'C:\Program
Files\Voicent\BroadcastByPhone\bin\vcast.exe',
'C:\My calllist\escalation.voc',
'911911',
'C:\My calllist\escalation.wav');
-
This will invoke BroadcastByPhone program on the gateway host
and start calling everyone one the call list defined in
'C:\My calllist\escalation.voc'. The audio message played
is 'C:\My
calllist\escalation.wav'. And as soon as anyone on the
list enters the confirmation code
'911911', the call will stop automatically.
-
-
package
Voicent;
use LWP::UserAgent;
use HTTP::Request::Common;
$voicent::host = "localhost";
$voicent::port = 8155;
sub _call_now {
my %params = %{$_[0]}
my $ua = LWP::UserAgent->new(agent => 'Mozilla/4.0');
my $url = 'http://' . $host . ':' . $port;
$url = $url . '/ocall/callreqHandler.jsp';
my $resp = $ua->request(
POST $url,
Content_Type =>
'application/x-www-form-urlencoded',
Content => [ %params ]);
unless ($resp->is_success) {
print "Error sending call request to
Voicent Gateway";
return "";
}
$result = $resp->content();
$pos = index ($result, '[ReqId=');
unless ($pos >=0) {
print "Error getting call request id
from Voicent Gateway";
return "";
}
$pos = $pos + 7;
$pos2 = index ($result, ']', $pos);
$reqId = substr($result, $pos, $pos2 - $pos);
return $reqId;
}
-
sub call_audio {
my ($phoneno, $audiofile, $selfdelete) = @_;
my %params = ();
$params{'info'} = 'call ' . $phoneno;
$params{'phoneno'} = $phoneno;
$params{'firstocc'} = '10';
$params{'audiofile'} = $audiofile;
$params{'selfdelete'} = $selfdelete;
return _call_now(\%params);
}
sub call_status {
my ($reqId) = @_;
my $url = 'http://' . $host . ':' . $port;
$url = $url . '/ocall/callstatusHandler.jsp';
$url = $url . '?reqid=' . $reqId;
my $ua = LWP::UserAgent->new(agent => 'Mozilla/4.0');
my $resp = $ua->request(GET $url);
unless ($resp->is_success) {
print "Error sending call request to
Voicent Gateway";
return "";
}
$result = $resp->content();
if ($result =~ m#\Q^made^\E#) { return "Call Made"; }
if ($result =~ m#\Q^failed^\E#) { return "Call Failed"; }
print "";
}
sub call_remove {
my ($reqId) = @_;
my $url = 'http://' . $host . ':' . $port;
$url = $url . '/ocall/callremoveHandler.jsp';
$url = $url . '?reqid=' . $reqId;
my $ua = LWP::UserAgent->new(agent => 'Mozilla/4.0');
my $resp = $ua->request(GET $url);
unless ($resp->is_success) {
print "Error sending call request to
Voicent Gateway";
return "";
}
}
# voc file must reside on the same machine as the gateway
# this function can be achieved using command line interface
# vcast.exe -startnow -confirmcode [code] -wavfile [wavfile]
sub call_till_confirm {
my ($vcast, $vocfile, $confirmCode, $wavfile) = @_;
my %params = ();
$params{'info'} = 'call till concel';
$params{'phoneno'} = '0000000';
$params{'firstocc'} = '10';
$params{'startexec'} = $vcast;
$params{'selfdelete'} = '1';
my $cmdline = '"' . $vocfile . '" -startnow';
$cmdline = $cmdline . ' -confirmcode ' . $confirmcode;
$cmdline = $cmdline . ' -wavfile "' . $wavfile . '"';
$params{'cmdline'} = $cmdline;
return _call_now(\%params);
}
|