private async Task <IEnumerable <Hotel> > GetHotelsAsync(HotelsQuery searchQuery)
        {
            var hotels = new List <Hotel>();

            // Filling the hotels results manually just for demo purposes
            for (int i = 1; i <= 5; i++)
            {
                var   random = new Random(i);
                Hotel hotel  = new Hotel()
                {
                    Name            = $"{searchQuery.Destination} Hotel {i}",
                    Location        = searchQuery.Destination,
                    Rating          = random.Next(1, 5),
                    NumberOfReviews = random.Next(0, 5000),
                    PriceStarting   = random.Next(80, 450),
                    Image           = $"https://placeholdit.imgix.net/~text?txtsize=35&txt=Hotel+{i}&w=500&h=260"
                };

                hotels.Add(hotel);
            }

            hotels.Sort((h1, h2) => h1.PriceStarting.CompareTo(h2.PriceStarting));

            return(hotels);
        }
Exemple #2
0
        private async Task <IEnumerable <Hotel> > GetHotelsAsync(HotelsQuery searchQuery)
        {
            var hotelNames = new List <string>()
            {
                "Excellent", "Splendid", "Supreme", "Excelsior", "High Class"
            };
            var hotels = new List <Hotel>();

            // Filling the hotels results manually just for demo purposes
            for (int i = 1; i <= 5; i++)
            {
                var   random = new Random(i);
                Hotel hotel  = new Hotel()
                {
                    //Name = $"{searchQuery.Destination ?? searchQuery.AirportCode} Hotel {i}",
                    Name            = $"{hotelNames[i-1]} Hotel",
                    Location        = searchQuery.Destination ?? searchQuery.AirportCode,
                    Rating          = random.Next(1, 5),
                    NumberOfReviews = random.Next(0, 5000),
                    PriceStarting   = random.Next(80, 450),
                    Image           = $"https://placeholdit.imgix.net/~text?txtsize=35&txt=Hotel+{i}&w=500&h=260"
                };

                hotels.Add(hotel);
            }

            hotels.Sort((h1, h2) => h1.PriceStarting.CompareTo(h2.PriceStarting));

            // Waste some time to simulate database search
            await Task.Delay(3000);

            return(hotels);
        }
        private async Task <IEnumerable <Hotel> > GetHotelsAsync(HotelsQuery searchQuery)
        {
            var hotels = new List <Hotel>();


            for (int i = 1; i <= 5; i++)
            {
                var   random = new Random(i);
                Hotel hotel  = new Hotel()
                {
                    Name            = $"{searchQuery.Destination} Hotel {i}",
                    Location        = searchQuery.Destination,
                    Rating          = random.Next(1, 5),
                    NumberOfReviews = random.Next(0, 5000),
                    PriceStarting   = random.Next(80, 450),
                    Image           = $"https://www.dublinairport.com/images/default-source/default-album/radisson.jpg?sfvrsn=0"
                };

                hotels.Add(hotel);
            }

            hotels.Sort((h1, h2) => h1.PriceStarting.CompareTo(h2.PriceStarting));

            return(hotels);
        }
        public async Task Search(IDialogContext context, IAwaitable <IMessageActivity> activity, LuisResult result)
        {
            var message = await activity;
            await context.PostAsync($"Bem vindo ao buscador de hotel! Estamos verificando a sua mensagem: '{message.Text}'...");

            var hotelsQuery = new HotelsQuery();

            var hotelsFormDialog = new FormDialog <HotelsQuery>(hotelsQuery, this.BuildHotelsForm, FormOptions.PromptInStart, result.Entities);

            context.Call(hotelsFormDialog, this.ResumeAfterHotelsFormDialog);
        }
Exemple #5
0
        public async Task Search(IDialogContext context, IAwaitable <IMessageActivity> activity, LuisResult result)
        {
            var message = await activity;
            await context.PostAsync($"Welcome to the Hotels finder! We are analyzing your message: '{message.Text}'...");

            var hotelsQuery = new HotelsQuery();

            EntityRecommendation cityEntityRecommendation;

            if (result.TryFindEntity(EntityGeographyCity, out cityEntityRecommendation))
            {
                cityEntityRecommendation.Type = "Destination";
            }

            var hotelsFormDialog = new FormDialog <HotelsQuery>(hotelsQuery, this.BuildHotelsForm, FormOptions.PromptInStart, result.Entities);

            context.Call(hotelsFormDialog, this.ResumeAfterHotelsFormDialog);
        }
