C++ 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 delivering a message. The interaction can be implemented by using the low level gateway VoiceXML interface. However, using the low level API is time consuming and an 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. You can find the tutorial below.

C++ IVR Interface

Call Text

Synopsis - CallText

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

Description - CallText

Objective

Make a phone call and play the specified text message. The text message is convert to voice by Voicent'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', 1)
                    

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.



                        CString reqId = CallText('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 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

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

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', 1)
                    

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.



                        CString reqId = CallAudio('123-4567', 'C:\my audios\hello.wav', 0)
                    

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

CallStatus(const char* reqId)

Description - CallStatus

Objective

Check the status of a call.

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


                        Cstring status = CallStatus('11234035434')
                    

Call Remove

Synopsis - CallRemove

CallRemove(const char* reqId)

Description - CallRemove

Objective

Remove the record of the call. 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(const char* vcastexe, const char* vocfile, const char* confirmcode, const char* wavfile)

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
<vcast prog> The BroadcastByPhone program. It is usually C:\Program Files\Voicent\BroadcastByPhone\bin\vcast.exe on the gateway host.
<vcast doc> The BroadcastByPhone call list to use.
<confirmcode> The confirm code to use for the broadcast.
<wavfile> The audio file to use for the broadcast.

Example - CallTillConfirm


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

Source Code


                        ---------------
                        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 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);
                        }