Visual Basic API | Simple Gateway API

  1. CallText
  2. CallAudio
  3. CallStatus
  4. CallRemove
  5. CallTillConfirm
  6. Source Code

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.

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.

Visual Basic IVR Interface

Call Text

Synopsis - CallText

String CallText(ByVal phoneno As String, ByVal text as String, ByVal selfdelete As Boolean)

Description - CallText

Objective

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.

Parameters
phoneno The phone number to call.
textmessage The message for the phone call. This message will be converted to audio using Voicent's text-to-speech software.
selfdelete Ask the gateway to automatically delete the call request after the call is made if it is set to '1'.
Returns
reqId The return value is the call request ID.

Example - CallText


                        CallText("123-4567", "Hello, how are you doing", True)
                    

Makes a call to the phone number '123-4567' and says 'Hello, how are you doing'. Since the selfdelete bit is set to 1, 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 doing', False)
                    

Make a call to phone number '123-4567' and say 'Hello, how are you doing'. Since the selfdelete bit is set to 0, 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.

Call Audio

Synopsis - CallAudio

string CallAudio(ByVal phoneno As String, ByVal audiofile As String, ByVal selfdelete As Boolean)

Description - CallAudio

Objective

Make a phone call and play the specified audio message.

Parameters
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 the Voicent Gateway.
selfdelete Ask the gateway to automatically delete the call request after the call is made if it is set to '1'.
Returns
reqId The return value is the call request ID.

Example - CallAudio


                        CallAudio("123-4567", "C:\my audios\hello.wav", True)
                    

Makes a call to the phone number '123-4567' and says 'Hello, how are you doing'. Since the selfdelete bit is set to 1, the call request record in the gateway will be removed automatically after the call.



                        reqId = CallAudio("123-4567", "C:\my audios\hello.wav", False)
                    

Make a call to phone number '123-4567' and say 'Hello, how are you doing'. Since the selfdelete bit is set to 0, 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.

Call Status

Synopsis - CallStatus

String CallStatus(ByVal reqId As String)

Description - CallStatus

Objective

Check the call status given the reqId.

Parameters
reqId The call request ID.
Returns
'Call Made' Returns the string 'Call Made' if the call was made.
'Call Failed' Returns the string 'Call Failed' if the call failed.
' ' Returns an empty string if the call is in progress or if the call was neither made or failed.

Example - CallStatus


                        Dim status As String = CallStatus("11234035434")
                    

Call Remove

Synopsis - CallRemove

CallRemove(ByVal reqId As String)

Description - CallRemove

Objective

Remove the call record given the <reqId>. If the call is not made yet, it will also be removed.

Parameters
<reqId> The call request ID.

Example - CallRemove


                        CallRemove("11234035434")
                    

Call Till Confirm

Synopsis - CallTillConfirm

CallTillConfirm(ByVal vcastexe As String, ByVal vocfile As String, ByVal wavfile As String, ByVal ccode As String))

Description - CallTillConfirm

Objective

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 invoked over a remote machine, this perl function uses the gateway to schedule an event, which in turn invokes the command on the gateway host.

Parameters
vcastexe The BroadcastByPhone program. It is usually C:\Program Files\Voicent\BroadcastByPhone\bin\vcast.exe on the gateway host.
vcastdoc The BroadcastByPhone call list to use.
wavfile The audio file to use for the broadcast.
ccode The confirm code to use for the broadcast.

Example - CallTillConfirm


                        CallTillConfirm("C:\Program Files\Voicent\BroadcastByPhone\bin\vcast.exe", "C:\My calllist\escalation.voc", "C:\My calllist\escalation.wav", "911911");
                    

Source Code


                        ----------------
                        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