internal LocationRetrieverDialogBase(
     IGeoSpatialService geoSpatialService,
     LocationOptions options,
     LocationRequiredFields requiredFields,
     LocationResourceManager resourceManager) : base(resourceManager)
 {
     SetField.NotNull(out this.geoSpatialService, nameof(geoSpatialService), geoSpatialService);
     this.options        = options;
     this.requiredFields = requiredFields;
 }
Esempio n. 2
0
 public FacebookNativeLocationRetrieverDialog(
     string prompt,
     IGeoSpatialService geoSpatialService,
     LocationOptions options,
     LocationRequiredFields requiredFields,
     LocationResourceManager resourceManager)
     : base(geoSpatialService, options, requiredFields, resourceManager)
 {
     SetField.NotNull(out this.prompt, nameof(prompt), prompt);
 }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LocationDialog"/> class.
 /// </summary>
 /// <param name="geoSpatialService">The Geo-Special Service</param>
 /// <param name="apiKey">The geo spatial service API key.</param>
 /// <param name="prompt">The prompt posted to the user when dialog starts.</param>
 /// <param name="supportsKeyboard">Indicates whether channel supports keyboard buttons or not.</param>
 /// <param name="resourceManager">The resource manager.</param>
 internal RichLocationRetrieverDialog(
     IGeoSpatialService geoSpatialService,
     string apiKey,
     string prompt,
     bool supportsKeyboard,
     LocationResourceManager resourceManager) : base(resourceManager)
 {
     SetField.NotNull(out this.geoSpatialService, nameof(geoSpatialService), geoSpatialService);
     SetField.NotNull(out this.apiKey, nameof(apiKey), apiKey);
     this.prompt           = prompt;
     this.supportsKeyboard = supportsKeyboard;
 }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LocationDialog"/> class.
 /// </summary>
 /// <param name="apiKey">The geo spatial API key.</param>
 /// <param name="channelId">The channel identifier.</param>
 /// <param name="prompt">The prompt posted to the user when dialog starts.</param>
 /// <param name="geoSpatialService">The geo spatial location service.</param>
 /// <param name="options">The location options used to customize the experience.</param>
 /// <param name="requiredFields">The location required fields.</param>
 /// <param name="resourceManager">The location resource manager.</param>
 internal LocationDialog(
     string apiKey,
     string channelId,
     string prompt,
     IGeoSpatialService geoSpatialService,
     LocationOptions options = LocationOptions.None,
     LocationRequiredFields requiredFields   = LocationRequiredFields.None,
     LocationResourceManager resourceManager = null) : base(resourceManager)
 {
     SetField.NotNull(out this.apiKey, nameof(apiKey), apiKey);
     SetField.NotNull(out this.prompt, nameof(prompt), prompt);
     SetField.NotNull(out this.channelId, nameof(channelId), channelId);
     SetField.NotNull(out this.geoSpatialService, nameof(geoSpatialService), geoSpatialService);
     this.options        = options;
     this.requiredFields = requiredFields;
 }
Esempio n. 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LocationDialog"/> class.
 /// </summary>
 /// <param name="geoSpatialService">The Geo-Special Service.</param>
 /// <param name="cardBuilder">The card builder service.</param>
 /// <param name="prompt">The prompt posted to the user when dialog starts.</param>
 /// <param name="supportsKeyboard">Indicates whether channel supports keyboard buttons or not.</param>
 /// <param name="options">The location options used to customize the experience.</param>
 /// <param name="requiredFields">The location required fields.</param>
 /// <param name="resourceManager">The resource manager.</param>
 internal RichLocationRetrieverDialog(
     string prompt,
     bool supportsKeyboard,
     ILocationCardBuilder cardBuilder,
     IGeoSpatialService geoSpatialService,
     LocationOptions options,
     LocationRequiredFields requiredFields,
     LocationResourceManager resourceManager,
     bool skipPrompt = false)
     : base(geoSpatialService, options, requiredFields, resourceManager)
 {
     SetField.NotNull(out this.cardBuilder, nameof(cardBuilder), cardBuilder);
     SetField.NotNull(out this.prompt, nameof(prompt), prompt);
     this.supportsKeyboard = supportsKeyboard;
     this.skipPrompt       = skipPrompt;
 }
