Esempio n. 1
0
        public async Task GetRouteDirectionsViewCards(DialogContext sc, RouteDirections routeDirections)
        {
            var routes = routeDirections.Routes;
            var state  = await _accessors.PointOfInterestSkillState.GetAsync(sc.Context);

            var cardsData = new List <RouteDirectionsModelCardData>();
            var routeId   = 0;

            if (routes != null)
            {
                state.FoundRoutes = routes.ToList();

                foreach (var route in routes)
                {
                    TimeSpan travelTimeSpan  = TimeSpan.FromSeconds(route.Summary.TravelTimeInSeconds);
                    TimeSpan trafficTimeSpan = TimeSpan.FromSeconds(route.Summary.TrafficDelayInSeconds);

                    RouteDirectionsModelCardData routeDirectionsModel = new RouteDirectionsModelCardData()
                    {
                        Location     = state.ActiveLocation.Name,
                        TravelTime   = GetFormattedTravelTimeSpanString(travelTimeSpan),
                        TrafficDelay = GetFormattedTrafficDelayString(trafficTimeSpan),
                        RouteId      = routeId,
                    };

                    cardsData.Add(routeDirectionsModel);
                    routeId++;
                }

                if (cardsData.Count() > 1)
                {
                    var replyMessage = sc.Context.Activity.CreateAdaptiveCardGroupReply(PointOfInterestBotResponses.MultipleRoutesFound, "Dialogs/Shared/Resources/Cards/RouteDirectionsViewCard.json", AttachmentLayoutTypes.Carousel, cardsData);
                    await sc.Context.SendActivityAsync(replyMessage);
                }
                else
                {
                    // state.ActiveRoute = routes.Single();
                    var replyMessage = sc.Context.Activity.CreateAdaptiveCardReply(PointOfInterestBotResponses.SingleRouteFound, "Dialogs/Shared/Resources/Cards/RouteDirectionsViewCard.json", cardsData.SingleOrDefault());
                    await sc.Context.SendActivityAsync(replyMessage);
                }
            }
            else
            {
                var replyMessage = sc.Context.Activity.CreateReply(PointOfInterestBotResponses.NoLocationsFound, _responseBuilder);
                await sc.Context.SendActivityAsync(replyMessage);
            }
        }
Esempio n. 2
0
        public async Task <DialogTurnResult> GetRoutesToActiveLocation(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var state = await _accessors.PointOfInterestSkillState.GetAsync(sc.Context);

                var service         = _serviceManager.InitMapsService(_services.AzureMapsKey);
                var routeDirections = new RouteDirections();

                if (state.ActiveLocation == null)
                {
                    // No ActiveLocation found
                    return(await sc.PromptAsync(Action.Prompt, new PromptOptions { Prompt = sc.Context.Activity.CreateReply(PointOfInterestBotResponses.MissingActiveLocationErrorMessage, _responseBuilder) }));
                }

                if (!string.IsNullOrEmpty(state.SearchDescriptor))
                {
                    routeDirections = await service.GetRouteDirectionsAsync(state.CurrentCoordinates.Latitude, state.CurrentCoordinates.Longitude, state.ActiveLocation.Point.Coordinates[0], state.ActiveLocation.Point.Coordinates[1], state.SearchDescriptor);

                    await GetRouteDirectionsViewCards(sc, routeDirections);
                }
                else
                {
                    routeDirections = await service.GetRouteDirectionsAsync(state.CurrentCoordinates.Latitude, state.CurrentCoordinates.Longitude, state.ActiveLocation.Point.Coordinates[0], state.ActiveLocation.Point.Coordinates[1]);

                    await GetRouteDirectionsViewCards(sc, routeDirections);
                }

                if (routeDirections?.Routes?.ToList().Count == 1)
                {
                    return(await sc.PromptAsync(Action.ConfirmPrompt, new PromptOptions { Prompt = sc.Context.Activity.CreateReply(PointOfInterestBotResponses.PromptToStartRoute, _responseBuilder) }));
                }

                return(await sc.EndDialogAsync());
            }
            catch
            {
                await sc.Context.SendActivityAsync(sc.Context.Activity.CreateReply(PointOfInterestBotResponses.PointOfInterestErrorMessage, _responseBuilder));

                var state = await _accessors.PointOfInterestSkillState.GetAsync(sc.Context);

                state.Clear();
                await _accessors.PointOfInterestSkillState.SetAsync(sc.Context, state);

                return(await sc.CancelAllDialogsAsync());
            }
        }
Esempio n. 3
0
        public async Task <DialogTurnResult> GetRoutesToActiveLocation(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var state = await Accessor.GetAsync(sc.Context);

                var service         = ServiceManager.InitMapsService(GetAzureMapsKey());
                var routeDirections = new RouteDirections();

                state.CheckForValidCurrentCoordinates();

                if (state.ActiveLocation == null)
                {
                    // No ActiveLocation found
                    return(await sc.PromptAsync(Action.Prompt, new PromptOptions { Prompt = sc.Context.Activity.CreateReply(RouteResponses.MissingActiveLocationErrorMessage, ResponseBuilder) }));
                }

                if (!string.IsNullOrEmpty(state.SearchDescriptor))
                {
                    routeDirections = await service.GetRouteDirectionsAsync(state.CurrentCoordinates.Latitude, state.CurrentCoordinates.Longitude, state.ActiveLocation.Point.Coordinates[0], state.ActiveLocation.Point.Coordinates[1], state.SearchDescriptor);

                    await GetRouteDirectionsViewCards(sc, routeDirections);
                }
                else
                {
                    routeDirections = await service.GetRouteDirectionsAsync(state.CurrentCoordinates.Latitude, state.CurrentCoordinates.Longitude, state.ActiveLocation.Point.Coordinates[0], state.ActiveLocation.Point.Coordinates[1]);

                    await GetRouteDirectionsViewCards(sc, routeDirections);
                }

                if (routeDirections?.Routes?.ToList().Count == 1)
                {
                    return(await sc.PromptAsync(Action.ConfirmPrompt, new PromptOptions { Prompt = sc.Context.Activity.CreateReply(RouteResponses.PromptToStartRoute, ResponseBuilder) }));
                }

                state.ClearLuisResults();

                return(await sc.EndDialogAsync());
            }
            catch
            {
                await HandleDialogException(sc);

                throw;
            }
        }