Alexa.NET.APL 7.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Alexa.NET.APL --version 7.2.0                
NuGet\Install-Package Alexa.NET.APL -Version 7.2.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Alexa.NET.APL" Version="7.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Alexa.NET.APL --version 7.2.0                
#r "nuget: Alexa.NET.APL, 7.2.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. 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=7.2.0

// Install Alexa.NET.APL as a Cake Tool
#tool nuget:?package=Alexa.NET.APL&version=7.2.0                

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 All APL Support

    APLSupport.Add();

Add support for APL Directives

	RenderDocumentDirective.AddSupport();
	ExecuteCommandsDirective.AddSupport();

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

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

If you already have a JSON Layout

If you've used the Alexa designer to generate your APL and just want to send it exactly as-is in the response, we recommend not using the strongly typed APLDocument and RenderDocumentDirective. ###If the APL is stored in the authoring tool - link directly

var directive = new RenderDocumentDirective(new APLDocumentLink("doc://alexa/apl/documents/<document-name>"));

###If your APL is stored elsewhere Instead we've contributed to the core Alexa.NET library to enable the JSONDirective type, which saves on the extra processing and complexity of converting to and from an object model for no added benefit.

  var directive = new JsonDirective(RenderDocumentDirective.APLDirectiveType);
  directive.Properties.Add("document",aplDocumentJson);

Create an audio document from scratch

As of v6 Alexa.NET.APL now supports APL for Audio

var lyrics = new Speech { Content = "Row, row row your boat, gently down the stream. Merrily merrily merrily merrily life is but a dream" };
new APLADocument
    {
        MainTemplate = new AudioLayout(
            new Mixer
            {
                Items = new List<APLAComponent>{
                    lyrics,
                    new Sequencer
                    {
                        Items = new List<APLAComponent>{
                            new Silence{Duration = 1500},
                            lyrics
                        }
                    },
                    new Sequencer
                    {
                        Items = new List<APLAComponent>{
                            new Silence{Duration = 3000},
                            lyrics
                        }
                    }
                }
            })
    };

Creating a Layout Document from scratch

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"});

Data Binding / Expressions

If the component property is of type APLValue<T> that means you can data bind to it or use an expression instead For example

  component.When = APLValue.To<bool?>("${@viewportProfile == @hubLandscapeSmall}");

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 Directive

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
    }
});

Enabling an APL Extension

var doc = new APLDocument(APLDocumentVersion.V1_4);
var backstack = new BackstackExtension("Back");

doc.Extensions.Value.Add(backstack);
doc.Settings = new APLDocumentSettings(); 
doc.Settings.Add(backstack.Name, new BackStackSettings{BackstackId = "myDocument"});

var goback = GoBackCommand.For(backstack);

Check for extension support

//Use APLSkillRequest, not SkillRequest
skillRequest.Context.Extensions.Available.Contains(SmartMotionExtension.URL)

Add extension event handler

var doc = new APLDocument();
var smartMotion = new SmartMotionExtension("SmartMotion");
smartMotion.OnDeviceStateChanged(doc, listOfCommands);

Use SmartMotion Extension to move Echo Show

    var response = ResponseBuilder.Tell("Just an example");

    var ext = new SmartMotionExtension("SmartMotion");
    var doc = new APLDocument(APLDocumentVersion.V1_6) {Extensions = {Value = new List<APLExtension> {ext}}};
    //... add document components here...
    var token = Guid.NewGuid().ToString("N");

    response.Response.Directives.Add(new RenderDocumentDirective(doc){Token = token});
    response.Response.Directives.Add(
	new ExecuteCommandsDirective(token,
	PlayNamedChoreoCommand.For(ext, "ClockwiseMediumSweep")
	));
    return response;
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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 Downloads Last updated
8.4.0 1,227 4/4/2024
8.3.0 6,697 1/14/2024
8.2.0 23,662 8/24/2023
8.1.0 3,714 5/29/2023
8.0.0 186 5/27/2023
7.6.3 2,267 2/8/2023
7.6.2 1,864 10/22/2022
7.6.1 806 8/15/2022
7.6.0 4,546 6/9/2022
7.5.0 2,126 12/16/2021
7.4.0 1,397 10/1/2021
7.3.0 1,077 7/21/2021
7.2.0 18,434 4/3/2021
7.1.0 709 2/17/2021
7.0.0 5,561 11/20/2020
6.1.0 1,177 9/26/2020
6.0.4 1,527 7/24/2020
6.0.3 610 7/23/2020
6.0.2 597 7/23/2020
5.1.1 3,251 3/31/2020
5.1.0 572 3/26/2020
5.0.0 601 3/26/2020
4.9.1 552 3/17/2020
4.9.0 814 1/6/2020
4.8.1 587 12/19/2019
4.8.0 610 12/5/2019
4.7.0 671 11/26/2019
4.6.0 959 11/7/2019
4.5.1 627 11/1/2019
4.4.2 605 10/30/2019
4.4.1 596 10/30/2019
4.4.0 600 10/25/2019
4.3.1 561 10/24/2019
4.3.0 585 10/24/2019
4.2.3 667 9/10/2019
4.2.1 582 9/10/2019
4.2.0 2,898 8/9/2019
4.1.2 656 8/8/2019
4.1.1 661 8/8/2019
4.1.0 695 8/7/2019
4.0.13 741 7/28/2019
4.0.12 678 7/28/2019
4.0.11 729 7/15/2019
4.0.10 709 7/14/2019
4.0.9 649 7/14/2019
4.0.8 644 7/14/2019
4.0.7 704 7/14/2019
4.0.6 712 7/11/2019
4.0.5 705 7/10/2019
4.0.4 697 7/10/2019
4.0.2 698 7/10/2019
4.0.1 708 7/7/2019
4.0.0 646 7/6/2019
3.15.0 735 5/15/2019
3.14.0 705 5/9/2019
3.13.0 689 5/5/2019
3.12.0 686 5/4/2019
3.11.0 1,247 3/27/2019
3.10.0 670 3/27/2019
3.9.0 647 3/18/2019
3.8.0 771 3/4/2019
3.7.0 724 3/3/2019
3.6.3 796 1/31/2019
3.6.2 815 1/23/2019
3.6.1 1,399 1/14/2019
3.5.0 820 1/14/2019
3.4.0 846 1/9/2019
3.3.0 784 1/9/2019
3.1.0 819 12/26/2018
3.0.0 749 12/25/2018
2.1.0 766 12/25/2018
2.0.0 896 12/13/2018
1.6.4 798 12/7/2018
1.6.3 1,111 11/11/2018
1.6.1 880 11/11/2018
1.6.0 790 11/11/2018
1.5.0 868 11/6/2018
1.4.3 847 11/6/2018
1.4.2 793 11/6/2018
1.4.1 800 11/6/2018
1.4.0 814 11/5/2018
1.3.2 881 11/5/2018
1.2.2 839 11/5/2018
1.2.1 870 11/5/2018
1.2.0 859 11/5/2018
1.1.0 837 11/4/2018
1.0.0 764 11/2/2018

APL v1.6 support