AlexaVoxCraft.Lambda 5.0.1.100

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package AlexaVoxCraft.Lambda --version 5.0.1.100
                    
NuGet\Install-Package AlexaVoxCraft.Lambda -Version 5.0.1.100
                    
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="AlexaVoxCraft.Lambda" Version="5.0.1.100" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AlexaVoxCraft.Lambda" Version="5.0.1.100" />
                    
Directory.Packages.props
<PackageReference Include="AlexaVoxCraft.Lambda" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AlexaVoxCraft.Lambda --version 5.0.1.100
                    
#r "nuget: AlexaVoxCraft.Lambda, 5.0.1.100"
                    
#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.
#:package AlexaVoxCraft.Lambda@5.0.1.100
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AlexaVoxCraft.Lambda&version=5.0.1.100
                    
Install as a Cake Addin
#tool nuget:?package=AlexaVoxCraft.Lambda&version=5.0.1.100
                    
Install as a Cake Tool

๐Ÿ”ฃ AlexaVoxCraft

AlexaVoxCraft is a modular C# .NET library for building Amazon Alexa skills using modern .NET practices. It provides comprehensive support for Alexa skill development with CQRS patterns, visual interfaces, and AWS Lambda hosting.

Key Features

  • ๐ŸŽฏ MediatR Integration: CQRS-style request handling with compile-time source-generated DI registration
  • ๐ŸŽจ APL Support: Complete Alexa Presentation Language implementation for rich visual interfaces
  • โšก Lambda Hosting: Optimized AWS Lambda runtime with custom serialization and ReadyToRun publishing
  • ๐Ÿ“Š Session Management: Robust session attribute handling and game state persistence
  • ๐Ÿ”ง Pipeline Behaviors: Request/response interceptors for cross-cutting concerns like logging and validation
  • ๐Ÿงช Testing Support: Comprehensive testing utilities with AutoFixture integration and property-based testing

๐Ÿ“ฆ Packages

Package NuGet Downloads
AlexaVoxCraft.Model NuGet Downloads
AlexaVoxCraft.Model.Apl NuGet Downloads
AlexaVoxCraft.MediatR NuGet Downloads
AlexaVoxCraft.Lambda NuGet Downloads
AlexaVoxCraft.Lambda.Host NuGet Downloads
AlexaVoxCraft.MediatR.Lambda NuGet Downloads
AlexaVoxCraft.Observability NuGet Downloads
AlexaVoxCraft.Smapi NuGet Downloads

Build Status

๐Ÿš€ Quick Start

Install Core Packages

# Core MediatR integration and Lambda hosting
dotnet add package AlexaVoxCraft.MediatR.Lambda

# APL visual interface support (optional)
dotnet add package AlexaVoxCraft.Model.Apl

# OpenTelemetry observability (optional)
dotnet add package AlexaVoxCraft.Observability

# CloudWatch-compatible JSON logging (optional)
dotnet add package LayeredCraft.Logging.CompactJsonFormatter

Requirements

โš ๏ธ SDK Version Required: To use source-generated dependency injection with interceptors, you must use at least version 8.0.400 of the .NET SDK. This ships with Visual Studio 2022 version 17.11 or higher.

# Check your SDK version
dotnet --version
# Should show 8.0.400 or higher

Create a Basic Skill

// Program.cs
using AlexaVoxCraft.MediatR.Lambda;
using AlexaVoxCraft.Model.Response;

return await LambdaHostExtensions.RunAlexaSkill<MySkillFunction, SkillRequest, SkillResponse>();

// Function.cs
public class MySkillFunction : AlexaSkillFunction<SkillRequest, SkillResponse>
{
    protected override void Init(IHostBuilder builder)
    {
        builder
            .UseHandler<LambdaHandler, SkillRequest, SkillResponse>()
            .ConfigureServices((context, services) =>
            {
                // Handlers are automatically discovered and registered at compile time
                services.AddSkillMediator(context.Configuration);
            });
    }
}

// Handler.cs
public class LaunchRequestHandler : IRequestHandler<LaunchRequest>
{
    public bool CanHandle(IHandlerInput handlerInput) =>
        handlerInput.RequestEnvelope.Request is LaunchRequest;

    public async Task<SkillResponse> Handle(IHandlerInput input, CancellationToken cancellationToken)
    {
        return await input.ResponseBuilder
            .Speak("Welcome to my skill!")
            .Reprompt("What would you like to do?")
            .GetResponse(cancellationToken);
    }
}

๐Ÿ“– Documentation

๐Ÿ“š Complete Documentation - Comprehensive guides and examples

