private async Task RunStep(DialogContext dc, object result = null)
        {
            if (dc == null)
            {
                throw new ArgumentNullException(nameof(dc));
            }

            var instance = (WaterfallInstance)dc.Instance.State;
            var step     = instance.Step;

            if (step >= 0 && step < _steps.Length)
            {
                SkipStepFunction next = (r) => {
                    // Skip to next step
                    instance.Step++;
                    return(RunStep(dc, r));
                };

                // Execute step
                await _steps[step](dc, result, next);
            }
            else
            {
                // End of waterfall so just return to parent
                await dc.End(result);
            }
        }
Пример #2
0
        private async Task CarTypeStep(DialogContext dialogContext, object result, SkipStepFunction next)
        {
            var state = dialogContext.Context.GetConversationState <ReservationData>();

            if (state.CarType == null)
            {
                // Your code goes here
                var actions = new[]
                {
                    new CardAction(type: ActionTypes.ImBack, title: "Sedan", value: "Sedan"),
                    new CardAction(type: ActionTypes.ImBack, title: "SUV", value: "SUV"),
                    new CardAction(type: ActionTypes.ImBack, title: "Sports car", value: "Sports car")
                };

                var heroCard = new HeroCard(buttons: actions);
                var activity = (Activity)MessageFactory.Carousel(new[] { heroCard.ToAttachment() }, "Please select a car type.");
                var choices  = actions.Select(x => new Choice {
                    Action = x, Value = (string)x.Value
                }).ToList();
                await dialogContext.Prompt(PromptStep.CarTypePrompt, activity, new ChoicePromptOptions { Choices = choices });

                //    await dialogContext.Context.SendActivity("What kind of vehicle would you like?");
                //    await dialogContext.Prompt(PromptStep.CarTypePrompt, $"Available options are: {string.Join(", ", BotConstants.CarTypes)}");
            }
            else
            {
                await next();
            }
        }
Пример #3
0
        private async Task AskAgeStep(DialogContext dialogContext, object result, SkipStepFunction next)
        {
            var state = dialogContext.Context.GetConversationState <EchoState>();

            state.RecipientName = (result as TextResult).Value;
            await dialogContext.Prompt(PromptStep.AgePrompt, "What is your age?");
        }
Пример #4
0
        /// <summary>
        /// Method to finish the order after all info is collected.
        /// Sends a response and clears the order details.
        /// </summary>
        private async Task CompleteOrder(DialogContext dialogContext, object result, SkipStepFunction next)
        {
            // Get the current dialog
            var service           = new ConversationModelService();
            var conversationModel = service.ConversationModel();

            // Send the flow's outcome response with the user's inputed values
            var   state    = dialogContext.Context.GetConversationState <Dictionary <string, object> >();
            Regex _regex   = new Regex(@"\{(\w+)\}", RegexOptions.Compiled);
            var   response = _regex.Replace(conversationModel.Outcome.Value,
                                            match => state[service.GetPrompt(match.Groups[1].Value).PropertyName].ToString());
            await dialogContext.Context.SendActivity(response, response, InputHints.AcceptingInput);

            // TODO: Business logic to process the user's inputed values would go here

            // Clear the user's inputed values for the current dialog
            foreach (var entity in conversationModel.Entities)
            {
                state.Remove(service.GetPrompt(entity).PropertyName);
            }

            // End dialog
            stepsCollected = false;
            await dialogContext.End();
        }
Пример #5
0
        private async Task ShowHelpStep(DialogContext dialogContext, object args, SkipStepFunction next)
        {
            await dialogContext.Context.SendActivity("These are the commands I support:\n" +
                                                     ".... To be implemented");

            await dialogContext.End();
        }
Пример #6
0
        private async Task GetPlaceTask(DialogContext dialogContext, object result, SkipStepFunction next)
        {
            var state = dialogContext.Context.GetConversationState <BotState>();

            state.Name = ((TextResult)result).Value;
            await dialogContext.Prompt(Constants.DialogSteps.PlaceStep.ToString(), $"Hi {state.Name}, I am Weather Assistant Bot. \n I can get weather reports for you.\n Please enter a name of place.");
        }
Пример #7
0
        private async Task RunStepAsync(DialogContext dc, IDictionary <string, object> result = null)
        {
            if (dc == null)
            {
                throw new ArgumentNullException(nameof(dc));
            }

            var step = dc.ActiveDialog.Step;

            if (step >= 0 && step < _steps.Length)
            {
                SkipStepFunction next = (r) =>
                {
                    // Skip to next step
                    dc.ActiveDialog.Step++;
                    return(RunStepAsync(dc, r));
                };

                // Execute step
                await _steps[step](dc, result, next).ConfigureAwait(false);
            }
            else
            {
                // End of waterfall so just return to parent
                await dc.EndAsync(result).ConfigureAwait(false);
            }
        }