Esempio n. 6
0
 public FavoriteLocationRetrieverDialog(
     bool supportsKeyboard,
     IFavoritesManager favoritesManager,
     ILocationDialogFactory locationDialogFactory,
     ILocationCardBuilder cardBuilder,
     IGeoSpatialService geoSpatialService,
     LocationOptions options,
     LocationRequiredFields requiredFields,
     LocationResourceManager resourceManager)
     : base(geoSpatialService, options, requiredFields, resourceManager)
 {
     SetField.NotNull(out this.favoritesManager, nameof(favoritesManager), favoritesManager);
     SetField.NotNull(out this.locationDialogFactory, nameof(locationDialogFactory), locationDialogFactory);
     SetField.NotNull(out this.cardBuilder, nameof(cardBuilder), cardBuilder);
     this.supportsKeyboard = supportsKeyboard;
 }
 internal LocationDialogFactory(
     string apiKey,
     string channelId,
     string prompt,
     IGeoSpatialService geoSpatialService,
     LocationOptions options,
     LocationRequiredFields requiredFields,
     LocationResourceManager resourceManager)
 {
     SetField.NotNull(out this.apiKey, nameof(apiKey), apiKey);
     SetField.NotNull(out this.channelId, nameof(channelId), channelId);
     SetField.NotNull(out this.prompt, nameof(prompt), prompt);
     this.geoSpatialService = geoSpatialService;
     this.options           = options;
     this.requiredFields    = requiredFields;
     this.resourceManager   = resourceManager ?? new LocationResourceManager();
 }
