Creating Do Not Disturb (DND) using C# to improve your VoIP PBX

Rajnarayan
Posted by in C# category on for Intermediate level | Points: 250 | Views : 1723 red flag
Rating: 4 out of 5  
 1 vote(s)

This short article is meant to be a great explanation on how to create Do Not Disturb (DND) functionality in C# to make your PBX more effective. This solution is a nothing more than a simple console application operating as a softphone that works as an ’unavailable SIP extension’. DND feature prevents this SIP extension from ringing.


 Download source code for Creating Do Not Disturb (DND) using C# to improve your VoIP PBX

This short article is meant to be a great explanation on how to create Do Not Disturb (DND) functionality in C# to make your PBX more effective. This solution is a nothing more than a simple console application operating as a softphone that works as an ’unavailable SIP extension’. DND feature prevents this SIP extension from ringing.

Contents


I. About the technology
I.1. What is Do Not Disturb (DND)
II. C# development
II.1. Configuration steps
II.2. Implementation of the Console application
II.3. Test call
Summary
References 



I. About the technology


In the age Voice Over IP (VoIP) Internet-based communication provides many smart ways for improving corporate telephone systems. In addition to the lower costs, it offers increased functionality. The feature set of a VoIP PBX can contain call conferencing, call forwarding, call holding, click-to-dialing, call cerording, voicemail, call monitoring, etc. Do Not Disturb feature can be also configured. This article focuses on the programming of this functionality that allows you to ignore phone call if you are busy.
 
 

Figure 1: Do Not Disturb warning




I.1. What is Do Not Disturb (DND)


Quoting the highly respected VoIP-Info.org, „Do Not Disturb or DND functionality is the ability of a phone or client to ignore any incoming calls.” The implementation of this functionality can vary:

  • Ringer Off or Ringer Mute: In this case the call rings normally but does not alert the user. 
  • Busy Mode: In this mode the phone is taken off-hook or sends a signal to the PBX stating it is busy, and not available for calls.
  • Mixed Mode: This mode can be used to not be disturbed by everyday calls, but get notified about priority calls. When there is a normal incoming call, it is handled by the Ringer Off or Busy Mode rules. Other users have the ability to mark a call as Priority, bypassing the DND mode and forcing the extension to ring.

There are some special configurations combining DND with other features such as call forwarding or voicemail. It provides a great way to avoid any missed calls, since they will be accepted by an another phone or the voicemail service.




II. C# development


The rest of the article will present how to implement a Do Not Disturb feature. The SIP-based console application that will be presented below works as a softphone on which the DND mode is enabled. This application can ignore incoming calls according to the busy mode (it sends a signal to the PBX stating it is busy). 




II.1. Configuration steps


In order to implement this Do Not Disturb feature, first of all, make your system ready for the project.

  1. Open your development environment (such as Microsoft Visual Studio 2012)
  2. Create a new project for creating an application with a Windows Forms user interface
  3. Make sure that .NET Framework 4.0 is installed on your PC and that this is the target framework in your IDE
  4. Add the Ozeki VoIPSDK.dll file to your references
  5. For registering your console application as a SIP extension, install an IP PBX. 
  6. To be able to test your application, you will need an additional VoIP phone (desktop or softphone) to make a test call.

If you miss any of the software listed above, you can obtain them from the following places for free:




II.2. Implementation of the Console application


To implement this Do Not Disturb software, you only need one class: Program.cs. Let’s see step-by-step how to create it.

First of all, add the necessary using lines:

using System;
using Ozeki.VoIP;
using Ozeki.VoIP.SDK;
Code 1: The necessary using lines


Concerning that this console application will function as a „virtual softphone”, there is a need for implementing the background of a softphone application. Its first step is creating the necessary softphone and phoneline objects:

static ISoftPhone softphone;
static IPhoneLine phoneLine;
static IPhoneCall call;
Code 2: The necessary objects


Therafter, take a closer look at the Main method. In this method you need to create a softphone object with RTP port range. (The 5000 and 10000 parameters determine the port interval.) Here there is also a need for creating a new SIP account to be able to register the application to your PBX. For this purpose you need to set the followings:

  • registration required (true)
  • display name (710)
  • user name (710)
  • authentication ID (710)
  • register password (710)
  • domain host (192.168.115.100 - IP address of the PBX)
  • domain port (5060 - port number of the PBX)

