Voicent Gateway SDK Reference Table of Content << Previous Next >>

Voicent Gateway C++ Simple Interface

The Voicent C++ 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 C++ interface source code is included at the end of this section.

A Sample SimpleCall using this interface class is also provided.

This C++ Simple Interface is developed based on Voicent Gateway Simple Outbound Call Interface.

Comparing with the SDK C++ API, this interface is quite limited.

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

CString CallText(const char* phoneno, const char* text, BOOL selfdelete = false)

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

CString CallAudio(const char* phoneno, const char* audiofile, BOOL selfdelete = false)

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

CString CallStatus(const char* 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 "".

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

CString status = CallStatus("11234035434");
 

SYNOPSIS

void CallRemove(const char* 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

void CallTillConfirm(cosnt char* vcastexe, const char* vocfile, const char* confirmcode, const char* 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:

 
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.
confirmcode 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",
    "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.
 

Source Code

The following Voicent class is included in the sample SimpleCall.

---------------
File Voicent.h:
---------------

class Voicent
{
public:
  Voicent(const char* host, int port);
  ~Voicent();

  // ** Standard Operations **

  // Call Request. Return reqId of this call record on the gateway

  CString
CallText(
    const char* phoneno, // phone number
    const char* text,    // text message using text-to-speech
    BOOL selfDelete = false); // delete call record after call made

  // Call Request. Return reqId of this call record on the gateway

  CString
CallAudio(
    const char* phoneno, // phone number
    const char* wavfile, // audio file to play (PCM 16bit, 8KHz, mono)
    BOOL selfDelete = false); // delete call record after call made

  // Get call status

  CString
CallStatus(const char* reqId); // Call record reqId

  // Remove call record

  void
CallRemove(const char* reqId); // Call record ReqId

  // ** BroadcastByPhone **

  // Invoke BroadcastByPhone
  void
CallTillConfirm(
    const char* vcastexe, // BroadcastByPhone executable path
    const char* vocfile, // Broadcast file
    const char* ccode, // confirmation code
    const char* wavfile); // audio file (PCM 16bit, 8KHz, mono)

private:
  CString m_host;
  int m_port;
};

-----------------
File voicent.cpp:
-----------------

#include "stdafx.h"
#include "afxinet.h"
#include "voicent.h"


///////////////////////////////////////////////////////////////
// Utility Routines

// simple URLEncoding

static CString
URLEncode(CString ToCode)
{
  int max = (unsigned int)ToCode.GetLength();

  CString RetStr;
  for(int i=0;i<max;i++) {
    unsigned char c = ToCode[i];
    unsigned short asc = c;

    if(asc > 47 && asc < 58)
      RetStr += c;
    else if(asc > 64 && asc < 91)
      RetStr += c;
    else if(asc > 96 && asc < 123)
      RetStr+=c;
    else if (asc == 32)
      RetStr+="+";
    else {
      CString AddStr;
      AddStr.Format("%%%2x", asc);
      int iv = (int)AddStr.GetAt(1);
      if((int)AddStr.GetAt(1) == 32) {
        AddStr.SetAt(1,'0');
      }
      RetStr+=AddStr;
    }
  }

  return RetStr;
}

static BOOL
PostToGateway(
          const char* host, // host name
          int port, // port number
          const CString& urlstr, // call scheduler url
          const CString& poststr, // http post string
          CString& rcstr) // returned html page from gateway
{
  CInternetSession sess;
  try {
    CHttpConnection* conn = sess.GetHttpConnection(host, (INTERNET_PORT)port);
    CHttpFile* pFile = conn->OpenRequest(CHttpConnection::HTTP_VERB_POST, urlstr);
    pFile->AddRequestHeaders("Content-Type: application/x-www-form-urlencoded\r\n");
    pFile->SendRequest(NULL, 0, (void*)(const char*)poststr, strlen(poststr));

    DWORD dwRet;
    pFile->QueryInfoStatusCode(dwRet);
    if (dwRet >= 300) {
      rcstr = "Failed to connect to Voicent Gateway. Make sure it is started.";
      delete conn;
      delete pFile;
      return false;
    }

    // parse return value
    CString strRetBufLen;
    pFile->QueryInfo(HTTP_QUERY_CONTENT_LENGTH, strRetBufLen);
    long max = atol((LPCSTR)strRetBufLen);
    if(max <= 0)
    max = pFile->GetLength();

    // Read Data
    char buf[1024];
    int len = pFile->Read(buf, 1024);
    rcstr = CString(buf, len);

    pFile->Close();
    conn->Close();
    delete pFile;
    delete conn;

    return true;
  }
  catch (CInternetException* ex) {
    char errbuf[1024];
    ex->GetErrorMessage(errbuf, 1024);
    rcstr = errbuf;
    ex->Delete();
    return false;
  }
}

// search for pattern [ReqId=*]
static CString
GetReqId(const CString& rcstr)
{
  int index1 = rcstr.Find("[ReqId=");
  if (index1 == -1)
    return "";
  index1 += 7;

  int index2 = rcstr.Find("]", index1);
  if (index2 == -1)
    return "";

  return rcstr.Mid(index1, index2 - index1);
}

// search for pattern ^made^ or ^failed^
static CString
GetCallStatus(const CString& rcstr)
{
  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 "";
}



////////////////////////////////////////////////////////////////////
// Voicent

Voicent::Voicent(const char* host, int port)
{
  m_host = host;
  m_port = port;
}

Voicent::~Voicent()
{
}


// Please refer to http://www.voicent.com/devnet/docs/simpleintf.htm
// for detailed information on these parameters

CString Voicent::
CallText(const char* phoneno, const char* text, BOOL selfDelete)
{
  // call request url
  CString urlstr = "/ocall/callreqHandler.jsp";

  // setting the http post string
  CString poststr;

  poststr += "info=";
  poststr += URLEncode(CString("Simple Text Call ") + phoneno);

  poststr += "&phoneno=";
  poststr += phoneno;

  poststr += "&firstocc=10";

  poststr += "&selfdelete=";
  poststr += (selfDelete ? "1" : "0");

  poststr += "&txt=";
  poststr += URLEncode(text);

  // Send Call Request
  CString rcstr;
  if (! PostToGateway(m_host, m_port, urlstr, poststr, rcstr))
    return "";

  return GetReqId(rcstr);
}

CString Voicent::
CallAudio(const char* phoneno, const char* audiofile, BOOL selfDelete)
{
  // call request url
  CString urlstr = "/ocall/callreqHandler.jsp";

  // setting the http post string
  CString poststr;

  poststr += "info=";
  poststr += URLEncode(CString("Simple Audio Call ") + phoneno);

  poststr += "&phoneno=";
  poststr += phoneno;

  poststr += "&firstocc=10";

  poststr += "&selfdelete=";
  poststr += (selfDelete ? "1" : "0");

  poststr += "&audiofile=";
  poststr += URLEncode(audiofile);

  // Send Call Request
  CString rcstr;
  if (! PostToGateway(m_host, m_port, urlstr, poststr, rcstr))
    return "";

  return GetReqId(rcstr);
}

CString Voicent::
CallStatus(const char* reqId)
{
  // call status url
  CString urlstr = "/ocall/callstatusHandler.jsp";

  // setting the http post string
  CString poststr = "reqid=";
  poststr += URLEncode(reqId);

  // Send Call Request
  CString rcstr;
  if (! PostToGateway(m_host, m_port, urlstr, poststr, rcstr))
    return "";

  return GetCallStatus(rcstr);
}

void Voicent::
CallRemove(const char* reqId)
{
  // call status url
  CString urlstr = "/ocall/callremoveHandler.jsp";

  // setting the http post string
  CString poststr = "reqid=";
  poststr += URLEncode(reqId);

  // Send Call Request
  CString rcstr;
  PostToGateway(m_host, m_port, urlstr, poststr, rcstr);
}

// Call scheduler can launch program also
void Voicent::
CallTillConfirm(const char* vcastexe,
  const char* vocfile,
  const char* ccode,
  const char* wavfile)
{
  // call request url
  CString urlstr = "/ocall/callreqHandler.jsp";

  // setting the http post string
  CString poststr;

  poststr += "info=";
  poststr += URLEncode("Simple Call till Confirm");

  poststr += "&phoneno=1111111"; // any number

  poststr += "&firstocc=10";
  poststr += "&selfdelete=0";

  poststr += "&startexec=";
  poststr += URLEncode(vcastexe);

  CString cmdline;
  cmdline = "\"";
  cmdline += vocfile;
  cmdline += "\"";
  cmdline += " -startnow";
  cmdline += " -confirmcode ";
  cmdline += ccode;
  cmdline += " -wavfile ";
  cmdline += "\"";
  cmdline += wavfile;
  cmdline += "\"";

  // add -cleanstatus if necessary

  poststr += "&cmdline=";
  poststr += URLEncode(cmdline);

  // Send Call Request
  CString rcstr;
  PostToGateway(m_host, m_port, urlstr, poststr, rcstr);
}

 


SimpleCall Sample

(Click here to download the sample)

The SimpleCall Sample uses the C++ Simple Interface class Voicent to make phone calls, check status, and remove call record. It also uses CallTillConfirm to launch BroadcastByPhone. The following is the interface.

Just fill in the phone number, select whether to make a text call or audio call, then click Call Now button. The call request is sent to Voicent Gateway Call Scheduler. Upon return, the call record reqId is returned.

Once the reqId is returned, Click on the GetStatus Button to get the call status. If the call is successful, you should see the status field showing "Call Made".

Click on the Remove Call Record Button to remove the call record on the gateway.




 

Developer Network Table of Content << Previous Next >>