예제 #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));
            }
        }
예제 #2
0
        private async Task <DialogTurnResult> ExecuteActionStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var processDetails  = (ProcessDetails)stepContext.Options;
            var selectedProcess = processDetails.ProcessSelected;

            selectedProcess.StartedBy = "chat_bot";
            var action = (FoundChoice)stepContext.Result;

            processDetails.ConfirmAction = action.Value;
            var config = new RPAService();

            if (action.Value == "Yes")
            {
                if (processDetails.Action == "start")
                {
                    //save activity id for when process finish
                    var activityId = stepContext.Context.Activity.Id;

                    var response = config.StartProcess(selectedProcess, string.Empty);
                    if (!string.IsNullOrEmpty(response.Content))
                    {
                        if (response.IsSuccess)
                        {
                            processDetails.Jobs = JsonConvert.DeserializeObject <List <Job> >(response.Content);
                        }
                        else
                        {
                            processDetails.Error = JsonConvert.DeserializeObject <Job>(response.Content).Error;
                        }
                        return(await stepContext.ReplaceDialogAsync(nameof(MainDialog), processDetails, cancellationToken));

                        /*return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions
                         * { Prompt = MessageFactory.Text("Process " + processDetails.ProcessSelected.Name + " was started, you will be notified when it finishes. Meanwhile, is there something else can I assist you with?") },
                         * cancellationToken);*/
                    }
                    else//there was an error
                    {
                        return(await stepContext.PromptAsync(nameof(ChoicePrompt), new PromptOptions
                        {
                            Prompt = MessageFactory.Text("To continue to run this bot, please contact RPA Support. "),
                            Choices = new List <Choice> {
                                new Choice
                                {
                                    Value = "rpaSupport",
                                    Action = new CardAction(ActionTypes.OpenUrl, "Click Here", value: "bam?id=rpa_new_request&type=incident")
                                }
                            }
                        }, cancellationToken));
                    }
                }
                else if (processDetails.Action == "check status")
                {
                    return(await stepContext.BeginDialogAsync(nameof(StatusDialog), processDetails, cancellationToken));
                }
                else
                {
                    return(await stepContext.BeginDialogAsync(nameof(StopProcessDialog), processDetails, cancellationToken));
                }
            }
            else
            {
                //start over
                return(await stepContext.ReplaceDialogAsync(nameof(MainDialog), processDetails, cancellationToken));
            }
        }
예제 #3
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));
            }
        }