Beispiel #1
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));
            }
        }
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));
            }
        }
Beispiel #3
0
        private async Task <DialogTurnResult> StartProcessStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            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 != "Confirm")
                {
                    processDetails.Action = "pastMenu";
                    return(await stepContext.ReplaceDialogAsync(nameof(MainDialog), processDetails, cancellationToken));
                }
                result = promptOption.Value;
            }

            if (result.ToLower() == "yes" || result.ToLower() == "y")
            {
                var rpaService = new RPAService();
                //save activity id for when process finish
                var activityId = stepContext.Context.Activity.Id;
                //check if the process can start
                if (processDetails.ProcessSelected.LastRun.State == "Faulted" || processDetails.ProcessSelected.LastRun.State == "Successful" || processDetails.ProcessSelected.LastRun.State == "Stopped" || string.IsNullOrEmpty(processDetails.ProcessSelected.LastRun.State))
                {
                    //check if has asset
                    var assetsWithValueFromChild = rpaService.HasAnyAsset(processDetails.ProcessSelected);
                    if (assetsWithValueFromChild.Count > 0)
                    {
                        var response = rpaService.MakeAssetFromChild(assetsWithValueFromChild);
                        if (response.Body != "Success")
                        {
                            var choices   = new List <Choice>();
                            var rpaOption = rpaService.GetMainMenuOption();
                            if (response.MissingAsset)
                            {
                                //create incident
                                var incident      = rpaService.CreateRPAIncident(processDetails.ProcessSelected);
                                var incidentValue = JsonConvert.SerializeObject(new PromptOption {
                                    Id = "incident", Value = "bam?id=rpa_request&table=u_robot_incident&sys_id=" + incident.Sys_Id
                                });
                                choices = new List <Choice>
                                {
                                    new Choice
                                    {
                                        Value  = "bam?id=rpa_request&table=u_robot_incident&sys_id=" + incident.Sys_Id,
                                        Action = new CardAction(ActionTypes.PostBack, incident.Number, null, incident.Number, "openUrl", value: incidentValue, null)
                                    }
                                };
                                choices.Add(rpaOption);

                                return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions
                                {
                                    Prompt = (Activity)ChoiceFactory.SuggestedAction(choices, "Process " + processDetails.ProcessSelected.Name + " requires an asset associated to your user, an incident has been opened to RPA Support." + Environment.NewLine + "Click incident number below to open it")
                                }, cancellationToken));
                            }
                            else
                            {
                                var assetValue = JsonConvert.SerializeObject(new PromptOption {
                                    Id = "asset", Value = "bam?id=rpa_process_assets&process=" + processDetails.ProcessSelected.Sys_id
                                });
                                choices = new List <Choice>
                                {
                                    new Choice
                                    {
                                        Value  = "bam?id=rpa_process_assets&process=" + processDetails.ProcessSelected.Sys_id,
                                        Action = new CardAction(ActionTypes.PostBack, "Update Asset", null, "Update Asset", "openUrl", value: assetValue, null)
                                    }
                                };
                                choices.Add(rpaOption);
                                //send the user to SN UI page
                                return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions
                                {
                                    Prompt = (Activity)ChoiceFactory.SuggestedAction(choices, response.Body + Environment.NewLine + "Please enter them before running the process by pressing Update Asset button below.")
                                }, cancellationToken));
                            }
                        }
                    }
                    if (processDetails.ProcessSelected.Releases.Any(r => r.robots.Count > 1))
                    {
                        processDetails.ProcessSelected.FirstBot = true;
                        return(await stepContext.ReplaceDialogAsync(nameof(RobotsDialog), processDetails, cancellationToken));
                    }                    //check if process need params
                    else if (processDetails.ProcessSelected.Releases.Any(r => r.parameters_required == true))
                    {
                        //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
                {
                    processDetails.Action = "error";
                    processDetails.Error  = "Cannot start " + processDetails.ProcessSelected.Name + " because the process is already running.";
                    return(await stepContext.ReplaceDialogAsync(nameof(MainDialog), processDetails, cancellationToken));
                }
            }
            else if (result.ToLower() == "no" || result.ToLower() == "n")            //when no is selected
            {
                processDetails.Action = string.Empty;
                return(await stepContext.ReplaceDialogAsync(nameof(MainDialog), null, cancellationToken));
            }
            else             //when something is typed
            {
                processDetails.Action = string.Empty;
                return(await stepContext.ReplaceDialogAsync(nameof(MainDialog), null, cancellationToken));
            }
        }