Beispiel #1
0
        public async Task <IActionResult> Get([FromQuery] string body)
        {
            var spotify = new SpotifyClient(SPOTIFY_ID, SPOTIFY_SECRET);
            var song    = await spotify.GetSong(body);

            var messagingResponse = new MessagingResponse();

            if (song == null)
            {
                messagingResponse.Message("Sending back a sample message since Spotify couldn't find our results!");
            }
            else
            {
                var stringBuilder = new StringBuilder();
                stringBuilder.AppendLine($"Artist: {song["artist"].ToString()}");
                stringBuilder.AppendLine($"Title: {song["title"].ToString()}");
                var previewUrl = song["previewUrl"].ToString();
                if (string.IsNullOrEmpty(previewUrl))
                {
                    stringBuilder.AppendLine("Sorry we couldn't find a preview. But try visiting Spotify to listen to the full track");
                }
                else
                {
                    stringBuilder.AppendLine($"Here's the preview: {previewUrl}");
                }
                var message = new Message();
                message.Body(stringBuilder.ToString());
                message.Media(new Uri(song["image"].ToString()));
                messagingResponse.Append(message);
            }

            return(new ContentResult {
                Content = messagingResponse.ToString(), ContentType = "application/xml"
            });
        }