public void SendMessageWaitingNotification(Guid extensionID)
        {
            WOSI.CallButler.Data.CallButlerDataset.ExtensionsRow extension = dataProvider.GetExtension(Properties.Settings.Default.CustomerID, extensionID);

            if (extension != null)
            {
                SendMessageWaitingNotification(extension);
            }
        }
        public void CreateVoicemail(Guid voicemailID, Guid extensionID, string callerDisplayName, string callerHost, string callerUsername)
        {
            // Get our extension
            WOSI.CallButler.Data.CallButlerDataset.ExtensionsRow extension = dataProvider.GetExtension(Properties.Settings.Default.CustomerID, extensionID);

            if (extension != null)
            {
                // Create a new voicemail record
                WOSI.CallButler.Data.CallButlerDataset.VoicemailsDataTable voicemailsTable = new WOSI.CallButler.Data.CallButlerDataset.VoicemailsDataTable();
                WOSI.CallButler.Data.CallButlerDataset.VoicemailsRow       voicemail       = voicemailsTable.NewVoicemailsRow();
                voicemail.CallerDisplayName = callerDisplayName;
                voicemail.CallerHost        = callerHost;
                voicemail.CallerUsername    = callerUsername;
                voicemail.ExtensionID       = extensionID;
                voicemail.VoicemailID       = voicemailID;
                voicemail.Timestamp         = DateTime.Now;
                voicemailsTable.AddVoicemailsRow(voicemail);

                dataProvider.PersistVoicemail(voicemail);

                // Run the voicemail through any VM plugins
                CallButler.Service.Plugin.CallButlerVoicemailHandlerPlugin[] vmHandlers = pluginManager.GetAllPluginsOfType <CallButler.Service.Plugin.CallButlerVoicemailHandlerPlugin>();
                foreach (CallButler.Service.Plugin.CallButlerVoicemailHandlerPlugin vmHandler in vmHandlers)
                {
                    try
                    {
                        vmHandler.OnNewVoicemail(voicemail.CallerDisplayName, voicemail.CallerHost, voicemail.ExtensionID.ToString(), voicemail.VoicemailID.ToString(), WOSI.Utilities.FileUtils.GetApplicationRelativePath(Properties.Settings.Default.VoicemailRootDirectory) + "\\" + voicemail.ExtensionID.ToString() + "\\" + voicemail.VoicemailID.ToString() + ".snd");
                    }
                    catch (Exception e)
                    {
                        LoggingService.AddLogEntry(WOSI.CallButler.ManagementInterface.LogLevel.ErrorsOnly, string.Format("Voicemail Handler Plugin Failed\r\n\r\n{0} ({1})\r\n\r\n{2}", vmHandler.PluginName, vmHandler.PluginID.ToString(), e.Message), true);
                    }
                }

                // Queue our voicemail Email
                vmMailerService.QueueVoicemailEmail(extension, voicemail);

                // Notify the any PBX phones of a new message
                if (registrarService != null)
                {
                    registrarService.SendMessageWaitingNotification(extension.ExtensionNumber);
                }

                // Notify anyone else of the new message
                WOSI.Utilities.EventUtils.FireAsyncEvent(NewVoicemail, this, new VoicemailEventArgs(voicemail));
            }
        }
