Exemplo n.º 1
0
 public LocationRequiredFieldsDialog(Bing.Location location, LocationRequiredFields requiredFields, LocationResourceManager resourceManager)
     : base(resourceManager)
 {
     SetField.NotNull(out this.location, nameof(location), location);
     this.requiredFields   = requiredFields;
     this.location.Address = this.location.Address ?? new Bing.Address();
 }
Exemplo n.º 2
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="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>
 public LocationDialog(
     string apiKey,
     string channelId,
     string prompt,
     LocationOptions options = LocationOptions.None,
     LocationRequiredFields requiredFields   = LocationRequiredFields.None,
     LocationResourceManager resourceManager = null)
     : this(apiKey, channelId, prompt, new BingGeoSpatialService(), options, requiredFields, resourceManager)
 {
 }
Exemplo n.º 3
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);
 }
 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;
 }
Exemplo n.º 5
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="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>
 public LocationDialog(
     string apiKey,
     string channelId,
     string prompt,
     LocationOptions options = LocationOptions.None,
     LocationRequiredFields requiredFields   = LocationRequiredFields.None,
     LocationResourceManager resourceManager = null)
     : this(new LocationDialogFactory(apiKey, channelId, prompt, ((!string.IsNullOrEmpty(apiKey) && apiKey.Length <= 60) ? (IGeoSpatialService) new AzureMapsSpatialService(apiKey) : new BingGeoSpatialService(apiKey)), options, requiredFields, resourceManager), new FavoritesManager(), resourceManager)
 {
     this.options = options;
 }
Exemplo n.º 6
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="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>
 public LocationDialog(
     string apiKey,
     string channelId,
     string prompt,
     LocationOptions options = LocationOptions.None,
     LocationRequiredFields requiredFields   = LocationRequiredFields.None,
     LocationResourceManager resourceManager = null)
     : this(new LocationDialogFactory(apiKey, channelId, prompt, new GoogleGeocodingService(apiKey), options, requiredFields, resourceManager), new FavoritesManager(), resourceManager)
 {
     this.options = options;
 }
Exemplo n.º 7
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="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>
 /// <param name="announceDirectionsToUser">Flag to announce directions for the captured address.</param>
 /// <param name="destination">The destination address to use for turn by turn directions</param>
 public LocationDialog(
     string apiKey,
     string channelId,
     string prompt,
     LocationOptions options = LocationOptions.None,
     LocationRequiredFields requiredFields   = LocationRequiredFields.None,
     LocationResourceManager resourceManager = null, bool announceDirectionsToUser = false, string destination = "")
     : this(apiKey, channelId, prompt, new BingGeoSpatialService(), options, requiredFields, resourceManager)
 {
     announceDirections = announceDirectionsToUser;
     addressDestination = destination;
 }
Exemplo n.º 8
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;
 }
Exemplo n.º 9
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;
 }
Exemplo n.º 10
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();
 }