According to this configuration, the Do Not Disturb feature will be enabled on the numbered 710 SIP account. (This account should be also registered in your PBX.)

Furthermore, the RegisterAccount is used to send the SIP registration request to the PBX, and the Console.Readline will prevent the termination of the application.

private static void Main(string[] args)
{
    softphone = SoftPhoneFactory.CreateSoftPhone(5000, 10000);

    var registrationRequired = true;
    var userName = "710";
    var displayName = "710";
    var authenticationId = "710";
    var registerPassword = "710";
    var domainHost = "192.168.115.100";
    var domainPort = 5060;

    var account = new SIPAccount(registrationRequired, displayName, userName, authenticationId, registerPassword, domainHost, domainPort);

    RegisterAccount(account);

    Console.ReadLine();
}
Code 3: Code for creating a new SIP account


The RegisterAccount can be used to register the SIP account to the PBX. In addition, there is also a need to create the phone line to be able to communicate with the PBX. The RegisterPhoneLine can be used to register it. If you set in this section the DoNotDisturb to „true”, the Do Not Disturb feature will be enabled for the previously specified SIP account.

static void RegisterAccount(SIPAccount account)
{
    try
    {
        phoneLine = softphone.CreatePhoneLine(account);
        phoneLine.DoNotDisturb = true;
        phoneLine.RegistrationStateChanged += line_RegStateChanged;
        softphone.IncomingCall += softphone_IncomingCall;
        softphone.RegisterPhoneLine(phoneLine);
    }
    catch (Exception ex)
    {
        Console.WriteLine("Error during SIP registration: " + ex);
    }
}
Code 4: Code for registering the SIP account


The following code is responsible for indicating the state of the registration procedure. If the registration was successful, the „Registration succeeded – Online!” message will appear in the console. Otherwise the „Registration succeeded – Online!” message will be displayed.

static void line_RegStateChanged(object sender, RegistrationStateChangedArgs e)
{
    if (e.State == RegState.NotRegistered || e.State == RegState.Error)
        Console.WriteLine("Registration failed!");

    if (e.State == RegState.RegistrationSucceeded)
        Console.WriteLine("Registration succeeded - Online!");
}
Code 5: Code for displaying the state of the registration procedure


If there is an incoming call (that is another phone calls the DND-enabled SIP extension, the following method will be called. In order to get notified about the state of the call, you need to subscribe to the proper event:

static void softphone_IncomingCall(object sender, VoIPEventArgs e)
{
    call = e.Item;
    call.CallStateChanged += call_CallStateChanged;
}

Code 6: Handling the incoming calls


And last but not least, the following code is responsible for indicating the state of the calls:

static void call_CallStateChanged(object sender, CallStateChangedArgs e)
{
    Console.WriteLine("Call state: {0}.", e.State);
}
Code 7: Code for displaying the state of the calls




II.3. Test call


After finishing the implementation of the program, let’s start debugging by pressing F5. As it was mentioned above, you need to create the same SIP account in your PBX that you have specified for this console application (Code 3). After this, thee „Registration succeeded – Online!” message will appear in the console:




Figure 2: The registration of the SIP account was successful


To make a test call, launch a VoIP phone that has been registered previously to the PBX and dial the telephone number of the DND-enabled SIP account. Below you can see that I have registered a softphone (numbered 720) to my PBX and I dialled „710” that is the phone number of the virtual softphone with DND feature.




Figure 3: A test call is established by using a SIP softphone (Source: Self-made)


It is as easy as that! :-) Do not hesitate to add DND to your communication system. Congratulations for your job!



Summary


Hope you found this article useful and meaningful. This tutorial provided a complete solution related to implementing Do Not Disturb (DND) feature using C#. Due to this application, you can enable DND mode on your VoIP phone, therefore you can ignore calls (that is set budy mode automatically) if busy and unabe to accept the call. This solution can be improved by combining DND with voicemail or call forwarding.



References 




Page copy protected against web site content infringement by Copyscape

About the Author

Rajnarayan
Full Name: Rajesh Narayan
Member Level: Starter
Member Status: Member
Member Since: 2/2/2015 4:47:17 AM
Country: India



Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)