Beispiel #3
0
        protected override void OnExternalCommand(string command, string commandData, string eventToken, TelecomScriptInterface tsInterface, CallButler.Telecom.TelecomProviderBase telecomProvider, WOSI.CallButler.Data.DataProviders.CallButlerDataProviderBase dataProvider)
        {
            // Parse out our external event action
            if (Enum.IsDefined(typeof(StandardExternalCommands), command))
            {
                StandardExternalCommands externalCommand = WOSI.Utilities.EnumUtils <StandardExternalCommands> .Parse(command);

                switch (externalCommand)
                {
                case StandardExternalCommands.CALLBUTLERINTERNAL_ChooseLanguage:
                {
                    if (!Properties.Settings.Default.Multilingual)
                    {
                        tsInterface.IMLInterpreter.SignalExternalEvent(StandardExternalEvents.CALLBUTLERINTERNAL_NotMultilingual.ToString());
                    }
                    else
                    {
                        tsInterface.IMLInterpreter.SignalEventCallback(eventToken);
                    }
                    break;
                }

                case StandardExternalCommands.CALLBUTLERINTERNAL_SetLanguageID:
                {
                    List <string> languages = new List <string>();
                    languages.Add(Properties.Settings.Default.DefaultLanguage);
                    languages.AddRange(Properties.Settings.Default.Languages.Split(';'));

                    int languageNumber = Convert.ToInt32(commandData);

                    if (languageNumber > 0 && languageNumber <= languages.Count)
                    {
                        // Set our language ID variable
                        tsInterface.IMLInterpreter.SetLocalVariable("LanguageID", languages[languageNumber - 1]);
                        tsInterface.IMLInterpreter.SignalEventCallback(eventToken);
                    }
                    else
                    {
                        tsInterface.IMLInterpreter.SignalExternalEvent(StandardExternalEvents.CALLBUTLERINTERNAL_InvalidLanguage.ToString());
                    }

                    break;
                }

                case StandardExternalCommands.CALLBUTLERINTERNAL_ProcessMainMenuOption:
                {
                    WOSI.CallButler.Data.CallButlerDataset.DepartmentsDataTable departments = dataProvider.GetDepartments(Properties.Settings.Default.CustomerID);

                    WOSI.CallButler.Data.CallButlerDataset.DepartmentsRow[] choosenDepartments = (WOSI.CallButler.Data.CallButlerDataset.DepartmentsRow[])departments.Select("OptionNumber = " + commandData);

                    if (choosenDepartments.Length > 0)
                    {
                        WOSI.CallButler.Data.CallButlerDataset.DepartmentsRow choosenDepartment = choosenDepartments[0];

                        switch (choosenDepartment.Type)
                        {
                        case (short)WOSI.CallButler.Data.DepartmentTypes.Greeting:
                            tsInterface.IMLInterpreter.SetLocalVariable("MainMenuOptionGreetingID", choosenDepartment.DepartmentID.ToString());
                            tsInterface.IMLInterpreter.SignalExternalEvent(StandardExternalEvents.CALLBUTLERINTERNAL_GreetingMenuOption.ToString());
                            break;

                        case (short)WOSI.CallButler.Data.DepartmentTypes.Extension:

                            // Find our extension number
                            try
                            {
                                WOSI.CallButler.Data.CallButlerDataset.ExtensionsRow extension = dataProvider.GetExtension(Properties.Settings.Default.CustomerID, new Guid(choosenDepartment.Data1));

                                if (extension != null)
                                {
                                    tsInterface.IMLInterpreter.SetLocalVariable("Extension", extension.ExtensionNumber.ToString());
                                }
                            }
                            catch
                            {
                            }

                            tsInterface.IMLInterpreter.SignalExternalEvent(StandardExternalEvents.CALLBUTLERINTERNAL_ExtensionMenuOption.ToString());
                            break;

                        case (short)WOSI.CallButler.Data.DepartmentTypes.Script:
                            tsInterface.IMLInterpreter.SetLocalVariable("CustomScriptPath", choosenDepartment.Data1);
                            tsInterface.IMLInterpreter.SignalExternalEvent(StandardExternalEvents.CALLBUTLERINTERNAL_ScriptMenuOption.ToString());

                            break;

                        case (short)WOSI.CallButler.Data.DepartmentTypes.Number:
                            tsInterface.IMLInterpreter.SetLocalVariable("TransferToNumber", choosenDepartment.Data1);
                            tsInterface.IMLInterpreter.SignalExternalEvent(StandardExternalEvents.CALLBUTLERINTERNAL_NumberTransferMenuOption.ToString());

                            break;

                        case (short)WOSI.CallButler.Data.DepartmentTypes.Module:
                            tsInterface.IMLInterpreter.SetLocalVariable("AddonModuleID", choosenDepartment.Data1);
                            tsInterface.IMLInterpreter.SignalExternalEvent(StandardExternalEvents.CALLBUTLERINTERNAL_AddonModuleMenuOption.ToString());

                            break;
                        }
                    }
                    else
                    {
                        tsInterface.IMLInterpreter.SignalExternalEvent(StandardExternalEvents.CALLBUTLERINTERNAL_InvalidMenuOption.ToString());
                    }

                    break;
                }

                case StandardExternalCommands.CALLBUTLERINTERNAL_DialByNameSearch:

                    // Find our extensions for this search string
                    WOSI.CallButler.Data.CallButlerDataset.ExtensionsDataTable extensions = dataProvider.GetExtensions(Properties.Settings.Default.CustomerID);

                    WOSI.CallButler.Data.CallButlerDataset.ExtensionsRow[] matchingExtensions = (WOSI.CallButler.Data.CallButlerDataset.ExtensionsRow[])extensions.Select("SearchNumber LIKE '" + commandData + "*' AND EnableSearch = True");

                    // Get our extension search index
                    int searchIndex = Convert.ToInt32(tsInterface.IMLInterpreter.GetLocalVariable("ExtensionSearchIndex"));
                    searchIndex++;

                    if (matchingExtensions.Length > 0 && searchIndex < matchingExtensions.Length)
                    {
                        tsInterface.IMLInterpreter.SetLocalVariable("Extension", matchingExtensions[searchIndex].ExtensionNumber.ToString());
                        tsInterface.IMLInterpreter.SetLocalVariable("ExtensionName", matchingExtensions[searchIndex].FirstName + " " + matchingExtensions[searchIndex].LastName);
                        tsInterface.IMLInterpreter.SetLocalVariable("ExtensionSearchIndex", searchIndex.ToString());
                    }
                    else
                    {
                        tsInterface.IMLInterpreter.SignalExternalEvent(StandardExternalEvents.CALLBUTLERINTERNAL_ExtensionNotFound.ToString());
                    }

                    tsInterface.IMLInterpreter.SignalEventCallback(eventToken);

                    break;

                case StandardExternalCommands.CALLBUTLERINTERNAL_VoicemailManagement:
                {
                    try
                    {
                        WOSI.CallButler.Data.CallButlerDataset.ExtensionsRow extension = dataProvider.GetExtensionNumber(Properties.Settings.Default.CustomerID, Convert.ToInt32(tsInterface.IMLInterpreter.GetLocalVariable("Extension")));

                        if (extension != null)
                        {
                            tsInterface.ScriptProcessor = new VoicemailManagementScriptProcessor(extension, pbxRegistrar);
                            tsInterface.ScriptProcessor.StartProcessing(tsInterface, telecomProvider, dataProvider);

                            break;
                        }
                    }
                    catch
                    {
                    }

                    tsInterface.IMLInterpreter.SignalTransferFailure();

                    break;
                }

                    /*case StandardExternalCommands.CALLBUTLERINTERNAL_StartAddonModule:
                     *  {
                     *      CallButler.Service.Plugin.CallButlerAddonModulePlugin[] addonModules = pluginManager.GetAllPluginsOfType<CallButler.Service.Plugin.CallButlerAddonModulePlugin>();
                     *
                     *      foreach (CallButler.Service.Plugin.CallButlerAddonModulePlugin addonModule in addonModules)
                     *      {
                     *          if (addonModule.PluginID.ToString() == commandData)
                     *          {
                     *              try
                     *              {
                     *                  // Make sure the module is licensed
                     *                  if (!addonModule.IsLicensed)
                     *                      break;
                     *
                     *                  // We found our module and we should load the script it uses
                     *                  tsInterface.ScriptProcessor = new AddonModuleScriptProcessor(addonModule);
                     *                  tsInterface.ScriptProcessor.StartProcessing(tsInterface, telecomProvider, dataProvider);
                     *                  return;
                     *
                     *              }
                     *              catch (Exception e)
                     *              {
                     *                  LoggingService.AddLogEntry(WOSI.CallButler.ManagementInterface.LogLevel.ErrorsOnly, "Failed to load Addon-Module '" + addonModule.PluginName + "'\r\n\r\n" + e.Message + "\r\n\r\n" + e.StackTrace, true);
                     *              }
                     *          }
                     *      }
                     *
                     *      tsInterface.ScriptProcessor = this;
                     *      tsInterface.IMLInterpreter.SignalExternalEvent(StandardExternalEvents.CALLBUTLERINTERNAL_AddonModuleFailed.ToString());
                     *
                     *      break;
                     *  }*/
                }
            }
        }
