Technical Helpweb

- more articles

C# sample: 'SimpleIVR'

C# sample: 'SimpleIVR'

Although the Dialogic® Diva® Software Development Kit (SDK) C# Framework has more functionality than the Dialogic® Diva® Component API, some customers have expressed a preference for programming in C# using the Diva Component API.

The existing Microsoft® Visual Basic® (VB) .NET sample 'SimpleIVR' has now been converted into C#, so that this can be used as a starting point for a C# application.

Summary

The C# sample 'SimpleIVR' uses the Diva Component API. The sample services multiple incoming calls, answers the calls, and plays a main menu. Depending on DTMF input from the caller, a sub-menu is played or a call transfer to the operator is initiated. Note that the sample provides the same functionality as the VB .NET sample that is also called 'SimpleIVR'.

Building the sample program

The sample can be built using Microsoft® Visual Studio 2005 or later.

Using the sample program

The sample is a console program, and is started without parameters. It automatically enumerates the available communication channels and waits for calls on channels that it finds. Call progress messages are printed with a virtual channel identifier. To terminate the program, press 'q' .

When dialing into the program, a main menu is played. Using DTMF tones 1, 2, and 3 the user can select a sub-menu, which plays another menu prompt and returns to the main menu. Pressing '*' terminates the call and '#' transfers the call to an operator by dialing a "0".

Code Tour

Programming using the Dialogic® Diva® Component API does not require many lines of source code; therefore the sample has only one source file named "SimpleIVR.cs". Two objects are implemented, MainInstance and SingleCallHandler.

MainInstance Object

A single MainInstance object is created by the static entry method of the sample. The Start method enumerates the available communication resources using the DivaSystem object and registers for communication using the DivaInstance object. For each available communication channel, a SingleCallHandler object is created and the Start method of this object is called. Once the initialization is completed, the MainInstance object waits for keyboard input and if 'q' is pressed, the SingleCallHanders are terminated and the sample terminates.

SingleCallHandler Object

Each SingleCallHandler object serves one incoming call. When the MainInstance object creates the SingleCallHandler object it also calls the Start method. This method creates a DivaCall object and registers the OnIncomingCall event handler to receive notification of incoming calls. The DivaCall object is initialized to signal events (CallObj.SignalEvents = 1;) and to process the request in synchronous mode (CallObj.AsyncMode = 0;). The call to CallObject.Listen indicates that incoming calls should be signaled.

When the Diva Component API processes an incoming call, it will call the OnIncomingCall event handler of the SingleCallHandler object. Multiple calls are processed in synchronous mode, with no thread handling functionality in the sample program; the thread handling is done inside the Diva Component API. The Diva Component API calls OnIncomingCall on a separate thread and allows methods of DivaCall to be called in either asynchronous or synchronous (blocking) mode.

The OnIncomingCall method processes the call like a script. The call to CallObject.Answer will return when the call is answered and the data channel is successfully connected. The main menu will be repeated when returning from a sub-menu; therefore, the sample program enters a loop. The call to CallObj.SendVoiceFilesEx for the PromptMainMenu will play the main prompt and return if one of the following conditions is fulfilled:

• The DTMF digit 1, 2, 3, * or # is received
• The prompt has been played to the end of the audio file
• The remote party has disconnected

The program detects the condition using the result code of CallObj.SendVocieFilesEx. If a valid DTMF tone is detected the result is DivaResultCodes.DivaResultToneDetected. If a DTMF digit 1, 2, or 3 is detected, a sub-menu is processed. The sub-menu is handled in another method that returns when the sub-menu is processed. To add more menus, the ProcessMenu1 to ProcessMenu3 methods must be enhanced or additional menu processing methods must be added.

When the call is completed, the OnIncomingCall method returns control to the Diva Component API, which then waits for another call to process in the same way.



Feedback

Please rate the usefulness of this page:  
0 - not useful at all
1 - potentially useful
2 - quite useful
3 - very useful
4 - exactly the information I needed     

Please enter a comment about this page:

First published: 12-Jan-2009
Open access: Product rule: ; Page rule: Auto

Service Center Logon