From d6981d50af7eb85a0cb485c9e21ef27c480ff360 Mon Sep 17 00:00:00 2001 From: Steven Pears Date: Tue, 2 Jul 2019 08:27:29 +0100 Subject: [PATCH 01/13] Initial structure and tests --- Alexa.NET.Tests/Alexa.NET.Tests.csproj | 3 ++ .../Examples/PrintPDFConnection.json | 12 +++++ Alexa.NET.Tests/SkillConnectionTests.cs | 24 +++++++++ .../Converters/ConnectionTaskConverter.cs | 49 +++++++++++++++++++ .../Response/Converters/DirectiveConverter.cs | 1 + .../ConnectionTasks/IConnectionTask.cs | 12 +++++ .../IConnectionTaskExtensions.cs | 15 ++++++ .../Directive/ConnectionTasks/PrintPdf.cs | 28 +++++++++++ .../Directive/StartConnectionDirective.cs | 29 +++++++++++ 9 files changed, 173 insertions(+) create mode 100644 Alexa.NET.Tests/Examples/PrintPDFConnection.json create mode 100644 Alexa.NET.Tests/SkillConnectionTests.cs create mode 100644 Alexa.NET/Response/Converters/ConnectionTaskConverter.cs create mode 100644 Alexa.NET/Response/Directive/ConnectionTasks/IConnectionTask.cs create mode 100644 Alexa.NET/Response/Directive/ConnectionTasks/IConnectionTaskExtensions.cs create mode 100644 Alexa.NET/Response/Directive/ConnectionTasks/PrintPdf.cs create mode 100644 Alexa.NET/Response/Directive/StartConnectionDirective.cs diff --git a/Alexa.NET.Tests/Alexa.NET.Tests.csproj b/Alexa.NET.Tests/Alexa.NET.Tests.csproj index ae2964d..217c8f8 100644 --- a/Alexa.NET.Tests/Alexa.NET.Tests.csproj +++ b/Alexa.NET.Tests/Alexa.NET.Tests.csproj @@ -62,6 +62,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/Alexa.NET.Tests/Examples/PrintPDFConnection.json b/Alexa.NET.Tests/Examples/PrintPDFConnection.json new file mode 100644 index 0000000..29495ca --- /dev/null +++ b/Alexa.NET.Tests/Examples/PrintPDFConnection.json @@ -0,0 +1,12 @@ +{ + "type": "Connections.StartConnection", + "uri": "connection://AMAZON.PrintPDF/1", + "input": { + "@type": "PrintPDFRequest", + "@version": "1", + "title": "title", + "description": "description", + "url": "http://www.example.com/flywheel.pdf" + }, + "token": "none" +} \ No newline at end of file diff --git a/Alexa.NET.Tests/SkillConnectionTests.cs b/Alexa.NET.Tests/SkillConnectionTests.cs new file mode 100644 index 0000000..5298029 --- /dev/null +++ b/Alexa.NET.Tests/SkillConnectionTests.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Alexa.NET.Response.Directive; +using Alexa.NET.Response.Directive.ConnectionTasks; +using Xunit; + +namespace Alexa.NET.Tests +{ + public class SkillConnectionTests + { + [Fact] + public void StartConnectionDirectiveSerializesCorrectly() + { + var task = new PrintPdfV1 + { + Title = "title", + Description = "description", + Url = new Uri("http://www.example.com/flywheel.pdf") + }; + Utility.CompareJson(task.ToConnectionDirective("none"), "PrintPDFConnection.json"); + } + } +} diff --git a/Alexa.NET/Response/Converters/ConnectionTaskConverter.cs b/Alexa.NET/Response/Converters/ConnectionTaskConverter.cs new file mode 100644 index 0000000..d30f279 --- /dev/null +++ b/Alexa.NET/Response/Converters/ConnectionTaskConverter.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using Alexa.NET.Response.Directive.ConnectionTasks; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +namespace Alexa.NET.Response.Converters +{ + public class ConnectionTaskConverter:JsonConverter + { + public static Dictionary> TaskFactoryFromUri = new Dictionary> + { + {"connection://AMAZON.PrintPDF/1",() => new PrintPdfV1() } + }; + + public override bool CanRead => true; + public override bool CanWrite => false; + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + throw new NotImplementedException(); + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + var jsonObject = JObject.Load(reader); + var typeKey = jsonObject["uri"] ?? jsonObject["Uri"]; + var typeValue = typeKey.Value(); + var hasFactory = TaskFactoryFromUri.ContainsKey(typeValue); + + if (!hasFactory) + throw new Exception( + $"unable to deserialize response. " + + $"unrecognized directive type '{typeValue}'" + ); + + var directive = TaskFactoryFromUri[typeValue](); + + serializer.Populate(jsonObject.CreateReader(), directive); + + return directive; + } + + public override bool CanConvert(Type objectType) + { + return objectType == typeof(IConnectionTask); + } + } +} \ No newline at end of file diff --git a/Alexa.NET/Response/Converters/DirectiveConverter.cs b/Alexa.NET/Response/Converters/DirectiveConverter.cs index d98428e..1930596 100644 --- a/Alexa.NET/Response/Converters/DirectiveConverter.cs +++ b/Alexa.NET/Response/Converters/DirectiveConverter.cs @@ -24,6 +24,7 @@ public class DirectiveConverter : JsonConverter { "Hint", () => new HintDirective() }, { "AudioPlayer.Stop", () => new StopDirective() }, { "VideoApp.Launch", () => new VideoAppDirective() }, + { "Connections.StartDirective", () => new StartConnectionDirective() } }; public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) diff --git a/Alexa.NET/Response/Directive/ConnectionTasks/IConnectionTask.cs b/Alexa.NET/Response/Directive/ConnectionTasks/IConnectionTask.cs new file mode 100644 index 0000000..d6c1b60 --- /dev/null +++ b/Alexa.NET/Response/Directive/ConnectionTasks/IConnectionTask.cs @@ -0,0 +1,12 @@ +using System.Text; +using Alexa.NET.Response.Converters; +using Newtonsoft.Json; + +namespace Alexa.NET.Response.Directive.ConnectionTasks +{ + [JsonConverter(typeof(ConnectionTaskConverter))] + public interface IConnectionTask + { + + } +} diff --git a/Alexa.NET/Response/Directive/ConnectionTasks/IConnectionTaskExtensions.cs b/Alexa.NET/Response/Directive/ConnectionTasks/IConnectionTaskExtensions.cs new file mode 100644 index 0000000..97df44b --- /dev/null +++ b/Alexa.NET/Response/Directive/ConnectionTasks/IConnectionTaskExtensions.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Alexa.NET.Response.Directive.ConnectionTasks +{ + public static class IConnectionTaskExtensions + { + + public static StartConnectionDirective ToConnectionDirective(this IConnectionTask task, string token) + { + return new StartConnectionDirective(task, token); + } + } +} diff --git a/Alexa.NET/Response/Directive/ConnectionTasks/PrintPdf.cs b/Alexa.NET/Response/Directive/ConnectionTasks/PrintPdf.cs new file mode 100644 index 0000000..54716bc --- /dev/null +++ b/Alexa.NET/Response/Directive/ConnectionTasks/PrintPdf.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; + +namespace Alexa.NET.Response.Directive.ConnectionTasks +{ + public class PrintPdfV1:IConnectionTask + { + public const string AssociatedUri = "connection://AMAZON.PrintPDF/1"; + + [JsonProperty("@type")] + public string Type => "PrintPDFRequest"; + + [JsonProperty("@version")] + public int Version = 1; + + [JsonProperty("title")] + public string Title { get; set; } + + [JsonProperty("description")] + public string Description { get; set; } + + [JsonProperty("url")] + public Uri Url { get; set; } + + } +} diff --git a/Alexa.NET/Response/Directive/StartConnectionDirective.cs b/Alexa.NET/Response/Directive/StartConnectionDirective.cs new file mode 100644 index 0000000..ec96d4f --- /dev/null +++ b/Alexa.NET/Response/Directive/StartConnectionDirective.cs @@ -0,0 +1,29 @@ +using System; +using Alexa.NET.Response.Directive.ConnectionTasks; +using Newtonsoft.Json; + +namespace Alexa.NET.Response.Directive +{ + public class StartConnectionDirective:IDirective + { + [JsonProperty("type")] + public string Type => "Connections.StartConnection"; + + [JsonProperty("uri")] + public Uri Uri { get; set; } + + [JsonProperty("input")] + public IConnectionTask Input { get; set; } + + [JsonProperty("token")] + public string Token { get; set; } + + public StartConnectionDirective(){} + + public StartConnectionDirective(IConnectionTask input, string token) + { + this.Input = input; + this.Token = token; + } + } +} From 5b88db9214187684434b6aed0ebd48424269de56 Mon Sep 17 00:00:00 2001 From: Steven Pears Date: Tue, 2 Jul 2019 08:40:48 +0100 Subject: [PATCH 02/13] Update deserialization tests and converter logic for tasks --- Alexa.NET.Tests/SkillConnectionTests.cs | 14 ++++++++++++++ .../Response/Converters/ConnectionTaskConverter.cs | 13 +++++++------ .../Response/Converters/DirectiveConverter.cs | 2 +- .../Response/Directive/StartConnectionDirective.cs | 2 +- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Alexa.NET.Tests/SkillConnectionTests.cs b/Alexa.NET.Tests/SkillConnectionTests.cs index 5298029..4b32233 100644 --- a/Alexa.NET.Tests/SkillConnectionTests.cs +++ b/Alexa.NET.Tests/SkillConnectionTests.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text; +using Alexa.NET.Response; using Alexa.NET.Response.Directive; using Alexa.NET.Response.Directive.ConnectionTasks; using Xunit; @@ -20,5 +21,18 @@ public void StartConnectionDirectiveSerializesCorrectly() }; Utility.CompareJson(task.ToConnectionDirective("none"), "PrintPDFConnection.json"); } + + [Fact] + public void StartConnectionDirectiveDeserializesCorrectly() + { + var raw = Utility.ExampleFileContent("PrintPDFConnection.json"); + Assert.NotNull(raw); + + var directive = Assert.IsType(raw); + Assert.Equal("none", directive.Token); + Assert.Equal(PrintPdfV1.AssociatedUri,directive.Uri.ToString()); + + Assert.IsType(directive.Input); + } } } diff --git a/Alexa.NET/Response/Converters/ConnectionTaskConverter.cs b/Alexa.NET/Response/Converters/ConnectionTaskConverter.cs index d30f279..b17baf0 100644 --- a/Alexa.NET/Response/Converters/ConnectionTaskConverter.cs +++ b/Alexa.NET/Response/Converters/ConnectionTaskConverter.cs @@ -10,7 +10,7 @@ public class ConnectionTaskConverter:JsonConverter { public static Dictionary> TaskFactoryFromUri = new Dictionary> { - {"connection://AMAZON.PrintPDF/1",() => new PrintPdfV1() } + {"PrintPDFRequest/1",() => new PrintPdfV1() } }; public override bool CanRead => true; @@ -24,17 +24,18 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var jsonObject = JObject.Load(reader); - var typeKey = jsonObject["uri"] ?? jsonObject["Uri"]; - var typeValue = typeKey.Value(); - var hasFactory = TaskFactoryFromUri.ContainsKey(typeValue); + var typeKey = jsonObject.Value("@type"); + var versionKey = jsonObject.Value("@version"); + var factoryKey = $"{typeKey}/{versionKey}"; + var hasFactory = TaskFactoryFromUri.ContainsKey(factoryKey); if (!hasFactory) throw new Exception( $"unable to deserialize response. " + - $"unrecognized directive type '{typeValue}'" + $"unrecognized task type '{typeKey}' with version '{versionKey}'" ); - var directive = TaskFactoryFromUri[typeValue](); + var directive = TaskFactoryFromUri[factoryKey](); serializer.Populate(jsonObject.CreateReader(), directive); diff --git a/Alexa.NET/Response/Converters/DirectiveConverter.cs b/Alexa.NET/Response/Converters/DirectiveConverter.cs index 1930596..ce85681 100644 --- a/Alexa.NET/Response/Converters/DirectiveConverter.cs +++ b/Alexa.NET/Response/Converters/DirectiveConverter.cs @@ -24,7 +24,7 @@ public class DirectiveConverter : JsonConverter { "Hint", () => new HintDirective() }, { "AudioPlayer.Stop", () => new StopDirective() }, { "VideoApp.Launch", () => new VideoAppDirective() }, - { "Connections.StartDirective", () => new StartConnectionDirective() } + { "Connections.StartConnection", () => new StartConnectionDirective() } }; public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) diff --git a/Alexa.NET/Response/Directive/StartConnectionDirective.cs b/Alexa.NET/Response/Directive/StartConnectionDirective.cs index ec96d4f..ed85cd0 100644 --- a/Alexa.NET/Response/Directive/StartConnectionDirective.cs +++ b/Alexa.NET/Response/Directive/StartConnectionDirective.cs @@ -10,7 +10,7 @@ public class StartConnectionDirective:IDirective public string Type => "Connections.StartConnection"; [JsonProperty("uri")] - public Uri Uri { get; set; } + public string Uri { get; set; } [JsonProperty("input")] public IConnectionTask Input { get; set; } From 2cede33d2eebe227d53ffd7693279722ea5e5e2c Mon Sep 17 00:00:00 2001 From: Steven Pears Date: Wed, 3 Jul 2019 08:26:59 +0100 Subject: [PATCH 03/13] Add session resumed request --- Alexa.NET.Tests/Alexa.NET.Tests.csproj | 3 ++ .../Examples/SessionResumedRequest.json | 16 ++++++++++ Alexa.NET.Tests/SkillConnectionTests.cs | 31 +++++++++++++++++++ Alexa.NET/Request/SkillRequest.cs | 1 - .../SkillConnectionRequestTypeConverter.cs | 19 ++++++++++++ Alexa.NET/Request/Type/Request.cs | 1 + Alexa.NET/Request/Type/RequestConverter.cs | 3 +- .../Request/Type/SessionResumedRequest.cs | 17 ++++++++++ .../Type/SessionResumedRequestCause.cs | 19 ++++++++++++ .../Type/SessionResumedRequestCauseStatus.cs | 21 +++++++++++++ 10 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 Alexa.NET.Tests/Examples/SessionResumedRequest.json create mode 100644 Alexa.NET/Request/Type/Converters/SkillConnectionRequestTypeConverter.cs create mode 100644 Alexa.NET/Request/Type/SessionResumedRequest.cs create mode 100644 Alexa.NET/Request/Type/SessionResumedRequestCause.cs create mode 100644 Alexa.NET/Request/Type/SessionResumedRequestCauseStatus.cs diff --git a/Alexa.NET.Tests/Alexa.NET.Tests.csproj b/Alexa.NET.Tests/Alexa.NET.Tests.csproj index 217c8f8..fc77aa4 100644 --- a/Alexa.NET.Tests/Alexa.NET.Tests.csproj +++ b/Alexa.NET.Tests/Alexa.NET.Tests.csproj @@ -74,6 +74,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/Alexa.NET.Tests/Examples/SessionResumedRequest.json b/Alexa.NET.Tests/Examples/SessionResumedRequest.json new file mode 100644 index 0000000..ee08f10 --- /dev/null +++ b/Alexa.NET.Tests/Examples/SessionResumedRequest.json @@ -0,0 +1,16 @@ +{ + "type": "SessionResumedRequest", + "requestId": "string", + "timestamp": "2019-07-03T00:00:00", + "locale": "en-GB", + "originIpAddress": "string", + "cause": { + "type": "ConnectionCompleted", + "token": "1234", + "status": { + "code": 200, + "message": "OK" + }, + "result": null + } +} \ No newline at end of file diff --git a/Alexa.NET.Tests/SkillConnectionTests.cs b/Alexa.NET.Tests/SkillConnectionTests.cs index 4b32233..6641a71 100644 --- a/Alexa.NET.Tests/SkillConnectionTests.cs +++ b/Alexa.NET.Tests/SkillConnectionTests.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text; +using Alexa.NET.Request.Type; using Alexa.NET.Response; using Alexa.NET.Response.Directive; using Alexa.NET.Response.Directive.ConnectionTasks; @@ -34,5 +35,35 @@ public void StartConnectionDirectiveDeserializesCorrectly() Assert.IsType(directive.Input); } + + [Fact] + public void SessionResumedSerializesProperly() + { + var task = new SessionResumedRequest + { + RequestId = "string", + Timestamp = new DateTime(2019,07,03), + Locale = "en-GB", + OriginIpAddress = "string", + Cause = new SessionResumedRequestCause + { + Type="ConnectionCompleted", + Token="1234", + Status = new SessionResumedRequestCauseStatus(200,"OK") + } + }; + Utility.CompareJson(task, "SessionResumedRequest.json"); + } + + [Fact] + public void SessionResumedDeserializesProperly() + { + var result = Utility.ExampleFileContent("SessionResumedRequest.json"); + var request = Assert.IsType(result); + + Assert.Equal("1234",request.Cause.Token); + Assert.Equal(200,request.Cause.Status.Code); + Assert.Equal("OK",request.Cause.Status.Message); + } } } diff --git a/Alexa.NET/Request/SkillRequest.cs b/Alexa.NET/Request/SkillRequest.cs index bed96f7..07f0eea 100644 --- a/Alexa.NET/Request/SkillRequest.cs +++ b/Alexa.NET/Request/SkillRequest.cs @@ -15,7 +15,6 @@ public class SkillRequest public Context Context { get; set; } [JsonProperty("request")] - [JsonConverter(typeof(RequestConverter))] public Type.Request Request { get; set; } public System.Type GetRequestType() diff --git a/Alexa.NET/Request/Type/Converters/SkillConnectionRequestTypeConverter.cs b/Alexa.NET/Request/Type/Converters/SkillConnectionRequestTypeConverter.cs new file mode 100644 index 0000000..b7f1614 --- /dev/null +++ b/Alexa.NET/Request/Type/Converters/SkillConnectionRequestTypeConverter.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Alexa.NET.Request.Type +{ + public class SkillConnectionRequestTypeConverter:IRequestTypeConverter + { + public bool CanConvert(string requestType) + { + return requestType == "SessionResumedRequest"; + } + + public Request Convert(string requestType) + { + return new SessionResumedRequest(); + } + } +} diff --git a/Alexa.NET/Request/Type/Request.cs b/Alexa.NET/Request/Type/Request.cs index 42bec23..69f460d 100644 --- a/Alexa.NET/Request/Type/Request.cs +++ b/Alexa.NET/Request/Type/Request.cs @@ -4,6 +4,7 @@ namespace Alexa.NET.Request.Type { + [JsonConverter(typeof(RequestConverter))] public abstract class Request { [JsonProperty("type")] diff --git a/Alexa.NET/Request/Type/RequestConverter.cs b/Alexa.NET/Request/Type/RequestConverter.cs index c3674b9..9dbcde3 100644 --- a/Alexa.NET/Request/Type/RequestConverter.cs +++ b/Alexa.NET/Request/Type/RequestConverter.cs @@ -14,7 +14,8 @@ public class RequestConverter : JsonConverter new AudioPlayerRequestTypeConverter(), new PlaybackRequestTypeConverter(), new TemplateEventRequestTypeConverter(), - new SkillEventRequestTypeConverter() + new SkillEventRequestTypeConverter(), + new SkillConnectionRequestTypeConverter() }); public override bool CanWrite => false; diff --git a/Alexa.NET/Request/Type/SessionResumedRequest.cs b/Alexa.NET/Request/Type/SessionResumedRequest.cs new file mode 100644 index 0000000..4e8f13e --- /dev/null +++ b/Alexa.NET/Request/Type/SessionResumedRequest.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +namespace Alexa.NET.Request.Type +{ + public class SessionResumedRequest:Request + { + [JsonProperty("originIpAddress")] + public string OriginIpAddress { get; set; } + + [JsonProperty("cause")] + public SessionResumedRequestCause Cause { get; set; } + } +} diff --git a/Alexa.NET/Request/Type/SessionResumedRequestCause.cs b/Alexa.NET/Request/Type/SessionResumedRequestCause.cs new file mode 100644 index 0000000..743f089 --- /dev/null +++ b/Alexa.NET/Request/Type/SessionResumedRequestCause.cs @@ -0,0 +1,19 @@ +using Newtonsoft.Json; + +namespace Alexa.NET.Request.Type +{ + public class SessionResumedRequestCause + { + [JsonProperty("type")] + public string Type { get; set; } + + [JsonProperty("token")] + public string Token { get; set; } + + [JsonProperty("status")] + public SessionResumedRequestCauseStatus Status { get; set; } + + [JsonProperty("result")] + public object Result { get; set; } + } +} \ No newline at end of file diff --git a/Alexa.NET/Request/Type/SessionResumedRequestCauseStatus.cs b/Alexa.NET/Request/Type/SessionResumedRequestCauseStatus.cs new file mode 100644 index 0000000..a71a7fe --- /dev/null +++ b/Alexa.NET/Request/Type/SessionResumedRequestCauseStatus.cs @@ -0,0 +1,21 @@ +using Newtonsoft.Json; + +namespace Alexa.NET.Request.Type +{ + public class SessionResumedRequestCauseStatus + { + public SessionResumedRequestCauseStatus() { } + + public SessionResumedRequestCauseStatus(int code, string message) + { + Code = code; + Message = message; + } + + [JsonProperty("code")] + public int Code { get; set; } + + [JsonProperty("message")] + public string Message { get; set; } + } +} \ No newline at end of file From 1ddb1b9cef09d4ea5e71c06fcd486686a41bc2b2 Mon Sep 17 00:00:00 2001 From: Steven Pears Date: Wed, 3 Jul 2019 08:42:29 +0100 Subject: [PATCH 04/13] Add task to LaunchRequest --- Alexa.NET.Tests/Alexa.NET.Tests.csproj | 3 +++ .../Examples/LaunchRequestWithTask.json | 18 ++++++++++++++++++ Alexa.NET.Tests/SkillConnectionTests.cs | 14 +++++++++++--- .../ConnectionTasks/IConnectionTask.cs | 2 +- .../IConnectionTaskExtensions.cs | 3 ++- .../Directive => }/ConnectionTasks/PrintPdf.cs | 2 +- Alexa.NET/Request/Type/LaunchRequest.cs | 6 +++++- Alexa.NET/Request/Type/LaunchRequestTask.cs | 17 +++++++++++++++++ .../Converters/ConnectionTaskConverter.cs | 2 +- .../Directive/StartConnectionDirective.cs | 2 +- 10 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 Alexa.NET.Tests/Examples/LaunchRequestWithTask.json rename Alexa.NET/{Response/Directive => }/ConnectionTasks/IConnectionTask.cs (78%) rename Alexa.NET/{Response/Directive => }/ConnectionTasks/IConnectionTaskExtensions.cs (82%) rename Alexa.NET/{Response/Directive => }/ConnectionTasks/PrintPdf.cs (91%) create mode 100644 Alexa.NET/Request/Type/LaunchRequestTask.cs diff --git a/Alexa.NET.Tests/Alexa.NET.Tests.csproj b/Alexa.NET.Tests/Alexa.NET.Tests.csproj index fc77aa4..f9680d0 100644 --- a/Alexa.NET.Tests/Alexa.NET.Tests.csproj +++ b/Alexa.NET.Tests/Alexa.NET.Tests.csproj @@ -50,6 +50,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/Alexa.NET.Tests/Examples/LaunchRequestWithTask.json b/Alexa.NET.Tests/Examples/LaunchRequestWithTask.json new file mode 100644 index 0000000..56e0908 --- /dev/null +++ b/Alexa.NET.Tests/Examples/LaunchRequestWithTask.json @@ -0,0 +1,18 @@ +{ + "type": "LaunchRequest", + "requestId": "string", + "timestamp": "2019-07-03T00:00:00", + "locale": "string", + "originIpAddress": "string", + "task": { + "name": "AMAZON.PrintPDF", + "version": "1", + "input": { + "@type": "PrintPDFRequest", + "@version": "1", + "title": "Flywheel", + "description": "Flywheel", + "url": "http://www.example.com/flywheel.pdf" + } + } +} \ No newline at end of file diff --git a/Alexa.NET.Tests/SkillConnectionTests.cs b/Alexa.NET.Tests/SkillConnectionTests.cs index 6641a71..c8c00c8 100644 --- a/Alexa.NET.Tests/SkillConnectionTests.cs +++ b/Alexa.NET.Tests/SkillConnectionTests.cs @@ -1,10 +1,8 @@ using System; -using System.Collections.Generic; -using System.Text; +using Alexa.NET.ConnectionTasks; using Alexa.NET.Request.Type; using Alexa.NET.Response; using Alexa.NET.Response.Directive; -using Alexa.NET.Response.Directive.ConnectionTasks; using Xunit; namespace Alexa.NET.Tests @@ -65,5 +63,15 @@ public void SessionResumedDeserializesProperly() Assert.Equal(200,request.Cause.Status.Code); Assert.Equal("OK",request.Cause.Status.Message); } + + [Fact] + public void LaunchRequestWithTaskDeserializesCorrectly() + { + var result = Utility.ExampleFileContent("LaunchRequestWithTask.json"); + Assert.NotNull(result.Task); + Assert.Equal("AMAZON.PrintPDF",result.Task.Name); + Assert.Equal("1",result.Task.Version); + Assert.IsType(result.Task.Input); + } } } diff --git a/Alexa.NET/Response/Directive/ConnectionTasks/IConnectionTask.cs b/Alexa.NET/ConnectionTasks/IConnectionTask.cs similarity index 78% rename from Alexa.NET/Response/Directive/ConnectionTasks/IConnectionTask.cs rename to Alexa.NET/ConnectionTasks/IConnectionTask.cs index d6c1b60..3270da6 100644 --- a/Alexa.NET/Response/Directive/ConnectionTasks/IConnectionTask.cs +++ b/Alexa.NET/ConnectionTasks/IConnectionTask.cs @@ -2,7 +2,7 @@ using Alexa.NET.Response.Converters; using Newtonsoft.Json; -namespace Alexa.NET.Response.Directive.ConnectionTasks +namespace Alexa.NET.ConnectionTasks { [JsonConverter(typeof(ConnectionTaskConverter))] public interface IConnectionTask diff --git a/Alexa.NET/Response/Directive/ConnectionTasks/IConnectionTaskExtensions.cs b/Alexa.NET/ConnectionTasks/IConnectionTaskExtensions.cs similarity index 82% rename from Alexa.NET/Response/Directive/ConnectionTasks/IConnectionTaskExtensions.cs rename to Alexa.NET/ConnectionTasks/IConnectionTaskExtensions.cs index 97df44b..5d9e808 100644 --- a/Alexa.NET/Response/Directive/ConnectionTasks/IConnectionTaskExtensions.cs +++ b/Alexa.NET/ConnectionTasks/IConnectionTaskExtensions.cs @@ -1,8 +1,9 @@ using System; using System.Collections.Generic; using System.Text; +using Alexa.NET.Response.Directive; -namespace Alexa.NET.Response.Directive.ConnectionTasks +namespace Alexa.NET.ConnectionTasks { public static class IConnectionTaskExtensions { diff --git a/Alexa.NET/Response/Directive/ConnectionTasks/PrintPdf.cs b/Alexa.NET/ConnectionTasks/PrintPdf.cs similarity index 91% rename from Alexa.NET/Response/Directive/ConnectionTasks/PrintPdf.cs rename to Alexa.NET/ConnectionTasks/PrintPdf.cs index 54716bc..a0d8d5a 100644 --- a/Alexa.NET/Response/Directive/ConnectionTasks/PrintPdf.cs +++ b/Alexa.NET/ConnectionTasks/PrintPdf.cs @@ -3,7 +3,7 @@ using System.Text; using Newtonsoft.Json; -namespace Alexa.NET.Response.Directive.ConnectionTasks +namespace Alexa.NET.ConnectionTasks { public class PrintPdfV1:IConnectionTask { diff --git a/Alexa.NET/Request/Type/LaunchRequest.cs b/Alexa.NET/Request/Type/LaunchRequest.cs index e31c999..795899e 100644 --- a/Alexa.NET/Request/Type/LaunchRequest.cs +++ b/Alexa.NET/Request/Type/LaunchRequest.cs @@ -1,6 +1,10 @@ -namespace Alexa.NET.Request.Type +using Newtonsoft.Json; + +namespace Alexa.NET.Request.Type { public class LaunchRequest : Request { + [JsonProperty("task",NullValueHandling = NullValueHandling.Ignore)] + public LaunchRequestTask Task { get; set; } } } \ No newline at end of file diff --git a/Alexa.NET/Request/Type/LaunchRequestTask.cs b/Alexa.NET/Request/Type/LaunchRequestTask.cs new file mode 100644 index 0000000..17bfa1a --- /dev/null +++ b/Alexa.NET/Request/Type/LaunchRequestTask.cs @@ -0,0 +1,17 @@ +using Alexa.NET.ConnectionTasks; +using Newtonsoft.Json; + +namespace Alexa.NET.Request.Type +{ + public class LaunchRequestTask + { + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("version")] + public string Version { get; set; } + + [JsonProperty("input")] + public IConnectionTask Input { get; set; } + } +} \ No newline at end of file diff --git a/Alexa.NET/Response/Converters/ConnectionTaskConverter.cs b/Alexa.NET/Response/Converters/ConnectionTaskConverter.cs index b17baf0..2cd117d 100644 --- a/Alexa.NET/Response/Converters/ConnectionTaskConverter.cs +++ b/Alexa.NET/Response/Converters/ConnectionTaskConverter.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using Alexa.NET.Response.Directive.ConnectionTasks; +using Alexa.NET.ConnectionTasks; using Newtonsoft.Json; using Newtonsoft.Json.Linq; diff --git a/Alexa.NET/Response/Directive/StartConnectionDirective.cs b/Alexa.NET/Response/Directive/StartConnectionDirective.cs index ed85cd0..40609ec 100644 --- a/Alexa.NET/Response/Directive/StartConnectionDirective.cs +++ b/Alexa.NET/Response/Directive/StartConnectionDirective.cs @@ -1,5 +1,5 @@ using System; -using Alexa.NET.Response.Directive.ConnectionTasks; +using Alexa.NET.ConnectionTasks; using Newtonsoft.Json; namespace Alexa.NET.Response.Directive From 78e58ea8e84c8c4d8f8ee928b82caddfac44ec27 Mon Sep 17 00:00:00 2001 From: Steven Pears Date: Wed, 3 Jul 2019 08:53:27 +0100 Subject: [PATCH 05/13] add context providerid to connection task --- Alexa.NET.Tests/Examples/PrintPDFConnection.json | 3 +++ Alexa.NET.Tests/SkillConnectionTests.cs | 6 ++++-- Alexa.NET/ConnectionTasks/ConnectionTaskContext.cs | 10 ++++++++++ Alexa.NET/ConnectionTasks/IConnectionTask.cs | 9 ++++++++- .../{PrintPdf.cs => Inputs/PrintPdfV1.cs} | 9 +++++---- .../Response/Converters/ConnectionTaskConverter.cs | 1 + 6 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 Alexa.NET/ConnectionTasks/ConnectionTaskContext.cs rename Alexa.NET/ConnectionTasks/{PrintPdf.cs => Inputs/PrintPdfV1.cs} (75%) diff --git a/Alexa.NET.Tests/Examples/PrintPDFConnection.json b/Alexa.NET.Tests/Examples/PrintPDFConnection.json index 29495ca..1a406a3 100644 --- a/Alexa.NET.Tests/Examples/PrintPDFConnection.json +++ b/Alexa.NET.Tests/Examples/PrintPDFConnection.json @@ -6,6 +6,9 @@ "@version": "1", "title": "title", "description": "description", + "context": { + "providerId": "your-provider-skill-id" + }, "url": "http://www.example.com/flywheel.pdf" }, "token": "none" diff --git a/Alexa.NET.Tests/SkillConnectionTests.cs b/Alexa.NET.Tests/SkillConnectionTests.cs index c8c00c8..46bbd6b 100644 --- a/Alexa.NET.Tests/SkillConnectionTests.cs +++ b/Alexa.NET.Tests/SkillConnectionTests.cs @@ -1,5 +1,6 @@ using System; using Alexa.NET.ConnectionTasks; +using Alexa.NET.ConnectionTasks.Inputs; using Alexa.NET.Request.Type; using Alexa.NET.Response; using Alexa.NET.Response.Directive; @@ -16,7 +17,8 @@ public void StartConnectionDirectiveSerializesCorrectly() { Title = "title", Description = "description", - Url = new Uri("http://www.example.com/flywheel.pdf") + Url = new Uri("http://www.example.com/flywheel.pdf"), + Context = new ConnectionTaskContext { ProviderId="your-provider-skill-id"} }; Utility.CompareJson(task.ToConnectionDirective("none"), "PrintPDFConnection.json"); } @@ -29,7 +31,7 @@ public void StartConnectionDirectiveDeserializesCorrectly() var directive = Assert.IsType(raw); Assert.Equal("none", directive.Token); - Assert.Equal(PrintPdfV1.AssociatedUri,directive.Uri.ToString()); + Assert.Equal(PrintPdfV1.AssociatedUri,directive.Uri); Assert.IsType(directive.Input); } diff --git a/Alexa.NET/ConnectionTasks/ConnectionTaskContext.cs b/Alexa.NET/ConnectionTasks/ConnectionTaskContext.cs new file mode 100644 index 0000000..6728312 --- /dev/null +++ b/Alexa.NET/ConnectionTasks/ConnectionTaskContext.cs @@ -0,0 +1,10 @@ +using Newtonsoft.Json; + +namespace Alexa.NET.ConnectionTasks +{ + public class ConnectionTaskContext + { + [JsonProperty("providerId")] + public string ProviderId { get; set; } + } +} \ No newline at end of file diff --git a/Alexa.NET/ConnectionTasks/IConnectionTask.cs b/Alexa.NET/ConnectionTasks/IConnectionTask.cs index 3270da6..0310d21 100644 --- a/Alexa.NET/ConnectionTasks/IConnectionTask.cs +++ b/Alexa.NET/ConnectionTasks/IConnectionTask.cs @@ -7,6 +7,13 @@ namespace Alexa.NET.ConnectionTasks [JsonConverter(typeof(ConnectionTaskConverter))] public interface IConnectionTask { - + [JsonProperty("@type")] + string Type { get; } + + [JsonProperty("@version")] + int Version { get; } + + [JsonProperty("context",NullValueHandling = NullValueHandling.Ignore)] + ConnectionTaskContext Context { get; set; } } } diff --git a/Alexa.NET/ConnectionTasks/PrintPdf.cs b/Alexa.NET/ConnectionTasks/Inputs/PrintPdfV1.cs similarity index 75% rename from Alexa.NET/ConnectionTasks/PrintPdf.cs rename to Alexa.NET/ConnectionTasks/Inputs/PrintPdfV1.cs index a0d8d5a..0885f27 100644 --- a/Alexa.NET/ConnectionTasks/PrintPdf.cs +++ b/Alexa.NET/ConnectionTasks/Inputs/PrintPdfV1.cs @@ -1,9 +1,7 @@ using System; -using System.Collections.Generic; -using System.Text; using Newtonsoft.Json; -namespace Alexa.NET.ConnectionTasks +namespace Alexa.NET.ConnectionTasks.Inputs { public class PrintPdfV1:IConnectionTask { @@ -12,8 +10,11 @@ public class PrintPdfV1:IConnectionTask [JsonProperty("@type")] public string Type => "PrintPDFRequest"; + [JsonProperty("context")] + public ConnectionTaskContext Context { get; set; } + [JsonProperty("@version")] - public int Version = 1; + public int Version => 1; [JsonProperty("title")] public string Title { get; set; } diff --git a/Alexa.NET/Response/Converters/ConnectionTaskConverter.cs b/Alexa.NET/Response/Converters/ConnectionTaskConverter.cs index 2cd117d..ae7c6c0 100644 --- a/Alexa.NET/Response/Converters/ConnectionTaskConverter.cs +++ b/Alexa.NET/Response/Converters/ConnectionTaskConverter.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Alexa.NET.ConnectionTasks; +using Alexa.NET.ConnectionTasks.Inputs; using Newtonsoft.Json; using Newtonsoft.Json.Linq; From 6401351ad26bb98b67291dee9ebda16f0488ec54 Mon Sep 17 00:00:00 2001 From: Steven Pears Date: Wed, 3 Jul 2019 09:01:26 +0100 Subject: [PATCH 06/13] Add complete task directive --- Alexa.NET.Tests/SkillConnectionTests.cs | 9 ++++++++- .../TaskStatus.cs} | 8 ++++---- .../Request/Type/SessionResumedRequestCause.cs | 5 +++-- .../Response/Directive/CompleteTaskDirective.cs | 16 ++++++++++++++++ 4 files changed, 31 insertions(+), 7 deletions(-) rename Alexa.NET/{Request/Type/SessionResumedRequestCauseStatus.cs => ConnectionTasks/TaskStatus.cs} (55%) create mode 100644 Alexa.NET/Response/Directive/CompleteTaskDirective.cs diff --git a/Alexa.NET.Tests/SkillConnectionTests.cs b/Alexa.NET.Tests/SkillConnectionTests.cs index 46bbd6b..c38a55e 100644 --- a/Alexa.NET.Tests/SkillConnectionTests.cs +++ b/Alexa.NET.Tests/SkillConnectionTests.cs @@ -49,7 +49,7 @@ public void SessionResumedSerializesProperly() { Type="ConnectionCompleted", Token="1234", - Status = new SessionResumedRequestCauseStatus(200,"OK") + Status = new TaskStatus(200,"OK") } }; Utility.CompareJson(task, "SessionResumedRequest.json"); @@ -75,5 +75,12 @@ public void LaunchRequestWithTaskDeserializesCorrectly() Assert.Equal("1",result.Task.Version); Assert.IsType(result.Task.Input); } + + [Fact] + public void TestCompleteTaskDirective() + { + //TODO: stop this failing + Assert.False(true); + } } } diff --git a/Alexa.NET/Request/Type/SessionResumedRequestCauseStatus.cs b/Alexa.NET/ConnectionTasks/TaskStatus.cs similarity index 55% rename from Alexa.NET/Request/Type/SessionResumedRequestCauseStatus.cs rename to Alexa.NET/ConnectionTasks/TaskStatus.cs index a71a7fe..7b86f44 100644 --- a/Alexa.NET/Request/Type/SessionResumedRequestCauseStatus.cs +++ b/Alexa.NET/ConnectionTasks/TaskStatus.cs @@ -1,12 +1,12 @@ using Newtonsoft.Json; -namespace Alexa.NET.Request.Type +namespace Alexa.NET.ConnectionTasks { - public class SessionResumedRequestCauseStatus + public class TaskStatus { - public SessionResumedRequestCauseStatus() { } + public TaskStatus() { } - public SessionResumedRequestCauseStatus(int code, string message) + public TaskStatus(int code, string message) { Code = code; Message = message; diff --git a/Alexa.NET/Request/Type/SessionResumedRequestCause.cs b/Alexa.NET/Request/Type/SessionResumedRequestCause.cs index 743f089..cd12579 100644 --- a/Alexa.NET/Request/Type/SessionResumedRequestCause.cs +++ b/Alexa.NET/Request/Type/SessionResumedRequestCause.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using Alexa.NET.ConnectionTasks; +using Newtonsoft.Json; namespace Alexa.NET.Request.Type { @@ -11,7 +12,7 @@ public class SessionResumedRequestCause public string Token { get; set; } [JsonProperty("status")] - public SessionResumedRequestCauseStatus Status { get; set; } + public TaskStatus Status { get; set; } [JsonProperty("result")] public object Result { get; set; } diff --git a/Alexa.NET/Response/Directive/CompleteTaskDirective.cs b/Alexa.NET/Response/Directive/CompleteTaskDirective.cs new file mode 100644 index 0000000..6785889 --- /dev/null +++ b/Alexa.NET/Response/Directive/CompleteTaskDirective.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Alexa.NET.ConnectionTasks; +using Newtonsoft.Json; + +namespace Alexa.NET.Response.Directive +{ + public class CompleteTaskDirective:IDirective + { + public string Type => "Tasks.CompleteTask"; + + [JsonProperty("status")] + public TaskStatus Status { get; set; } + } +} From dd6b3c607e2fe1b4203245105090ee2c786f76f3 Mon Sep 17 00:00:00 2001 From: Steven Pears Date: Thu, 4 Jul 2019 08:12:31 +0100 Subject: [PATCH 07/13] Add complete task directive --- Alexa.NET.Tests/Alexa.NET.Tests.csproj | 3 +++ Alexa.NET.Tests/Examples/CompleteTaskDirective.json | 7 +++++++ Alexa.NET.Tests/SkillConnectionTests.cs | 4 ++-- Alexa.NET/Response/Directive/CompleteTaskDirective.cs | 8 ++++++++ Alexa.NET/Response/ProgressiveResponse.cs | 8 ++++---- 5 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 Alexa.NET.Tests/Examples/CompleteTaskDirective.json diff --git a/Alexa.NET.Tests/Alexa.NET.Tests.csproj b/Alexa.NET.Tests/Alexa.NET.Tests.csproj index f9680d0..8ca85c8 100644 --- a/Alexa.NET.Tests/Alexa.NET.Tests.csproj +++ b/Alexa.NET.Tests/Alexa.NET.Tests.csproj @@ -20,6 +20,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/Alexa.NET.Tests/Examples/CompleteTaskDirective.json b/Alexa.NET.Tests/Examples/CompleteTaskDirective.json new file mode 100644 index 0000000..d0dc9c6 --- /dev/null +++ b/Alexa.NET.Tests/Examples/CompleteTaskDirective.json @@ -0,0 +1,7 @@ +{ + "type": "Tasks.CompleteTask", + "status": { + "code": 200, + "message": "return as desired" + } +} \ No newline at end of file diff --git a/Alexa.NET.Tests/SkillConnectionTests.cs b/Alexa.NET.Tests/SkillConnectionTests.cs index c38a55e..90a95c0 100644 --- a/Alexa.NET.Tests/SkillConnectionTests.cs +++ b/Alexa.NET.Tests/SkillConnectionTests.cs @@ -79,8 +79,8 @@ public void LaunchRequestWithTaskDeserializesCorrectly() [Fact] public void TestCompleteTaskDirective() { - //TODO: stop this failing - Assert.False(true); + var directive = new CompleteTaskDirective(200, "return as desired"); + Assert.True(Utility.CompareJson(directive,"CompleteTaskDirective.json")); } } } diff --git a/Alexa.NET/Response/Directive/CompleteTaskDirective.cs b/Alexa.NET/Response/Directive/CompleteTaskDirective.cs index 6785889..f924d85 100644 --- a/Alexa.NET/Response/Directive/CompleteTaskDirective.cs +++ b/Alexa.NET/Response/Directive/CompleteTaskDirective.cs @@ -8,6 +8,14 @@ namespace Alexa.NET.Response.Directive { public class CompleteTaskDirective:IDirective { + public CompleteTaskDirective() { } + + public CompleteTaskDirective(int statusCode, string statusMessage) + { + Status = new TaskStatus(statusCode,statusMessage); + } + + [JsonProperty("type")] public string Type => "Tasks.CompleteTask"; [JsonProperty("status")] diff --git a/Alexa.NET/Response/ProgressiveResponse.cs b/Alexa.NET/Response/ProgressiveResponse.cs index dc8c317..3655873 100644 --- a/Alexa.NET/Response/ProgressiveResponse.cs +++ b/Alexa.NET/Response/ProgressiveResponse.cs @@ -69,14 +69,14 @@ public ProgressiveResponse() } - public Task SendSpeech(Ssml.Speech speech) + public Task SendSpeech(Ssml.Speech ssml) { - return Send(new VoicePlayerSpeakDirective(speech)); + return Send(new VoicePlayerSpeakDirective(ssml)); } - public Task SendSpeech(string speech) + public Task SendSpeech(string ssml) { - return Send(new VoicePlayerSpeakDirective(speech)); + return Send(new VoicePlayerSpeakDirective(ssml)); } public bool CanSend() From c1d5fd19b8037326d96ace65eeaca8d2e60a2080 Mon Sep 17 00:00:00 2001 From: Steven Pears Date: Thu, 4 Jul 2019 21:34:19 +0100 Subject: [PATCH 08/13] sort out print image test --- Alexa.NET.Tests/Alexa.NET.Tests.csproj | 3 ++ .../Examples/PrintImageConnection.json | 12 ++++++ Alexa.NET.Tests/SkillConnectionTests.cs | 33 ++++++++++++++- Alexa.NET/ConnectionTasks/IConnectionTask.cs | 5 ++- .../ConnectionTasks/Inputs/PrintImageV1.cs | 42 +++++++++++++++++++ .../ConnectionTasks/Inputs/PrintPdfV1.cs | 9 ++-- .../Converters/ConnectionTaskConverter.cs | 3 +- .../Directive/StartConnectionDirective.cs | 3 +- 8 files changed, 103 insertions(+), 7 deletions(-) create mode 100644 Alexa.NET.Tests/Examples/PrintImageConnection.json create mode 100644 Alexa.NET/ConnectionTasks/Inputs/PrintImageV1.cs diff --git a/Alexa.NET.Tests/Alexa.NET.Tests.csproj b/Alexa.NET.Tests/Alexa.NET.Tests.csproj index 8ca85c8..521e046 100644 --- a/Alexa.NET.Tests/Alexa.NET.Tests.csproj +++ b/Alexa.NET.Tests/Alexa.NET.Tests.csproj @@ -68,6 +68,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/Alexa.NET.Tests/Examples/PrintImageConnection.json b/Alexa.NET.Tests/Examples/PrintImageConnection.json new file mode 100644 index 0000000..f73bffc --- /dev/null +++ b/Alexa.NET.Tests/Examples/PrintImageConnection.json @@ -0,0 +1,12 @@ +{ + "type": "Connections.StartConnection", + "uri": "connection://AMAZON.PrintImage/1", + "input": { + "@type": "PrintImageRequest", + "@version": "1", + "title": "Flywheel Document", + "description": "Flywheel", + "imageType": "JPEG", + "url": "http://www.example.com/flywheel.jpeg" + } +} \ No newline at end of file diff --git a/Alexa.NET.Tests/SkillConnectionTests.cs b/Alexa.NET.Tests/SkillConnectionTests.cs index 90a95c0..049195a 100644 --- a/Alexa.NET.Tests/SkillConnectionTests.cs +++ b/Alexa.NET.Tests/SkillConnectionTests.cs @@ -17,7 +17,7 @@ public void StartConnectionDirectiveSerializesCorrectly() { Title = "title", Description = "description", - Url = new Uri("http://www.example.com/flywheel.pdf"), + Url = "http://www.example.com/flywheel.pdf", Context = new ConnectionTaskContext { ProviderId="your-provider-skill-id"} }; Utility.CompareJson(task.ToConnectionDirective("none"), "PrintPDFConnection.json"); @@ -82,5 +82,36 @@ public void TestCompleteTaskDirective() var directive = new CompleteTaskDirective(200, "return as desired"); Assert.True(Utility.CompareJson(directive,"CompleteTaskDirective.json")); } + + [Fact] + public void PrintImageConnectionComparison() + { + var directive = new PrintImageV1 + { + Title = "Flywheel Document", + Description = "Flywheel", + ImageV1Type = PrintImageV1Type.JPEG, + Url = "http://www.example.com/flywheel.jpeg" + }.ToConnectionDirective(null); + Assert.Equal(PrintImageV1.AssociatedUri,directive.Uri); + Assert.True(Utility.CompareJson(directive,"PrintImageConnection.json")); + Assert.IsType(Utility.ExampleFileContent("PrintImageConnection.json").Input); + } + + [Fact] + public void PrintPDFConnectionComparison() + { + var directive = new PrintPdfV1 + { + Title = "title", + Description = "description", + Url = "http://www.example.com/flywheel.pdf", + Context = new ConnectionTaskContext { ProviderId = "your-provider-skill-id" } + }.ToConnectionDirective("none"); + Assert.Equal(PrintPdfV1.AssociatedUri, directive.Uri); + Assert.True(Utility.CompareJson(directive, "PrintPDFConnection.json")); + Assert.IsType(Utility.ExampleFileContent("PrintPDFConnection.json").Input); + } + } } diff --git a/Alexa.NET/ConnectionTasks/IConnectionTask.cs b/Alexa.NET/ConnectionTasks/IConnectionTask.cs index 0310d21..e1a79aa 100644 --- a/Alexa.NET/ConnectionTasks/IConnectionTask.cs +++ b/Alexa.NET/ConnectionTasks/IConnectionTask.cs @@ -7,11 +7,14 @@ namespace Alexa.NET.ConnectionTasks [JsonConverter(typeof(ConnectionTaskConverter))] public interface IConnectionTask { + [JsonIgnore] + string ConnectionUri { get; } + [JsonProperty("@type")] string Type { get; } [JsonProperty("@version")] - int Version { get; } + string Version { get; } [JsonProperty("context",NullValueHandling = NullValueHandling.Ignore)] ConnectionTaskContext Context { get; set; } diff --git a/Alexa.NET/ConnectionTasks/Inputs/PrintImageV1.cs b/Alexa.NET/ConnectionTasks/Inputs/PrintImageV1.cs new file mode 100644 index 0000000..c7a0658 --- /dev/null +++ b/Alexa.NET/ConnectionTasks/Inputs/PrintImageV1.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Alexa.NET.ConnectionTasks.Inputs +{ + public class PrintImageV1 : IConnectionTask + { + public const string AssociatedUri = "connection://AMAZON.PrintImage/1"; + [JsonIgnore] + public string ConnectionUri => AssociatedUri; + + [JsonProperty("@type")] + public string Type => "PrintImageRequest"; + + [JsonProperty("@version")] + public string Version => 1.ToString(); + + [JsonProperty("context", NullValueHandling = NullValueHandling.Ignore)] + public ConnectionTaskContext Context { get; set; } + + [JsonProperty("title")] + public string Title { get; set; } + + [JsonProperty("description")] + public string Description { get; set; } + + [JsonProperty("imageType"),JsonConverter(typeof(StringEnumConverter))] + public PrintImageV1Type ImageV1Type { get; set; } + + [JsonProperty("url")] + public string Url { get; set; } + } + + public enum PrintImageV1Type + { + JPG, + JPEG + } +} diff --git a/Alexa.NET/ConnectionTasks/Inputs/PrintPdfV1.cs b/Alexa.NET/ConnectionTasks/Inputs/PrintPdfV1.cs index 0885f27..453f508 100644 --- a/Alexa.NET/ConnectionTasks/Inputs/PrintPdfV1.cs +++ b/Alexa.NET/ConnectionTasks/Inputs/PrintPdfV1.cs @@ -7,14 +7,17 @@ public class PrintPdfV1:IConnectionTask { public const string AssociatedUri = "connection://AMAZON.PrintPDF/1"; + [JsonIgnore] + public string ConnectionUri => AssociatedUri; + [JsonProperty("@type")] public string Type => "PrintPDFRequest"; - [JsonProperty("context")] + [JsonProperty("context", NullValueHandling = NullValueHandling.Ignore)] public ConnectionTaskContext Context { get; set; } [JsonProperty("@version")] - public int Version => 1; + public string Version => 1.ToString(); [JsonProperty("title")] public string Title { get; set; } @@ -23,7 +26,7 @@ public class PrintPdfV1:IConnectionTask public string Description { get; set; } [JsonProperty("url")] - public Uri Url { get; set; } + public string Url { get; set; } } } diff --git a/Alexa.NET/Response/Converters/ConnectionTaskConverter.cs b/Alexa.NET/Response/Converters/ConnectionTaskConverter.cs index ae7c6c0..894022a 100644 --- a/Alexa.NET/Response/Converters/ConnectionTaskConverter.cs +++ b/Alexa.NET/Response/Converters/ConnectionTaskConverter.cs @@ -11,7 +11,8 @@ public class ConnectionTaskConverter:JsonConverter { public static Dictionary> TaskFactoryFromUri = new Dictionary> { - {"PrintPDFRequest/1",() => new PrintPdfV1() } + {"PrintPDFRequest/1",() => new PrintPdfV1() }, + {"PrintImageRequest/1", () => new PrintImageV1() } }; public override bool CanRead => true; diff --git a/Alexa.NET/Response/Directive/StartConnectionDirective.cs b/Alexa.NET/Response/Directive/StartConnectionDirective.cs index 40609ec..de5706a 100644 --- a/Alexa.NET/Response/Directive/StartConnectionDirective.cs +++ b/Alexa.NET/Response/Directive/StartConnectionDirective.cs @@ -15,13 +15,14 @@ public class StartConnectionDirective:IDirective [JsonProperty("input")] public IConnectionTask Input { get; set; } - [JsonProperty("token")] + [JsonProperty("token",NullValueHandling = NullValueHandling.Ignore)] public string Token { get; set; } public StartConnectionDirective(){} public StartConnectionDirective(IConnectionTask input, string token) { + this.Uri = input.ConnectionUri; this.Input = input; this.Token = token; } From f88743b974843c7cf5c3771e34cc6b562a9561f6 Mon Sep 17 00:00:00 2001 From: Steven Pears Date: Thu, 4 Jul 2019 21:39:18 +0100 Subject: [PATCH 09/13] Add PrintWebPage Task --- Alexa.NET.Tests/Alexa.NET.Tests.csproj | 3 ++ .../Examples/PrintWebPageConnection.json | 11 +++++++ Alexa.NET.Tests/SkillConnectionTests.cs | 16 +++++++++- .../IConnectionTaskExtensions.cs | 2 +- .../ConnectionTasks/Inputs/PrintWebPageV1.cs | 32 +++++++++++++++++++ .../Converters/ConnectionTaskConverter.cs | 3 +- 6 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 Alexa.NET.Tests/Examples/PrintWebPageConnection.json create mode 100644 Alexa.NET/ConnectionTasks/Inputs/PrintWebPageV1.cs diff --git a/Alexa.NET.Tests/Alexa.NET.Tests.csproj b/Alexa.NET.Tests/Alexa.NET.Tests.csproj index 521e046..831e021 100644 --- a/Alexa.NET.Tests/Alexa.NET.Tests.csproj +++ b/Alexa.NET.Tests/Alexa.NET.Tests.csproj @@ -74,6 +74,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/Alexa.NET.Tests/Examples/PrintWebPageConnection.json b/Alexa.NET.Tests/Examples/PrintWebPageConnection.json new file mode 100644 index 0000000..c354542 --- /dev/null +++ b/Alexa.NET.Tests/Examples/PrintWebPageConnection.json @@ -0,0 +1,11 @@ +{ + "type": "Connections.StartConnection", + "uri": "connection://AMAZON.PrintWebPage/1", + "input": { + "@type": "PrintWebPageRequest", + "@version": "1", + "title": "title", + "description": "description", + "url": "http://www.example.com/flywheel.html" + } +} \ No newline at end of file diff --git a/Alexa.NET.Tests/SkillConnectionTests.cs b/Alexa.NET.Tests/SkillConnectionTests.cs index 049195a..ee9b82e 100644 --- a/Alexa.NET.Tests/SkillConnectionTests.cs +++ b/Alexa.NET.Tests/SkillConnectionTests.cs @@ -92,7 +92,7 @@ public void PrintImageConnectionComparison() Description = "Flywheel", ImageV1Type = PrintImageV1Type.JPEG, Url = "http://www.example.com/flywheel.jpeg" - }.ToConnectionDirective(null); + }.ToConnectionDirective(); Assert.Equal(PrintImageV1.AssociatedUri,directive.Uri); Assert.True(Utility.CompareJson(directive,"PrintImageConnection.json")); Assert.IsType(Utility.ExampleFileContent("PrintImageConnection.json").Input); @@ -113,5 +113,19 @@ public void PrintPDFConnectionComparison() Assert.IsType(Utility.ExampleFileContent("PrintPDFConnection.json").Input); } + [Fact] + public void PrintWebPageConnectionComparison() + { + var directive = new PrintWebPageV1 + { + Title = "title", + Description = "description", + Url = "http://www.example.com/flywheel.html" + }.ToConnectionDirective(); + Assert.Equal(PrintWebPageV1.AssociatedUri, directive.Uri); + Assert.True(Utility.CompareJson(directive, "PrintWebPageConnection.json")); + Assert.IsType(Utility.ExampleFileContent("PrintPDFConnection.json").Input); + } + } } diff --git a/Alexa.NET/ConnectionTasks/IConnectionTaskExtensions.cs b/Alexa.NET/ConnectionTasks/IConnectionTaskExtensions.cs index 5d9e808..1cdac28 100644 --- a/Alexa.NET/ConnectionTasks/IConnectionTaskExtensions.cs +++ b/Alexa.NET/ConnectionTasks/IConnectionTaskExtensions.cs @@ -8,7 +8,7 @@ namespace Alexa.NET.ConnectionTasks public static class IConnectionTaskExtensions { - public static StartConnectionDirective ToConnectionDirective(this IConnectionTask task, string token) + public static StartConnectionDirective ToConnectionDirective(this IConnectionTask task, string token = null) { return new StartConnectionDirective(task, token); } diff --git a/Alexa.NET/ConnectionTasks/Inputs/PrintWebPageV1.cs b/Alexa.NET/ConnectionTasks/Inputs/PrintWebPageV1.cs new file mode 100644 index 0000000..113ac30 --- /dev/null +++ b/Alexa.NET/ConnectionTasks/Inputs/PrintWebPageV1.cs @@ -0,0 +1,32 @@ +using System; +using Newtonsoft.Json; + +namespace Alexa.NET.ConnectionTasks.Inputs +{ + public class PrintWebPageV1:IConnectionTask + { + public const string AssociatedUri = "connection://AMAZON.PrintWebPage/1"; + + [JsonIgnore] + public string ConnectionUri => AssociatedUri; + + [JsonProperty("@type")] + public string Type => "PrintWebPageRequest"; + + [JsonProperty("context", NullValueHandling = NullValueHandling.Ignore)] + public ConnectionTaskContext Context { get; set; } + + [JsonProperty("@version")] + public string Version => 1.ToString(); + + [JsonProperty("title")] + public string Title { get; set; } + + [JsonProperty("description")] + public string Description { get; set; } + + [JsonProperty("url")] + public string Url { get; set; } + + } +} diff --git a/Alexa.NET/Response/Converters/ConnectionTaskConverter.cs b/Alexa.NET/Response/Converters/ConnectionTaskConverter.cs index 894022a..324fdf9 100644 --- a/Alexa.NET/Response/Converters/ConnectionTaskConverter.cs +++ b/Alexa.NET/Response/Converters/ConnectionTaskConverter.cs @@ -12,7 +12,8 @@ public class ConnectionTaskConverter:JsonConverter public static Dictionary> TaskFactoryFromUri = new Dictionary> { {"PrintPDFRequest/1",() => new PrintPdfV1() }, - {"PrintImageRequest/1", () => new PrintImageV1() } + {"PrintImageRequest/1", () => new PrintImageV1() }, + {"PrintWebPageRequest/1",() => new PrintWebPageV1()} }; public override bool CanRead => true; From 8a3f21476e9fa3613d024863c4c3e6ff71589326 Mon Sep 17 00:00:00 2001 From: Steven Pears Date: Thu, 4 Jul 2019 22:27:51 +0100 Subject: [PATCH 10/13] Add ScheduleTaxi connection --- Alexa.NET.Tests/Alexa.NET.Tests.csproj | 3 ++ .../Examples/ScheduleTaxiReservation.json | 27 ++++++++++++++ Alexa.NET.Tests/SkillConnectionTests.cs | 28 +++++++++++++++ .../ConnectionTasks/Inputs/PostalAddress.cs | 18 ++++++++++ .../Inputs/ScheduleTaxiReservation.cs | 36 +++++++++++++++++++ .../Converters/ConnectionTaskConverter.cs | 3 +- 6 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 Alexa.NET.Tests/Examples/ScheduleTaxiReservation.json create mode 100644 Alexa.NET/ConnectionTasks/Inputs/PostalAddress.cs create mode 100644 Alexa.NET/ConnectionTasks/Inputs/ScheduleTaxiReservation.cs diff --git a/Alexa.NET.Tests/Alexa.NET.Tests.csproj b/Alexa.NET.Tests/Alexa.NET.Tests.csproj index 831e021..1607521 100644 --- a/Alexa.NET.Tests/Alexa.NET.Tests.csproj +++ b/Alexa.NET.Tests/Alexa.NET.Tests.csproj @@ -83,6 +83,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/Alexa.NET.Tests/Examples/ScheduleTaxiReservation.json b/Alexa.NET.Tests/Examples/ScheduleTaxiReservation.json new file mode 100644 index 0000000..5594bc0 --- /dev/null +++ b/Alexa.NET.Tests/Examples/ScheduleTaxiReservation.json @@ -0,0 +1,27 @@ +{ + "type": "Connections.StartConnection", + "uri": "connection://AMAZON.ScheduleTaxiReservation/1", + "input": { + "@type": "ScheduleTaxiReservationRequest", + "@version": "1", + "partySize": 4, + "pickupLocation": { + "@type": "PostalAddress", + "@version": "1", + "streetAddress": "415 106th Ave NE", + "locality": "Bellevue", + "region": "WA", + "postalCode": "98004", + "country": "US" + }, + "dropoffLocation": { + "@type": "PostalAddress", + "@version": "1", + "streetAddress": "2031 6th Ave.", + "locality": "Seattle", + "region": "WA", + "postalCode": "98121", + "country": "US" + } + } +} \ No newline at end of file diff --git a/Alexa.NET.Tests/SkillConnectionTests.cs b/Alexa.NET.Tests/SkillConnectionTests.cs index ee9b82e..323c997 100644 --- a/Alexa.NET.Tests/SkillConnectionTests.cs +++ b/Alexa.NET.Tests/SkillConnectionTests.cs @@ -127,5 +127,33 @@ public void PrintWebPageConnectionComparison() Assert.IsType(Utility.ExampleFileContent("PrintPDFConnection.json").Input); } + [Fact] + public void ScheduleTaxiReservationConnectionComparison() + { + var directive = new ScheduleTaxiReservation + { + PartySize = 4, + PickupLocation = new PostalAddress + { + StreetAddress = "415 106th Ave NE", + Locality = "Bellevue", + Region = "WA", + PostalCode = "98004", + Country = "US" + }, + DropoffLocation = new PostalAddress + { + StreetAddress = "2031 6th Ave.", + Locality = "Seattle", + Region = "WA", + PostalCode = "98121", + Country = "US" + } + }.ToConnectionDirective(); + Assert.Equal(ScheduleTaxiReservation.AssociatedUri, directive.Uri); + Assert.True(Utility.CompareJson(directive, "ScheduleTaxiReservation.json")); + Assert.IsType(Utility.ExampleFileContent("ScheduleTaxiReservation.json").Input); + } + } } diff --git a/Alexa.NET/ConnectionTasks/Inputs/PostalAddress.cs b/Alexa.NET/ConnectionTasks/Inputs/PostalAddress.cs new file mode 100644 index 0000000..aaf8f86 --- /dev/null +++ b/Alexa.NET/ConnectionTasks/Inputs/PostalAddress.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; + +namespace Alexa.NET.ConnectionTasks.Inputs +{ + public class PostalAddress + { + [JsonProperty("@type")] public string Type => "PostalAddress"; + [JsonProperty("@version")] public string Version = 1.ToString(); + [JsonProperty("streetAddress")] public string StreetAddress { get; set; } + [JsonProperty("locality")] public string Locality { get; set; } + [JsonProperty("region")] public string Region { get; set; } + [JsonProperty("postalCode")] public string PostalCode { get; set; } + [JsonProperty("country", NullValueHandling = NullValueHandling.Ignore)] public string Country { get; set; } + } +} diff --git a/Alexa.NET/ConnectionTasks/Inputs/ScheduleTaxiReservation.cs b/Alexa.NET/ConnectionTasks/Inputs/ScheduleTaxiReservation.cs new file mode 100644 index 0000000..2a16793 --- /dev/null +++ b/Alexa.NET/ConnectionTasks/Inputs/ScheduleTaxiReservation.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Alexa.NET.Helpers; +using Newtonsoft.Json; + +namespace Alexa.NET.ConnectionTasks.Inputs +{ + public class ScheduleTaxiReservation:IConnectionTask + { + public const string AssociatedUri = "connection://AMAZON.ScheduleTaxiReservation/1"; + [JsonIgnore] + public string ConnectionUri => AssociatedUri; + + [JsonProperty("@type")] + public string Type => "ScheduleTaxiReservationRequest"; + + [JsonProperty("@version")] + public string Version => 1.ToString(); + + [JsonProperty("context", NullValueHandling = NullValueHandling.Ignore)] + public ConnectionTaskContext Context { get; set; } + + [JsonProperty("partySize")] + public int PartySize { get; set; } + + [JsonProperty("pickupLocation",NullValueHandling = NullValueHandling.Ignore)] + public PostalAddress PickupLocation { get; set; } + + [JsonProperty("dropoffLocation",NullValueHandling = NullValueHandling.Ignore)] + public PostalAddress DropoffLocation { get; set; } + + [JsonProperty("pickupTime",NullValueHandling = NullValueHandling.Ignore),JsonConverter(typeof(MixedDateTimeConverter))] + public DateTime? PickupTime { get; set; } + } +} diff --git a/Alexa.NET/Response/Converters/ConnectionTaskConverter.cs b/Alexa.NET/Response/Converters/ConnectionTaskConverter.cs index 324fdf9..18890c8 100644 --- a/Alexa.NET/Response/Converters/ConnectionTaskConverter.cs +++ b/Alexa.NET/Response/Converters/ConnectionTaskConverter.cs @@ -13,7 +13,8 @@ public class ConnectionTaskConverter:JsonConverter { {"PrintPDFRequest/1",() => new PrintPdfV1() }, {"PrintImageRequest/1", () => new PrintImageV1() }, - {"PrintWebPageRequest/1",() => new PrintWebPageV1()} + {"PrintWebPageRequest/1",() => new PrintWebPageV1()}, + {"ScheduleTaxiReservationRequest/1",() => new ScheduleTaxiReservation() } }; public override bool CanRead => true; From 62db59997e658f8ae6a180418d8b2aab7eca649a Mon Sep 17 00:00:00 2001 From: Steven Pears Date: Thu, 4 Jul 2019 22:48:28 +0100 Subject: [PATCH 11/13] Add schedule food connection --- Alexa.NET.Tests/Alexa.NET.Tests.csproj | 3 + .../ScheduleFoodEstablishmentReservation.json | 24 ++++++++ Alexa.NET.Tests/SkillConnectionTests.cs | 55 ++++++++++++++----- .../ConnectionTasks/Inputs/Restaurant.cs | 19 +++++++ .../ScheduleFoodEstablishmentReservation.cs | 33 +++++++++++ .../Converters/ConnectionTaskConverter.cs | 5 +- 6 files changed, 122 insertions(+), 17 deletions(-) create mode 100644 Alexa.NET.Tests/Examples/ScheduleFoodEstablishmentReservation.json create mode 100644 Alexa.NET/ConnectionTasks/Inputs/Restaurant.cs create mode 100644 Alexa.NET/ConnectionTasks/Inputs/ScheduleFoodEstablishmentReservation.cs diff --git a/Alexa.NET.Tests/Alexa.NET.Tests.csproj b/Alexa.NET.Tests/Alexa.NET.Tests.csproj index 1607521..53fe502 100644 --- a/Alexa.NET.Tests/Alexa.NET.Tests.csproj +++ b/Alexa.NET.Tests/Alexa.NET.Tests.csproj @@ -83,6 +83,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/Alexa.NET.Tests/Examples/ScheduleFoodEstablishmentReservation.json b/Alexa.NET.Tests/Examples/ScheduleFoodEstablishmentReservation.json new file mode 100644 index 0000000..369fdec --- /dev/null +++ b/Alexa.NET.Tests/Examples/ScheduleFoodEstablishmentReservation.json @@ -0,0 +1,24 @@ +{ + "type": "Connections.StartConnection", + "uri": "connection://AMAZON.ScheduleFoodEstablishmentReservation/1", + "input": { + "@type": "ScheduleFoodEstablishmentReservationRequest", + "@version": "1", + "startTime": "2018-04-08T01:15:46Z", + "partySize": 2, + "restaurant": { + "@type": "Restaurant", + "@version": "1", + "name": "Amazon Day 1 Restaurant", + "location": { + "@type": "PostalAddress", + "@version": "1", + "streetAddress": "2121 7th Avenue", + "locality": "Seattle", + "region": "WA", + "postalCode": "98121", + "country": "US" + } + } + } +} \ No newline at end of file diff --git a/Alexa.NET.Tests/SkillConnectionTests.cs b/Alexa.NET.Tests/SkillConnectionTests.cs index 323c997..08b72c1 100644 --- a/Alexa.NET.Tests/SkillConnectionTests.cs +++ b/Alexa.NET.Tests/SkillConnectionTests.cs @@ -18,7 +18,7 @@ public void StartConnectionDirectiveSerializesCorrectly() Title = "title", Description = "description", Url = "http://www.example.com/flywheel.pdf", - Context = new ConnectionTaskContext { ProviderId="your-provider-skill-id"} + Context = new ConnectionTaskContext { ProviderId = "your-provider-skill-id" } }; Utility.CompareJson(task.ToConnectionDirective("none"), "PrintPDFConnection.json"); } @@ -31,7 +31,7 @@ public void StartConnectionDirectiveDeserializesCorrectly() var directive = Assert.IsType(raw); Assert.Equal("none", directive.Token); - Assert.Equal(PrintPdfV1.AssociatedUri,directive.Uri); + Assert.Equal(PrintPdfV1.AssociatedUri, directive.Uri); Assert.IsType(directive.Input); } @@ -42,14 +42,14 @@ public void SessionResumedSerializesProperly() var task = new SessionResumedRequest { RequestId = "string", - Timestamp = new DateTime(2019,07,03), + Timestamp = new DateTime(2019, 07, 03), Locale = "en-GB", OriginIpAddress = "string", Cause = new SessionResumedRequestCause { - Type="ConnectionCompleted", - Token="1234", - Status = new TaskStatus(200,"OK") + Type = "ConnectionCompleted", + Token = "1234", + Status = new TaskStatus(200, "OK") } }; Utility.CompareJson(task, "SessionResumedRequest.json"); @@ -61,9 +61,9 @@ public void SessionResumedDeserializesProperly() var result = Utility.ExampleFileContent("SessionResumedRequest.json"); var request = Assert.IsType(result); - Assert.Equal("1234",request.Cause.Token); - Assert.Equal(200,request.Cause.Status.Code); - Assert.Equal("OK",request.Cause.Status.Message); + Assert.Equal("1234", request.Cause.Token); + Assert.Equal(200, request.Cause.Status.Code); + Assert.Equal("OK", request.Cause.Status.Message); } [Fact] @@ -71,16 +71,16 @@ public void LaunchRequestWithTaskDeserializesCorrectly() { var result = Utility.ExampleFileContent("LaunchRequestWithTask.json"); Assert.NotNull(result.Task); - Assert.Equal("AMAZON.PrintPDF",result.Task.Name); - Assert.Equal("1",result.Task.Version); + Assert.Equal("AMAZON.PrintPDF", result.Task.Name); + Assert.Equal("1", result.Task.Version); Assert.IsType(result.Task.Input); } [Fact] - public void TestCompleteTaskDirective() + public void TestCompleteTaskDirective() { var directive = new CompleteTaskDirective(200, "return as desired"); - Assert.True(Utility.CompareJson(directive,"CompleteTaskDirective.json")); + Assert.True(Utility.CompareJson(directive, "CompleteTaskDirective.json")); } [Fact] @@ -93,8 +93,8 @@ public void PrintImageConnectionComparison() ImageV1Type = PrintImageV1Type.JPEG, Url = "http://www.example.com/flywheel.jpeg" }.ToConnectionDirective(); - Assert.Equal(PrintImageV1.AssociatedUri,directive.Uri); - Assert.True(Utility.CompareJson(directive,"PrintImageConnection.json")); + Assert.Equal(PrintImageV1.AssociatedUri, directive.Uri); + Assert.True(Utility.CompareJson(directive, "PrintImageConnection.json")); Assert.IsType(Utility.ExampleFileContent("PrintImageConnection.json").Input); } @@ -155,5 +155,30 @@ public void ScheduleTaxiReservationConnectionComparison() Assert.IsType(Utility.ExampleFileContent("ScheduleTaxiReservation.json").Input); } + [Fact] + public void ScheduleFoodReservationConnectionComparison() + { + var directive = new ScheduleFoodEstablishmentReservation + { + PartySize = 2, + StartTime = new DateTime(2018,04,08,01,15,46), + Restaurant = new Restaurant + { + Name = "Amazon Day 1 Restaurant", + Location = new PostalAddress + { + StreetAddress = "2121 7th Avenue", + Locality = "Seattle", + Region = "WA", + PostalCode = "98121", + Country = "US" + } + } + }.ToConnectionDirective(); + Assert.Equal(ScheduleFoodEstablishmentReservation.AssociatedUri, directive.Uri); + Assert.True(Utility.CompareJson(directive, "ScheduleFoodEstablishmentReservation.json")); + Assert.IsType(Utility.ExampleFileContent("ScheduleFoodEstablishmentReservation.json").Input); + } + } } diff --git a/Alexa.NET/ConnectionTasks/Inputs/Restaurant.cs b/Alexa.NET/ConnectionTasks/Inputs/Restaurant.cs new file mode 100644 index 0000000..c3786d8 --- /dev/null +++ b/Alexa.NET/ConnectionTasks/Inputs/Restaurant.cs @@ -0,0 +1,19 @@ +using Newtonsoft.Json; + +namespace Alexa.NET.ConnectionTasks.Inputs +{ + public class Restaurant + { + [JsonProperty("@type")] + public string Type => "Restaurant"; + + [JsonProperty("@version")] + public string Version => 1.ToString(); + + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("location")] + public PostalAddress Location { get; set; } + } +} \ No newline at end of file diff --git a/Alexa.NET/ConnectionTasks/Inputs/ScheduleFoodEstablishmentReservation.cs b/Alexa.NET/ConnectionTasks/Inputs/ScheduleFoodEstablishmentReservation.cs new file mode 100644 index 0000000..4bd46dc --- /dev/null +++ b/Alexa.NET/ConnectionTasks/Inputs/ScheduleFoodEstablishmentReservation.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Alexa.NET.Helpers; +using Newtonsoft.Json; + +namespace Alexa.NET.ConnectionTasks.Inputs +{ + public class ScheduleFoodEstablishmentReservation:IConnectionTask + { + public const string AssociatedUri = "connection://AMAZON.ScheduleFoodEstablishmentReservation/1"; + [JsonIgnore] + public string ConnectionUri => AssociatedUri; + + [JsonProperty("@type")] + public string Type => "ScheduleFoodEstablishmentReservationRequest"; + + [JsonProperty("@version")] + public string Version => 1.ToString(); + + [JsonProperty("context", NullValueHandling = NullValueHandling.Ignore)] + public ConnectionTaskContext Context { get; set; } + + [JsonProperty("partySize",NullValueHandling = NullValueHandling.Ignore)] + public int PartySize { get; set; } + + [JsonProperty("startTime",NullValueHandling = NullValueHandling.Ignore),JsonConverter(typeof(MixedDateTimeConverter))] + public DateTime? StartTime { get; set; } + + [JsonProperty("restaurant")] + public Restaurant Restaurant { get; set; } + } +} diff --git a/Alexa.NET/Response/Converters/ConnectionTaskConverter.cs b/Alexa.NET/Response/Converters/ConnectionTaskConverter.cs index 18890c8..b3b7d58 100644 --- a/Alexa.NET/Response/Converters/ConnectionTaskConverter.cs +++ b/Alexa.NET/Response/Converters/ConnectionTaskConverter.cs @@ -7,14 +7,15 @@ namespace Alexa.NET.Response.Converters { - public class ConnectionTaskConverter:JsonConverter + public class ConnectionTaskConverter : JsonConverter { public static Dictionary> TaskFactoryFromUri = new Dictionary> { {"PrintPDFRequest/1",() => new PrintPdfV1() }, {"PrintImageRequest/1", () => new PrintImageV1() }, {"PrintWebPageRequest/1",() => new PrintWebPageV1()}, - {"ScheduleTaxiReservationRequest/1",() => new ScheduleTaxiReservation() } + {"ScheduleTaxiReservationRequest/1",() => new ScheduleTaxiReservation() }, + {"ScheduleFoodEstablishmentReservationRequest/1",() => new ScheduleFoodEstablishmentReservation()} }; public override bool CanRead => true; From 92587a1c130d7cbfd98dc99e602dd03fbbd7e377 Mon Sep 17 00:00:00 2001 From: Steven Pears Date: Thu, 4 Jul 2019 23:04:55 +0100 Subject: [PATCH 12/13] Add Tasks.CompleteTask directive to converter --- Alexa.NET/Response/Converters/DirectiveConverter.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Alexa.NET/Response/Converters/DirectiveConverter.cs b/Alexa.NET/Response/Converters/DirectiveConverter.cs index ce85681..9887c5c 100644 --- a/Alexa.NET/Response/Converters/DirectiveConverter.cs +++ b/Alexa.NET/Response/Converters/DirectiveConverter.cs @@ -24,7 +24,8 @@ public class DirectiveConverter : JsonConverter { "Hint", () => new HintDirective() }, { "AudioPlayer.Stop", () => new StopDirective() }, { "VideoApp.Launch", () => new VideoAppDirective() }, - { "Connections.StartConnection", () => new StartConnectionDirective() } + { "Connections.StartConnection", () => new StartConnectionDirective() }, + { "Tasks.CompleteTask",() => new CompleteTaskDirective()} }; public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) From 3736124c20994bf186b0fdb5ac2019166c877d42 Mon Sep 17 00:00:00 2001 From: Tim Heuer Date: Mon, 8 Jul 2019 11:31:33 -0700 Subject: [PATCH 13/13] Bumped version number --- Alexa.NET/Alexa.NET.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Alexa.NET/Alexa.NET.csproj b/Alexa.NET/Alexa.NET.csproj index 22081ec..2c7941a 100644 --- a/Alexa.NET/Alexa.NET.csproj +++ b/Alexa.NET/Alexa.NET.csproj @@ -3,13 +3,13 @@ A simple .NET Core library for handling Alexa Skill request/responses. Alexa.NET - 1.6.3 + 1.7.0 Tim Heuer, Steven Pears netstandard1.6 Alexa.NET Alexa.NET amazon;alexa;echo;dot;echo dot;skills - Added SessionEnd error object; Fix deserialization error; Added permission scopes (by @VinceGusmini); Added response type converters (by @rdlaitila); Added Dynamic Entity support (by @stoiveyp) + Added core support for Skill connections (by @stoiveyp) and in association with Alexa.NET.Management enables the end-to-end. https://github.com/timheuer/alexa-skills-dotnet MIT https://github.com/timheuer/alexa-skills-dotnet