Alexa.NET.Annotations 1.0.0-beta2

This is a prerelease version of Alexa.NET.Annotations.
dotnet add package Alexa.NET.Annotations --version 1.0.0-beta2
NuGet\Install-Package Alexa.NET.Annotations -Version 1.0.0-beta2
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.Annotations" Version="1.0.0-beta2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Alexa.NET.Annotations --version 1.0.0-beta2
#r "nuget: Alexa.NET.Annotations, 1.0.0-beta2"
#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.Annotations as a Cake Addin
#addin nuget:?package=Alexa.NET.Annotations&version=1.0.0-beta2&prerelease

// Install Alexa.NET.Annotations as a Cake Tool
#tool nuget:?package=Alexa.NET.Annotations&version=1.0.0-beta2&prerelease

Alexa.NET.Annotations

Library to help make writing your first Alexa skill smaller and easier

Creating an Alexa Skill

To create a skill, add Alexa.NET.Annotations as a NuGet reference and then you can tag a class with the AlexaSkill attribute. The big requirement is that the class has to be partial as the generator adds code to your class behind the scenes.

using Alexa.NET;
using Alexa.NET.Annotations.Markers;
using Alexa.NET.Request.Type;
using Alexa.NET.Response;

[AlexaSkill]
public partial class RockPaperScissors
{
    [Launch]
    public SkillResponse Launch(LaunchRequest intent)
    {
        return ResponseBuilder.Ask("What's your move? Rock, Paper or scissors?", new("What's your move?"));
    }

    [Intent("MakeMyMove")]
    public async Task<SkillResponse> PlayAGame(IntentRequest intentRequest)
    {
        return ResponseBuilder.Tell("You Win", null);
    }

    [Intent(BuiltInIntent.Help)]
    public SkillResponse Help(IntentRequest _) => ResponseBuilder.Empty();
}

These attributes add an Execute method to your class, which has this signature, and can be called by your code.

public virtual Task<SkillResponse> Execute(SkillRequest skillRequest, object context = null);

Attributes

There are several attributes available right now. The method name you attach these two doesn't matter and can be called anything, they're just examples.

Launch

The launch attribute is for when your skill starts.

Return Type must be either SkillResponse or Task<SkillResponse>

public SkillResponse Launch();
public Task<SkillResponse> Launch(LaunchRequest intent);

Intent(IntentName)

The intent attribute wires up to a specific intent, named in the attribute argument. If the signature contains string or Slot parameters, they are mapped to intent slots.

Return Type must be either SkillResponse or Task<SkillResponse>

Example signatures

[Intent("Test")]
public async Task<SkillResponse> Intent(IntentRequest intentRequest);

[Intent("Test2")]
public SkillResponse Intent(IntentRequest intentRequest);

[Intent("Test3")]
public SkillResponse Intent(string slotOne, Slot slotTwo);

BeforeResponse/AfterResponse

These two attributes are used to run common functionality you want to run before or after the handlers are run to generate the response.

Their return type can be either void, SkillResponse' or 'Task<SkillResponse>

AfterResponse also has access to the SkillResponse that is going to be returned as an optional argument

Examples


[BeforeResponse]
public void LogBefore() {
    Logger.Information("running before the response is generated")
}

[AfterResponse]
public SkillResponse LogAfter(SkillResponse response) {
    return response;
}

Wiring up an AWS Lambda

If you plan to use an AWS Lambda project with the .NET 6 runtime, Alexa.NET.Annotations has an extra attribute you can place at the class level which will wire up the AWS Lambda straight to your skill.

[AlexaSkill]
[AlexaLambda]
public partial class RockPaperScissors
{
    ...

There are two requirements to make this work

This will generate a Program class and Main method straight to your skill pipeline. The ILambdaContext object passed into your lambda will automatically be wired up as the context parameter in your Execute method.

To make this work - when you push your code to AWS Lambda, where you'd normally reference the handler in a format of [AssemblyName]::[Type]::[Method] you just put [AssemblyName]]

Here's an example of this using the AWS Lambda Upload screen in Visual Studio

AWS Lambda upload screen in visual studio showing the assembly handler attribute

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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0-beta2 141 9/13/2022
1.0.0-beta1 100 9/9/2022
1.0.0-alpha9 89 9/6/2022
1.0.0-alpha7 99 8/22/2022
1.0.0-alpha6 100 8/13/2022
1.0.0-alpha5 93 8/12/2022
1.0.0-alpha4 91 8/12/2022
1.0.0-alpha3 97 8/12/2022
1.0.0-alpha2 93 8/11/2022
1.0.0-alpha1 103 8/10/2022

Support for pipeline context object