Voicent Gateway Visual Basic Simple
Interface
The Voicent Visual Basic Simple Interface class 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 Visual Basic interface source code is
included at the end of this section.
This Visual Basic Simple Interface is developed based on
Voicent Gateway Simple Outbound Call
Interface.
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
- String
CallText(ByVal phoneno As String, ByVal text As
String, ByVal selfdelete As Boolean)
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 |
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
- CallText("123-4567",
"Hello, how are you doing", True)
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.
- Dim reqId
As string =
CallText("123-4567", "Hello, how are you", 0)
- Make a call to phone number '123-4567' and say 'Hello, how
are you'. 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
CallStatus to get the call status, or use
CallRemove to remove the call record.
SYNOPSIS
- String
CallAudio(ByVal phoneno As String, ByVal audiofile As String,
ByVal selfdelete As Boolean)
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
- CallAudio("123-4567", "C:\my audios\hello.wav",
True)
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 =
CallAudio("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
CallStatus to get the call status, or use
CallRemove to remove the call record.
-
SYNOPSIS
- String
CallStatus(ByVal reqId As String)
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',
or if the call will retry, the return value is "Call Will
Retry", 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
- Dim status
As String =
CallStatus("11234035434")
-
SYNOPSIS
- CallRemove(ByVal reqId
As String)
DESCRIPTION
- Remove the call record of the call with reqId.
If the call is not made yet, it will be removed also.
EXAMPLE
- CallRemove("11234035434")
-
SYNOPSIS
-
CallTillConfirm(ByVal vcastexe As String, ByVal vocfile As
String, ByVal wavfile As String,
ByVal ccode As String)
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:
vcastexe |
The BroadcastByPhone program. It is usually
'C:\Program Files\Voicent\BroadcastByPhone\bin\vcast.exe' on the
gateway host. |
vocfile |
The BroadcastByPhone call list to use. |
ccode |
The confirmation code use for the broadcast |
wavfile |
The audio file to use for the broadcast |
EXAMPLE
-
CallTillConfirm(
"C:\Program Files\Voicent\BroadcastByPhone\bin\vcast.exe",
"C:\My calllist\escalation.voc",
"C:\My calllist\escalation.wav",
-
"911911")
-
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.
-
----------------
File Voicent.vb:
----------------
Imports System
Imports System.Net
Imports System.IO
Public Class Voicent
Public Sub New()
MyBase.New()
m_host = "localhost"
m_port = 8155
End Sub
Public Sub New(ByVal host As
String, ByVal port As Integer)
MyBase.New()
m_host = host
m_port = port
End Sub
Public Function CallText(ByVal
phoneno As String, ByVal text As String, ByVal selfdelete As
Boolean)
Dim urlstr As String = "/ocall/callreqHandler.jsp"
' setting the http post string
Dim poststr As String = "info=Simple Text Call " + phoneno
poststr += "&phoneno=" + phoneno
poststr += "&firstocc=10"
poststr += "&selfdelete="
If (selfdelete) Then
poststr += "1"
Else
poststr += "0"
End If
poststr += "&txt=" + text
' Send Call Request
Dim rcstr As String = PostToGateway(urlstr, poststr)
Return GetRequestID(rcstr)
End Function
Public Function CallAudio(ByVal
phoneno As String, ByVal wavefile As String, ByVal selfdelete As
Boolean)
Dim urlstr As String = "/ocall/callreqHandler.jsp"
' setting the http post string
Dim poststr As String = "info=Simple Audio Call " + phoneno
poststr += "&phoneno=" + phoneno
poststr += "&firstocc=10"
poststr += "&selfdelete="
If (selfdelete) Then
poststr += "1"
Else
poststr += "0"
End If
poststr += "&audiofile=" + wavefile
' Send Call Request
Dim rcstr As String = PostToGateway(urlstr, poststr)
Return GetRequestID(rcstr)
End Function
Public Function CallStatus(ByVal
reqID)
' call status url
Dim urlstr As String = "/ocall/callstatusHandler.jsp"
Dim poststr As String
poststr = "reqid=" + reqID
' Send Call Request
Dim rcstr As String = PostToGateway(urlstr, poststr)
If (rcstr.IndexOf("^made^") > -1) Then
Return "Call Made"
End If
If (rcstr.IndexOf("^failed^") > -1) Then
Return "Call Failed"
End If
If (rcstr.IndexOf("^retry^") > -1) Then
Return "Call Will Retry"
End If
Return ""
End Function
Public Function CallRemove(ByVal
reqID As String)
' call status url
Dim urlstr As String = "/ocall/callremoveHandler.jsp"
Dim poststr As String
poststr = "reqid=" + reqID
' Send Call Request
PostToGateway(urlstr, poststr)
End Function
Public Function CallTillConfirm(ByVal
vcastexe As String, ByVal vocfile As String, ByVal wavfile As
String, ByVal ccode As String)
' call request url
Dim urlstr As String = "/ocall/callreqHandler.jsp"
' setting the http post string
Dim poststr As String = "info=Simple Call till Confirm"
poststr += "&phoneno=1111111"
poststr += "&firstocc=10"
poststr += "&selfdelete=0"
poststr += "&startexec=" + vcastexe
Dim cmdline As String = """" + vocfile + """ -startnow"
cmdline += " -confirmcode " + ccode
cmdline += " -wavfile " + """" + wavfile + """"
' add -cleanstatus if necessary
poststr += "&cmdline=" + cmdline
PostToGateway(urlstr, poststr)
End Function
Private Function PostToGateway(ByVal urlstr As String, ByVal poststr As
String)
Dim url As Uri = New Uri("http://" + m_host + ":" +
m_port.ToString() + urlstr)
Dim HttpWRequest As HttpWebRequest =
CType(WebRequest.Create(url), HttpWebRequest)
HttpWRequest.Headers.Set("Pragma", "no-cache")
HttpWRequest.Timeout = 60000
HttpWRequest.Method = "POST"
HttpWRequest.ContentType = "application/x-www-form-urlencoded"
Dim PostData As Byte() =
System.Text.Encoding.ASCII.GetBytes(poststr)
HttpWRequest.ContentLength = PostData.Length
Dim tempStream As Stream = HttpWRequest.GetRequestStream()
tempStream.Write(PostData, 0, PostData.Length)
tempStream.Close()
Dim HttpWResponse As HttpWebResponse =
CType(HttpWRequest.GetResponse(), HttpWebResponse)
Dim receiveStream As Stream = HttpWResponse.GetResponseStream()
'Dim encode As Encoding = System.Text.Encoding.GetEncoding("utf-8")
Dim readStream As StreamReader = New
StreamReader(receiveStream)
Dim rcstr As String = ""
Dim read(256) As [Char]
Dim count As Integer = readStream.Read(read, 0, 256)
While (count > 0)
rcstr += New String(read, 0, count)
count = readStream.Read(read, 0, 256)
End While
HttpWResponse.Close()
readStream.Close()
Return rcstr
End Function
Private Function GetRequestID(ByVal rcstr As String)
Dim index1 As Integer = rcstr.IndexOf("[ReqId=")
If (index1 = -1) Then
Return ""
End If
index1 += 7
Dim index2 As Integer = rcstr.IndexOf("]", index1)
If (index2 = -1) Then
Return ""
End If
Return rcstr.Substring(index1, index2 - index1)
End Function
Private m_host As String
Private m_port As Integer
End Class
--------------------
File TextVoicent.cs:
--------------------
Imports System
Imports System.Threading
Imports Voicent
Public Class TestVoicent
Public Shared Sub Main()
' Replace it with your number
Dim phoneno As String = "111-2222"
Dim voicent As Voicent.Voicent = New Voicent.Voicent
' Test CallText
Dim reqId As String = voicent.CallText(phoneno,
"Hello, how are you", True)
Console.WriteLine("Call request ID = " + reqId)
' Test CallAudio
reqId = voicent.CallAudio(phoneno,
"C:/Program Files/Voicent/MyRecordings/sample_message.wav",
False)
Console.WriteLine("Call request ID = " + reqId)
' try to get status
Dim status As String = ""
While (status.Length = 0)
' wair for 20 seconds
Thread.Sleep(20000)
status = voicent.CallStatus(reqId)
Console.WriteLine("Call Status: " + status)
End While
' remove the call request on the gateway
voicent.CallRemove(reqId)
' Test call-till-confirm
voicent.CallTillConfirm("C:/Program
Files/Voicent/BroadcastByPhone/bin/vcast.exe", "C:/temp/testctf.voc",
"C:/Program Files/Voicent/MyRecordings/sample_message.wav",
"12345")
End Sub
End Class
|