Click here to Skip to main content
15,891,204 members
Articles / Programming Languages / C#

How to develop a call queue with periodically played informational messages in C# for improving your VoIP PBX

Rate me:
Please Sign up or sign in to vote.
4.75/5 (6 votes)
22 Jul 2014CPOL8 min read 26.3K   1.3K   18  
It explains how to create a virtual call queue extension in your C# IP PBX in order to make your Automatic Call Distribution (ACD) system more effective.
using System.Collections.Generic;
using Ozeki.VoIP;
using Ozeki.VoIP.PBX;
using Ozeki.VoIP.PBX.Extensions;
using Ozeki.VoIP.PBX.Services;

namespace MyPBX.CallQueue
{
    class CallQueueExtension : IExtension
    {
        IExtensionContainer extensionContainer;
        IPBXCallFactory callFactory;
        List<CallQueueCallHandler> callHandlers;
        ICallManager callManager;
        List<string> members;
        object sync;

        public CallQueueExtension(string extensionId, IExtensionContainer extensionContainer, IPBXCallFactory callFactory, ICallManager callManager, List<string> members)
        {
            sync = new object();
            callHandlers = new List<CallQueueCallHandler>();
            Account = new Account(extensionId, extensionId, "ozekiphone.com");
            this.extensionContainer = extensionContainer;
            this.callFactory = callFactory;
            this.callManager = callManager;

            this.members = members;
        }
        public Account Account { get; private set; }

        public Ozeki.VoIP.PBX.PhoneCalls.ISIPCall OnCalled(Ozeki.VoIP.PBX.PhoneCalls.RouteInfo callInfo)
        {
            lock (sync)
            {
                var call = callFactory.CreateIncomingPBXCall(this, SRTPMode.None);

                var callQueueHandler = new CallQueueCallHandler(call, callManager, extensionContainer, members);
                callQueueHandler.Completed += CallHandlerCompleted;
                callHandlers.Add(callQueueHandler);

                if (callHandlers.Count == 1)
                {
                    callQueueHandler.Start();
                }

                return call;
            }
           
        }

        void CallHandlerCompleted(object sender, System.EventArgs e)
        {
            lock (sync)
            {
                var callHandler = (CallQueueCallHandler)sender;

                if (callHandlers[0] == callHandler)
                {
                    callHandlers.Remove(callHandler);

                    if (callHandlers.Count >= 1)
                    {
                        var nextCallHandler = callHandlers[0];
                        nextCallHandler.Start();
                    }
                }
                else
                {
                    callHandlers.Remove(callHandler);
                }
            }
        }

        public void SendMessage(Ozeki.VoIP.PBX.Message message)
        {
        }

        public string Type
        {
            get { return "CallQueue"; }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions