public async Task CreateReservation(IDialogContext context, IAwaitable <IMessageActivity> activity, LuisResult result) { // attempt to parse the reservation location (city, state) if provided and set to state if (result.TryFindEntity("RestaurantReservation.Address", out var locationRecommendation)) { context.SetLocation(locationRecommendation.Entity); } // attempt to parse the cuisine preference if provided and set to state if (result.TryFindEntity("RestaurantReservation.Cuisine", out var cuisineRecommendation)) { context.SetCuisine(cuisineRecommendation.Entity); } // if the user enters a full date (for example, tomorrow night at 9pm), set to state if (result.TryFindDateTime("builtin.datetimeV2.datetime", out var date)) { context.SetWhen(date.Value); } else if (result.TryFindDateTime("builtin.datetimeV2.time", out var time)) { // if the user only enters a time (9pm), we parse the time into the current date context.SetWhen(time.Value); } // if the user provided the number of people, set the value in state if (result.TryFindInteger("builtin.number", out var partySize)) { context.SetPartySize(partySize.Value); } // send a message to the user confirming their intent to create a reservation await context.PostAsync(Properties.Resources.GREETING); // we need to make sure we capture the following information for the reservation: // 1. User's location (city, state) // 2. User's preferred cuisine (thai, italian, etc.) // 3. Restaurant (based on location and cuisine) // 4. Date / time of the reservation // 5. Number of people // we start by first invoking a dialog for requesting the location // and in turn call other state-specific dialogs in sequence context.Call(new LocationDialog(), null); }
public async Task CreateReservation(IDialogContext context, IAwaitable <IMessageActivity> activity, LuisResult result) { await context.PostAsync("Looks like your attempting to create a reservation. Let's see what information we were able to pull"); // attempt to parse the location from the request if provided by the user if (result.TryFindEntity("RestaurantReservation.Address", out var locationRecommendation)) { context.PrivateConversationData.SetValue("LOCATION", locationRecommendation.Entity); } // attempt to parse a cuisine from the luis result if provided by the user if (result.TryFindEntity("RestaurantReservation.Cuisine", out var cuisineRecommendation)) { context.PrivateConversationData.SetValue("CUISINE", cuisineRecommendation.Entity); } // attempt to parse the date time if provided by the user if (result.TryFindDateTime("builtin.datetimeV2.datetime", out var when)) { context.PrivateConversationData.SetValue("WHEN", when.Value.ToString()); } // attempt to parse the number of people if provided by the user if (result.TryFindInteger("builtin.number", out var partySize)) { context.PrivateConversationData.SetValue("PARTY_SIZE", partySize.Value); } // reply with the parsed location if we saved in state if (context.PrivateConversationData.ContainsKey("LOCATION")) { await context.PostAsync($"Location Preference: {context.PrivateConversationData.GetValueOrDefault<string>("LOCATION")}"); } // reply with the parsed cuisine if we saved in state if (context.PrivateConversationData.ContainsKey("CUISINE")) { await context.PostAsync($"Cuisine Preference: {context.PrivateConversationData.GetValueOrDefault<string>("CUISINE")}"); } // reply with the parsed date / time if we saved in state if (context.PrivateConversationData.ContainsKey("WHEN")) { await context.PostAsync($"Date Preference: {context.PrivateConversationData.GetValueOrDefault<DateTime>("WHEN")}"); } // reply with the parsed number of people if saved in state if (context.PrivateConversationData.ContainsKey("PARTY_SIZE")) { await context.PostAsync($"Party Size Preference: {context.PrivateConversationData.GetValueOrDefault<int>("PARTY_SIZE")}"); } // end the conversation context.EndConversation(EndOfConversationCodes.CompletedSuccessfully); }
public async Task CreateReservation(IDialogContext context, IAwaitable <IMessageActivity> activity, LuisResult result) { // attempt to parse the reservation location (city, state) if provided and set to state if (result.TryFindEntity("RestaurantReservation.Address", out var locationRecommendation)) { context.SetLocation(locationRecommendation.Entity); } // attempt to parse the cuisine preference if provided and set to state if (result.TryFindEntity("RestaurantReservation.Cuisine", out var cuisineRecommendation)) { context.SetCuisine(cuisineRecommendation.Entity); } // if the user enters a full date (for example, tomorrow night at 9pm), set to state if (result.TryFindDateTime("builtin.datetimeV2.datetime", out var date)) { context.SetWhen(date.Value); } else if (result.TryFindDateTime("builtin.datetimeV2.time", out var time)) { // if the user only enters a time (9pm), we parse the time into the current date context.SetWhen(time.Value); } // if the user provided the number of people, set the value in state if (result.TryFindInteger("builtin.number", out var partySize)) { context.SetPartySize(partySize.Value); } // notify the user that you received their request await context.PostAsync(Properties.Resources.CONFIRMATION); // pass off to the location dialog to walk through the reservation state chain context.Call(new LocationDialog(), null); }
public async Task SetReservationDate(IDialogContext context, IAwaitable <IMessageActivity> activity, LuisResult result) { DateTime?when = null; // if the user enters a full date (for example, tomorrow night at 9pm), set to state if (result.TryFindDateTime("builtin.datetimeV2.datetime", out var date)) { context.SetWhen(date.Value); when = date.Value; } else if (result.TryFindDateTime("builtin.datetimeV2.time", out var time)) { // if the user only enters a time (9pm), we parse the time into the current date context.SetWhen(time.Value); when = time.Value; } // send message to the user confirming their newly selected reservation date and time var response = string.Format(Properties.Resources.WHEN_CONFIRMATION, when.Value.ToLongDateString(), when.Value.ToLongTimeString()); await context.PostAsync(response); // pass off to the location dialog to walk through the reservation state chain context.Call(new LocationDialog(), null); }