Пример #8
0
        private async Task HelpInfo(DialogContext dialogContext, object args, SkipStepFunction next)
        {
            await dialogContext.Context.SendActivityAsync($"Currently I have two functions.");

            await dialogContext.Context.SendActivityAsync($"Tell me a type (e.g. 'Fire') and I will send you a card detailing super effective and super ineffective moves are.");

            await dialogContext.Context.SendActivityAsync($"Give me a Pokemon name (e.g. 'Pikachu') and I will tell you what types are super effective against that Pokemon, and if you would like, what types are weak against that Pokemon.")
        }
Пример #9
0
        private async Task CheckInventory(DialogContext dialogContext, object args, SkipStepFunction next)
        {
            await dialogContext.Context.SendActivity($"Ik zal even kijken wat we hebben, moment...");

            await _dataContext.Database.EnsureCreatedAsync();

            await dialogContext.Context.SendActivity($"Ik heb even snel in de pantry gekeken en de inventorie bijgewerkt. Snel he?");
        }
Пример #10
0
        private static async Task Waterfall2_Step2(DialogContext dc, object args, SkipStepFunction next)
        {
            if (args != null)
            {
                var numberResult = (NumberResult <int>)args;
                await dc.Context.SendActivity($"Thanks for '{numberResult.Value}'");
            }
            await dc.Context.SendActivity("step2");

            await dc.Prompt("number", "Enter a number.", new PromptOptions { RetryPromptString = "It must be a number" });
        }
Пример #11
0
        private async Task ConfirmShow(DialogContext dialogContext, object args, SkipStepFunction next)
        {
            var userContext = dialogContext.Context.GetUserState <UserState>();

            if (args is Prompts.ChoiceResult choice)
            {
                var reminder = userContext.Reminders[choice.Value.Index];
                await dialogContext.Context.SendActivity($"Reminder: {reminder.Title}");
            }
            await dialogContext.End();
        }
Пример #12
0
        private async Task WaterfallStep3(DialogContext dc, object args, SkipStepFunction next)
        {
            if (args != null)
            {
                var numberResult = (NumberResult <int>)args;
                await dc.Context.SendActivity($"Thanks for '{numberResult.Value}'");
            }
            await dc.Context.SendActivity("step3");

            await dc.End();
        }
Пример #13
0
        private async Task AskNameStep(DialogContext dialogContext, object result, SkipStepFunction next)
        {
            var state = dialogContext.Context.GetConversationState <EchoState>();

            if (state.RecipientName != null)
            {
                await dialogContext.Continue();
            }

            await dialogContext.Prompt(PromptStep.NamePrompt, "What is your name?");

            var t = "";
        }
Пример #14
0
        private static async Task Waterfall2_Step3(DialogContext dc, object args, SkipStepFunction next)
        {
            if (args != null)
            {
                var numberResult = (NumberResult <int>)args;
                await dc.Context.SendActivity($"Thanks for '{numberResult.Value}'");
            }
            await dc.Context.SendActivity("step3");

            await dc.End(new Dictionary <string, object> {
                { "Value", "All Done!" }
            });
        }
Пример #15
0
        private async Task TimeStep(DialogContext dialogContext, object result, SkipStepFunction next)
        {
            var state = dialogContext.Context.GetConversationState <ReservationData>();

            if (string.IsNullOrEmpty(state.Time))
            {
                var msg = "When do you need the reservation?";
                await dialogContext.Prompt(PromptStep.TimePrompt, msg, new PromptOptions { Speak = _ttsService.GenerateSsml(msg, BotConstants.EnglishLanguage) });
            }
            else
            {
                await next();
            }
        }
Пример #16
0
        private async Task SaveReminder(DialogContext dialogContext, object args, SkipStepFunction next)
        {
            var reminder = new Reminder(dialogContext.ActiveDialog.State);

            if (args is Prompts.TextResult textResult)
            {
                reminder.Title = textResult.Value;
            }
            await dialogContext.Context.SendActivity($"Your reminder named '{reminder.Title}' is set.");

            var userContext = dialogContext.Context.GetUserState <UserState>();

            userContext.Reminders.Add(reminder);
            await dialogContext.End();
        }
Пример #17
0
        private async Task AskNameStep(DialogContext dialogContext, object result, SkipStepFunction next)
        {
            var state = dialogContext.Context.GetConversationState <BotState>();

            if ((result as TextResult).Value != Configuration[Constants.TeacherRegistrationTokenKey])
            {
                await dialogContext.Context.SendActivity("Неверный ключ регистрации!");

                await dialogContext.End();
            }
            else
            {
                await dialogContext.Prompt(PromptStep.NamePrompt, "Введите ФИО:");
            }
        }