Core Components

Examples

๐Ÿ“ Project Structure

AlexaVoxCraft/
โ”œโ”€โ”€ ๐Ÿ“‚ src/                                    # Core library packages
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ฆ AlexaVoxCraft.Model/                # Base Alexa skill models & serialization
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ฆ AlexaVoxCraft.Model.Apl/            # APL (Alexa Presentation Language) support
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ฆ AlexaVoxCraft.MediatR/              # MediatR integration & request handling
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ฆ AlexaVoxCraft.MediatR.Generators/   # Source generator for compile-time DI
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ฆ AlexaVoxCraft.Lambda/               # Core Lambda abstractions & serialization
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ฆ AlexaVoxCraft.Lambda.Host/          # Modern minimal API-style Lambda hosting
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ฆ AlexaVoxCraft.MediatR.Lambda/       # Legacy Lambda hosting (AlexaSkillFunction)
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ฆ AlexaVoxCraft.Observability/        # OpenTelemetry instrumentation & telemetry
โ”‚   โ””โ”€โ”€ ๐Ÿ“ฆ AlexaVoxCraft.Smapi/                # Skill Management API (SMAPI) client
โ”‚
โ”œโ”€โ”€ ๐Ÿ“‚ samples/                                # Working example projects
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ฑ Sample.Skill.Function/              # Basic skill (legacy hosting)
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ฑ Sample.Host.Function/               # Modern minimal API hosting
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ฑ Sample.Generated.Function/          # Source-generated DI demonstration
โ”‚   โ””โ”€โ”€ ๐Ÿ“ฑ Sample.Apl.Function/                # APL skill with visual interfaces
โ”‚
โ”œโ”€โ”€ ๐Ÿ“‚ test/                                   # Comprehensive test coverage
โ”‚   โ”œโ”€โ”€ ๐Ÿงช AlexaVoxCraft.Model.Tests/          # Core model & serialization tests
โ”‚   โ”œโ”€โ”€ ๐Ÿงช AlexaVoxCraft.Model.Apl.Tests/      # APL functionality tests
โ”‚   โ”œโ”€โ”€ ๐Ÿงช AlexaVoxCraft.MediatR.Tests/        # MediatR integration tests
โ”‚   โ”œโ”€โ”€ ๐Ÿงช AlexaVoxCraft.MediatR.Lambda.Tests/ # Lambda hosting tests
โ”‚   โ””โ”€โ”€ ๐Ÿงช AlexaVoxCraft.Smapi.Tests/          # SMAPI client tests
โ”‚
โ”œโ”€โ”€ ๐Ÿ“‚ AlexaVoxCraft.TestKit/                  # Testing utilities & AutoFixture support
โ””โ”€โ”€ ๐Ÿ“‚ docs/                                   # Documentation source

๐Ÿ›  Core Concepts

Request Handling Pattern

Skills use the MediatR pattern where:

  1. Requests implement IRequestHandler<T>
  2. Handlers optionally implement ICanHandle for routing logic
  3. Pipeline behaviors handle cross-cutting concerns (logging, exceptions)
  4. Lambda functions derive from AlexaSkillFunction<TRequest, TResponse>

Package Breakdown

Package Purpose Key Features
AlexaVoxCraft.Model Core Alexa models Request/response types, SSML, cards, directives, System.Text.Json serialization
AlexaVoxCraft.Model.Apl APL support 40+ components, commands, audio, vector graphics, extensions (DataStore, SmartMotion)
AlexaVoxCraft.MediatR Request handling Handler routing, pipeline behaviors, attributes management, DI integration
AlexaVoxCraft.MediatR.Lambda Lambda hosting AWS Lambda functions, context management, custom serialization, hosting extensions
AlexaVoxCraft.Observability OpenTelemetry integration Opt-in telemetry, metrics, spans, semantic attributes, ADOT/CloudWatch support

๐Ÿงช Testing

AlexaVoxCraft includes comprehensive testing support:

  • xUnit v3 with Microsoft.Testing.Platform
  • AutoFixture integration for property-based testing
  • AwesomeAssertions for fluent assertions
  • TestKit with specimen builders and test utilities

โš ๏ธ Error Handling

Implement the IExceptionHandler interface for centralized error handling:

public class GlobalExceptionHandler : IExceptionHandler
{
    public Task<bool> CanHandle(IHandlerInput handlerInput, Exception ex, CancellationToken cancellationToken)
    {
        return Task.FromResult(true); // Handle all exceptions
    }

