High performance VoIP SDK for .Net developers

VoIP SIP SDK

How to implement Auto Answer (AA)

Explanation

Prerequisities

Download: 15_AutoAnsweringSoftphone.zip

For creating a splendid softphone your best choice is Ozeki VoIP SIP SDK. It provides superb background and tools for your project. This article explains in details how you can implement Auto Answer function in your softphone with Ozeki SIP SDK.

Introduction

In VoIP communication there are cases when the callee cannot answer the calls but wants to inform the callers about this fact. This is when the auto answer function can be used (Figure 1).

Auto answer can be a previously captured audio file or a text message that is read up by the VoIP client. The basic idea behind it is that when there is an incoming call, it is automatically accepted but instead of speaking to the callee, the caller can listen to a message played into the call.


Figure 1 - Auto answer in a VoIP call

The following program code uses the background support of Ozeki VoIP SIP SDK, therefore you will need to download and install the SDK on your computer before starting to use the program code. You will also need to have Visual Studio 2010 or compatible IDE and .NET Framework installed on your system, as the program code below is written in C# language.

The simplest auto answering softphone

In the sample program of this article the simplest auto answering softphone is built up. In this case the program can only register to a PBX with the specified SIP account and it waits for an incoming call to accept. When there is an incoming call the softphone accepts it and the communication can be started.

The GUI of the example program is really simple, it only contains the PBX registration form, some notification labels and a button that can be used for ending the call (Figure 2). As this is an auto-answering softphone you cannot cancel the call or in this case you cannot even start a call with it.


Figure 2 - The graphical user interface for the auto answering softphone

This program works similar to an ordinary softphone. You can set the SIP and PBX data on the form and press the OK button that will start the registration (Code 1). If you have set the proper information, the registration to the PBX will be succeeded and your auto answering softphone will wait for the calls.

displayname = DisplayNameTB.Text;
    username = UserNameTB.Text;
    registername = RegNameTB.Text;
    regpass = RegPwdTB.Text;

    try
    {
        int i;
        i = Int32.Parse(IP1.Text);
        if (!(i >= 0 && i <= 255))
            throw new Exception();
        i = Int32.Parse(IP2.Text);
        if (!(i >= 0 && i <= 255))
            throw new Exception();
        i = Int32.Parse(IP3.Text);
        if (!(i >= 0 && i <= 255))
            throw new Exception();
        i = Int32.Parse(IP4.Text);
        if (!(i >= 0 && i <= 255))
            throw new Exception();
    }
    catch (Exception ex)
    {
        MessageBox.Show(String.Format("The IP address you set is invalid, please set a valid IP address.\n {0}", ex.Message), string.Empty, MessageBoxButtons.OK,
    MessageBoxIcon.Error);
    }
    domainhost = string.Empty;
    domainhost = IP1.Text + "." + IP2.Text + "." + IP3.Text + "." + IP4.Text;
    try
    {
        port = Int32.Parse(PortNo.Text);
    }
    catch (Exception ex)
    {

        MessageBox.Show(String.Format("The port number you set is invalid, please set a valid port number.\n {0}", ex.Message), string.Empty, MessageBoxButtons.OK,
    MessageBoxIcon.Error);
    }
    switch (NAT.SelectedIndex)
    {
        case -1:
        case 0:
            natTraversal = NatTraversalMethod.None;
            break;
        case 1:
            natTraversal = NatTraversalMethod.STUN;
            break;
        case 2:
            natTraversal = NatTraversalMethod.TURN;
            break;
    }
    InitializeSoftPhone();

Code 1 - Setting the registration data for the PBX

The InitializeSoftPhone(); instruction will do the actual registration.

The actual difference between a normal softphone and this application can be seen in Code 2. In this case when an incoming call comes the call is accepted without waiting for a user interaction.

private void softPhone_IncomingCall(object sender, VoIPEventArgs<IPhoneCall> e)
{
    InvokeGUIThread(() =>
    {
        RegistrationState.Text = "Incoming call";
        DialedNumber.Text = String.Format("from {0}\n", e.Item.DialInfo);
        call = e.Item;
        WireUpCallEvents();
        inComingCall = true;
        call.Accept();
    });
}

Code 2 - The code that handles the incoming calls

In this example the program answers the phone as it was a normal softphone and you had pressed the Pick Up button. This means that you can talk to the caller after the call is accepted.

Auto answering systems are usually used for answering machines or IVR (interactive voice response) servers or call center servers instead of a simple softphone that accepts the call instead of you. If you want to use auto answering for those purposes, you will need to modify the CallStateChanged method that defines the operations in case of an accepted call. In that method you can, for example, specify an audio file to be played or any other process you want to implement.

This article introduced you the auto answer technology and showed how Ozeki VoIP SIP SDK can help you integrate this functionality into your softphone. If you have read through this page carefully, you already have all the knowledge you need to start your own solution.

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

You can select a suitable Ozeki VoIP SIP SDK for building your softphone on Pricing and licensing information page

Related Pages

Operating system: Windows 8, Windows 7, Vista, 200x, XP
Development environment: Visual Studio 2010 (Recommended), Visual Studio 2008, Visual Studio 2005
Programming language: C#.NET
Supported .NET framework: .NET Framework 4.5, .NET Framework 4.0, .NET Framework 3.5 SP1
Software development kit: OZEKI VoIP SIP SDK (Download)
VoIP connection: 1 SIP account
System memory: 512 MB+
Free disk space: 100 MB+