Пример #18
0
        private async Task ShowCardStep(DialogContext dialogContext, object result, SkipStepFunction next)
        {
            var selectedCard = (result as Microsoft.Bot.Builder.Prompts.ChoiceResult).Value.Value;
            var activity     = dialogContext.Context.Activity;

            switch (selectedCard)
            {
            case REPORT_ACCIDENT_CARD_ID:
                await dialogContext.Begin(PromptStep.GatherInfo);

                break;

            case "session":
                await dialogContext.Begin("session");

                break;
            }
        }
Пример #19
0
        private async Task TimeStep(DialogContext dialogContext, object result, SkipStepFunction next)
        {
            var state = dialogContext.Context.GetConversationState <ReservationData>();

            if (result != null)
            {
                // state.CarType = (result as TextResult).Value;
                state.CarType = ((ChoiceResult)result).Value.Value;
            }

            if (string.IsNullOrEmpty(state.Time))
            {
                await dialogContext.Prompt(PromptStep.TimePrompt, "When do you need the ride?");
            }
            else
            {
                await next();
            }
        }
Пример #20
0
        private async Task NameStep(DialogContext dialogContext, object result, SkipStepFunction next)
        {
            var state = dialogContext.Context.GetConversationState <ReservationData>();

            if (result != null)
            {
                state.AmountPeople = (result as TextResult).Value;
            }

            if (state.FullName == null)
            {
                var msg = "And the name on the reservation?";
                await dialogContext.Prompt(PromptStep.NamePrompt, msg, new PromptOptions { Speak = _ttsService.GenerateSsml(msg, BotConstants.EnglishLanguage) });
            }
            else
            {
                await next();
            }
        }
Пример #21
0
        private async Task LocationStep(DialogContext dialogContext, object result, SkipStepFunction next)
        {
            var state = dialogContext.Context.GetConversationState <ReservationData>();

            if (result != null)
            {
                var time = (result as TextResult).Value;
                state.Time = time;
            }

            if (state.Location == null)
            {
                await dialogContext.Prompt(PromptStep.LocationPrompt, "Where are you heading to?");
            }
            else
            {
                await next();
            }
        }
Пример #22
0
        private async Task FinalStep(DialogContext dialogContext, object result, SkipStepFunction next)
        {
            var state = dialogContext.Context.GetConversationState <ReservationData>();

            if (result != null)
            {
                state.Location = (result as TextResult).Value;
            }
            //steps
            var receipt = await GetReceiptCard(state);

            var message = MessageFactory.Attachment(receipt);
            await dialogContext.Context.SendActivity(message);

            // Your code goes here

            await dialogContext.Context.SendActivity("Thanks for your reservation!");

            await dialogContext.End(state);
        }
Пример #23
0
        private async Task AddToCart(DialogContext dialogContext, object args, SkipStepFunction next)
        {
            var luisResult  = dialogContext.Context.Services.Get <RecognizerResult>(LuisRecognizerMiddleware.LuisRecognizerResultKey);
            var productName = luisResult.GetEntity <string>("Product");
            var amount      = luisResult.GetEntity <int>("Amount");

            if (!string.IsNullOrWhiteSpace(productName))
            {
                var entry = new ShoppingCartEntry {
                    ProductName = productName, Amount = (amount > 0 ? amount : 1)
                };
                _dataContext.ShoppingCartEntries.Add(entry);
                _dataContext.SaveChanges();
                await dialogContext.Context.SendActivity($"Goede keus! Ik heb het op het boodschappenlijstje gezet voor je.");
            }
            else
            {
                await dialogContext.Prompt("ProductPrompt", "Sorry, wat wil je dat ik op het boodschappenlijstje zet?");
            }
        }
Пример #24
0
        private async Task ReplyBackTask(DialogContext dialogContext, object result, SkipStepFunction next)
        {
            var state         = dialogContext.Context.GetConversationState <BotState>();
            int serviceChoice = 0;

            int.TryParse(((TextResult)result).Value, out serviceChoice);
            if (serviceChoice == 1 || serviceChoice == 2)
            {
                state.ServiceChoice = serviceChoice;
                WeatherHelper weatherHelper = new WeatherHelper();
                string        weatherReport = await weatherHelper.GetWeatherReport(state.Place, state.ServiceChoice);

                await dialogContext.Context.SendActivity($"Dear {state.Name}, \n {weatherReport}");
            }
            else
            {
                await dialogContext.Context.SendActivity($"Hi {state.Name}, \n You have entered {serviceChoice} which is incorrect. \n Thanks for using WeatherAssitant");
            }

            await dialogContext.End();
        }
