Beispiel #1
0
        private async Task <DialogTurnResult> IntroStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var processDetails = (ProcessDetails)stepContext.Options;

            //2nd attempt to start process
            var rpaService = new RPAService();
            var response   = rpaService.StartProcess(processDetails.ProcessSelected, stepContext.Context.Activity.Conversation.Id);
            var error      = false;

            if (string.IsNullOrEmpty(response.Content) || !response.IsSuccess)
            {
                error = true;
            }
            if (error)
            {
                var rpaSupportChoice = rpaService.GetRPASupportOption();
                return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions
                {
                    Prompt = (Activity)ChoiceFactory.SuggestedAction(new List <Choice> {
                        rpaSupportChoice
                    }, "There was an issue running " + processDetails.ProcessSelected.Name + " process, please contact RPA Support.")

                             /*Prompt = MessageFactory.Text("There was an issue running " + processDetails.ProcessSelected.Name + " process, please contact RPA Support. "),
                              * Choices = new List<Choice> { rpaSupportChoice }*/
                }, cancellationToken));
            }
            else
            {
                var choices = rpaService.GetConfirmChoices();
                processDetails.Jobs = JsonConvert.DeserializeObject <List <Job> >(response.Content);

                return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions
                {
                    Prompt = (Activity)ChoiceFactory.SuggestedAction(choices, processDetails.ProcessSelected.Name + " process has started and you will be notified when it finishes." + Environment.NewLine + "Do you want to run another process??")

                             /*Prompt = MessageFactory.Text(processDetails.ProcessSelected.Name + " process  has started, you will be notified when it finishes. Do you want to run another process?"),
                              * Choices = ChoiceFactory.ToChoices(new List<string> { "Yes", "No" })*/
                }, cancellationToken));
            }
        }
Beispiel #2
0
        private async Task <DialogTurnResult> IntroStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var processDetails = (ProcessDetails)stepContext.Options;
            var bot            = new Robot();

            foreach (var r in processDetails.ProcessSelected.Releases)
            {
                if (r.robots.Count > 1)
                {
                    if (r.robots.Any(b => b.Shown == false))
                    {
                        bot       = r.robots.Find(b => b.Shown == false);
                        bot.Shown = true;
                        break;
                    }
                    bot = new Robot();
                }
            }

            if (string.IsNullOrEmpty(bot.id))
            {
                processDetails.ProcessSelected.FirstBot = true;
                //all processed
                foreach (var r in processDetails.ProcessSelected.Releases)
                {
                    if (r.robots.Count > 1)
                    {
                        var robots = new List <string>();
                        foreach (var b in r.robots)
                        {
                            if (b.Selected)
                            {
                                robots.Add(b.id);
                            }
                        }
                        if (robots.Count == 0)
                        {
                            foreach (var re in processDetails.ProcessSelected.Releases)
                            {
                                if (re.robots.Count > 1)
                                {
                                    foreach (var b in re.robots)
                                    {
                                        b.Shown = false;
                                    }
                                }
                            }
                            processDetails.ProcessSelected.ReEnterBot = true;
                            return(await stepContext.ReplaceDialogAsync(nameof(RobotsDialog), processDetails, cancellationToken));
                        }
                        r.u_robots = string.Join(',', robots);
                    }
                }
                //if needs params
                if (processDetails.ProcessSelected.Releases.Any(r => r.parameters_required == true))
                {
                    var rpaService = new RPAService();
                    //set all params for this conversation to false(maybe was interrupted by a notification)
                    rpaService.DeactivatedConversationFlow(string.Empty, stepContext.Context.Activity.Conversation.Id);
                    rpaService.SaveConversationFlow(processDetails.ProcessSelected, stepContext.Context.Activity.Conversation.Id);
                    return(await stepContext.ReplaceDialogAsync(nameof(ParametersProcessDialog), processDetails, cancellationToken));
                }
                else
                {
                    return(await stepContext.ReplaceDialogAsync(nameof(StartProcessSharedDialog), processDetails, cancellationToken));
                }
            }
            else
            {
                var message = string.Empty;
                if (processDetails.ProcessSelected.FirstBot)
                {
                    if (processDetails.ProcessSelected.ReEnterBot)
                    {
                        message = "You have to select at least one Bot." + Environment.NewLine;
                        processDetails.ProcessSelected.ReEnterBot = false;
                    }
                    message += "Select the Bot(s) to trigger " + processDetails.ProcessSelected.Name + " process." + Environment.NewLine + "For each one select " + '"' + "Yes or No" + '"';
                    processDetails.ProcessSelected.FirstBot = false;
                }
                processDetails.ProcessSelected.Bot = bot;
                var rpaService = new RPAService();
                var choices    = rpaService.GetConfirmChoices();
                return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions
                {
                    Prompt = (Activity)ChoiceFactory.SuggestedAction(choices, message + Environment.NewLine + bot.name)
                }, cancellationToken));
            }
        }
        private async Task <DialogTurnResult> ConfirmStopProcessStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var rpaService     = new RPAService();
            var processDetails = (ProcessDetails)stepContext.Options;
            var result         = stepContext.Result.ToString();
            var promptOption   = new PromptOption();

            try
            {
                promptOption = JsonConvert.DeserializeObject <PromptOption>(stepContext.Result.ToString());
            }
            catch (Exception) { }

            if (!string.IsNullOrEmpty(promptOption.Id))
            {
                if (promptOption.Id != "availableProcesses" && promptOption.Id != "rpaSuport")
                {
                    processDetails.Action = "pastMenu";
                    return(await stepContext.ReplaceDialogAsync(nameof(MainDialog), processDetails, cancellationToken));
                }
                result = promptOption.Value;
            }

            var response = rpaService.GetUser(stepContext.Context.Activity.Conversation.Id);
            var user     = new List <User>();

            if (response.IsSuccess)
            {
                user = JsonConvert.DeserializeObject <List <User> >(response.Content);
            }
            //var _user = await _userAccessor.GetAsync(stepContext.Context, () => new User(), cancellationToken);
            switch (result.ToLower())
            {
            case "load_more":
                processDetails.LoadMore = true;
                return(await stepContext.ReplaceDialogAsync(nameof(StopProcessDialog), processDetails, cancellationToken));

            case "*****@*****.**":
                //save index
                user[0].u_last_index = "0";
                rpaService.UpdateUser(user[0], stepContext.Context.Activity.Conversation.Id);
                //_user.u_last_index = 0;
                //await _userAccessor.SetAsync(stepContext.Context, _user, cancellationToken);
                processDetails.Action = string.Empty;
                return(await stepContext.ReplaceDialogAsync(nameof(MainDialog), processDetails, cancellationToken));

            default:
                processDetails.ProcessSelected = rpaService.GetSelectedProcess(processDetails.Processes, result);
                if (!string.IsNullOrEmpty(processDetails.ProcessSelected.Sys_id))
                {
                    //save index
                    user[0].u_last_index = "0";
                    rpaService.UpdateUser(user[0], stepContext.Context.Activity.Conversation.Id);
                    //_user.u_last_index = 0;
                    //await _userAccessor.SetAsync(stepContext.Context, _user, cancellationToken);
                    var choices = rpaService.GetConfirmChoices();
                    return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions
                    {
                        Prompt = (Activity)ChoiceFactory.SuggestedAction(choices, "You have selected " + processDetails.ProcessSelected.Name + ". Stop this process?")

                                 /*Prompt = MessageFactory.Text("You have selected " + processDetails.ProcessSelected.Name + ". Stop this process?"),
                                  * Choices = ChoiceFactory.ToChoices(new List<string> { "Yes", "No" })*/
                    }, cancellationToken));
                }
                else
                {
                    return(await stepContext.ReplaceDialogAsync(nameof(MainDialog), null, cancellationToken));
                }
            }
        }
        private async Task <DialogTurnResult> ShowRunningProcessStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var rpaService     = new RPAService();
            var processDetails = (ProcessDetails)stepContext.Options;
            var result         = stepContext.Result.ToString();
            var promptOption   = new PromptOption();

            try
            {
                promptOption = JsonConvert.DeserializeObject <PromptOption>(stepContext.Result.ToString());
            }
            catch (Exception) { }

            if (!string.IsNullOrEmpty(promptOption.Id))
            {
                if (promptOption.Id != "availableProcesses" && promptOption.Id != "menu")
                {
                    processDetails.Action = "pastMenu";
                    return(await stepContext.ReplaceDialogAsync(nameof(MainDialog), processDetails, cancellationToken));
                }
                result = promptOption.Value;
            }
            var _response = rpaService.GetUser(stepContext.Context.Activity.Conversation.Id);
            var user      = new List <User>();

            if (_response.IsSuccess)
            {
                user = JsonConvert.DeserializeObject <List <User> >(_response.Content);
            }
            if (result.ToLower() == "menu" || result.ToLower() == "m" /*"*****@*****.**"*/)
            {
                //save index
                user[0].u_last_index = "0";
                rpaService.UpdateUser(user[0], stepContext.Context.Activity.Conversation.Id);
                //_user.u_last_index = 0;
                //await _userAccessor.SetAsync(stepContext.Context, _user, cancellationToken);
                processDetails.Action = string.Empty;
                return(await stepContext.ReplaceDialogAsync(nameof(MainDialog), null, cancellationToken));
            }
            else if (result.ToLower() == "load_more")
            {
                processDetails.LoadMore = true;
                return(await stepContext.ReplaceDialogAsync(nameof(StatusDialog), processDetails, cancellationToken));
            }
            else
            {
                processDetails.ProcessSelected = rpaService.GetSelectedProcess(processDetails.Processes, result);
                //check if a process was selected, or something was written
                if (!string.IsNullOrEmpty(processDetails.ProcessSelected.Sys_id))
                {
                    //save index
                    user[0].u_last_index = "0";
                    rpaService.UpdateUser(user[0], stepContext.Context.Activity.Conversation.Id);
                    //_user.u_last_index = 0;
                    //await _userAccessor.SetAsync(stepContext.Context, _user, cancellationToken);
                    var apiRequest = new APIRequest
                    {
                        ProcessId = processDetails.ProcessSelected.Sys_id
                    };
                    if (!string.IsNullOrEmpty(processDetails.ProcessSelected.queuedId))
                    {
                        apiRequest.Queued = true;
                    }

                    var jobIds     = new List <string>();
                    var releaseIds = new List <string>();
                    //if there was a process started
                    if (processDetails.Jobs.Count > 0)
                    {
                        foreach (var job in processDetails.Jobs)
                        {
                            foreach (var item in job.Result.Body.Value)
                            {
                                jobIds.Add(item.Id);
                            }
                        }
                        apiRequest.Ids   = jobIds;
                        apiRequest.IsJob = true;
                    }
                    else
                    {
                        foreach (var release in processDetails.ProcessSelected.Releases)
                        {
                            releaseIds.Add(release.sys_id);
                        }
                        apiRequest.Ids   = releaseIds;
                        apiRequest.IsJob = false;
                    }

                    var response = rpaService.ProcessStatus(apiRequest);
                    var text     = string.Empty;
                    if (response.IsSuccess)
                    {
                        var processSatus = JsonConvert.DeserializeObject <List <ProcessStatus> >(response.Content);

                        text  = processSatus.Count > 1 ? "Here are the status for " : "Here is the latest status for ";
                        text += processDetails.ProcessSelected.Name + " process." + Environment.NewLine;
                        foreach (var item in processSatus)
                        {
                            var include = "Total Transactions Processed: " + item.TotalTransactions + Environment.NewLine;                            /* +
                                                                                                                                                       * "Run Time: " + item.Runtime + Environment.NewLine;*/
                            if (item.ProcessType == "procedural")
                            {
                                include = string.Empty;
                            }
                            var endTime   = item.End != null ? "End Time: " + item.End + Environment.NewLine : string.Empty;
                            var startTime = item.Start != null ? "Start Time: " + item.Start + Environment.NewLine : string.Empty;

                            text +=
                                "Status: " + item.State.label + Environment.NewLine +
                                startTime +
                                endTime +
                                include +
                                "Total Transactions Successful: " + Convert.ToInt32(item.TotalTransSuccessful) + Environment.NewLine +
                                "Total Exceptions: " + Convert.ToInt32(item.TotalExceptions) + Environment.NewLine +
                                "Bot Name: " + item.Robot + Environment.NewLine +
                                "Started By: " + item.startedBy;
                        }
                    }
                    else
                    {
                        text = response.Content;
                    }
                    var choices = rpaService.GetConfirmChoices();
                    return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions
                    {
                        Prompt = (Activity)ChoiceFactory.SuggestedAction(choices, text + Environment.NewLine + "Do you want to check the status of another process?")

                                 /*Prompt = MessageFactory.Text(text + Environment.NewLine + "Do you want to check the status of another process?"),
                                  * Choices = ChoiceFactory.ToChoices(new List<string> { "Yes", "No" })*/
                    }, cancellationToken));
                }
                else
                {
                    return(await stepContext.ReplaceDialogAsync(nameof(MainDialog), null, cancellationToken));
                }
            }
        }
