From d304947c6eac3ceda4622a832ffad033a92a81b7 Mon Sep 17 00:00:00 2001 From: Tobias Viehweger Date: Thu, 29 Dec 2016 17:35:26 +0100 Subject: [PATCH 1/7] Add support for Directives --- Alexa.NET/Response/IDirective.cs | 14 ++++++++++++++ Alexa.NET/Response/Response.cs | 4 ++++ 2 files changed, 18 insertions(+) create mode 100644 Alexa.NET/Response/IDirective.cs diff --git a/Alexa.NET/Response/IDirective.cs b/Alexa.NET/Response/IDirective.cs new file mode 100644 index 0000000..0333f73 --- /dev/null +++ b/Alexa.NET/Response/IDirective.cs @@ -0,0 +1,14 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Alexa.NET.Response +{ + public interface IDirective + { + [JsonRequired] + string Type { get; } + } +} diff --git a/Alexa.NET/Response/Response.cs b/Alexa.NET/Response/Response.cs index 4a2d54a..b1c7f99 100644 --- a/Alexa.NET/Response/Response.cs +++ b/Alexa.NET/Response/Response.cs @@ -1,4 +1,5 @@ using Newtonsoft.Json; +using System.Collections.Generic; namespace Alexa.NET.Response { @@ -16,5 +17,8 @@ public class ResponseBody [JsonProperty("shouldEndSession")] [JsonRequired] public bool ShouldEndSession { get; set; } + + [JsonProperty("directives", NullValueHandling = NullValueHandling.Ignore)] + public IList Directives { get; set; } = new List(); } } \ No newline at end of file From 6c7a2abca04a1c126255af6e8ad9a8b2f8f3d81c Mon Sep 17 00:00:00 2001 From: Tobias Viehweger Date: Thu, 29 Dec 2016 17:35:38 +0100 Subject: [PATCH 2/7] Add support for AudioPlay.Play directive --- Alexa.NET/Response/Directive/AudioItem.cs | 11 +++++++++ .../Response/Directive/AudioItemStream.cs | 23 +++++++++++++++++++ .../Directive/AudioPlayerPlayDirective.cs | 20 ++++++++++++++++ Alexa.NET/Response/Directive/PlayBehavior.cs | 18 +++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 Alexa.NET/Response/Directive/AudioItem.cs create mode 100644 Alexa.NET/Response/Directive/AudioItemStream.cs create mode 100644 Alexa.NET/Response/Directive/AudioPlayerPlayDirective.cs create mode 100644 Alexa.NET/Response/Directive/PlayBehavior.cs diff --git a/Alexa.NET/Response/Directive/AudioItem.cs b/Alexa.NET/Response/Directive/AudioItem.cs new file mode 100644 index 0000000..c222acc --- /dev/null +++ b/Alexa.NET/Response/Directive/AudioItem.cs @@ -0,0 +1,11 @@ +using Newtonsoft.Json; + +namespace Alexa.NET.Response.Directive +{ + public class AudioItem + { + [JsonRequired] + [JsonProperty("stream")] + public AudioItemStream Stream { get; set; } + } +} diff --git a/Alexa.NET/Response/Directive/AudioItemStream.cs b/Alexa.NET/Response/Directive/AudioItemStream.cs new file mode 100644 index 0000000..71c6dc9 --- /dev/null +++ b/Alexa.NET/Response/Directive/AudioItemStream.cs @@ -0,0 +1,23 @@ +using Newtonsoft.Json; + +namespace Alexa.NET.Response.Directive +{ + public class AudioItemStream + { + [JsonRequired] + [JsonProperty("url")] + public string Url { get; set; } + + [JsonRequired] + [JsonProperty("token")] + public string Token { get; set; } + + [JsonRequired] + [JsonProperty("expectedPreviousToken")] + public string ExpectedPreviousToken { get; set; } + + [JsonRequired] + [JsonProperty("offsetInMilliseconds")] + public int OffsetInMilliseconds { get; set; } + } +} diff --git a/Alexa.NET/Response/Directive/AudioPlayerPlayDirective.cs b/Alexa.NET/Response/Directive/AudioPlayerPlayDirective.cs new file mode 100644 index 0000000..c5d08f1 --- /dev/null +++ b/Alexa.NET/Response/Directive/AudioPlayerPlayDirective.cs @@ -0,0 +1,20 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Alexa.NET.Response.Directive +{ + public class AudioPlayerDirective : IDirective + { + [JsonProperty("playBehavior")] + [JsonRequired] + [JsonConverter(typeof(StringEnumConverter))] + public PlayBehavior PlayBehavior { get; set; } + + [JsonProperty("audioItem")] + [JsonRequired] + public AudioItem AudioPlayerAudioItem { get; set; } + + [JsonProperty("type")] + public string Type => "AudioPlayer.Play"; + } +} diff --git a/Alexa.NET/Response/Directive/PlayBehavior.cs b/Alexa.NET/Response/Directive/PlayBehavior.cs new file mode 100644 index 0000000..8b40629 --- /dev/null +++ b/Alexa.NET/Response/Directive/PlayBehavior.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Threading.Tasks; + +namespace Alexa.NET.Response.Directive +{ + public enum PlayBehavior + { + [EnumMember(Value = "REPLACE_ALL")] + ReplaceAll, + [EnumMember(Value = "ENQUEUE")] + Enqueue, + [EnumMember(Value = "REPLACE_ENQUEUED")] + ReplaceEnqueued + } +} From 32c2a3e8278a0fde3c5d023fbd0b2d526cee23b7 Mon Sep 17 00:00:00 2001 From: Tobias Viehweger Date: Thu, 29 Dec 2016 18:26:02 +0100 Subject: [PATCH 3/7] Refactor request deserialization to JsonConverter & add AudioPlayer request --- Alexa.NET/Request/RequestBundle.cs | 39 ------------- Alexa.NET/Request/SkillRequest.cs | 8 ++- Alexa.NET/Request/Type/AudioPlayerRequest.cs | 26 +++++++++ Alexa.NET/Request/Type/Error.cs | 17 ++++++ .../{IIntentRequest.cs => IntentRequest.cs} | 2 +- .../{ILaunchRequest.cs => LaunchRequest.cs} | 2 +- Alexa.NET/Request/Type/PlaybackState.cs | 20 +++++++ .../Request/Type/{IRequest.cs => Request.cs} | 2 +- Alexa.NET/Request/Type/RequestBundle.cs | 38 ------------- Alexa.NET/Request/Type/RequestConverter.cs | 56 +++++++++++++++++++ ...EndedRequest.cs => SessionEndedRequest.cs} | 2 +- 11 files changed, 128 insertions(+), 84 deletions(-) delete mode 100644 Alexa.NET/Request/RequestBundle.cs create mode 100644 Alexa.NET/Request/Type/AudioPlayerRequest.cs create mode 100644 Alexa.NET/Request/Type/Error.cs rename Alexa.NET/Request/Type/{IIntentRequest.cs => IntentRequest.cs} (64%) rename Alexa.NET/Request/Type/{ILaunchRequest.cs => LaunchRequest.cs} (52%) create mode 100644 Alexa.NET/Request/Type/PlaybackState.cs rename Alexa.NET/Request/Type/{IRequest.cs => Request.cs} (89%) delete mode 100644 Alexa.NET/Request/Type/RequestBundle.cs create mode 100644 Alexa.NET/Request/Type/RequestConverter.cs rename Alexa.NET/Request/Type/{ISessionEndedRequest.cs => SessionEndedRequest.cs} (72%) diff --git a/Alexa.NET/Request/RequestBundle.cs b/Alexa.NET/Request/RequestBundle.cs deleted file mode 100644 index 16b4796..0000000 --- a/Alexa.NET/Request/RequestBundle.cs +++ /dev/null @@ -1,39 +0,0 @@ -using Alexa.NET.Request.Type; -using Newtonsoft.Json; -using System; - -namespace Alexa.NET.Request -{ - public class RequestBundle : IIntentRequest, ILaunchRequest, ISessionEndedRequest - { - [JsonProperty("type")] - public string Type { get; set; } - - [JsonProperty("requestId")] - public string RequestId { get; set; } - - [JsonProperty("timestamp")] - public DateTime Timestamp { get; set; } - - [JsonProperty("intent")] - public Intent Intent { get; set; } - - [JsonProperty("reason")] - public string Reason { get; set; } - - public System.Type GetRequestType() - { - switch (Type) - { - case "IntentRequest": - return typeof(IIntentRequest); - case "LaunchRequest": - return typeof(ILaunchRequest); - case "SessionEndedRequest": - return typeof(ISessionEndedRequest); - default: - throw new ArgumentOutOfRangeException(nameof(Type), $"Unknown request type: {Type}."); - } - } - } -} \ No newline at end of file diff --git a/Alexa.NET/Request/SkillRequest.cs b/Alexa.NET/Request/SkillRequest.cs index e2c4dfa..e1b6fe0 100644 --- a/Alexa.NET/Request/SkillRequest.cs +++ b/Alexa.NET/Request/SkillRequest.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using Alexa.NET.Request.Type; +using Newtonsoft.Json; namespace Alexa.NET.Request { @@ -11,11 +12,12 @@ public class SkillRequest public Session Session { get; set; } [JsonProperty("request")] - public RequestBundle Request { get; set; } + [JsonConverter(typeof(RequestConverter))] + public Type.Request Request { get; set; } public System.Type GetRequestType() { - return Request?.GetRequestType(); + return Request?.GetType(); } } } \ No newline at end of file diff --git a/Alexa.NET/Request/Type/AudioPlayerRequest.cs b/Alexa.NET/Request/Type/AudioPlayerRequest.cs new file mode 100644 index 0000000..e7573ad --- /dev/null +++ b/Alexa.NET/Request/Type/AudioPlayerRequest.cs @@ -0,0 +1,26 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Alexa.NET.Request.Type +{ + public class AudioPlayerRequest: Request + { + [JsonProperty("token")] + string Token { get; set; } + + [JsonProperty("locale")] + string Locale { get; set; } + + [JsonProperty("offsetInMilliseconds")] + string OffsetInMilliseconds { get; set; } + + [JsonProperty("error")] + Error Error { get; set; } + + [JsonProperty("currentPlaybackState")] + PlaybackState CurrentPlaybackState { get; set; } + } +} diff --git a/Alexa.NET/Request/Type/Error.cs b/Alexa.NET/Request/Type/Error.cs new file mode 100644 index 0000000..39d3318 --- /dev/null +++ b/Alexa.NET/Request/Type/Error.cs @@ -0,0 +1,17 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Alexa.NET.Request.Type +{ + public class Error + { + [JsonProperty("type")] + string Type { get; set; } + + [JsonProperty("message")] + string Message { get; set; } + } +} diff --git a/Alexa.NET/Request/Type/IIntentRequest.cs b/Alexa.NET/Request/Type/IntentRequest.cs similarity index 64% rename from Alexa.NET/Request/Type/IIntentRequest.cs rename to Alexa.NET/Request/Type/IntentRequest.cs index 1d9a543..e5aa717 100644 --- a/Alexa.NET/Request/Type/IIntentRequest.cs +++ b/Alexa.NET/Request/Type/IntentRequest.cs @@ -1,6 +1,6 @@ namespace Alexa.NET.Request.Type { - public interface IIntentRequest : IRequest + public class IntentRequest : Request { Intent Intent { get; set; } } diff --git a/Alexa.NET/Request/Type/ILaunchRequest.cs b/Alexa.NET/Request/Type/LaunchRequest.cs similarity index 52% rename from Alexa.NET/Request/Type/ILaunchRequest.cs rename to Alexa.NET/Request/Type/LaunchRequest.cs index d73517a..e31c999 100644 --- a/Alexa.NET/Request/Type/ILaunchRequest.cs +++ b/Alexa.NET/Request/Type/LaunchRequest.cs @@ -1,6 +1,6 @@ namespace Alexa.NET.Request.Type { - public interface ILaunchRequest : IRequest + public class LaunchRequest : Request { } } \ No newline at end of file diff --git a/Alexa.NET/Request/Type/PlaybackState.cs b/Alexa.NET/Request/Type/PlaybackState.cs new file mode 100644 index 0000000..539a86d --- /dev/null +++ b/Alexa.NET/Request/Type/PlaybackState.cs @@ -0,0 +1,20 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Alexa.NET.Request.Type +{ + public class PlaybackState + { + [JsonProperty("token")] + string Token { get; set; } + + [JsonProperty("offsetInMilliseconds")] + string OffsetInMilliseconds { get; set; } + + [JsonProperty("playerActivity")] + string PlayerActivity { get; set; } + } +} diff --git a/Alexa.NET/Request/Type/IRequest.cs b/Alexa.NET/Request/Type/Request.cs similarity index 89% rename from Alexa.NET/Request/Type/IRequest.cs rename to Alexa.NET/Request/Type/Request.cs index f1e4fd9..171b426 100644 --- a/Alexa.NET/Request/Type/IRequest.cs +++ b/Alexa.NET/Request/Type/Request.cs @@ -3,7 +3,7 @@ namespace Alexa.NET.Request.Type { - public interface IRequest + public abstract class Request { [JsonProperty("type")] string Type { get; set; } diff --git a/Alexa.NET/Request/Type/RequestBundle.cs b/Alexa.NET/Request/Type/RequestBundle.cs deleted file mode 100644 index 46f30f9..0000000 --- a/Alexa.NET/Request/Type/RequestBundle.cs +++ /dev/null @@ -1,38 +0,0 @@ -using Newtonsoft.Json; -using System; - -namespace Alexa.NET.Request.Type -{ - public class RequestBundle : IIntentRequest, ILaunchRequest, ISessionEndedRequest - { - [JsonProperty("type")] - public string Type { get; set; } - - [JsonProperty("requestId")] - public string RequestId { get; set; } - - [JsonProperty("timestamp")] - public DateTime Timestamp { get; set; } - - [JsonProperty("intent")] - public Intent Intent { get; set; } - - [JsonProperty("reason")] - public string Reason { get; set; } - - public System.Type GetRequestType() - { - switch (Type) - { - case "IntentRequest": - return typeof(IIntentRequest); - case "LaunchRequest": - return typeof(ILaunchRequest); - case "SessionEndedRequest": - return typeof(ISessionEndedRequest); - default: - throw new ArgumentOutOfRangeException(nameof(Type), $"Unknown request type: {Type}."); - } - } - } -} \ No newline at end of file diff --git a/Alexa.NET/Request/Type/RequestConverter.cs b/Alexa.NET/Request/Type/RequestConverter.cs new file mode 100644 index 0000000..3bc8c2f --- /dev/null +++ b/Alexa.NET/Request/Type/RequestConverter.cs @@ -0,0 +1,56 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; + +namespace Alexa.NET.Request.Type +{ + public class RequestConverter : JsonConverter + { + public override bool CanWrite => false; + + public override bool CanConvert(System.Type objectType) + { + return objectType == typeof(Request); + } + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + throw new NotImplementedException(); + } + + public override object ReadJson(JsonReader reader, System.Type objectType, object existingValue, JsonSerializer serializer) + { + // Load JObject from stream + var jObject = JObject.Load(reader); + + // Create target request object based on "type" property + var target = Create(jObject["type"].Value()); + + // Populate the object properties + serializer.Populate(jObject.CreateReader(), target); + + return target; + } + + public Request Create(string requestType) + { + //AudioPlayer requests are very similar, map to single type + if (requestType.StartsWith("AudioPlayer")) + requestType = "AudioPlayer"; + + switch (requestType) + { + case "IntentRequest": + return new IntentRequest(); + case "LaunchRequest": + return new LaunchRequest(); + case "SessionEndedRequest": + return new SessionEndedRequest(); + case "AudioPlayer": + return new AudioPlayerRequest(); + default: + throw new ArgumentOutOfRangeException(nameof(Type), $"Unknown request type: {requestType}."); + } + } + } +} \ No newline at end of file diff --git a/Alexa.NET/Request/Type/ISessionEndedRequest.cs b/Alexa.NET/Request/Type/SessionEndedRequest.cs similarity index 72% rename from Alexa.NET/Request/Type/ISessionEndedRequest.cs rename to Alexa.NET/Request/Type/SessionEndedRequest.cs index bd8b40a..7623e3c 100644 --- a/Alexa.NET/Request/Type/ISessionEndedRequest.cs +++ b/Alexa.NET/Request/Type/SessionEndedRequest.cs @@ -2,7 +2,7 @@ namespace Alexa.NET.Request.Type { - public interface ISessionEndedRequest : IRequest + public class SessionEndedRequest : Request { [JsonProperty("reason")] string Reason { get; set; } From 579dd604062fdab595ab2e80ad3cd953616d21a6 Mon Sep 17 00:00:00 2001 From: Tobias Viehweger Date: Thu, 29 Dec 2016 18:31:18 +0100 Subject: [PATCH 4/7] make properties public --- Alexa.NET/Request/Type/AudioPlayerRequest.cs | 10 +++++----- Alexa.NET/Request/Type/Error.cs | 4 ++-- Alexa.NET/Request/Type/IntentRequest.cs | 2 +- Alexa.NET/Request/Type/PlaybackState.cs | 6 +++--- Alexa.NET/Request/Type/Request.cs | 6 +++--- Alexa.NET/Request/Type/SessionEndedRequest.cs | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Alexa.NET/Request/Type/AudioPlayerRequest.cs b/Alexa.NET/Request/Type/AudioPlayerRequest.cs index e7573ad..98f69da 100644 --- a/Alexa.NET/Request/Type/AudioPlayerRequest.cs +++ b/Alexa.NET/Request/Type/AudioPlayerRequest.cs @@ -9,18 +9,18 @@ namespace Alexa.NET.Request.Type public class AudioPlayerRequest: Request { [JsonProperty("token")] - string Token { get; set; } + public string Token { get; set; } [JsonProperty("locale")] - string Locale { get; set; } + public string Locale { get; set; } [JsonProperty("offsetInMilliseconds")] - string OffsetInMilliseconds { get; set; } + public string OffsetInMilliseconds { get; set; } [JsonProperty("error")] - Error Error { get; set; } + public Error Error { get; set; } [JsonProperty("currentPlaybackState")] - PlaybackState CurrentPlaybackState { get; set; } + public PlaybackState CurrentPlaybackState { get; set; } } } diff --git a/Alexa.NET/Request/Type/Error.cs b/Alexa.NET/Request/Type/Error.cs index 39d3318..64ee8c5 100644 --- a/Alexa.NET/Request/Type/Error.cs +++ b/Alexa.NET/Request/Type/Error.cs @@ -9,9 +9,9 @@ namespace Alexa.NET.Request.Type public class Error { [JsonProperty("type")] - string Type { get; set; } + public string Type { get; set; } [JsonProperty("message")] - string Message { get; set; } + public string Message { get; set; } } } diff --git a/Alexa.NET/Request/Type/IntentRequest.cs b/Alexa.NET/Request/Type/IntentRequest.cs index e5aa717..c51f8a9 100644 --- a/Alexa.NET/Request/Type/IntentRequest.cs +++ b/Alexa.NET/Request/Type/IntentRequest.cs @@ -2,6 +2,6 @@ namespace Alexa.NET.Request.Type { public class IntentRequest : Request { - Intent Intent { get; set; } + public Intent Intent { get; set; } } } \ No newline at end of file diff --git a/Alexa.NET/Request/Type/PlaybackState.cs b/Alexa.NET/Request/Type/PlaybackState.cs index 539a86d..9183e8c 100644 --- a/Alexa.NET/Request/Type/PlaybackState.cs +++ b/Alexa.NET/Request/Type/PlaybackState.cs @@ -9,12 +9,12 @@ namespace Alexa.NET.Request.Type public class PlaybackState { [JsonProperty("token")] - string Token { get; set; } + public string Token { get; set; } [JsonProperty("offsetInMilliseconds")] - string OffsetInMilliseconds { get; set; } + public string OffsetInMilliseconds { get; set; } [JsonProperty("playerActivity")] - string PlayerActivity { get; set; } + public string PlayerActivity { get; set; } } } diff --git a/Alexa.NET/Request/Type/Request.cs b/Alexa.NET/Request/Type/Request.cs index 171b426..db9e67d 100644 --- a/Alexa.NET/Request/Type/Request.cs +++ b/Alexa.NET/Request/Type/Request.cs @@ -6,12 +6,12 @@ namespace Alexa.NET.Request.Type public abstract class Request { [JsonProperty("type")] - string Type { get; set; } + public string Type { get; set; } [JsonProperty("requestId")] - string RequestId { get; set; } + public string RequestId { get; set; } [JsonProperty("timestamp")] - DateTime Timestamp { get; set; } + public DateTime Timestamp { get; set; } } } \ No newline at end of file diff --git a/Alexa.NET/Request/Type/SessionEndedRequest.cs b/Alexa.NET/Request/Type/SessionEndedRequest.cs index 7623e3c..4ccee6c 100644 --- a/Alexa.NET/Request/Type/SessionEndedRequest.cs +++ b/Alexa.NET/Request/Type/SessionEndedRequest.cs @@ -5,6 +5,6 @@ namespace Alexa.NET.Request.Type public class SessionEndedRequest : Request { [JsonProperty("reason")] - string Reason { get; set; } + public string Reason { get; set; } } } \ No newline at end of file From 5f8c5272af5c6096d3fe5d5f12882ea8e5dd9023 Mon Sep 17 00:00:00 2001 From: Tobias Viehweger Date: Thu, 29 Dec 2016 18:34:19 +0100 Subject: [PATCH 5/7] style fixes --- Alexa.NET/Response/Directive/AudioPlayerPlayDirective.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Alexa.NET/Response/Directive/AudioPlayerPlayDirective.cs b/Alexa.NET/Response/Directive/AudioPlayerPlayDirective.cs index c5d08f1..81259df 100644 --- a/Alexa.NET/Response/Directive/AudioPlayerPlayDirective.cs +++ b/Alexa.NET/Response/Directive/AudioPlayerPlayDirective.cs @@ -3,7 +3,7 @@ namespace Alexa.NET.Response.Directive { - public class AudioPlayerDirective : IDirective + public class AudioPlayerPlayDirective : IDirective { [JsonProperty("playBehavior")] [JsonRequired] @@ -12,7 +12,7 @@ public class AudioPlayerDirective : IDirective [JsonProperty("audioItem")] [JsonRequired] - public AudioItem AudioPlayerAudioItem { get; set; } + public AudioItem AudioItem { get; set; } [JsonProperty("type")] public string Type => "AudioPlayer.Play"; From 893fdcd524fa379e21c16c7bba201ac706f6f206 Mon Sep 17 00:00:00 2001 From: Tobias Viehweger Date: Thu, 29 Dec 2016 18:47:11 +0100 Subject: [PATCH 6/7] remove required attribute for ExpectedPreviousToken in AudioItemStream --- Alexa.NET/Response/Directive/AudioItemStream.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Alexa.NET/Response/Directive/AudioItemStream.cs b/Alexa.NET/Response/Directive/AudioItemStream.cs index 71c6dc9..55ade21 100644 --- a/Alexa.NET/Response/Directive/AudioItemStream.cs +++ b/Alexa.NET/Response/Directive/AudioItemStream.cs @@ -11,8 +11,7 @@ public class AudioItemStream [JsonRequired] [JsonProperty("token")] public string Token { get; set; } - - [JsonRequired] + [JsonProperty("expectedPreviousToken")] public string ExpectedPreviousToken { get; set; } From 2907b7d4f1f6563229a829f7d47d4a9b588d8f2e Mon Sep 17 00:00:00 2001 From: Tobias Viehweger Date: Fri, 30 Dec 2016 16:30:44 +0100 Subject: [PATCH 7/7] Add builder methods for AudioPlayerPlay --- Alexa.NET/ResponseBuilder.cs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Alexa.NET/ResponseBuilder.cs b/Alexa.NET/ResponseBuilder.cs index 071c56f..d31b2be 100644 --- a/Alexa.NET/ResponseBuilder.cs +++ b/Alexa.NET/ResponseBuilder.cs @@ -1,5 +1,6 @@ using Alexa.NET.Request; using Alexa.NET.Response; +using Alexa.NET.Response.Directive; using System; using System.Collections.Generic; using System.Linq; @@ -63,6 +64,37 @@ public static SkillResponse Ask(IOutputSpeech speechResponse, Reprompt reprompt, return BuildResponse(speechResponse, false, sessionAttributes, reprompt, null); } + public static SkillResponse AudioPlayerPlay(PlayBehavior playBehavior, string url, string token) + { + return AudioPlayerPlay(playBehavior, url, token, 0); + } + + public static SkillResponse AudioPlayerPlay(PlayBehavior playBehavior, string url, string token, int offsetInMilliseconds) + { + return AudioPlayerPlay(playBehavior, url, token, null, offsetInMilliseconds); + } + + public static SkillResponse AudioPlayerPlay(PlayBehavior playBehavior, string url, string token, string expectedPreviousToken, int offsetInMilliseconds) + { + var response = BuildResponse(null, true, null, null, null); + response.Response.Directives.Add(new AudioPlayerPlayDirective() + { + PlayBehavior = playBehavior, + AudioItem = new AudioItem() + { + Stream = new AudioItemStream() + { + Url = url, + Token = token, + ExpectedPreviousToken = expectedPreviousToken, + OffsetInMilliseconds = offsetInMilliseconds + } + } + }); + + return response; + } + private static SkillResponse BuildResponse(IOutputSpeech outputSpeech, bool shouldEndSession, Session sessionAttributes, Reprompt reprompt, ICard card) { SkillResponse response = new Response.SkillResponse();