Ejemplo n.º 1
0
        public override async Task <SkillResponse> HandleIntent(SkillRequest skillRequest, IntentRequest intentRequest,
                                                                ILambdaContext context)
        {
            var genreName = intentRequest.GetSlotValue("GenreNameSlot");
            var items     = await SpotifyClient.SearchItemsAsync($"genre:{genreName}", SearchType.Track);

            if (items.HasError())
            {
                return(TellWithoutEnding("There was an error with searching for the genre"));
            }

            if (!items.Tracks.Items.Any())
            {
                return(TellWithoutEnding($"Sorry. Couldn't find any songs for the {genreName}, genre"));
            }

            var firstTrack = items.Tracks.Items.Shuffle().FirstOrDefault();

            if (firstTrack == null || firstTrack.HasError())
            {
                return(TellWithoutEnding("There was an error with shuffling the tracks"));
            }

            await SpotifyClient.ResumePlaybackAsync("", "", new List <string> {
                firstTrack.Uri
            }, "");

            return(TellWithoutEnding(
                       $"Surprising you with the following song: {firstTrack.Name}"));
        }