Пример #25
0
        /// <summary>
        /// Method to collect info from the user.
        /// </summary>
        private async Task CollectStep(DialogContext dialogContext, object result, SkipStepFunction next)
        {
            // Check to see if info was already collected
            var state     = dialogContext.Context.GetConversationState <Dictionary <string, object> >();
            var collected = state.TryGetValue(collectSteps[0].PropertyName, out object userInput);

            if (collected)
            {
                // If found, remove this step from the dialog and continue
                collectSteps.Remove(collectSteps[0]);
                await dialogContext.Continue();
            }
            else
            {
                // Prompt for info
                var options = new PromptOptions
                {
                    Speak = collectSteps[0].Value,
                };
                await dialogContext.Prompt($"{collectSteps[0].EntityName}Prompt", collectSteps[0].Value, options);
            }
        }
Пример #26
0
        private async Task OrderOverview(DialogContext dialogContext, object args, SkipStepFunction next)
        {
            var entries = _dataContext.ShoppingCartEntries.ToList();

            var builder = new StringBuilder();

            builder.AppendLine("Op het lijstje staan nu:");

            if (entries.Count > 0)
            {
                foreach (var entry in entries)
                {
                    builder.AppendLine($"- {entry.ProductName} x {entry.Amount}");
                }

                await dialogContext.Context.SendActivity(builder.ToString());
            }
            else
            {
                await dialogContext.Context.SendActivity($"Het boodschappenlijstje is nogal kaal! Bestel iets lekkers zou ik zeggen! Het kost jouw namelijk niks dus leef uit :smirk:");
            }
        }
Пример #27
0
        private async Task FinalStep(DialogContext dialogContext, object result, SkipStepFunction next)
        {
            var state = dialogContext.Context.GetConversationState <ReservationData>();

            if (result != null)
            {
                var    confirmation = (result as ConfirmResult).Confirmation;
                string msg          = null;
                if (confirmation)
                {
                    msg = $"Great, we will be expecting you this {state.Time}. Thanks for your reservation {state.FirstName}!";
                }
                else
                {
                    msg = "Thanks for using the Contoso Assistance. See you soon!";
                }

                await dialogContext.Context.SendActivity(msg, _ttsService.GenerateSsml(msg, BotConstants.EnglishLanguage));
            }

            await dialogContext.End(state);
        }
Пример #28
0
        private async Task ShowReminders(DialogContext dialogContext, object args, SkipStepFunction next)
        {
            var userContext = dialogContext.Context.GetUserState <UserState>();

            if (userContext.Reminders.Count == 0)
            {
                await dialogContext.Context.SendActivity("No reminders found.");

                await dialogContext.End();
            }
            else
            {
                var choices = userContext.Reminders.Select(x => new Prompts.Choices.Choice()
                {
                    Value = x.Title.Length < 15 ? x.Title : x.Title.Substring(0, 15) + "..."
                }).ToList();
                await dialogContext.Prompt("ShowReminderPrompt", "Select the reminder to show: ", new ChoicePromptOptions()
                {
                    Choices = choices
                });
            }
        }
Пример #29
0
        private async Task BookingRoomTime(DialogContext dialogContext, object args, SkipStepFunction next)
        {
            var state = new TechClubAssistantBotState(dialogContext.ActiveDialog.State);

            dialogContext.ActiveDialog.State = state;


            if (args is Microsoft.Bot.Builder.Prompts.ChoiceResult choiceResult)
            {
                state.MeetingRoom = choiceResult.Value.Value;
            }

            if (String.IsNullOrEmpty(state.Time))
            {
                await dialogContext.Prompt(TimePrompt, "Enter date and time: ", new PromptOptions()
                {
                    RetryPromptString = "Please enter correct date and time"
                });
            }
            else
            {
                await dialogContext.Continue();
            }
        }
Пример #30
0
        private async Task UploadPhotos(DialogContext dialogContext, object result, SkipStepFunction next)
        {
            Stream urlToStream(string url)
            {
                byte[] imageData = null;
                using (var wc = new System.Net.WebClient())
                    imageData = wc.DownloadData(url);
                return new MemoryStream(imageData);
            }

            var context = dialogContext.Context;
            var state = context.GetConversationState<BotState>();

            if (state.ImgUrls.Count >= MinPhoto)
            {
                await next();
                return;
            }

            foreach (var attachment in dialogContext.Context.Activity.Attachments)
            {
                var url = await StorageProvider.Load(urlToStream(attachment.ContentUrl),
                    attachment.Name);
                state.AddImgUrl(url.ToString());
            }

            Thread.Sleep(1000);

            if (state.ImgUrls.Count >= MinPhoto)
            {
                await next();
                return;
            }

            await dialogContext.Prompt(PromptStep.PhotoPrompt, $"Прикрепи еще фото (осталось {MinPhoto - state.ImgUrls.Count}).");
        }