    public Task<SkillResponse> Handle(IHandlerInput handlerInput, Exception ex, CancellationToken cancellationToken)
    {
        return handlerInput.ResponseBuilder
            .Speak("Sorry, something went wrong. Please try again.")
            .GetResponse(cancellationToken);
    }
}

๐Ÿ“‹ Version 4.0.0+ Breaking Changes

Cancellation Token Support

Version 4.0.0 introduces cancellation token support for Lambda functions. This is a breaking change that requires updates to your existing lambda handlers.

Required Changes

1. Update Lambda Handlers

Lambda handlers must now accept and pass the cancellation token:

// โŒ Before (v3.x)
public class LambdaHandler : ILambdaHandler<SkillRequest, SkillResponse>
{
    public async Task<SkillResponse> HandleAsync(SkillRequest input, ILambdaContext context)
    {
        return await _skillMediator.Send(input);
    }
}

// โœ… After (v4.0+)
public class LambdaHandler : ILambdaHandler<SkillRequest, SkillResponse>
{
    public async Task<SkillResponse> HandleAsync(SkillRequest input, ILambdaContext context, CancellationToken cancellationToken)
    {
        return await _skillMediator.Send(input, cancellationToken);
    }
}

2. Update AlexaSkillFunction Override

If you override FunctionHandlerAsync in your skill function class, you must update the signature:

// โŒ Before (v3.x)
public class MySkillFunction : AlexaSkillFunction<SkillRequest, SkillResponse>
{
    public override async Task<SkillResponse> FunctionHandlerAsync(SkillRequest input, ILambdaContext context)
    {
        // Custom logic here
        return await base.FunctionHandlerAsync(input, context);
    }
}

// โœ… After (v4.0+)
public class MySkillFunction : AlexaSkillFunction<SkillRequest, SkillResponse>
{
    public override async Task<SkillResponse> FunctionHandlerAsync(SkillRequest input, ILambdaContext context, CancellationToken cancellationToken)
    {
        // Custom logic here
        return await base.FunctionHandlerAsync(input, context, cancellationToken);
    }
}
Configuration Options

You can now configure the cancellation timeout buffer in your appsettings.json:

{
  "SkillConfiguration": {
    "SkillId": "amzn1.ask.skill.your-skill-id",
    "CancellationTimeoutBufferMilliseconds": 500
  }
}

The timeout buffer (default: 250ms) is subtracted from Lambda's remaining execution time to allow graceful shutdown and telemetry flushing.

๐Ÿ“‹ Version 5.0.0+ Breaking Changes

Overview

Version 5.0.0 introduces a modern minimal API-style hosting model powered by the AwsLambda.Host package. This update also restructures the package architecture to better separate concerns and provide more flexibility. The legacy hosting approach remains fully supported for backward compatibility.

Package Restructuring

Version 5.0.0 introduces two new packages and refactors the existing Lambda hosting:

Package Purpose Status
AlexaVoxCraft.Lambda Core Lambda abstractions and serialization New (extracted from MediatR.Lambda)
AlexaVoxCraft.Lambda.Host Modern minimal API-style Lambda hosting New (recommended for new projects)
AlexaVoxCraft.MediatR.Lambda Legacy Lambda hosting with AlexaSkillFunction Existing (still fully supported)

Namespace Changes

Core Lambda abstractions have been moved to the new AlexaVoxCraft.Lambda package:

Classes Moved:

  • ILambdaHandler<TRequest, TResponse>
  • HandlerDelegate<TRequest, TResponse>
  • AlexaLambdaSerializer
  • SystemTextDestructuringPolicy

Removed Obsolete Classes

The following obsolete class has been removed:

PollyVoices - This class was marked as obsolete in previous versions and has been removed. Use the AlexaSupportedVoices class instead for Amazon Polly voice name constants.

Before (v4.x):

using AlexaVoxCraft.MediatR.Lambda.Abstractions;
using AlexaVoxCraft.MediatR.Lambda.Serialization;

public class LambdaHandler : ILambdaHandler<SkillRequest, SkillResponse>
{
    // Implementation
}

After (v5.0+):

using AlexaVoxCraft.Lambda.Abstractions;
using AlexaVoxCraft.Lambda.Serialization;

public class LambdaHandler : ILambdaHandler<SkillRequest, SkillResponse>
{
    // Implementation
}

Two Hosting Approaches

Version 5.0.0 provides two ways to host Alexa skills in AWS Lambda:

Use AlexaVoxCraft.Lambda.Host for a familiar minimal API-style hosting experience:

dotnet add package AlexaVoxCraft.Lambda.Host
// Program.cs
using AlexaVoxCraft.Lambda.Host;
using AlexaVoxCraft.Lambda.Host.Extensions;
using AwsLambda.Host.Builder;

