Alexa.NET.APL 4.2.1

Small helper library to allow Alexa.NET skills to work with APL

There is a newer version of this package available.
See the version list below for details.
Install-Package Alexa.NET.APL -Version 4.2.1
dotnet add package Alexa.NET.APL --version 4.2.1
<PackageReference Include="Alexa.NET.APL" Version="4.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Alexa.NET.APL --version 4.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Alexa.NET.APL, 4.2.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Alexa.NET.APL as a Cake Addin
#addin nuget:?package=Alexa.NET.APL&version=4.2.1

// Install Alexa.NET.APL as a Cake Tool
#tool nuget:?package=Alexa.NET.APL&version=4.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Alexa.NET.APL

Small helper library to allow Alexa.NET skills to work with APL

Access to APL ViewPort Data within your skill

There are new Display and Viewport properties available within the request being sent to an APL enabled skill.
Rather than create a forced dependency for Alexa.NET - APL skills have an enhanced SkillRequest object with these new properties
Amazon information on Viewport information: https://developer.amazon.com/docs/alexa-presentation-language/apl-viewport-characteristics.html
Here's an example signature and opening line for a lambda function

public Task<SkillResponse> FunctionHandler(APLSkillRequest input, ILambdaContext context)
var shape = input.Context.Viewport?.Shape;

Add support for APL Directives

	RenderDocumentDirective.AddSupport();
	ExecutiveCommandsDirective.AddSupport();

Check APL support in a request / which version of APL is supported

	skillRequest.APLSupported();
	var aplDocumentVersion = skillRequest.APLInterfaceDetails().Runtime.MaxVersion;

Creating a Layout Document

Alexa.NET.APL has a set of APL components so that creating layouts is entirely within the C# object model
All properties are of Type APLValue&lt;T&gt; - which allows you to specify an absolute value or an APL data binding expression for each property

  new Layout(
    new Container(
      new Text("APL in C#") {FontSize = "24dp", TextAlign = "Center"}, 
      new Image("https://example.com/image.jpg") {Width = 400, Height = 400}
	)
    { Direction = "row"});

Adding an AlexaHeader or Footer layout

Alexa.NET.APL has support for the custom Layouts provided by the Alexa team.
These need to be imported into a document before the layout can be used inside a document.

var document = new APLDocument();
document.AddResponsiveDesign();

document.MainTemplate = new Layout(
    new AlexaFooter("Hint Text")
).AsMain();

Sending a RenderDocument Directove

RenderDocument hooks into the same Alexa.NET directive mechanism that already exists, you just reference the layout, document token and any data sources you want to send along with it

            var shape = input.Context.Viewport?.Shape;
            var response = ResponseBuilder.Tell($"Your viewport is {shape.ToString() ?? "Non existent"}");

            var directive = new RenderDocumentDirective
            {
                Token = "randomToken",
                Document = new APLDocument
                {
                    MainTemplate = new Layout(new[]
                    {
                        new Container(new APLComponent[]{
                            new Text("APL in C#"){FontSize = "24dp",TextAlign= "Center"},
                            new Image("https://images.example.com/photos/2143/lights-party-dancing-music.jpg?cs=srgb&dl=cheerful-club-concert-2143.jpg&fm=jpg"){Width = 400,Height=400}
                        }){Direction = "row"}
                    })
                }
            };

            response.Response.Directives.Add(directive);

Receiving SendEvent Commands from your layout

Commands are supported within Alexa.NET.APL - to send events back from your layout to your skill you need the SendEvent Command:

https://developer.amazon.com/docs/alexa-presentation-language/apl-standard-commands.html#sendevent-command

var wrapper = new TouchWrapper
{
   OnPress = new SendEvent
   {
     Arguments = new Dictionary<string, object> {{"sent", true}}
   }
};

To receive these events you need to add support for the UserEventRequest, which can be placed in your Lambda constructor

new UserEventRequestHandler().AddToRequestConverter();

and then you treat them like any other request type, for example

if (input.Request is UserEventRequest userEvent)
{
    var token = userEvent.Token;
    var argument = userEvent.Arguments["sent"];
}

Obviously your user may interact with your skill through voice means, at which point you need to be able to send commands down to your layout. This is done with the ExecuteCommands directive

using Alexa.NET.APL.Commands;
...
var sendEvent = new ExecuteCommandsDirective("token",new []
{
    new SetPage
    {
        ComponentId="exampleId",
        Value=3
    }
});

Alexa.NET.APL

Small helper library to allow Alexa.NET skills to work with APL

Access to APL ViewPort Data within your skill

There are new Display and Viewport properties available within the request being sent to an APL enabled skill.
Rather than create a forced dependency for Alexa.NET - APL skills have an enhanced SkillRequest object with these new properties
Amazon information on Viewport information: https://developer.amazon.com/docs/alexa-presentation-language/apl-viewport-characteristics.html
Here's an example signature and opening line for a lambda function

public Task<SkillResponse> FunctionHandler(APLSkillRequest input, ILambdaContext context)
var shape = input.Context.Viewport?.Shape;

Add support for APL Directives

	RenderDocumentDirective.AddSupport();
	ExecutiveCommandsDirective.AddSupport();

Check APL support in a request / which version of APL is supported

	skillRequest.APLSupported();
	var aplDocumentVersion = skillRequest.APLInterfaceDetails().Runtime.MaxVersion;

Creating a Layout Document

Alexa.NET.APL has a set of APL components so that creating layouts is entirely within the C# object model
All properties are of Type APLValue&lt;T&gt; - which allows you to specify an absolute value or an APL data binding expression for each property

  new Layout(
    new Container(
      new Text("APL in C#") {FontSize = "24dp", TextAlign = "Center"}, 
      new Image("https://example.com/image.jpg") {Width = 400, Height = 400}
	)
    { Direction = "row"});

