private async Task <DialogTurnResult> ShowProcessStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var processDetails = (ProcessDetails)stepContext.Options;
            var processes      = processDetails.Processes;
            var text           = "Here are your processes in progress. ";

            if (processDetails.LoadMore)
            {
                text = string.Empty;
                processDetails.LoadMore = false;
            }
            if (processes.Count > 0)
            {
                var rpaService = new RPAService();
                //var _user = await _userAccessor.GetAsync(stepContext.Context, () => new User(), cancellationToken);
                //get last index
                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 result  = rpaService.GetListOfProcess(processes, Convert.ToInt32(user[0].u_last_index));
                var choices = result.Choices;
                //add one choice for rpa support
                var rpaSupportChoice = rpaService.GetRPASupportOption();
                choices.Add(rpaSupportChoice);
                //save index
                user[0].u_last_index = result.LastIndex.ToString();
                rpaService.UpdateUser(user[0], stepContext.Context.Activity.Conversation.Id);
                //_user.u_last_index = result.LastIndex;
                //await this._userAccessor.SetAsync(stepContext.Context, _user, cancellationToken);

                return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions
                {
                    Prompt = (Activity)ChoiceFactory.HeroCard(choices, text + "Which one would you like to stop?")

                             /*Prompt = MessageFactory.Text(text+ "Which one would you like to stop?"),
                              * Choices = choices,
                              * Style = ListStyle.Auto*/
                }, cancellationToken));
            }
            else
            {
                processDetails.Action = "error";
                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;

            //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));
            }
        }
        private async Task <DialogTurnResult> RecognizeText(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var user = new User();

            var processDetails = new ProcessDetails();

            try
            {
                var promptOption = new PromptOption();
                try
                {
                    promptOption = JsonConvert.DeserializeObject <PromptOption>(stepContext.Context.Activity.Text);
                }
                catch (Exception) { }
                if (!string.IsNullOrEmpty(promptOption.Value))
                {
                    stepContext.Context.Activity.Text = promptOption.Value;
                }

                var luisResult = await _luisRecognizer.RecognizeAsync <Process>(stepContext.Context, cancellationToken);

                switch (luisResult.TopIntent().intent)
                {
                case Process.Intent.RPA:
                    var choices    = new List <Choice>();
                    var rpaOptions = new RPAOptions();

                    foreach (var option in rpaOptions.Options)
                    {
                        var value = JsonConvert.SerializeObject(option);

                        choices.Add(new Choice
                        {
                            Value  = option.Value,
                            Action = new CardAction(ActionTypes.PostBack, option.Text, null, option.Text, option.DisplayText, value: value, null)
                                     //ActionTypes.PostBack, "Click Here", null, "Click Here", "openUrl", value: value, null
                        });
                    }

                    return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions
                    {
                        Prompt = (Activity)ChoiceFactory.HeroCard(choices, "Below is a list of available commands:"),                                //.ForChannel(stepContext.Context.Activity.ChannelId, choices, "Here is a list of your available commands.", null, ChoiceFactoryOptions.),
                    }, cancellationToken));

                /*return await stepContext.PromptAsync(nameof(ChoicePrompt), new PromptOptions
                 * {
                 *      Prompt = MessageFactory.Text("Here is a list of your available commands."),
                 *      Choices = choices,
                 *      Style = ListStyle.HeroCard
                 * }, cancellationToken);*/

                default:
                    processDetails.Action = "default";
                    // Catch all for unhandled intents
                    var didntUnderstandMessageText = "I am sorry, I do not understand your request. Please try asking a different way or type " + '"' + "Menu" + '"' + " for available options.";
                    var didntUnderstandMessage     = MessageFactory.Text(didntUnderstandMessageText, didntUnderstandMessageText, InputHints.IgnoringInput);
                    //start this dialog again
                    return(await stepContext.NextAsync(processDetails, cancellationToken));                           //.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = didntUnderstandMessage }, cancellationToken);
                }
                // return await stepContext.BeginDialogAsync(nameof(ProcessDialog), processDetails, cancellationToken);
            }
            catch (Exception ex)
            {
                var rpaService = new RPAService();
                var rpaSupport = rpaService.GetRPASupportOption();
                var choices    = new List <Choice> {
                    rpaSupport
                };
                processDetails.Action = "error";

                return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions
                {
                    Prompt = (Activity)ChoiceFactory.SuggestedAction(choices, "To continue to run this bot, please contact RPA Support.")

                             /*Prompt = MessageFactory.Text("To continue to run this bot, please contact RPA Support."),
                              * Choices = choices*/
                }, cancellationToken));
            }
        }