Beispiel #4
0
        public static bool ProcessPersonalizedGreeting(WOSI.CallButler.Data.DataProviders.CallButlerDataProviderBase dataProvider, ref WOSI.IVR.IML.Classes.ScriptPage scriptPage, int customerID, string callerDisplayName, string callerPhoneNumber, string callerHost, string dialedPhoneNumber)
        {
            // Loop through our personalized greetings and see if we can find one that matches our caller
            WOSI.CallButler.Data.CallButlerDataset.PersonalizedGreetingsDataTable personalGreetings    = dataProvider.GetPersonalizedGreetings(customerID);
            WOSI.CallButler.Data.CallButlerDataset.PersonalizedGreetingsRow       personalizedGreeting = null;

            foreach (WOSI.CallButler.Data.CallButlerDataset.PersonalizedGreetingsRow pgRow in personalGreetings)
            {
                string matchExpression = "";

                // Try our dialed number first
                if (pgRow.DialedUsername.Length > 0)
                {
                    if (!pgRow.UseRegex)
                    {
                        matchExpression = pgRow.DialedUsername.Replace("*", ".*");
                    }
                    else
                    {
                        matchExpression = pgRow.DialedUsername;
                    }

                    if (Regex.IsMatch(dialedPhoneNumber, matchExpression, RegexOptions.IgnoreCase))
                    {
                        personalizedGreeting = pgRow;
                        break;
                    }
                }

                // Next try our caller username/phone number
                if (pgRow.CallerUsername.Length > 0)
                {
                    if (!pgRow.UseRegex)
                    {
                        matchExpression = pgRow.CallerUsername.Replace("*", ".*");
                    }
                    else
                    {
                        matchExpression = pgRow.CallerUsername;
                    }

                    // First find by the caller number
                    if (Regex.IsMatch(callerPhoneNumber, matchExpression, RegexOptions.IgnoreCase))
                    {
                        personalizedGreeting = pgRow;
                        break;
                    }
                }

                // Next try the host
                if (pgRow.CallerHost.Length > 0)
                {
                    if (!pgRow.UseRegex)
                    {
                        matchExpression = pgRow.CallerHost.Replace("*", ".*");
                    }
                    else
                    {
                        matchExpression = pgRow.CallerHost;
                    }

                    if (Regex.IsMatch(callerHost, matchExpression, RegexOptions.IgnoreCase))
                    {
                        personalizedGreeting = pgRow;
                        break;
                    }
                }

                // Next try the caller id/name
                if (pgRow.CallerDisplayName.Length > 0)
                {
                    if (!pgRow.UseRegex)
                    {
                        matchExpression = pgRow.CallerDisplayName.Replace("*", ".*");
                    }
                    else
                    {
                        matchExpression = pgRow.CallerDisplayName;
                    }

                    if (Regex.IsMatch(callerDisplayName, matchExpression, RegexOptions.IgnoreCase))
                    {
                        personalizedGreeting = pgRow;
                        break;
                    }
                }
            }

            // If we have a personalized greeting, tell the interpreter to play it
            if (personalizedGreeting != null && (!personalizedGreeting.PlayOnce || (personalizedGreeting.PlayOnce && !personalizedGreeting.HasPlayed)))
            {
                scriptPage.Actions.Add(ScriptUtils.CreateGreetingExternalAction(personalizedGreeting.PersonalizedGreetingID));

                switch (personalizedGreeting.Type)
                {
                case (short)WOSI.CallButler.Data.PersonalizedGreetingType.CustomScript:
                    GotoPage gotoCustomScript = new GotoPage();
                    gotoCustomScript.Location = personalizedGreeting.Data;
                    scriptPage.Actions.Add(gotoCustomScript);
                    break;

                case (short)WOSI.CallButler.Data.PersonalizedGreetingType.Hangup:
                    scriptPage.Actions.Add(new HangupCall());
                    break;

                case (short)WOSI.CallButler.Data.PersonalizedGreetingType.SendToExtension:
                    // Get the proper extension
                    WOSI.CallButler.Data.CallButlerDataset.ExtensionsRow extension = dataProvider.GetExtension(customerID, new Guid(personalizedGreeting.Data));

                    if (extension != null)
                    {
                        TransferCall transferCall = new TransferCall();
                        transferCall.TransferTo  = extension.ExtensionNumber.ToString();
                        transferCall.IsExtension = true;

                        scriptPage.Actions.Add(transferCall);
                    }

                    break;

                case (short)WOSI.CallButler.Data.PersonalizedGreetingType.Module:

                    ExternalAction moduleAction = new ExternalAction();

                    moduleAction.Async         = false;
                    moduleAction.Action        = BaseExternalCommands.CALLBUTLERINTERNAL_StartAddonModule.ToString();
                    moduleAction.ParameterData = personalizedGreeting.Data;

                    scriptPage.Actions.Add(moduleAction);

                    break;
                }

                if (personalizedGreeting.PlayOnce)
                {
                    personalizedGreeting.HasPlayed = true;
                    dataProvider.PersistPersonalizedGreeting(personalizedGreeting);
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
        protected override void OnExternalCommand(string command, string commandData, string eventToken, TelecomScriptInterface tsInterface, CallButler.Telecom.TelecomProviderBase telecomProvider, WOSI.CallButler.Data.DataProviders.CallButlerDataProviderBase dataProvider)
        {
            // Parse out our external event action
            if (Enum.IsDefined(typeof(ExtensionExternalCommands), command))
            {
                ExtensionExternalCommands externalCommand = WOSI.Utilities.EnumUtils <ExtensionExternalCommands> .Parse(command);

                switch (externalCommand)
                {
                case ExtensionExternalCommands.CALLBUTLERINTERNAL_ForwardCall:
                {
                    onholdTsInterface.IMLInterpreter.SetLocalVariable("TransferNumber", commandData);
                    onholdTsInterface.IMLInterpreter.SignalExternalEvent(VoicemailExternalEvents.CALLBUTLERINTERNAL_CallForwarded.ToString());

                    break;
                }

                case ExtensionExternalCommands.CALLBUTLERINTERNAL_ConfirmingTransfer:
                {
                    if (disableCallScreening || !extension.EnableCallScreening)
                    {
                        tsInterface.IMLInterpreter.SignalExternalEvent(ExtensionExternalEvents.CALLBUTLERINTERNAL_SkipConfirmation.ToString());
                    }
                    else
                    {
                        tsInterface.IMLInterpreter.SignalEventCallback(eventToken);
                    }

                    break;
                }

                case ExtensionExternalCommands.CALLBUTLERINTERNAL_GetNextNumber:
                {
                    string callerID     = onholdTsInterface.IMLInterpreter.CallerDisplayName;
                    string callerNumber = onholdTsInterface.IMLInterpreter.CallerUsername;

                    if (callerID == null || callerID.Length == 0)
                    {
                        callerID = "Unknown Caller";
                    }

                    if (callerNumber == null || callerNumber.Length == 0)
                    {
                        callerNumber = "";
                    }

                    // If we have a previous call, end it
                    if (telecomProvider.IsLineInUse(tsInterface.LineNumber))
                    {
                        telecomProvider.EndCall(tsInterface.LineNumber);
                    }
                    else
                    {
                        // Get our extension contact numbers
                        List <WOSI.CallButler.Data.CallButlerDataset.ExtensionContactNumbersRow> contactNumbers = new List <WOSI.CallButler.Data.CallButlerDataset.ExtensionContactNumbersRow>((WOSI.CallButler.Data.CallButlerDataset.ExtensionContactNumbersRow[])dataProvider.GetExtensionContactNumbers(extension.ExtensionID).Select("", "Priority ASC"));

                        if (extensionNumberIndex + 1 >= contactNumbers.Count && parentExtension != null)
                        {
                            extensionNumberIndex = parentExtensionIndex;
                            parentExtensionIndex = -1;

                            extension       = parentExtension;
                            parentExtension = null;

                            contactNumbers.Clear();
                            contactNumbers.AddRange((WOSI.CallButler.Data.CallButlerDataset.ExtensionContactNumbersRow[])dataProvider.GetExtensionContactNumbers(extension.ExtensionID).Select("", "Priority ASC"));
                        }

                        extensionNumberIndex++;

                        List <string> callBlastNumbers  = new List <string>();
                        List <string> callBlastProfiles = new List <string>();
                        int           callBlastTimeout  = Properties.Settings.Default.CallBlastTimeout;

                        while (extensionNumberIndex < contactNumbers.Count)
                        {
                            WOSI.CallButler.Data.CallButlerDataset.ExtensionContactNumbersRow contactNumber = contactNumbers[extensionNumberIndex];

                            // Is the number online?
                            if (contactNumber.Online)
                            {
                                // Does the number have hours?
                                TimeSpan utcOffset = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now);

                                if (!contactNumber.IsHoursOfOperationUTCOffsetNull())
                                {
                                    utcOffset = contactNumber.HoursOfOperationUTCOffset;
                                }

                                if (!contactNumber.HasHoursOfOperation || (contactNumber.HasHoursOfOperation && ScriptUtils.IsInHoursOfOperation(contactNumber.HoursOfOperation, utcOffset)))
                                {
                                    // Check to see if this number is a PBX IP line
                                    if ((contactNumber.CallPBXPhone || (WOSI.CallButler.Data.ExtensionContactNumberType)contactNumber.Type == WOSI.CallButler.Data.ExtensionContactNumberType.IPPhone) && registrarService != null)
                                    {
                                        int extNumber = extension.ExtensionNumber;

                                        // If this was filled in from another extension, we'll need to check the status of that extension
                                        if (contactNumber.ExtensionID != extension.ExtensionID)
                                        {
                                            WOSI.CallButler.Data.CallButlerDataset.ExtensionsRow tmpExtension = dataProvider.GetExtension(Properties.Settings.Default.CustomerID, contactNumber.ExtensionID);

                                            if (tmpExtension != null)
                                            {
                                                extNumber = tmpExtension.ExtensionNumber;
                                            }
                                        }

                                        // Check to see if this pbx phone is online
                                        PBXPresenceInfo[] presInfos = registrarService.GetPresenceInfoForExtension(extNumber);

                                        if (presInfos != null && presInfos.Length > 0)
                                        {
                                            foreach (PBXPresenceInfo presInfo in presInfos)
                                            {
                                                if (presInfo.Status == PBXPresenceStatus.Online)
                                                {
                                                    if (presInfos.Length > 1 || extension.UseCallBlast)
                                                    {
                                                        if (contactNumbers.Count == 1)
                                                        {
                                                            callBlastTimeout = contactNumber.Timeout;
                                                        }

                                                        string callBlastNumber = string.Format("sip:{0}@{1}:{2}", presInfo.ExtensionNumber, presInfo.RemoteAddress, presInfo.RemotePort);

                                                        if (!callBlastNumbers.Contains(callBlastNumber))
                                                        {
                                                            callBlastNumbers.Add(callBlastNumber);
                                                            callBlastProfiles.Add(TelecomScriptInterface.InternalProviderProfileName);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        TryContactNumber(tsInterface, string.Format("sip:{0}@{1}:{2}", presInfo.ExtensionNumber, presInfo.RemoteAddress, presInfo.RemotePort), callerID, callerNumber, TelecomScriptInterface.InternalProviderProfileName, contactNumber.Timeout.ToString(), eventToken);
                                                        return;
                                                    }
                                                }
                                            }

                                            if (!extension.UseCallBlast && callBlastNumbers.Count > 0)
                                            {
                                                break;
                                            }
                                        }
                                    }
                                    else if ((WOSI.CallButler.Data.ExtensionContactNumberType)contactNumber.Type == WOSI.CallButler.Data.ExtensionContactNumberType.TelephoneNumber)
                                    {
                                        if (extension.UseCallBlast)
                                        {
                                            if (!callBlastNumbers.Contains(contactNumber.ContactNumber))
                                            {
                                                callBlastNumbers.Add(contactNumber.ContactNumber);
                                                callBlastProfiles.Add("");
                                            }
                                        }
                                        else
                                        {
                                            TryContactNumber(tsInterface, contactNumber.ContactNumber, callerID, callerNumber, "", contactNumber.Timeout.ToString(), eventToken);
                                            return;
                                        }
                                    }
                                    else if ((WOSI.CallButler.Data.ExtensionContactNumberType)contactNumber.Type == WOSI.CallButler.Data.ExtensionContactNumberType.Extension && parentExtension == null)
                                    {
                                        try
                                        {
                                            // Get our new extension
                                            WOSI.CallButler.Data.CallButlerDataset.ExtensionsRow newExtension = dataProvider.GetExtension(Properties.Settings.Default.CustomerID, new Guid(contactNumber.ContactNumber));

                                            if (newExtension != null)
                                            {
                                                if (extension.UseCallBlast)
                                                {
                                                    WOSI.CallButler.Data.CallButlerDataset.ExtensionContactNumbersRow[] newContacts = (WOSI.CallButler.Data.CallButlerDataset.ExtensionContactNumbersRow[])dataProvider.GetExtensionContactNumbers(newExtension.ExtensionID).Select("Type <> " + (int)WOSI.CallButler.Data.ExtensionContactNumberType.Extension, "Priority ASC");
                                                    contactNumbers.AddRange(newContacts);
                                                }
                                                else
                                                {
                                                    parentExtension      = extension;
                                                    parentExtensionIndex = extensionNumberIndex;

                                                    extensionNumberIndex = -1;
                                                    extension            = newExtension;

                                                    tsInterface.IMLInterpreter.SignalExternalEvent(ExtensionExternalEvents.CALLBUTLERINTERNAL_GetNextNumber.ToString());
                                                    return;
                                                }
                                            }
                                        }
                                        catch
                                        {
                                        }
                                    }
                                }
                            }

                            extensionNumberIndex++;
                        }

                        if (callBlastNumbers.Count > 0)
                        {
                            TryCallBlast(telecomProvider, tsInterface, callBlastNumbers.ToArray(), callBlastProfiles.ToArray(), callerID, callerNumber, callBlastTimeout.ToString());
                            return;
                        }
                        else
                        {
                            tsInterface.IMLInterpreter.SignalExternalEvent(ExtensionExternalEvents.CALLBUTLERINTERNAL_NoMoreNumbers.ToString());
                        }
                    }

                    break;
                }

                case ExtensionExternalCommands.CALLBUTLERINTERNAL_SendToVoicemail:
                {
                    onholdTsInterface.IMLInterpreter.SyncExternalAction -= IMLInterpreter_SyncExternalAction;

                    // Allow this line to answer calls again
                    tsInterface.Locked = false;

                    if (telecomProvider.IsLineInUse(onholdTsInterface.LineNumber))
                    {
                        telecomProvider.SendingToVoicemail(onholdTsInterface.LineNumber);
                    }

                    onholdTsInterface.IMLInterpreter.SignalExternalEvent(VoicemailExternalEvents.CALLBUTLERINTERNAL_ExtensionNotAvailable.ToString());
                    tsInterface.IMLInterpreter.SignalEventCallback(eventToken);

                    break;
                }

                case ExtensionExternalCommands.CALLBUTLERINTERNAL_ConnectCalls:
                {
                    onholdTsInterface.IMLInterpreter.SyncExternalAction -= IMLInterpreter_SyncExternalAction;

                    onholdTsInterface.IMLInterpreter.SignalExternalEvent(ExtensionExternalCommands.CALLBUTLERINTERNAL_ConnectCalls.ToString());

                    // Allow this line to answer calls again
                    tsInterface.Locked = false;

                    if (autoConnect)
                    {
                        if (telecomProvider.IsLineInUse(tsInterface.LineNumber) && telecomProvider.IsLineInUse(onholdTsInterface.LineNumber))
                        {
                            if (extension.IsUseConferenceTransferNull() || !extension.UseConferenceTransfer /*|| !Licensing.Management.AppPermissions.StatIsPermitted("Handoff")*/)
                            {
                                telecomProvider.TransferCallAttended(onholdTsInterface.LineNumber, tsInterface.LineNumber, Properties.Settings.Default.UseBridgedTransfers);
                                tsInterface.IMLInterpreter.SignalEventCallback(eventToken);
                            }
                            else
                            {
                                telecomProvider.StopSound(tsInterface.LineNumber);
                                telecomProvider.StopSound(onholdTsInterface.LineNumber);
                                int conferenceID = telecomProvider.ConferenceLines(tsInterface.LineNumber, onholdTsInterface.LineNumber);

                                // Check to see if the person calling is an internal extension
                                if (onholdTsInterface.Extension != null)
                                {
                                    onholdTsInterface.ScriptProcessor = new TransferConferenceScriptProcessor(conferenceID, scriptService, tsInterface, registrarService, extension, vmMailerService);
                                }
                                else
                                {
                                    onholdTsInterface.ScriptProcessor = new TransferConferenceParticipantScriptProcessor(conferenceID, tsInterface, extension, vmMailerService);
                                }

                                tsInterface.ScriptProcessor = new TransferConferenceScriptProcessor(conferenceID, scriptService, onholdTsInterface, registrarService, extension, vmMailerService);

                                onholdTsInterface.ScriptProcessor.StartProcessing(onholdTsInterface, telecomProvider, dataProvider);
                                tsInterface.ScriptProcessor.StartProcessing(tsInterface, telecomProvider, dataProvider);
                            }
                        }
                        else
                        {
                            tsInterface.IMLInterpreter.SignalEventCallback(eventToken);
                        }
                    }

                    break;
                }
                }
            }
        }