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

            if (processDetails.Action == "typed")
            {
                message = "Typing is not valid for this menu option." + Environment.NewLine + "Please return to the Main Menu and click on the option you want to select.";
                processDetails.Action = string.Empty;
                var rpaService = new RPAService();
                var choices    = new List <Choice>();
                choices.Add(rpaService.GetMainMenuOption());
                return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions
                {
                    Prompt = (Activity)ChoiceFactory.SuggestedAction(choices, message),
                }, cancellationToken));
            }

            return(await stepContext.ReplaceDialogAsync(nameof(MainDialog), processDetails, cancellationToken));
        }
示例#2
0
        private async Task <DialogTurnResult> IntroStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var processDetails = (ProcessDetails)stepContext.Options;
            var value          = JsonConvert.SerializeObject(new PromptOption {
                Id = "rpaSuport", Value = "*****@*****.**"
            });
            var choices = new List <Choice>
            {
                new Choice
                {
                    Value  = "rpaSupport",//[email protected]
                    Action = new CardAction(ActionTypes.PostBack, "To Contact RPA Support click here", null, "To Contact RPA Support click here", "openEmail", value: value, null)
                }
            };
            var rpaService = new RPAService();

            choices.Add(rpaService.GetMainMenuOption());
            return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions
            {
                Prompt = (Activity)ChoiceFactory.SuggestedAction(choices, "You have made 3 attempts, please contact RPA Support or go back to Main Menu.")
            },
                                                 cancellationToken));
        }
        private async Task <DialogTurnResult> SelectStrategyStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var msg            = string.Empty;
            var result         = stepContext.Result.ToString();
            var processDetails = (ProcessDetails)stepContext.Options;

            processDetails.Action = string.Empty;
            var rpaService   = new RPAService();
            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")
            {
                //check if process is queued
                if (!string.IsNullOrEmpty(processDetails.ProcessSelected.queuedId))
                {
                    var cancel = JsonConvert.SerializeObject(new PromptOption {
                        Id = "Stop", Value = "3"
                    });
                    var choices = new List <Choice>
                    {
                        new Choice {
                            Value  = "3",
                            Action = new CardAction(ActionTypes.PostBack, "Cancel Queued Process", null, "Cancel Queued Process", "Cancel Queued Process", value: cancel, null)
                        }
                    };
                    choices.Add(rpaService.GetMainMenuOption());
                    return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions
                    {
                        Prompt = (Activity)ChoiceFactory.SuggestedAction(choices, "Process " + processDetails.ProcessSelected.Name + " will be deleted from the queue and will not run." + Environment.NewLine + "Please click on below button to Cancel Queued Process")
                    }, cancellationToken));
                }
                else
                {
                    var stop = JsonConvert.SerializeObject(new PromptOption {
                        Id = "Stop", Value = "1"
                    });
                    var terminate = JsonConvert.SerializeObject(new PromptOption {
                        Id = "Stop", Value = "2"
                    });
                    var choices = new List <Choice>
                    {
                        new Choice {
                            Value  = "1",
                            Action = new CardAction(ActionTypes.PostBack, "Safely Stop Run", null, "Safely Stop Run", "Safely Stop Run", value: stop, null)
                        },
                        new Choice {
                            Value  = "2",
                            Action = new CardAction(ActionTypes.PostBack, "Terminate Process", null, "Terminate Process", "Terminate Process", value: terminate, null)
                        }
                    };
                    return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions
                    {
                        Prompt = (Activity)ChoiceFactory.SuggestedAction(choices, "Please select one of the buttons below to Stop the Process:")
                    }, cancellationToken));
                }
            }
            else if (result.ToLower() == "no" || result.ToLower() == "n")
            {
                return(await stepContext.ReplaceDialogAsync(nameof(MainDialog), processDetails, cancellationToken));
            }
            else
            {
                return(await stepContext.ReplaceDialogAsync(nameof(MainDialog), null, cancellationToken));
            }
        }
示例#4
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));
            }
        }