Voicent Gateway Python Simple 
              Interface
              The Voicent Python 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 Python interface source code is 
              included at the end of this section. 
              This Python 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 
              
                - callText(phoneno, 
                text, 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 | 
                    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", "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 = 
                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 
              
                - callAudio(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 
              
                - callAudio("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. 
  
                - 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 
              
                - callStatus(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', 
                or if the call will retry, the return value is "Call Will 
                Retry", and for any other status, the return value is
                "".
 
               
              EXAMPLE 
              
                - status = 
                callStatus("11234035434")
 
                -  
 
               
               
              SYNOPSIS 
              
                -  callRemove(reqId)
 
               
              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(vcastexe, vocfile, wavfile, ccode)
 
               
              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. 
                -  
 
               
               
              
              
                
                 
                import urllib 
              import time 
               
               
              class Voicent: 
  def __init__(self, host="localhost", port="8155"): 
    self.host_ = host 
    self.port_ = port 
               
  def callText(self, phoneno, text, 
              selfdelete): 
    urlstr = "/ocall/callreqHandler.jsp" 
               
    param = {'info' : 'simple text call', 
             'phoneno' 
              : phoneno, 
             'firstocc' 
              : 10, 
             'txt' : 
              text, 
             'selfdelete' 
              : selfdelete} 
               
    rcstr = self.postToGateway(urlstr, param) 
    return self.getReqId(rcstr) 
               
  def callAudio(self, phoneno, 
              filename, selfdelete): 
    urlstr = "/ocall/callreqHandler.jsp" 
               
    param = {'info' : 'simple audio call', 
             'phoneno' 
              : phoneno, 
             'firstocc' 
              : 10, 
             'audiofile' 
              : filename, 
             'selfdelete' 
              : selfdelete} 
               
    rcstr = self.postToGateway(urlstr, param) 
    return self.getReqId(rcstr) 
               
  def callStatus(self, reqId): 
    urlstr = "/ocall/callstatusHandler.jsp" 
    param = {'reqid' : reqId} 
    rcstr = self.postToGateway(urlstr, param) 
               
    if (rcstr.find("^made^") != -1): 
      return "Call Made" 
               
    if (rcstr.find("^failed^") != -1): 
      return "Call Failed" 
               
    if (rcstr.find("^retry^") != -1): 
      return "Call Will Retry" 
               
    return "" 
               
  def callRemove(self, reqId): 
    urlstr = "/ocall/callremoveHandler.jsp" 
    param = {'reqid' : reqId} 
    rcstr = self.postToGateway(urlstr, param) 
               
  def callTillConfirm(self, vcastexe, 
              vocfile, wavfile, ccode): 
    urlstr = "/ocall/callreqHandler.jsp" 
               
    cmdline = "\"" 
    cmdline += vocfile 
    cmdline += "\"" 
    cmdline += " -startnow" 
    cmdline += " -confirmcode " 
    cmdline += ccode 
    cmdline += " -wavfile " 
    cmdline += "\"" 
    cmdline += wavfile 
    cmdline += "\"" 
               
    param = {'info' : 'Simple Call till Confirm', 
             'phoneno' 
              : '1111111', 
             'firstocc' 
              : 10, 
             'selfdelete' 
              : 0, 
             'startexec' 
              : vcastexe, 
             'cmdline' 
              : cmdline} 
               
    self.postToGateway(urlstr, param) 
               
               
  def postToGateway(self, urlstr, 
              poststr): 
    params = urllib.urlencode(poststr) 
    url = "http://" + self.host_ + ":" + self.port_ + urlstr 
    f = urllib.urlopen(url, params) 
    return f.read() 
               
  def getReqId(self, rcstr): 
    index1 = rcstr.find("[ReqId=") 
    if (index1 == -1): 
      return "" 
    index1 += 7 
               
    index2 = rcstr.find("]", index1) 
    if (index2 == -1): 
      return "" 
               
    return rcstr[index1:index2] 
               
               
               
              # 
              # Uncomment out the following for your test 
              # 
              #put your own number there 
              #phoneno = "111-2222" 
              # 
              #v = Voicent() 
              #v.callText(phoneno, "hello, how are you", "1") 
               
              #reqid = v.callAudio(phoneno, "C:/Program Files/Voicent/MyRecordings/sample_message.wav", 
              "0") 
               
              #while (1): 
              # time.sleep(1) 
              # status = v.callStatus(reqid) 
              # if (status != ""): 
              # break 
               
              #v.callRemove(reqid) 
               
              #v.callTillConfirm("C:/Program Files/Voicent/BroadcastByPhone/bin/vcast.exe", 
              # "C:/temp/testctf.voc", 
              # "C:/Program Files/Voicent/MyRecordings/sample_message.wav", 
              # "1234") 
               
               
                 
 
                 |