Esempio n. 8
0
        internal LocationDialogFactory(
            string apiKey,
            string channelId,
            string prompt,
            IGeoSpatialService geoSpatialService,
            LocationOptions options,
            LocationRequiredFields requiredFields,
            LocationResourceManager resourceManager)
        {
            SetField.NotNull(out this.apiKey, nameof(apiKey), apiKey);
            SetField.NotNull(out this.channelId, nameof(channelId), channelId);
            SetField.NotNull(out this.prompt, nameof(prompt), prompt);
            this.geoSpatialService = geoSpatialService;
            this.options           = options;
            this.requiredFields    = requiredFields;
            this.resourceManager   = resourceManager ?? new LocationResourceManager();

            if (!string.IsNullOrEmpty(this.apiKey) && this.apiKey.Length > 60)
            {
                useAzureMaps = false;
            }
        }
        protected async Task <List <Card> > GetRouteDirectionsViewCards(DialogContext sc, RouteDirections routeDirections, IGeoSpatialService service)
        {
            var routes = routeDirections.Routes;
            var state  = await Accessor.GetAsync(sc.Context);

            var cardData = new List <RouteDirectionsModel>();
            var cards    = new List <Card>();
            var routeId  = 0;

            if (routes != null)
            {
                state.FoundRoutes = routes.Select(route => route.Summary).ToList();

                var destination = state.Destination;
                destination.Provider.Add(routeDirections.Provider);

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

                    // Set card data with formatted time strings and distance converted to miles
                    var routeDirectionsModel = new RouteDirectionsModel()
                    {
                        Name                    = destination.Name,
                        Address                 = destination.Address,
                        AvailableDetails        = destination.AvailableDetails,
                        Hours                   = destination.Hours,
                        PointOfInterestImageUrl = await service.GetRouteImageAsync(destination, route, ImageSize.RouteWidth, ImageSize.RouteHeight),
                        TravelTime              = GetShortTravelTimespanString(travelTimeSpan),
                        DelayStatus             = GetFormattedTrafficDelayString(trafficTimeSpan),
                        Distance                = $"{(route.Summary.LengthInMeters / 1609.344).ToString("N1")} {PointOfInterestSharedStrings.MILES_ABBREVIATION}",
                        ETA                   = route.Summary.ArrivalTime.ToShortTimeString(),
                        TravelTimeSpeak       = GetFormattedTravelTimeSpanString(travelTimeSpan),
                        TravelDelaySpeak      = GetFormattedTrafficDelayString(trafficTimeSpan),
                        ProviderDisplayText   = destination.GenerateProviderDisplayText(),
                        Speak                 = GetFormattedTravelTimeSpanString(travelTimeSpan),
                        ActionStartNavigation = PointOfInterestSharedStrings.START,
                        CardTitle             = PointOfInterestSharedStrings.CARD_TITLE
                    };

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

                foreach (var data in cardData)
                {
                    cards.Add(new Card(GetDivergedCardName(sc.Context, "PointOfInterestDetailsWithRoute"), data));
                }
            }

            return(cards);
        }
        // service: for details. the one generates pointOfInterestList
        protected async Task <List <Card> > GetPointOfInterestLocationCards(DialogContext sc, List <PointOfInterestModel> pointOfInterestList, IGeoSpatialService service)
        {
            var state = await Accessor.GetAsync(sc.Context);

            var cards = new List <Card>();

            if (pointOfInterestList != null && pointOfInterestList.Count > 0)
            {
                for (var i = 0; i < pointOfInterestList.Count; i++)
                {
                    pointOfInterestList[i] = await service.GetPointOfInterestDetailsAsync(pointOfInterestList[i], ImageSize.OverviewItemWidth, ImageSize.OverviewItemHeight);

                    // Increase by one to avoid zero based options to the user which are confusing
                    pointOfInterestList[i].Index = i + 1;

                    if (string.IsNullOrEmpty(pointOfInterestList[i].PointOfInterestImageUrl))
                    {
                        pointOfInterestList[i].PointOfInterestImageUrl = GetCardImageUri(FallbackPointOfInterestImageFileName);
                    }

                    if (string.IsNullOrEmpty(pointOfInterestList[i].Name))
                    {
                        // Show address as the name
                        pointOfInterestList[i].Name    = pointOfInterestList[i].Address;
                        pointOfInterestList[i].Address = pointOfInterestList[i].AddressAlternative;
                    }
                }

                // Loop again as name may have changed
                for (var i = 0; i < pointOfInterestList.Count; i++)
                {
                    // If multiple points of interest share the same name, use their combined name & address as the speak property.
                    // Otherwise, just use the name.
                    if (pointOfInterestList.Where(x => x.Name == pointOfInterestList[i].Name).Skip(1).Any())
                    {
                        var promptTemplate     = POISharedResponses.PointOfInterestSuggestedActionName;
                        var promptReplacements = new StringDictionary
                        {
                            { "Name", WebUtility.HtmlEncode(pointOfInterestList[i].Name) },
                            { "Address", $"<say-as interpret-as='address'>{WebUtility.HtmlEncode(pointOfInterestList[i].AddressForSpeak)}</say-as>" },
                        };
                        pointOfInterestList[i].Speak = ResponseManager.GetResponse(promptTemplate, promptReplacements).Speak;

                        promptReplacements = new StringDictionary
                        {
                            { "Name", pointOfInterestList[i].Name },
                            { "Address", pointOfInterestList[i].AddressForSpeak },
                        };
                        pointOfInterestList[i].RawSpeak = ResponseManager.GetResponse(promptTemplate, promptReplacements).Speak;
                    }
                    else
                    {
                        pointOfInterestList[i].Speak    = WebUtility.HtmlEncode(pointOfInterestList[i].Name);
                        pointOfInterestList[i].RawSpeak = pointOfInterestList[i].Name;
                    }
                }

                state.LastFoundPointOfInterests = pointOfInterestList;

                foreach (var pointOfInterest in pointOfInterestList)
                {
                    cards.Add(new Card(GetDivergedCardName(sc.Context, "PointOfInterestOverview"), pointOfInterest));
                }
            }

            return(cards);
        }
        protected async Task <Card> GetContainerCard(ITurnContext context, string name, LatLng currentCoordinates, List <PointOfInterestModel> pointOfInterestList, IGeoSpatialService service)
        {
            var model = new PointOfInterestModel
            {
                CardTitle = PointOfInterestSharedStrings.CARD_TITLE,
                PointOfInterestImageUrl = await service.GetAllPointOfInterestsImageAsync(currentCoordinates, pointOfInterestList, ImageSize.OverviewWidth, ImageSize.OverviewHeight),
                Provider = new SortedSet <string>
                {
                    service.Provider
                }
            };

            foreach (var poi in pointOfInterestList)
            {
                model.Provider.UnionWith(poi.Provider);
            }

            model.ProviderDisplayText = model.GenerateProviderDisplayText();

            return(new Card
            {
                Name = GetDivergedCardName(context, name),
                Data = model
            });
        }