info@voip-sip-sdk.com Tel: +36 1 371 0150
Course 3 / Lecture 3

How to build an IVR with Ozeki VoIP SIP SDK

How to develop a multi-level IVR in C#


Download: 04_Multi_Level_IVR.zip

In the previous example we created two IVR code examples written in C#: the first one is for demonstrating the Blind transfer functionality of the IVR system, and the other one is a Voice controlled IVR. With these options you are able to add numbers to the console application to use the blind transferring functionality and you can control your IVR system by using your voice if you would like to modernize your system with this feature. If you click on the following link, you can reach the full description of the Blind transferer and Voice controlled IVR example code.


In this tutorial example we will learn the followings:

  • How to modify our last blind transferer example to create a Multi-Level IVR system

Video Tutorial:


How to develop IVR by using Ozeki VoIP SDK - Tutorial 3

This example program allows you to listen welcome messages, sample mp3 songs, enter a lower menu level, make call transferring and then return to the main menu in your IVR system.

For the source code of the Multi-Level IVR, please click here!

Program.cs


Softphone.cs


CallHandler.cs


}

NewCallHandler.cs


We are using four classes in these examples:

  • Program.cs
    Our class with the Main() method, this class controls the console window, interacts with the user, by using softphone and callhandler objects.
  • Softphone.cs
    The softphone's implementation goes here, all of it's events, methods, functions, variables.
  • CallHandler.cs
    This class is for handling the incoming calls of the IVR and managing the IVR menu options.
  • NewCallHandler.cs
    This class is for handling the call in the lower menu system, and managing the blind transfer method and the returning option.

The implementation of the Multi-level IVR

To create an IVR seystem which is able to provide the user that he/she can enter a lower menu level, you need to modify and complete our Blind transferer code example. First you need to open the CallHandler class.

CallHandler.cs

First, we need to delete the Blind transfer section (at the switch statement) of the call_Dtmf_Received() method, because we are going to use it in the lower menu level. If the user pressed button three, then the system needs to navigate him/her to the sub menu. So you need to create a method, which handles this navigation. This will be the LowerMenu() method.

void call_DtmfReceived(object sender, VoIPEventArgs<DtmfInfo> e)
{
     DisposeCurrentHandler();
     switch (e.Item.Signal.Signal)
     {
           case 0: break;
           case 1: TextToSpeech("Ozeki Informatics Ltd. is a leading mobile messaging software vendor and Ozeki VoIP SIP SDK is an excellent software development kit that allows you to establish VoIP calls from your application easily and quickly. You do not need to have expert programming skills, with the most basic programming knowledge you will be able to create extraordinary VoIP solutions with this tool."); break;
           case 2: MP3ToSpeaker(); break;
           case 3: LowerMenu(); break;
     }
}

The LowerMenu() method

In this method the first thing we need to do is unsubscribing from all of our actual events: CallStateChanged and DtmfReceived events of the call and Elapsed event of the greetingMessageTimer. After this we need to create a new class which is able to handle the call in the sub menu. This will be the NewCallHandler class. After the creatin of the class return to the LowerMenu() method and create an object from the new class. Call two methods (BlindTransferNumber(), Start()) with this object and subscribe on the Completed event of it. But these methods and events don't exist yet, we will creat them soon when we creat the source code of the NewCallHandler class.

private void LowerMenu()
{
      call.CallStateChanged -= call_CallStateChanged;
      call.DtmfReceived -= call_DtmfReceived;
      greetingMessageTimer.Elapsed -= greetingMessageTimer_Elapsed;

      NewCallHandler newCallHandler = new NewCallHandler(call);
      newCallHandler.BlindTransferNumber(blindTransferNumber);
      newCallHandler.Completed += newCallHandler_Completed;
      newCallHandler.Start();
}

The newCallHandler_Completed() method

This method serves to subscribe back on the events and start the greeting message if the user press a DTMF buttun to finish and complete the sub menu and return to the main level.

void newCallHandler_Completed(object sender, EventArgs e)
{
     call.CallStateChanged +=call_CallStateChanged;
     call.DtmfReceived +=call_DtmfReceived;
     StartGreetingMessage();
     greetingMessageTimer.Start();
}

We finished the modification of the CallHandler class. Now it is time to complete our NewCallHandler class.

NewCallHandler.cs

When the user enter this sub menu, he/she will hear a greeting message with some informaton about the opertion of this menu level. After that, he/she can choose between two options: blind transferring to the added number or return to the main menu. We will focus on demonstrate you the differences and novelties between this class and the former Callhandler.cs, so if would like to read the full description of the CallHandler class, please visit our C# Basic IVR page.

The call_DtmfReceived() method

This is the first important section of the source code. In this, we defined that if the user presses button one, then the system transfer the call to the added number, and by pressing two, he/she can return to the main menu level. To reach this option, we need call and also create a method to manage this functionality: this will be the Return() method.

void call_DtmfReceived(object sender, VoIPEventArgs<DtmfInfo> e)
{
      DisposeCurrentHandler();
      switch (e.Item.Signal.Signal)
      {
          case 1:
             {
                 if (blindTransferNumber == "0")
                 {
                      TextToSpeech("You did not add any number for blind transferring!");
                      break;
                 }
                 else
                 {
                      call.BlindTransfer(blindTransferNumber);
                      break;
                 }
             }
          case 2: Return(); break;
      }
}

The Return() method

The operation of the Return() method happens when the user press the button two because he/she would like to return to the main menu. When it happens it is necessary to unsubscribe from the call_DtmfReceived()method, dispose the current handler, close the greetingMessageTimer and invoke the Completed event.

private void Return()
{
     call.DtmfReceived -= call_DtmfReceived;
     DisposeCurrentHandler();
     greetingMessageTimer.Close();

     var Handler = Completed;
     if (Handler != null)
        Handler(this, EventArgs.Empty);
}

The call_CallStateChanged() method

In this case the call state can change when the user press the button one and choose the blind transfer option. Then the call state changes to "Transferring" and the system needs to dispose the current handler and stop the greetingMessageNumber. When the call state changes back to "InCall" again, then the IVR restarts this timer.

		void call_CallStateChanged(object sender, CallStateChangedArgs e)
        {
            if (e.State == CallState.InCall) greetingMessageTimer.Start();
            if (e.State == CallState.Transferring) DisposeCurrentConnector(); greetingMessageTimer.Stop();
        }

Conclusion

As you can see, with the help of these examples, you can create and modernize your IVR system by using Ozeki VoIP SIP SDK. Now you are able to use the Blind Transfer method and the components of the SpeechToText class if you would like to control your IVR system via human speech.

The next example will introduce how to:

  • Create an IVR system written in C# by using XML codes

If you have any questions or need assistance, please contact us at info@voip-sip-sdk.com

Related Pages

Ozeki Cookie Policy
Ozeki Informatics Ltd uses cookies to provide you the best experience on this website. The further use of the website will be considered as an agreement to the use of cookies. For more information read this website.

Cookies are enabled You are browsing the optimized version of this website. For more information read this website.