AlexaVoxCraft.Logging
1.0.1.54
dotnet add package AlexaVoxCraft.Logging --version 1.0.1.54
NuGet\Install-Package AlexaVoxCraft.Logging -Version 1.0.1.54
<PackageReference Include="AlexaVoxCraft.Logging" Version="1.0.1.54" />
<PackageVersion Include="AlexaVoxCraft.Logging" Version="1.0.1.54" />
<PackageReference Include="AlexaVoxCraft.Logging" />
paket add AlexaVoxCraft.Logging --version 1.0.1.54
#r "nuget: AlexaVoxCraft.Logging, 1.0.1.54"
#addin nuget:?package=AlexaVoxCraft.Logging&version=1.0.1.54
#tool nuget:?package=AlexaVoxCraft.Logging&version=1.0.1.54
๐ฃ Alexa Vox Craft
Alexa Vox Craft is a modular, opinionated library for building Alexa skills in C# using .NET. It leverages System.Text.Json
, MediatR patterns, and extensible components for building and maintaining robust Alexa skills with support for:
- โ Clean separation of concerns using MediatR
- โ
JSON (de)serialization with full control via
System.Text.Json
- โ APL (Alexa Presentation Language) model support and utilities
- โ Custom converters for object, enum, and polymorphic types
- โ Lambda-ready with logging, tracing, and testability in mind
What does "AlexaVoxCraft" mean?
- Alexa: Represents the integration with Amazon Alexa, the voice service powering devices like Amazon Echo.
- VoxCraft: Signifies the focus on voice-driven interactions, leveraging the VoxCraft framework.
๐ฆ Credits:
- The core Alexa skill models (
AlexaVoxCraft.Model
) are based on the excellent work in timheuer/alexa-skills-dotnet.- APL support (
AlexaVoxCraft.Model.Apl
) is based on stoiveyp/Alexa.NET.APL.
๐๏ธ Packages
Package | Build Status | NuGet | GitHub | Downloads |
---|---|---|---|---|
AlexaVoxCraft.Model | ๐ Source | |||
AlexaVoxCraft.Model.Apl | ๐ Source | |||
AlexaVoxCraft.MediatR.Lambda | ๐ Source | |||
AlexaVoxCraft.MediatR | ๐ Source | |||
AlexaVoxCraft.Logging | ๐ Source |
๐ Getting Started
1. Install Required Packages
Install only the packages you need! If you're not using MediatR or APL features, you can omit those dependencies.
dotnet add package AlexaVoxCraft.Model
# Optional:
dotnet add package AlexaVoxCraft.MediatR.Lambda
2. Create a Lambda Entry Point
await LambdaHostExtensions.RunAlexaSkill<YourAlexaSkillFunction>();
3. Create Your Function Class
public sealed class YourAlexaSkillFunction : AlexaSkillFunction<SkillRequest, SkillResponse>
{
protected override void Init(IHostBuilder builder)
{
builder
.UseHandler<LambdaHandler, SkillRequest, SkillResponse>()
.ConfigureServices((context, services) =>
{
services.AddSkillMediator(context.Configuration,
cfg => { cfg.RegisterServicesFromAssemblyContaining<Program>(); });
});
}
}
4. Handle Requests with MediatR
Handlers in AlexaVoxCraft are expected to implement IRequestHandler<T>
and optionally implement ICanHandle
to provide routing logic.
public sealed class LaunchRequestHandler : IRequestHandler<LaunchRequest>
{
public bool CanHandle(IHandlerInput handlerInput) =>
handlerInput.RequestEnvelope.Request is LaunchRequest;
public async Task<SkillResponse> Handle(IHandlerInput input, CancellationToken cancellationToken = default)
{
return await input.ResponseBuilder.Speak("Hello world!").WithShouldEndSession(true)
.GetResponse(cancellationToken);
}
}
๐ Logging & Diagnostics
AlexaVoxCraft uses Serilog for structured logging by default. You can configure logging output by adding the following to your appsettings.json
:
"Serilog": {
"Using": [ "Serilog.Sinks.Console" ],
"WriteTo": [
{
"Name": "Console",
"Args": {
"formatter": "AlexaVoxCraft.Logging.Serialization.AlexaCompactJsonFormatter, AlexaVoxCraft.Logging"
}
}
],
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"Microsoft.AspNetCore": "Warning"
}
}
}
โน๏ธ Debugging Tip: To enable logging of raw Alexa skill requests and responses during development, add the following line under
Override
. This is not recommended for production environments."AlexaVoxCraft.MediatR.Lambda.Serialization": "Debug"
๐งพ Formatter Attribution
๐ง The
AlexaCompactJsonFormatter
included in this library is adapted fromSerilog.Formatting.Compact.CompactJsonFormatter
.
This customized formatter renames reserved field names (e.g.,@t
,@l
,@m
) to AWS-safe equivalents (_t
,_l
,_m
) to improve compatibility with CloudWatch Logs and metric filters.Original work ยฉ Serilog Contributors, licensed under the MIT License.
๐งช Unit Testing
Sample projects show how to load Alexa requests from JSON and assert deserialized structure. Tests include validation of:
- Correct parsing of SkillRequest types
- APL component deserialization
- Proper usage of custom converters
๐ Utilities and Helpers
EnumHelper
: Convert to/from[EnumMember]
-decorated enumsObjectConverter
: Deserialize polymorphic object valuesBasePolymorphicConverter<T>
: Handle APL and directive subtypesAlexaLambdaSerializer
: CustomILambdaSerializer
with logging support
โ ๏ธ Error Handling
To intercept and respond to exceptions in your MediatR pipeline, implement the IExceptionHandler
interface:
public sealed class MyExceptionHandler : IExceptionHandler
{
public Task<bool> CanHandle(IHandlerInput handlerInput, Exception ex, CancellationToken cancellationToken = default)
{
return Task.FromResult(true); // Catch all
}
public Task<SkillResponse> Handle(IHandlerInput handlerInput, Exception ex, CancellationToken cancellationToken = default)
{
var response = handlerInput.ResponseBuilder.Speak("Something went wrong. Please try again.");
return response.GetResponse(cancellationToken);
}
}
No manual registration is required. Exception handlers are picked up automatically via AddSkillMediator(...)
.
๐ Sample Projects
Sample Project | Description |
---|---|
Sample.Skill.Function |
A minimal Alexa skill using this library |
Sample.Apl.Function |
A sample APL skill to demonstrate working with APL |
Each sample demonstrates MediatR integration, serialization support, custom directives, and Lambda bootstrapping.
๐คญ Roadmap
- โ Full widget lifecycle support
- โ Advanced directive handling
- โ๏ธ OpenTelemetry & logging enrichment
- ๐ Documentation site
๐ค Contributing
PRs are welcome! Please submit issues and ideas to help make this toolkit even better.
Contributors โจ
Thanks goes to these wonderful people (emoji key):
<table> <tbody> <tr> <td align="center" valign="top" width="14.28%"><a href="https://github.com/LayeredCraft"><img src="https://avatars.githubusercontent.com/u/1405469?v=4?s=100" width="100px;" alt="Nick Cipollina"/><br /><sub><b>Nick Cipollina</b></sub></a><br /><a href="#content-LayeredCraft" title="Content">๐</a></td> </tr> </tbody> </table>
This project follows the all-contributors specification. Contributions of any kind welcome!
๐ License
MIT
This project is licensed under the MIT License. See the LICENSE file for details.
Stargazers over time
Product | Versions 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 was computed. 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. |
-
net8.0
- Amazon.Lambda.Core (>= 2.5.1)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.5)
- Serilog (>= 4.3.0)
- Serilog.Formatting.Compact (>= 3.0.0)
-
net9.0
- Amazon.Lambda.Core (>= 2.5.1)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.5)
- Serilog (>= 4.3.0)
- Serilog.Formatting.Compact (>= 3.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on AlexaVoxCraft.Logging:
Package | Downloads |
---|---|
AlexaVoxCraft.MediatR.Lambda
Lambda hosting and middleware integration for Alexa skills using MediatR and AlexaVoxCraft. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.1.54 | 158 | 5/21/2025 |
1.0.1.53 | 155 | 5/19/2025 |
1.0.1.50 | 254 | 5/13/2025 |
1.0.1.49 | 222 | 5/13/2025 |
1.0.1-beta.52 | 106 | 5/19/2025 |
1.0.1-beta.48 | 197 | 5/13/2025 |
1.0.1-beta.47 | 194 | 5/13/2025 |
1.0.1-beta.46 | 192 | 5/13/2025 |
1.0.1-beta.45 | 195 | 5/13/2025 |