Click here to Skip to main content
15,881,413 members
Articles / Programming Languages / Java / Java SE / J2EE
Article

IVR applications based on Voicent Gateway (C# Sample Interface)

Rate me:
Please Sign up or sign in to vote.
4.17/5 (4 votes)
10 Jul 2008CPOL4 min read 88.7K   37   13
IVR telephone notification software broadcast voice messages by phone. Ideal for group event reminders, marketing, lead generation, political campaign promotions, school fundraising, church communications, emergency notifications, and much more.

I've created a new article that containes java code.

You can click here.

IVR Introduction

Interactive Voice Response, IVR, is a phone technology that allows a computer to detect voice and touch tones using a phone call. The system based on IVR can respond with pre-recorded or dynamically generated audio to further direct callers on how to proceed. IVR enable callers to interact with any software,such as query or modify database information, over the normal phone or internet phone(like Skype). So callers can use their touch-tone pad to input request or just say what then want to do, such as requesting account balance information. Then the IVR will use the text-to-speech software to read information back.

Overall, the IVR can enable you to make hundreds of personalized calls with a single click.<o:p>

IVR telephone notification software broadcast voice messages by phone. Ideal for group event reminders, marketing, lead generation, political campaign promotions, school fundraising, church communications, emergency notifications, and much more.

You can also use IVR Studio to develop your IVR applications. This tool enables flexible application development without any knowledge of VoiceXML. All you need is point and click to draw a call flow diagram.

Using the IVR API

Since all these functions are implemented as a HTTP client communicating directly with a gateway, they can be run on any machine that has a connection to the host running the gateway.

Because my application will use the CallText methods only, so I'll introduce other methods briefly.

SYNOPSIS

string CallText(string phoneno, string text, bool 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:
phonenoThe phone number to call
textThe message for the phone call
selfdeleteAsk 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 IVR will be removed automatically after the call.
string 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.

Here is the other methods, there is detail in the Voicent Gateway Simple Outbound Call Interface.

SYNOPSIS

string CallAudio(string phoneno, string audiofile, bool selfdelete)

EXAMPLE

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

SYNOPSIS

string CallStatus(string reqId)

EXAMPLE

string status = CallStatus("11234035434");

SYNOPSIS

void CallRemove(string reqId)

EXAMPLE

CallRemove("11234035434");

SYNOPSIS

void CallTillConfirm(string vcastexe, string vocfile, string wavfile, string ccode)

EXAMPLE

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

Source Code

This application must be based on a gateway.here, we use the Voicent Gateway for the server, because I haven't find any free gateway by now. And you also can visit this website for more information about the IVR.

  ----------------

  File Voicent.cs:

  ----------------

  using System;
  using System.Net;
  using System.IO;
                            

namespace Voicent
{

  /// <summary>
  /// Interface class for making telephone calls using the simple
  /// API of Voicent Gateway.
  /// </summary>
  public class Voicent
  {
    /// <summary>
    /// Default constructor use <a href="%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22https://tor-proxy.net/cgi-bin/enc/nph-proxy_tor.cgi/111110A/687474703a2f2f6c6f63616c686f73743a38313535%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22">http://localhost:8155</a>
    /// </summary>
    public Voicent()
    {
      m_host = "localhost";

      m_port = 8155;
    }


    /// <summary>
    /// Constructor with host and port
    /// </summary>
    /// <param name="host">Hostname of Voicent Gateway</param>
    /// <param name="port">port number of Voicent Gateway</param>
    public Voicent(string 
                host, int port)
    {
      m_host = host;

      m_port = port;
    }


    /// <summary>
    /// Call the specified phone number and play the text using
    /// text-to-speech engine
    /// </summary>
    /// <param name="phoneno">telephone number to call</param>
    /// <param name="text">text message to play</param>
    /// <param name="selfdelete">if set to one, automatically 
                remove call record on 
    /// gateway after the call is made</param>
    /// <returns>Call Request ID on gateway</returns>
    public string CallText(string 
                phoneno, string text, bool selfdelete)
    {

      // call request url
      string urlstr = "/ocall/callreqHandler.jsp";


      // setting the http post string
      string poststr = "info=Simple Text Call " + 
                phoneno;


      poststr += "&phoneno=" + phoneno;

      poststr += "&firstocc=10";

      poststr += "&selfdelete=";

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

      poststr += "&txt=" + text;


      // Send Call Request
      String rcstr = PostToGateway(urlstr, poststr);

      return GetRequestID(rcstr);

    }


    /// <summary>
    /// Call the specified phone number and play the audio file
    /// </summary>
    /// <param name="phoneno">telephone number to call</param>
    /// <param name="filename">audio file path name</param>
    /// <param name="selfdelete">if set to one, automatically 
                remove call record on 
    /// gateway after the call is made</param>
    /// <returns>Call Request ID on gateway</returns>
    public string CallAudio(string 
                phoneno, string filename, bool selfdelete)
    {
      // call request url
      string urlstr = "/ocall/callreqHandler.jsp";


      // setting the http post string
      string poststr = "info=Simple Audio Call " + 
                      phoneno;


      poststr += "&phoneno=" + phoneno;

      poststr += "&firstocc=10";

      poststr += "&selfdelete=";

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

      poststr += "&audiofile=" + filename;


      // Send Call Request
      String rcstr = PostToGateway(urlstr, poststr);

      return GetRequestID(rcstr);
    }


    /// <summary>
    /// Get call request status
    /// </summary>
    /// <param name="reqID">Call request ID</param>
    /// <returns>status code</returns>
    public string CallStatus(string 
                reqID)
    {
      // call status url
      string urlstr = "/ocall/callstatusHandler.jsp";

      string poststr = "reqid=" + reqID;


      // Send Call Request
      String rcstr = PostToGateway(urlstr, poststr);


      if (rcstr.IndexOf("^made^") != -1)

        return "Call Made";

                

      if (rcstr.IndexOf("^failed^") != -1)

        return "Call Failed";

                

      if (rcstr.IndexOf("^retry^") != -1)

        return "Call Will Retry";


      return "";
    }


    /// <summary>
    /// Remove the call request on the gateway
    /// </summary>
    /// <param name="reqID">Call Request ID</param>
    public void CallRemove(string 
                reqID)
    {
      // call status url
      string urlstr = "/ocall/callremoveHandler.jsp";

      string poststr = "reqid=" + reqID;


      // Send Call Request
      PostToGateway(urlstr, poststr);
    }


    /// <summary>
    /// Invoke Voicent BroadcastByPhone and start the 
                call-till-confirm escalation process
    /// </summary>
    /// <param name="vcastexe">BroadcastByPhone executable file 
                path</param>
    /// <param name="vocfile">BroadcastByPhone call list file 
                path</param>
    /// <param name="wavfile">Audio file, must be PCM 8KHz, 
                16bit, mono wave file format</param>
    /// <param name="ccode">Confirmation code, numbers only</param>
    public void CallTillConfirm(string 
                vcastexe, string vocfile, string wavfile, string ccode)
    {
      // call request url
      string urlstr = "/ocall/callreqHandler.jsp";


      // setting the http post string
      string poststr = "info=Simple Call till Confirm";

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

      poststr += "&firstocc=10";

      poststr += "&selfdelete=0";

      poststr += "&startexec=" + vcastexe;


      string cmdline = "\"" + vocfile + "\" -startnow";

      cmdline += " -confirmcode " + ccode;

      cmdline += " -wavfile " + "\"" + wavfile + "\"";


      // add -cleanstatus if necessary
      poststr += "&cmdline=" + cmdline;


      PostToGateway(urlstr, poststr);
    }


    protected string PostToGateway(string urlstr, string poststr)
    {
      Uri url = new Uri("http://" + m_host + ":" + 
                m_port.ToString() + urlstr);

      HttpWebRequest HttpWRequest = (HttpWebRequest) 
                WebRequest.Create(url);

                

      HttpWRequest.Headers.Set("Pragma", "no-cache");

      HttpWRequest.Timeout = 60000;

      HttpWRequest.Method = "POST";

      HttpWRequest.ContentType = 
                "application/x-www-form-urlencoded";

                

      byte[] PostData = 
                System.Text.Encoding.ASCII.GetBytes(poststr);

      HttpWRequest.ContentLength = PostData.Length;

      Stream tempStream = HttpWRequest.GetRequestStream();

      tempStream.Write(PostData,0,PostData.Length);

      tempStream.Close();

                

      HttpWebResponse HttpWResponse = (HttpWebResponse) 
                HttpWRequest.GetResponse();

      Stream receiveStream = 
                HttpWResponse.GetResponseStream(); 

      StreamReader readStream = new 
                StreamReader(receiveStream);

                

      string rcstr = "";

      Char[] read = new Char[256]; 

      int count = 0;

      while ((count = readStream.Read(read, 0, 256)) > 
                0) {

        rcstr += new String(read, 0, count);

      }

      HttpWResponse.Close();

      readStream.Close();


      return rcstr;
    }


    protected string GetRequestID(string rcstr)
    {
      int index1 = rcstr.IndexOf("[ReqId=");

      if (index1 == -1)
        return "";

      index1 += 7;


      int index2 = rcstr.IndexOf("]", index1);

      if (index2 == -1)
        return "";


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


    private string m_host;

    private int m_port;

  }

}










                
  --------------------

  File TextVoicent.cs:

  --------------------

  using System;
  using System.Threading;
  using Voicent;

                

namespace csapi
{
  /// <summary>
  /// Simple class to test Voicent C# Simple Interface
  /// </summary>
  class TestVoicent
  {
    /// <summary>
    /// The main entry point for the application.
    /// </summary>

    [STAThread]

    static void Main(string[] args)
    {
      string phoneno = "8147838"; // Replace it with 
                      your number


      Voicent.Voicent voicent = new Voicent.Voicent();


      // Test CallText
      string reqId = 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
      while (true) {

        Thread.Sleep(20000); // wair for 20 
                seconds

        string status = 
                voicent.CallStatus(reqId);

        Console.WriteLine("Call Status: " + 
                status);

        if (status.Length != 0)

          break;

      }


      // 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");

    }

  }

}

Points of Interest about IVR

Ideal inbound & Outbound IVR solution

Self-service
Allow callers to get answers to standard inquiries simply and easily, and in seconds, without the need for an agent
Reach the right agent
Automatically capture relevant information from your callers and direct them to the appropriate agent to handle their call
24/7 customer service
Enable your customers to get the information they need, when they need it. Your IVR application is working even when you’re not, or it can transfer calls to your cell phone.
Automated Outbound IVR
Fully integrated with BroadcastByPhone Autodialer. Fully automated interactive outbound call applications to generate sales leads and keep in touch with your customers.

Inbound & Outbound IVR Solution Key Features

Point-and-click call flow design
Deployed on any PC with Windows 2000/2003/XP/Vista
Transfer call to any phone, such as your cell phone
Interactive touch tone response
Speech command response
Automatically convert text to speech
Easy integration with your website
(Developer feature) Integrate with any program through Java
Support Skype or voice modems for making calls
Support single phone line or multiple phone lines
Natural Text-to-speech engine for playing any text over the phone

IVR History

None.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralIVR DTMF System Pin
HubertBourg11-May-11 20:53
HubertBourg11-May-11 20:53 
GeneralHere is an open source example done in C# for a IVR system for Skype Pin
TheUberOverLord8-Apr-11 6:48
TheUberOverLord8-Apr-11 6:48 
QuestionHostname of Voicent Gateway ? Pin
jazzyvishal16-Aug-10 19:13
jazzyvishal16-Aug-10 19:13 
AnswerRe: Hostname of Voicent Gateway ? Pin
jedliu204616-Aug-10 19:40
jedliu204616-Aug-10 19:40 
http://localhost:8155/ocall/callreqHandler.jsp
The URL is just useful in my local machine, you can't visit it from remote, if you want test the code,you need create a project yourself.
GeneralHey..Regarding IVR Pin
yash_211-Mar-10 4:08
yash_211-Mar-10 4:08 
GeneralRe: Hey..Regarding IVR Pin
jedliu20461-Mar-10 14:29
jedliu20461-Mar-10 14:29 
GeneralRe: Hey..Regarding IVR Pin
TIFFCHOW8-Jan-13 1:31
TIFFCHOW8-Jan-13 1:31 
GeneralRe: Hey..Regarding IVR Pin
TIFFCHOW8-Jan-13 1:32
TIFFCHOW8-Jan-13 1:32 
QuestionDo you have some java code? Pin
srigvo8-Jun-08 22:33
srigvo8-Jun-08 22:33 
AnswerRe: Do you have some java code? Pin
jedliu204610-Jun-08 20:19
jedliu204610-Jun-08 20:19 
AnswerRe: Do you have some java code? Pin
jedliu204610-Jun-08 21:08
jedliu204610-Jun-08 21:08 
GeneralRe: Do you have some java code? Pin
srigvo11-Jun-08 1:15
srigvo11-Jun-08 1:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.