Beispiel #5
0
        private async Task <DialogTurnResult> IntroStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var processDetails = (ProcessDetails)stepContext.Options;

            /*conversationFlow.AskingForParameters = false;
             * await this._conversationFlow.SetAsync(stepContext.Context, conversationFlow);*/
            if (processDetails.ProcessSelected.LastRun.State == "Faulted" || processDetails.ProcessSelected.LastRun.State == "Successful" || processDetails.ProcessSelected.LastRun.State == "Stopped" || string.IsNullOrEmpty(processDetails.ProcessSelected.LastRun.State))
            {
                var rpaService     = new RPAService();
                var response       = new APIResponse();
                var hasInputParams = false;
                if (processDetails.ProcessSelected.Releases.Any(r => r.parameters_required == true))
                {
                    processDetails.ProcessSelected.ConversationId = stepContext.Context.Activity.Conversation.Id;
                    response       = rpaService.StartProcessWithParams(processDetails.ProcessSelected);
                    hasInputParams = true;
                }
                else
                {
                    response = rpaService.StartProcess(processDetails.ProcessSelected, stepContext.Context.Activity.Conversation.Id);
                }

                var error = false;
                if (string.IsNullOrEmpty(response.Content) || !response.IsSuccess)
                {
                    error = true;
                }
                if (error)
                {
                    if (hasInputParams)
                    {
                        processDetails.AttemptCount = processDetails.AttemptCount + 1;
                        if (processDetails.AttemptCount == 3)
                        {
                            processDetails.AttemptCount = 0;
                            //contact rpa support
                            return(await stepContext.ReplaceDialogAsync(nameof(StartProcessWithParamsErrorDialog), processDetails, cancellationToken));
                        }
                        else
                        {
                            rpaService.SaveConversationFlow(processDetails.ProcessSelected, stepContext.Context.Activity.Conversation.Id);
                            return(await stepContext.ReplaceDialogAsync(nameof(ParametersProcessDialog), processDetails, cancellationToken));
                        }
                    }
                    else
                    {
                        return(await stepContext.ReplaceDialogAsync(nameof(StartProcessErrorDialog), processDetails, cancellationToken));
                    }
                }
                else
                {
                    processDetails.AttemptCount = 0;
                    processDetails.Jobs         = JsonConvert.DeserializeObject <List <Job> >(response.Content);
                    var choices = rpaService.GetConfirmChoices();
                    return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions
                    {
                        Prompt = (Activity)ChoiceFactory.SuggestedAction(choices, processDetails.ProcessSelected.Name + "  process has started and you will be notified when it finishes." + Environment.NewLine + " Do you want to run another process?")
                    }, cancellationToken));
                }
            }
            else
            {
                processDetails.AttemptCount = 0;
                processDetails.Action       = "error";
                processDetails.Error        = "Cannot start " + processDetails.ProcessSelected.Name + " because the process is already running.";
                return(await stepContext.ReplaceDialogAsync(nameof(MainDialog), processDetails, cancellationToken));
            }
        }