예제 #1
0
        public override async Task <SkillResponse> HandleIntent(SkillRequest skillRequest, IntentRequest intentRequest,
                                                                ILambdaContext context)
        {
            var categoryName = intentRequest.GetSlotValue("CategoryName");
            var categories   = await SpotifyClient.GetCategoriesAsync(limit : 50);

            var list = (from playlist in categories.Categories.Items
                        let score = new SmithWatermanGotoh().GetSimilarity(playlist.Name.ToLower(), categoryName.ToLower())
                                    select new MostMatchingCategory(playlist, score)).ToList();

            var mostMatching = list.MaxBy(x => x.Score).FirstOrDefault();

            if (mostMatching == null)
            {
                return(TellWithoutEnding("Sorry. Couldn't find the requested playlist"));
            }

            var speech = $"Found {mostMatching.Category.Name}, is this the correct one?";

            skillRequest.Session.SetSessionValue("CategoryId", mostMatching.Category.Id);
            return(ResponseBuilder.Ask(speech, new Reprompt(speech), skillRequest.Session));
        }