Exemple #6
0
        public async Task Search(IDialogContext context, IAwaitable <IMessageActivity> activity, LuisResult result)
        {
            bool isWelcomeDone = false;

            context.ConversationData.TryGetValue <bool>("WelcomeDone", out isWelcomeDone);

            // Did we already do this? Has the user followed up an initial query with another one?
            if (!isWelcomeDone)
            {
                var response = context.MakeMessage();
                // For display text, use Summary to display large font, italics - this is to emphasize this
                // is the Skill speaking, not Cortana
                // Continue the displayed text using the Text property of the response message
                response.Summary = $"Welcome to the Hotels finder!";
                response.Text    = $"We are analyzing your message: '{(await activity).Text}'...";
                // Speak is what is spoken out
                response.Speak = @"<speak version=""1.0"" xml:lang=""en-US"">Welcome to the Hotels finder!<break time=""1000ms""/></speak>";;
                // InputHint influences how the microphone behaves
                response.InputHint = InputHints.IgnoringInput;
                // Post the response message
                await context.PostAsync(response);

                // Set a flag in conversation data to record that we already sent out the Welcome message
                context.ConversationData.SetValue <bool>("WelcomeDone", true);
            }

            // Check that the user has specified either a destination city, or an airport code
            var hotelsQuery = new HotelsQuery();

            EntityRecommendation cityEntityRecommendation;

            if (result.TryFindEntity(EntityGeographyCity, out cityEntityRecommendation))
            {
                cityEntityRecommendation.Type = "Destination";
            }

            // Use a FormDialog to query the user for missing destination, if necessary
            var hotelsFormDialog = new FormDialog <HotelsQuery>(hotelsQuery, this.BuildHotelsForm, FormOptions.PromptInStart, result.Entities);

            context.Call(hotelsFormDialog, this.ResumeAfterHotelsFormDialog);
        }
        private async Task <IEnumerable <Hotel> > GetHotelsAsync(HotelsQuery searchQuery)
        {
            var url = string.Empty;

            var apiKey = "AIzaSyCZtwsY0V0YLyRy0XhIZZ5bjJuZ7qpgK-c";

            if (!string.IsNullOrEmpty(searchQuery.Destination))
            {
                url = $"https://maps.googleapis.com/maps/api/place/textsearch/json?query=hotel%20{searchQuery.Destination}&l&key={apiKey}";
            }

            var hotels = new List <Hotel>();

            using (var client = new HttpClient())
            {
                using (var r = await client.GetAsync(new Uri(url)))
                {
                    string result = await r.Content.ReadAsStringAsync();

                    var data = JsonConvert.DeserializeObject <HotelResult>(result);

                    for (int i = 0; i < 5; i++)
                    {
                        Hotel hotel = new Hotel()
                        {
                            Name     = data.Results[i].Name,
                            Location = data.Results[0].Formatted_address,
                            Rating   = data.Results[i].Rating,
                        };
                        hotels.Add(hotel);
                    }
                }
            }

            return(hotels);
        }
Exemple #8
0
        private async Task ResumeAfterHotelsFormDialog(DialogContext context, HotelsQuery searchQuery)
        {
            try
            {
                var hotels = await this.GetHotelsAsync(searchQuery);

                await context.Context.SendActivityAsync($"I found in total {hotels.Count()} hotels for your dates:");

                var resultMessage = context.Context.Activity.CreateReply();
                resultMessage.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                resultMessage.Attachments      = new List <Attachment>();

                foreach (var hotel in hotels)
                {
                    HeroCard heroCard = new HeroCard()
                    {
                        Title    = hotel.Name,
                        Subtitle = $"{hotel.Rating} starts. {hotel.NumberOfReviews} reviews. From ${hotel.PriceStarting} per night.",
                        Images   = new List <CardImage>()
                        {
                            new CardImage()
                            {
                                Url = hotel.Image
                            }
                        },
                        Buttons = new List <CardAction>()
                        {
                            new CardAction()
                            {
                                Title = "More details",
                                Type  = ActionTypes.OpenUrl,
                                Value = $"https://www.bing.com/search?q=hotels+in+" + HttpUtility.UrlEncode(hotel.Location)
                            }
                        }
                    };

                    resultMessage.Attachments.Add(heroCard.ToAttachment());
                }

                await context.Context.SendActivityAsync(resultMessage);
            }
            catch (FormCanceledException ex)
            {
                string reply;

                if (ex.InnerException == null)
                {
                    reply = "You have canceled the operation. Quitting from the HotelsDialog";
                }
                else
                {
                    reply = $"Oops! Something went wrong :( Technical Details: {ex.InnerException.Message}";
                }

                await context.Context.SendActivityAsync(reply);
            }
            finally
            {
                await context.EndDialogAsync(null);
            }
        }