Ejemplo n.º 1
0
        private async Task <bool> IsDeviceActive(
            ITurnContext turnContext,
            string token,
            string commandQuery,
            CancellationToken cancellationToken,
            Playlist playlist = null)
        {
            var devices = await _spotifyService.GetDevices(token);

            if (devices.Any(d => d.IsActive))
            {
                return(true);
            }

            // No active devices

            var heroCard = new HeroCard {
                Buttons = new List <CardAction>()
            };

            if (playlist != null)
            {
                heroCard.Buttons.Add(
                    new CardAction
                {
                    Title = "Open Spotify",
                    Value = playlist.Uri,
                    Type  = ActionTypes.OpenUrl,
                });
                heroCard.Buttons.Add(
                    new CardAction
                {
                    Title = "Open Spotify Web Player",
                    Value = playlist.ExternalUrls.Spotify,
                    Type  = ActionTypes.OpenUrl,
                });
            }

            heroCard.Buttons.Add(
                new CardAction
            {
                Title = "Spotify is playing! Try Again",
                Type  = ActionTypes.ImBack,
                Value = commandQuery
            });

            var message = MessageFactory.Attachment(
                new Attachment {
                ContentType = HeroCard.ContentType, Content = heroCard
            },
                text: "To play or join with Ringo your Spotify app needs to be active or playing. Open Spotify and press play, then try again.");

            await turnContext.SendActivityAsync(message, cancellationToken : cancellationToken);

            return(false);
        }