Getting Started with IVR

Requirements: IPWorks VoIP

Introduction

The IVR (Interactive Voice Response) component provides access to simple and intuitive operations designed to implement an automated IVR menu. This guide will cover the basics of activating the component, handling incoming calls, handling user input, and more.

Contents

Activation

To use the component, one of the first steps is activation. This can be done by using the Activate method. The following properties are required before calling this method:

  • User
  • Password
  • Server
  • Port

The User and Password properties contain the credentials required to log in to the SIP provider you are using. Server contains the hostname or IP of the SIP provider. Port contains the port number the component will connect to, with a default value of 5060. The Activated event will fire once activation is successful. This could look like this:

ivr.User = "username"; ivr.Password = "password"; ivr.Server = "HostnameOrIP"; ivr.Port = 5060; ivr.Activate();

Handling Incoming Calls

Incoming calls can be handled using the IncomingCall event. You can use the Answer or Decline methods within this event to appropriately handle incoming calls. For example:

ivr.OnIncomingCall += (sender, e) => { ivr.Answer(e.CallId); // or ivr.Decline(e.CallId); };

Note that incoming calls will also appear in the Calls Collection. The Outgoing field (boolean) will determine if a call is outgoing (true) or incoming (false). You may want query this field, along with the corresponding CallId field, to answer or decline these calls.

Automated Responses

Throughout the menu, you can prompt the caller using PlayText, PlayFile, or PlayStream. For example, you may want to play an initial message for an answered call. To do so, handle the CallReady event and call one of the above methods. This could look something like:

ivr.OnCallReady += (sender, e) => { ivr.PlayText(e.CallId, "Please press 1 to be transferred to sales. Press 2 to be transferred to support."); };

Note that these methods are non-blocking. Once the audio has finished playing to a particular call, the Played event will fire, with the CallId as a parameter. The Playing field of a call can be used to determine if audio is currently being transmitted using one of the previously mentioned Play* methods. Also note that consecutive uses of these methods can prevent a prior audio transmission from completing, resulting in the Played event not firing for prior transmission. It is important to keep this in mind when designing the menu to ensure a call is receiving the intended audio. In the below example, Played will only fire for the second call to PlayText:

ipphone.PlayFile("callId", "C:\\hello.wav"); // Played will not fire for this ipphone.PlayText("callId", "This will interrupt the previous use if it has not finished playing.");

Handling User Input

The main purpose of an IVR menu is to effectively respond to the digits the incoming caller types in. The Digit event is fired for every detected input, with Digit and CallId event parameters. With this, you have a level of flexibility and control when it comes to designing and customizing menu options. Currently, the digits 0-9, *, and # can be recognized by the component. Following the above menu example, we can implement a very simple IVR menu like so:

ivr.OnDigit += (sender, e) => { if (e.Digit.Equals("1")) { ivr.Transfer(e.CallId, "Sales Number", false); } else if (e.Digit.Equals("2")) { ivr.Transfer(e.CallId, "Support Number", false); } // Invalid input, do nothing }

Note that a call's user input is also tracked through the UserInput field, which you can access using the call collection. A more detailed menu example can be found in the IVR demo.

We appreciate your feedback.  If you have any questions, comments, or suggestions about this article please contact our support team at kb@nsoftware.com.