diff --git a/Alexa.NET/Request/Type/Error.cs b/Alexa.NET/Request/Type/Error.cs index 64ee8c5..577ab5a 100644 --- a/Alexa.NET/Request/Type/Error.cs +++ b/Alexa.NET/Request/Type/Error.cs @@ -1,4 +1,5 @@ using Newtonsoft.Json; +using Newtonsoft.Json.Converters; using System; using System.Collections.Generic; using System.Linq; @@ -9,7 +10,8 @@ namespace Alexa.NET.Request.Type public class Error { [JsonProperty("type")] - public string Type { get; set; } + [JsonConverter(typeof(StringEnumConverter))] + public ErrorType Type { get; set; } [JsonProperty("message")] public string Message { get; set; } diff --git a/Alexa.NET/Request/Type/ErrorCause.cs b/Alexa.NET/Request/Type/ErrorCause.cs new file mode 100644 index 0000000..f48ac49 --- /dev/null +++ b/Alexa.NET/Request/Type/ErrorCause.cs @@ -0,0 +1,14 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Alexa.NET.Request.Type +{ + public class ErrorCause + { + [JsonProperty("requestId")] + public string requestId { get; set; } + } +} diff --git a/Alexa.NET/Request/Type/ErrorType.cs b/Alexa.NET/Request/Type/ErrorType.cs new file mode 100644 index 0000000..2bcfe01 --- /dev/null +++ b/Alexa.NET/Request/Type/ErrorType.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Threading.Tasks; + +namespace Alexa.NET.Request.Type +{ + public enum ErrorType + { + [EnumMember(Value = "INVALID_RESPONSE")] + InvalidResponse, + [EnumMember(Value = "DEVICE_COMMUNICATION_ERROR")] + DeviceCommunicationError, + [EnumMember(Value = "INTERNAL_ERROR")] + InternalError, + [EnumMember(Value = "MEDIA_ERROR_UNKNOWN")] + MediaErrorUnknown, + [EnumMember(Value = "MEDIA_ERROR_INVALID_REQUEST")] + InvalidMediaRequest, + [EnumMember(Value = "MEDIA_ERROR_SERVICE_UNAVAILABLE")] + MediaServiceUnavailable, + [EnumMember(Value = "MEDIA_ERROR_INTERNAL_SERVER_ERROR")] + InternalServerError, + [EnumMember(Value = "MEDIA_ERROR_INTERNAL_DEVICE_ERROR")] + InternalDeviceError + } +} diff --git a/Alexa.NET/Request/Type/PlaybackControllerRequest.cs b/Alexa.NET/Request/Type/PlaybackControllerRequest.cs new file mode 100644 index 0000000..460031c --- /dev/null +++ b/Alexa.NET/Request/Type/PlaybackControllerRequest.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Alexa.NET.Request.Type +{ + public class PlaybackControllerRequest : Request + { + public PlaybackControllerRequestType PlaybackRequestType + { + get + { + switch (this.Type.Split('.')[1]) + { + case "NextCommandIssued": + return PlaybackControllerRequestType.Next; + case "PauseCommandIssued": + return PlaybackControllerRequestType.Pause; + case "PlayCommandIssued": + return PlaybackControllerRequestType.Play; + case "PreviousCommandIssued": + return PlaybackControllerRequestType.Previous; + default: + return PlaybackControllerRequestType.Unknown; + } + } + } + } +} diff --git a/Alexa.NET/Request/Type/PlaybackControllerRequestType.cs b/Alexa.NET/Request/Type/PlaybackControllerRequestType.cs new file mode 100644 index 0000000..a78f830 --- /dev/null +++ b/Alexa.NET/Request/Type/PlaybackControllerRequestType.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Threading.Tasks; + +namespace Alexa.NET.Request.Type +{ + public enum PlaybackControllerRequestType + { + [EnumMember(Value = "NextCommandIssued")] + Next, + [EnumMember(Value = "PauseCommandIssued")] + Pause, + [EnumMember(Value = "PlayCommandIssued")] + Play, + [EnumMember(Value = "PreviousCommandIssued")] + Previous, + [EnumMember(Value = "Unknown")] + Unknown + } +} diff --git a/Alexa.NET/Request/Type/Reason.cs b/Alexa.NET/Request/Type/Reason.cs new file mode 100644 index 0000000..d50e4e4 --- /dev/null +++ b/Alexa.NET/Request/Type/Reason.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.Request.Type +{ + public enum Reason + { + [EnumMember(Value = "USER_INITATED")] + UserInitiated, + [EnumMember(Value = "ERROR")] + Error, + [EnumMember(Value = "EXCEEDED_MAX_REPROMPTS")] + ExceededMaxReprompts + } +} diff --git a/Alexa.NET/Request/Type/RequestConverter.cs b/Alexa.NET/Request/Type/RequestConverter.cs index 3bc8c2f..103e4ff 100644 --- a/Alexa.NET/Request/Type/RequestConverter.cs +++ b/Alexa.NET/Request/Type/RequestConverter.cs @@ -34,9 +34,12 @@ public override object ReadJson(JsonReader reader, System.Type objectType, objec public Request Create(string requestType) { - //AudioPlayer requests are very similar, map to single type + //AudioPlayer and PlaybackController requests are very similar, + // map them to respective types if (requestType.StartsWith("AudioPlayer")) requestType = "AudioPlayer"; + else if (requestType.StartsWith("PlaybackController")) + requestType = "PlaybackController"; switch (requestType) { @@ -48,6 +51,10 @@ public Request Create(string requestType) return new SessionEndedRequest(); case "AudioPlayer": return new AudioPlayerRequest(); + case "PlaybackController": + return new PlaybackControllerRequest(); + case "System.ExceptionEncountered": + return new SystemExceptionRequest(); default: throw new ArgumentOutOfRangeException(nameof(Type), $"Unknown request type: {requestType}."); } diff --git a/Alexa.NET/Request/Type/SessionEndedRequest.cs b/Alexa.NET/Request/Type/SessionEndedRequest.cs index 4ccee6c..6e54db3 100644 --- a/Alexa.NET/Request/Type/SessionEndedRequest.cs +++ b/Alexa.NET/Request/Type/SessionEndedRequest.cs @@ -1,10 +1,12 @@ using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace Alexa.NET.Request.Type { public class SessionEndedRequest : Request { [JsonProperty("reason")] - public string Reason { get; set; } + [JsonConverter(typeof(StringEnumConverter))] + public Reason Reason { get; set; } } } \ No newline at end of file diff --git a/Alexa.NET/Request/Type/SystemExceptionRequest.cs b/Alexa.NET/Request/Type/SystemExceptionRequest.cs new file mode 100644 index 0000000..dd9fb05 --- /dev/null +++ b/Alexa.NET/Request/Type/SystemExceptionRequest.cs @@ -0,0 +1,16 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Alexa.NET.Request.Type +{ + public class SystemExceptionRequest : Request + { + [JsonProperty("error")] + public Error Error { get; set; } + [JsonProperty("cause")] + public ErrorCause ErrorCause { get; set; } + } +} diff --git a/Alexa.NET/Response/Directive/ClearQueueDirective.cs b/Alexa.NET/Response/Directive/ClearQueueDirective.cs index c792179..16bb0cd 100644 --- a/Alexa.NET/Response/Directive/ClearQueueDirective.cs +++ b/Alexa.NET/Response/Directive/ClearQueueDirective.cs @@ -15,6 +15,6 @@ public class ClearQueueDirective : IDirective [JsonProperty("clearBehavior")] [JsonRequired] [JsonConverter(typeof(StringEnumConverter))] - public PlayBehavior ClearBehavior { get; set; } + public ClearBehavior ClearBehavior { get; set; } } } diff --git a/Alexa.NET/Response/Directive/StopDirective.cs b/Alexa.NET/Response/Directive/StopDirective.cs new file mode 100644 index 0000000..de2388a --- /dev/null +++ b/Alexa.NET/Response/Directive/StopDirective.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.Directive +{ + public class StopDirective : IDirective + { + [JsonProperty("type")] + public string Type => "AudioPlayer.Stop"; + } +} diff --git a/Alexa.NET/ResponseBuilder.cs b/Alexa.NET/ResponseBuilder.cs index 25118e8..d7af3a9 100644 --- a/Alexa.NET/ResponseBuilder.cs +++ b/Alexa.NET/ResponseBuilder.cs @@ -107,8 +107,25 @@ public static SkillResponse AudioPlayerPlay(PlayBehavior playBehavior, string ur return response; } + + public static SkillResponse AudioPlayerStop() + { + var response = BuildResponse(null, true, null, null, null); + response.Response.Directives.Add(new StopDirective()); + return response; + } + + public static SkillResponse AudioPlayerClearQueue(ClearBehavior clearBehavior) + { + var response = BuildResponse(null, true, null, null, null); + response.Response.Directives.Add(new ClearQueueDirective() + { + ClearBehavior = clearBehavior + }); + return response; + } #endregion - + #region Main Response Builder private static SkillResponse BuildResponse(IOutputSpeech outputSpeech, bool shouldEndSession, Session sessionAttributes, Reprompt reprompt, ICard card) { diff --git a/Alexa.NET/project.json b/Alexa.NET/project.json index 3c25fc1..a0f557f 100644 --- a/Alexa.NET/project.json +++ b/Alexa.NET/project.json @@ -1,7 +1,7 @@ { "name": "Alexa.NET", "title": "Alexa.NET", - "version": "1.0.0-beta-3", + "version": "1.0.0-beta-4", "authors": [ "Tim Heuer" ], "description": "A simple .NET Core library for handling Alexa Skill request/responses.", @@ -27,6 +27,6 @@ "repository": { "url": "https://github.com/timheuer/alexa-skills-dotnet" }, "requireLicenseAcceptance": false, "tags": [ "amazon", "alexa", "echo", "dot", "echo dot", "skills" ], - "releaseNotes": "Updated to include Locale and Audio request support." + "releaseNotes": "Updated to include Locale, Audio request, and PlayerController request support." } } diff --git a/README.md b/README.md index 54a91e3..83e5028 100644 --- a/README.md +++ b/README.md @@ -133,4 +133,4 @@ skillResponse.Response = responseBody; skillResponse.Version = "1.0"; return skillResponse; -``` \ No newline at end of file +```