var builder = LambdaApplication.CreateBuilder();

builder.Services.AddSerilog(/* ... */);
builder.Services.AddSkillMediator(builder.Configuration);
builder.Services.AddAlexaSkillHost<LambdaHandler, SkillRequest, SkillResponse>();

await using var app = builder.Build();
app.MapHandler(AlexaHandler.Invoke<SkillRequest, SkillResponse>);
await app.RunAsync();

Benefits:

  • Familiar minimal API-style builder pattern (similar to ASP.NET Core)
  • Uses industry-standard AwsLambda.Host package
  • More flexible service configuration
  • Better separation of concerns

Project Configuration:

<PropertyGroup>
  <InterceptorsNamespaces>$(InterceptorsNamespaces);AwsLambda.Host.Core.Generated</InterceptorsNamespaces>
</PropertyGroup>
Legacy Approach (Existing Projects)

Continue using AlexaVoxCraft.MediatR.Lambda with the AlexaSkillFunction pattern:

dotnet add package AlexaVoxCraft.MediatR.Lambda
// Program.cs
using AlexaVoxCraft.MediatR.Lambda;

return await LambdaHostExtensions.RunAlexaSkill<MySkillFunction, SkillRequest, SkillResponse>();

// Function.cs
public class MySkillFunction : AlexaSkillFunction<SkillRequest, SkillResponse>
{
    protected override void Init(IHostBuilder builder)
    {
        builder
            .UseHandler<LambdaHandler, SkillRequest, SkillResponse>()
            .ConfigureServices((context, services) =>
            {
                services.AddSkillMediator(context.Configuration);
            });
    }
}

This approach remains fully supported and requires no migration for existing projects.

Migration Impact

Who is affected:

  • Projects directly referencing AlexaVoxCraft.MediatR.Lambda.Abstractions namespace
  • Projects directly referencing AlexaVoxCraft.MediatR.Lambda.Serialization namespace
  • Projects wanting to adopt the modern hosting approach

Who is NOT affected:

  • Projects using AlexaSkillFunction<TRequest, TResponse> without directly referencing moved classes
  • Projects that don't import the moved namespaces

Required Actions for Migration

1. Update Namespace Imports

If you directly reference the moved classes, update your using statements:

// Change this:
using AlexaVoxCraft.MediatR.Lambda.Abstractions;
using AlexaVoxCraft.MediatR.Lambda.Serialization;

// To this:
using AlexaVoxCraft.Lambda.Abstractions;
using AlexaVoxCraft.Lambda.Serialization;
2. (Optional) Migrate to Modern Hosting

To adopt the new minimal API-style hosting:

  1. Replace package reference:

    dotnet remove package AlexaVoxCraft.MediatR.Lambda
    dotnet add package AlexaVoxCraft.Lambda.Host
    
  2. Update project file to include interceptors:

    <InterceptorsNamespaces>$(InterceptorsNamespaces);AwsLambda.Host.Core.Generated</InterceptorsNamespaces>
    
  3. Refactor Program.cs to use builder pattern (see example above)

  4. Remove Function class inheriting from AlexaSkillFunction

For detailed migration guidance, see the Lambda Hosting documentation.

๐Ÿค Contributing

PRs are welcome! Please submit issues and ideas to help make this toolkit even better.

๐Ÿ“œ Credits & Attribution

๐Ÿ“ฆ Credits:

๐Ÿ“œ License

This project is licensed under the MIT License.

Stargazers over time

Stargazers over time

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on AlexaVoxCraft.Lambda:

Package Downloads
AlexaVoxCraft.MediatR.Lambda

Lambda hosting and middleware integration for Alexa skills using MediatR and AlexaVoxCraft.

AlexaVoxCraft.Lambda.Host

Lambda hosting and middleware integration for Alexa skills using MediatR and AlexaVoxCraft.

AlexaVoxCraft.MinimalLambda

Minimal API-style Lambda hosting for AlexaVoxCraft skills powered by MinimalLambda.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
5.1.0-beta.101 57 12/12/2025
5.0.1.100 374 12/10/2025
5.0.0.99 755 12/1/2025
5.0.0.98 682 12/1/2025
5.0.0-beta.97 628 12/1/2025
5.0.0-beta.96 611 12/1/2025
5.0.0-beta.95 514 12/1/2025
5.0.0-beta.94 508 12/1/2025
5.0.0-beta.93 509 12/1/2025
5.0.0-beta.92 292 11/30/2025
5.0.0-beta.91 40 11/29/2025