Exemplo n.º 12
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;
            }
        }
        public LocationDialog(
            string apiKey,
            string prompt,
            BotState state,
            string dialogId         = DefaultLocationDialogId,
            bool skipPrompt         = false,
            bool useAzureMaps       = true,
            LocationOptions options = LocationOptions.None,
            LocationRequiredFields requiredFields   = LocationRequiredFields.None,
            LocationResourceManager resourceManager = null) : base(dialogId)
        {
            resourceManager = resourceManager ?? new LocationResourceManager();

            if (!options.HasFlag(LocationOptions.SkipFavorites) && state == null)
            {
                throw new ArgumentNullException(nameof(state),
                                                "If LocationOptions.SkipFavorites is not used then BotState object must be " +
                                                "provided to allow for storing / retrieval of favorites");
            }

            var favoriteLocations = state.CreateProperty <List <FavoriteLocation> >($"{nameof(LocationDialog)}.Favorites");
            var favoritesManager  = new FavoritesManager(favoriteLocations);

            IGeoSpatialService geoSpatialService;

            if (useAzureMaps)
            {
                geoSpatialService = new AzureMapsSpatialService(apiKey);
            }
            else
            {
                geoSpatialService = new BingGeoSpatialService(apiKey);
            }

            InitialDialogId = dialogId;

            AddDialog(new ChoicePrompt(PromptDialogIds.Choice));
            AddDialog(new TextPrompt(PromptDialogIds.Text));
            AddDialog(new ConfirmPrompt(PromptDialogIds.Confirm));

            AddDialog(new WaterfallDialog(InitialDialogId, new WaterfallStep[]
            {
                async(dc, cancellationToken) =>
                {
                    if (options.HasFlag(LocationOptions.SkipFavorites) ||
                        !favoritesManager.GetFavorites(dc.Context).Result.Any())
                    {
                        var isFacebookChannel = StringComparer.OrdinalIgnoreCase.Equals(
                            dc.Context.Activity.ChannelId, "facebook");

                        if (options.HasFlag(LocationOptions.UseNativeControl) && isFacebookChannel)
                        {
                            return(await dc.BeginDialogAsync(DialogIds.LocationRetrieverFacebookDialog));
                        }

                        return(await dc.BeginDialogAsync(DialogIds.LocationRetrieverRichDialog));
                    }

                    return(await dc.BeginDialogAsync(DialogIds.HeroStartCardDialog));
                },
                async(dc, cancellationToken) =>
                {
                    var selectedLocation = (Bing.Location)dc.Result;
                    dc.Values[StepContextKeys.SelectedLocation] = selectedLocation;

                    if (options.HasFlag(LocationOptions.SkipFinalConfirmation))
                    {
                        return(await dc.NextAsync());
                    }

                    await dc.PromptAsync(PromptDialogIds.Confirm,
                                         new PromptOptions()
                    {
                        Prompt = new Activity
                        {
                            Type = ActivityTypes.Message,
                            Text = string.Format(resourceManager.ConfirmationAsk,
                                                 selectedLocation.GetFormattedAddress(resourceManager.AddressSeparator))
                        },
                        RetryPrompt = new Activity
                        {
                            Type = ActivityTypes.Message,
                            Text = resourceManager.ConfirmationInvalidResponse
                        }
                    });

                    return(EndOfTurn);
                },
                async(dc, cancellationToken) =>
                {
                    if (dc.Result is bool result && !result)
                    {
                        await dc.Context.SendActivityAsync(resourceManager.ResetPrompt);
                        return(await dc.ReplaceDialogAsync(InitialDialogId));
                    }

                    if (!options.HasFlag(LocationOptions.SkipFavorites))
                    {
                        return(await dc.BeginDialogAsync(DialogIds.AddToFavoritesDialog,
                                                         new AddToFavoritesDialogOptions()
                        {
                            Location = (Bing.Location)dc.Values[StepContextKeys.SelectedLocation]
                        }
                                                         ));
                    }
                    else
                    {
                        await dc.NextAsync();
                    }

                    return(EndOfTurn);
                },
                async(dc, cancellationToken) =>
                {
                    var selectedLocation = (Bing.Location)dc.Values[StepContextKeys.SelectedLocation];
                    return(await dc.EndDialogAsync(CreatePlace(selectedLocation)));
                }
            }));
Exemplo n.º 14
0
        private async Task <bool> CompleteFieldIfMissing(IDialogContext context, string prompt, LocationRequiredFields field, string name, string value)
        {
            if (!this.requiredFields.HasFlag(field) || !string.IsNullOrEmpty(value))
            {
                return(false);
            }

            string message;

            if (this.lastInput == null)
            {
                string formattedAddress = this.location.GetFormattedAddress(this.ResourceManager.AddressSeparator);
                if (string.IsNullOrWhiteSpace(formattedAddress))
                {
                    message = string.Format(this.ResourceManager.AskForEmptyAddressTemplate, prompt);
                }
                else
                {
                    message = string.Format(this.ResourceManager.AskForPrefix, formattedAddress) +
                              string.Format(this.ResourceManager.AskForTemplate, prompt);
                }
            }
            else
            {
                message = string.Format(this.ResourceManager.AskForPrefix, this.lastInput) +
                          string.Format(this.ResourceManager.AskForTemplate, prompt);
            }

            this.currentFieldName = name;
            await context.PostAsync(message);

            context.Wait(this.MessageReceivedAsync);

            return(true);
        }
        public LocationDialog(
            string apiKey,
            string prompt,
            bool skipPrompt         = false,
            bool useAzureMaps       = true,
            LocationOptions options = LocationOptions.None,
            LocationRequiredFields requiredFields   = LocationRequiredFields.None,
            LocationResourceManager resourceManager = null) : base(MainDialogId)
        {
            resourceManager = resourceManager ?? new LocationResourceManager();
            var favoritesManager = new FavoritesManager();

            IGeoSpatialService geoSpatialService;

            if (useAzureMaps)
            {
                geoSpatialService = new AzureMapsSpatialService(apiKey);
            }
            else
            {
                geoSpatialService = new BingGeoSpatialService(apiKey);
            }

            Dialogs.Add(Inputs.Choice, new ChoicePrompt(Culture.English));
            Dialogs.Add(Inputs.Text, new TextPrompt());
            Dialogs.Add(Inputs.Confirm, new ConfirmPrompt(Culture.English));

            Dialogs.Add(MainDialogId, new WaterfallStep[]
            {
                async(dc, args, next) =>
                {
                    if (options.HasFlag(LocationOptions.SkipFavorites) ||
                        !favoritesManager.GetFavorites(dc.Context).Result.Any())
                    {
                        var isFacebookChannel = StringComparer.OrdinalIgnoreCase.Equals(
                            dc.Context.Activity.ChannelId, "facebook");

                        if (options.HasFlag(LocationOptions.UseNativeControl) && isFacebookChannel)
                        {
                            await dc.Begin(DialogIds.LocationRetrieverFacebookDialog);
                        }
                        else
                        {
                            await dc.Begin(DialogIds.LocationRetrieverRichDialog);
                        }
                    }
                    else
                    {
                        await dc.Begin(DialogIds.HeroStartCardDialog);
                    }
                },
                async(dc, args, next) =>
                {
                    Bing.Location selectedLocation = (Bing.Location)args[Outputs.SelectedLocation];
                    dc.ActiveDialog.State[Outputs.SelectedLocation] = selectedLocation;

                    if (options.HasFlag(LocationOptions.SkipFinalConfirmation))
                    {
                        await next();
                    }
                    else
                    {
                        await dc.Prompt(Inputs.Confirm,
                                        string.Format(resourceManager.ConfirmationAsk,
                                                      selectedLocation.GetFormattedAddress(resourceManager.AddressSeparator)),
                                        new PromptOptions()
                        {
                            RetryPromptString = resourceManager.ConfirmationInvalidResponse
                        });
                    }
                },
                async(dc, args, next) =>
                {
                    if (args is ConfirmResult result && !result.Confirmation)
                    {
                        await dc.Context.SendActivity(resourceManager.ResetPrompt);
                        await dc.Replace(MainDialogId);
                    }