Skip to content

A collection of classes annotated with JSON.NET to consume Amazon Alexa requests and build and serialize responses

Notifications You must be signed in to change notification settings

BLSully/CSharp-Alexa-Interface

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Summary

Collection of classes to make requests from and responses to Amazon's Alexa service easy. Uses JSON.NET for (de)serialization Request and Response bodies. It's pretty naive right now... no validation of constraints (e.g. response size limits in Cards, etc).

Methods

Request (from Alexa)

GetSessionAttribute(string key);

Response (to Alexa)

Following methods are chainable:

SetOutputSpeech(string speech, OutputSpeechType type);

SetCard(string title, string content, CardType type);

SetReprompt(string speech, OutputSpeechType type);

SetShouldEndSession(bool shouldEndSession);

AddSessionAttribute(string key, object attr);

Example

public ResponseBody AlexaEndpoint([FromBody]RequestBody body) {
    ResponseBody resp = new ResponseBody();
    
    switch(request.Request.Type) {
      case Request.RequestType.LaunchRequest:
        //todo: welcome message here
        break;
      case Request.RequestType.IntentRequest:
        IntentRequest intent = (IntentRequest)request.Request
        switch(intent.Intent.Name) {
          case "HelloWorldIntent":
            resp
                    .SetOutputSpeech("You invoked Hello World.", OutputSpeechType.PlainText)
                    .SetReprompt("Say another command.", OutputSpeechType.PlainText);
            break;
        }
        break;
      case Request.RequestType.SessionEndedRequest:
        break;
    }
  }

WebApiConfig

To configure JSON.NET to be able to deserialize IRequest interface, add this to App_Start/WebApiConfig.cs

config.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new AlexaInterface.JsonConverters.IRequestConverter());

About

A collection of classes annotated with JSON.NET to consume Amazon Alexa requests and build and serialize responses

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages