Whetstone.Alexa 0.1.1

Additional Details

This package is no longer supported.

There is a newer version of this package available.
See the version list below for details.
dotnet add package Whetstone.Alexa --version 0.1.1                
NuGet\Install-Package Whetstone.Alexa -Version 0.1.1                
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="Whetstone.Alexa" Version="0.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Whetstone.Alexa --version 0.1.1                
#r "nuget: Whetstone.Alexa, 0.1.1"                
#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 Whetstone.Alexa as a Cake Addin
#addin nuget:?package=Whetstone.Alexa&version=0.1.1

// Install Whetstone.Alexa as a Cake Tool
#tool nuget:?package=Whetstone.Alexa&version=0.1.1                

Processing Requests and Responses

The Whetstone.Alexa Nuget package includes classes for serialization and deserializing common requests and responses passed to and from Alexa Skills. The same structures apply irrespective of whether the client service is deployed as a web API or a Lambda Function.

Web Api Sample

using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Whetstone.Alexa;
. . .

namespace Whetstone.Alexa.EmailChecker.WebApi.Controllers
{
    [Produces("application/json")]
    [Route("api/alexa")]
    public class AlexaController : Controller
    {       
        [HttpPost]
        public async Task<ActionResult> ProcessAlexaRequest([FromBody] AlexaRequest request)
        {
           AlexaResponse resp = await _emailProcessor.ProcessEmailRequestAsync(request);
           return Ok(resp);
        }

Lambda Function Sample

using Amazon.Lambda.Core;
using Whetstone.Alexa
. . .

// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]

namespace Whetstone.Alexa.EmailChecker.Lambda
{
   public class Function
   {

       public async Task<AlexaResponse> FunctionHandlerAsync(AlexaRequest request, ILambdaContext context)
       {
           var emailProcessor = _serviceProvider.Value.GetRequiredService<IEmailProcessor>();
           return await emailProcessor.ProcessEmailRequestAsync(request);     
       }

<br/>

Processing the AlexaRequest

The most useful values on the AlexaRequest is the request type,
intent, and slot values.

Get the request type:

RequestType reqType = request.Request.Type;

Get the name of the intent:

string intent = request.Request.Intent.Name;

Get a slot value from the intent:

string selectedCity = request.Request.Intent.GetSlotValue("city"); 

Create a Response

Alexa can speak a plain text response to the user or process Speech Synthesis Markup Language (SSML). SSML include speech directives to tell change the volume of Alexa's voice, speed up or slow the response, and play MP3 files. The total time to provide the response the user cannot exceed 90 seconds. If the user does not respond, Alexa uses a reprompt to elicit a response from the user. Optionally, a card response can send plain text along with small images. Card responses appear in the user's Alexa mobile application and on alexa.amazon.com.

The following sample sends a plain text response, a reprompt, and a standard card response.

string textResp = "You are following a path in forest and have come to a fork. Would you like to go left or right?";
AlexaResponse resp = new AlexaResponse
{
    Version = "1.0",
    Response = new AlexaResponseAttributes
    {
        OutputSpeech = OutputSpeechBuilder.GetPlainTextSpeech(textResp),
        Card = CardBuilder.GetSimpleCardResponse("Fork in the Road", textResp),
        Reprompt = new RepromptAttributes
        {
            OutputSpeech = OutputSpeechBuilder.GetPlainTextSpeech("Left or right?"),
        },
        ShouldEndSession = false
    },
};

To include an image in the card response, provide a publicly accessible URL for both a small image (720w x 480h) and large image (1200w x 800h). For more information, please see Create a Home Card to Display Text and an Image.

   . . .
        Card = CardBuilder.GetStandardCardResponse("Fork in the Road",
                textResponse,
                "https://dev-customapp.s3.amazonaws.com/adventuregame/images/forkintheroad_720x800.png",
                "https://dev-customapp.s3.amazonaws.com/adventuregame/images/forkintheroad_1200x800.png"
                ),
   . . .
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 netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.3 is compatible.  netstandard1.4 was computed.  netstandard1.5 was computed.  netstandard1.6 is compatible.  netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 is compatible.  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 tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Universal Windows Platform uap was computed.  uap10.0 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.

Updated the Alexa Response to support custom session attributes.