// handle the user asking for the next track in an album or playlist
        // i.e. "Alexa, Next".  This can be expanded to the other AudioPlayer intents, such as repeat, back, etc.

        public override async Task <SpeechletResponse> OnAudioIntentAsync(AudioIntentRequest audioIntentRequest,
                                                                          Context context)
        {
            var httpClient = new HttpClient();

            if (audioIntentRequest.Intent.Name == "AMAZON.NextIntent")
            {
                return(await Groove.Music.EnqueueGrooveMusic(context, httpClient, "AMAZON.NextIntent"));
            }
            return(null);
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public static SpeechletRequestEnvelope FromJson(JObject json)
        {
            if (json["version"] != null && json.Value <string>("version") != Sdk.VERSION)
            {
                throw new SpeechletException("Request must conform to 1.0 schema.");
            }

            SpeechletRequest request;
            JObject          requestJson = json.Value <JObject>("request");
            string           requestType = requestJson.Value <string>("type");
            string           requestId   = requestJson.Value <string>("requestId");
            DateTime         timestamp   = requestJson.Value <DateTime>("timestamp");

            switch (requestType)
            {
            case "LaunchRequest":
                request = new LaunchRequest(requestId, timestamp);
                break;

            case "IntentRequest":
                string intentName = "";
                intentName = requestJson.Value <JObject>("intent").Value <string>("name");
                if (intentName == "AMAZON.NextIntent")
                {
                    request = new AudioIntentRequest(requestId, timestamp,
                                                     Intent.FromJson(requestJson.Value <JObject>("intent")));
                    return(new SpeechletRequestEnvelope
                    {
                        Request = request,
                        Version = json.Value <string>("version"),
                        Context = Context.FromJson(json.Value <JObject>("context"))
                    });
                }
                request = new IntentRequest(requestId, timestamp,
                                            Intent.FromJson(requestJson.Value <JObject>("intent")));
                break;

            case "SessionStartedRequest":
                request = new SessionStartedRequest(requestId, timestamp);
                break;

            case "SessionEndedRequest":
                SessionEndedRequest.ReasonEnum reason;
                Enum.TryParse <SessionEndedRequest.ReasonEnum>(requestJson.Value <string>("reason"), out reason);
                request = new SessionEndedRequest(requestId, timestamp, reason);
                break;

            case "AudioPlayer.PlaybackNearlyFinished":
                request = new AudioPlayerRequest(requestId, timestamp);
                break;

            default:
                System.Diagnostics.Debug.WriteLine("Unhandled requestType" + requestType);
                throw new ArgumentException("json");
            }

            if (requestType == "AudioPlayer.PlaybackNearlyFinished")
            {
                return(new SpeechletRequestEnvelope
                {
                    Request = request,
                    Version = json.Value <string>("version"),
                    Context = Context.FromJson(json.Value <JObject>("context"))
                });
            }

            return(new SpeechletRequestEnvelope {
                Request = request,
                Session = Session.FromJson(json.Value <JObject>("session")),
                Version = json.Value <string>("version")
            });
        }