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; } } } }