Adding an AlexaHeader or Footer layout

Alexa.NET.APL has support for the custom Layouts provided by the Alexa team.
These need to be imported into a document before the layout can be used inside a document.

var document = new APLDocument();
document.AddResponsiveDesign();

document.MainTemplate = new Layout(
    new AlexaFooter("Hint Text")
).AsMain();

Sending a RenderDocument Directove

RenderDocument hooks into the same Alexa.NET directive mechanism that already exists, you just reference the layout, document token and any data sources you want to send along with it

            var shape = input.Context.Viewport?.Shape;
            var response = ResponseBuilder.Tell($"Your viewport is {shape.ToString() ?? "Non existent"}");

            var directive = new RenderDocumentDirective
            {
                Token = "randomToken",
                Document = new APLDocument
                {
                    MainTemplate = new Layout(new[]
                    {
                        new Container(new APLComponent[]{
                            new Text("APL in C#"){FontSize = "24dp",TextAlign= "Center"},
                            new Image("https://images.example.com/photos/2143/lights-party-dancing-music.jpg?cs=srgb&dl=cheerful-club-concert-2143.jpg&fm=jpg"){Width = 400,Height=400}
                        }){Direction = "row"}
                    })
                }
            };

            response.Response.Directives.Add(directive);

Receiving SendEvent Commands from your layout

Commands are supported within Alexa.NET.APL - to send events back from your layout to your skill you need the SendEvent Command:

https://developer.amazon.com/docs/alexa-presentation-language/apl-standard-commands.html#sendevent-command

var wrapper = new TouchWrapper
{
   OnPress = new SendEvent
   {
     Arguments = new Dictionary<string, object> {{"sent", true}}
   }
};

To receive these events you need to add support for the UserEventRequest, which can be placed in your Lambda constructor

new UserEventRequestHandler().AddToRequestConverter();

and then you treat them like any other request type, for example

if (input.Request is UserEventRequest userEvent)
{
    var token = userEvent.Token;
    var argument = userEvent.Arguments["sent"];
}

Obviously your user may interact with your skill through voice means, at which point you need to be able to send commands down to your layout. This is done with the ExecuteCommands directive

using Alexa.NET.APL.Commands;
...
var sendEvent = new ExecuteCommandsDirective("token",new []
{
    new SetPage
    {
        ComponentId="exampleId",
        Value=3
    }
});

Release Notes

Add helper methods to AnimatedTransform to reduce AnimateItem size

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Alexa.NET.APL:

Package Downloads
Ask.Sdk.Core
Core SDK package that contains the basic components and default implementations of ASK SDK for .Net Core.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
7.2.0 632 4/3/2021
7.1.0 379 2/17/2021
7.0.0 2,872 11/20/2020
6.1.0 808 9/26/2020
6.0.4 1,162 7/24/2020
6.0.3 244 7/23/2020
6.0.2 249 7/23/2020
5.1.1 1,268 3/31/2020
5.1.0 238 3/26/2020
5.0.0 266 3/26/2020
4.9.1 217 3/17/2020
4.9.0 476 1/6/2020
4.8.1 235 12/19/2019
4.8.0 267 12/5/2019
4.7.0 343 11/26/2019
4.6.0 434 11/7/2019
4.5.1 234 11/1/2019
4.4.2 236 10/30/2019
4.4.1 242 10/30/2019
4.4.0 250 10/25/2019
4.3.1 228 10/24/2019
4.3.0 231 10/24/2019
4.2.3 335 9/10/2019
4.2.1 255 9/10/2019
4.2.0 2,311 8/9/2019
4.1.2 288 8/8/2019
4.1.1 283 8/8/2019
4.1.0 272 8/7/2019
4.0.13 340 7/28/2019
4.0.12 271 7/28/2019
4.0.11 321 7/15/2019
4.0.10 309 7/14/2019
4.0.9 266 7/14/2019
4.0.8 261 7/14/2019
4.0.7 323 7/14/2019
4.0.6 287 7/11/2019
4.0.5 290 7/10/2019
4.0.4 273 7/10/2019
4.0.2 271 7/10/2019
4.0.1 290 7/7/2019
4.0.0 279 7/6/2019
3.15.0 323 5/15/2019
3.14.0 304 5/9/2019
3.13.0 314 5/5/2019
3.12.0 327 5/4/2019
3.11.0 561 3/27/2019
3.10.0 301 3/27/2019
3.9.0 301 3/18/2019
3.8.0 360 3/4/2019
3.7.0 306 3/3/2019
3.6.3 389 1/31/2019
3.6.2 415 1/23/2019
3.6.1 982 1/14/2019
3.5.0 413 1/14/2019
3.4.0 434 1/9/2019
3.3.0 412 1/9/2019
3.1.0 402 12/26/2018
3.0.0 364 12/25/2018
2.1.0 372 12/25/2018
2.0.0 466 12/13/2018
1.6.4 400 12/7/2018
1.6.3 681 11/11/2018
1.6.1 439 11/11/2018
1.6.0 403 11/11/2018
1.5.0 454 11/6/2018
1.4.3 423 11/6/2018
1.4.2 393 11/6/2018
1.4.1 391 11/6/2018
1.4.0 412 11/5/2018
1.3.2 423 11/5/2018
1.2.2 426 11/5/2018
1.2.1 433 11/5/2018
1.2.0 417 11/5/2018
1.1.0 419 11/4/2018
1.0.0 425 11/2/2018
Show less