public void ProcessExtensionAuthentication(PreprocessSipRequestEventArgs e)
        {
            try
            {
                SIPURI fromURI = new SIPURI(e.Request.HeaderFields["From", "f"].FieldValue);

                // Is this coming from an internal extension
                WOSI.CallButler.Data.CallButlerDataset.ExtensionsRow extension = dataProvider.GetExtensionNumber(Properties.Settings.Default.CustomerID, Convert.ToInt32(fromURI.User));

                if (extension != null)
                {
                    if (ProcessRequestAuthorization(e, fromURI, false))
                    {
                        e.Handled = false;
                    }
                    else
                    {
                        e.Handled = true;
                    }
                }
            }
            catch
            {
            }
        }
        protected override void OnStartProcessing(TelecomScriptInterface tsInterface, CallButler.Telecom.TelecomProviderBase telecomProvider, WOSI.CallButler.Data.DataProviders.CallButlerDataProviderBase dataProvider)
        {
            string scriptLocation = WOSI.Utilities.FileUtils.GetApplicationRelativePath(Properties.Settings.Default.SystemScriptsRootDirectory) + "\\Outbound Call.xml";

            if (File.Exists(scriptLocation))
            {
                IMLScript imlScript = IMLScript.OpenScript(scriptLocation);

                tsInterface.IMLInterpreter.SetLocalVariable("HoldMusicLocation", WOSI.Utilities.FileUtils.GetApplicationRelativePath(Properties.Settings.Default.HoldMusicRootDirectory));

                tsInterface.IMLInterpreter.StartScript(imlScript, WOSI.Utilities.FileUtils.GetApplicationRelativePath(Properties.Settings.Default.SystemScriptsRootDirectory));

                WOSI.CallButler.Data.CallButlerDataset.ExtensionsRow extension = dataProvider.GetExtensionNumber(Properties.Settings.Default.CustomerID, outboundExtensionNumber);

                // If the outbound ts interface is null, then this means we don't have any available lines to make outbound calls.
                // Also check to see if this extension is allowed to make outbound calls
                if (outboundTsInterface == null || (outboundExtensionNumber >= 0 && extension != null && !extension.EnableOutboundCalls))
                {
                    tsInterface.IMLInterpreter.SignalCallFailure();
                    outboundTsInterface.Locked = false;
                }
                else
                {
                    // Link to our outbound script processor and start it
                    outboundTsInterface.ScriptProcessor.LinkScriptProcessor(this);
                    outboundTsInterface.ScriptProcessor.StartProcessing(outboundTsInterface, telecomProvider, dataProvider);
                }
            }
        }
Exemplo n.º 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;
                     *  }*/
                }
            }
        }
        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(Click2CallExternalCommands), command))
            {
                Click2CallExternalCommands externalCommand = WOSI.Utilities.EnumUtils <Click2CallExternalCommands> .Parse(command);

                switch (externalCommand)
                {
                case Click2CallExternalCommands.CALLBUTLERINTERNAL_ExtensionNotAvailable:

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

                    break;

                case Click2CallExternalCommands.CALLBUTLERINTERNAL_ConnectCalls:

                    // Check to see if this is a call to another extension
                    int  extensionNumber      = 0;
                    bool disableCallScreening = callMakerExtension == null ? false : true;

                    if (int.TryParse(numberToDial, out extensionNumber))
                    {
                        // If we're calling our own extension, send us to the voicemail management menu
                        if (extensionNumber == callMakerExtension.ExtensionNumber)
                        {
                            callMakerInterface.ScriptProcessor = new VoicemailManagementScriptProcessor(callMakerExtension, scriptService.registrarService);
                            callMakerInterface.ScriptProcessor.StartProcessing(callMakerInterface, telecomProvider, dataProvider);

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

                            break;
                        }
                        else
                        {
                            WOSI.CallButler.Data.CallButlerDataset.ExtensionsRow extension = dataProvider.GetExtensionNumber(Properties.Settings.Default.CustomerID, extensionNumber);

                            if (extension != null)
                            {
                                scriptService.TransferToExtension(extensionNumber.ToString(), callMakerInterface, disableCallScreening);

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

                                break;
                            }
                        }
                    }

                    // Send the caller to main menu
                    if (numberToDial == "*")
                    {
                        scriptService.SetupAutoAttendantAnswer(callMakerInterface.LineNumber, callMakerInterface);
                        callMakerInterface.ScriptProcessor.StartProcessing(callMakerInterface, telecomProvider, dataProvider);

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

                        break;
                    }

                    // If we get here, we make an outbound call to an external number
                    if (callMakerExtension != null)
                    {
                        scriptService.MakeOutboundCall(callMakerInterface, numberToDial, string.Format("{0} {1}", callMakerExtension.FirstName, callMakerExtension.LastName), callMakerExtension.ExtensionNumber, false, true);
                    }

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

                    break;
                }

                tsInterface.IMLInterpreter.SignalEventCallback(eventToken);
            }
        }
        void telecomProvider_CallConnected(object sender, CallEventArgs e)
        {
            if (e.LineNumber == lineNumber && scriptProcessor != null)
            {
                LoggingService.AddLogEntry(LogLevel.Basic, "(Line " + e.LineNumber + ") Call Connected", false);

                callStartTime = DateTime.Now;

                // Set our language
                imlInterp.DefaultSpeechVoice = Properties.Settings.Default.DefaultTTSVoice;
                imlInterp.SetLocalVariable("LanguageID", Properties.Settings.Default.DefaultLanguage);

                // Set our volumes
                telecomProvider.SetRecordVolume(e.LineNumber, Properties.Settings.Default.RecordVolume);
                telecomProvider.SetSoundVolume(e.LineNumber, Properties.Settings.Default.SoundVolume);
                telecomProvider.SetSpeechVolume(e.LineNumber, Properties.Settings.Default.SpeechVolume);

                // Set our call info
                imlInterp.CallerDisplayName = e.CallerDisplayName;
                imlInterp.CallerHost        = e.CallerMiscInfo;
                imlInterp.CallerUsername    = e.CallerPhoneNumber;
                imlInterp.DialedUsername    = e.CallingToNumber;
                imlInterp.DialedHost        = e.CallingToMiscInfo;

                if (autoRunScript && !imlInterp.ScriptIsRunning)
                {
                    scriptProcessor.StartProcessing(this, telecomProvider, dataProvider);
                }

                imlInterp.SignalCallConnected();

                if (scriptProcessor != null)
                {
                    scriptProcessor.OnCallConnected(telecomProvider, e);
                }

                // Check to see if this is an extension making or receiving a call. If so, update the status of the extension.
                if (Properties.Settings.Default.EnableKinesisServer && this.Extension == null)
                {
                    int extNumber = 0;

                    if (e.Outbound)
                    {
                        if (int.TryParse(e.CallingToNumber, out extNumber))
                        {
                            this.Extension = dataProvider.GetExtensionNumber(Properties.Settings.Default.CustomerID, extNumber);
                        }
                    }
                    else
                    {
                        if (int.TryParse(e.CallerPhoneNumber, out extNumber))
                        {
                            this.Extension = dataProvider.GetExtensionNumber(Properties.Settings.Default.CustomerID, extNumber);
                        }
                    }
                }

                if (callID == null)
                {
                    callID = Guid.NewGuid();
                }

                //UpdateExtensionCallStatus(CallStatus.OnCall);
                //UpdateExtensionCall(e.LineNumber, CallStatus.OnCall, e.CallerDisplayName, e.CallerPhoneNumber);
            }
        }