Categorygithub.com/ericdaugherty/alexa-skills-kit-golang
modulepackage
0.0.0-20200820151434-52c9a4ba7aae
Repository: https://github.com/ericdaugherty/alexa-skills-kit-golang.git
Documentation: pkg.go.dev

# README

ericdaugherty/alexa-skills-kit-golang

alexa-skills-kit-golang is a lightweight port of the Amazon alexa-skills-kit-java SDK and Samples.

License godoc

Usage

This explanation assumes familiarity with with AWS Documentation. Please review Developing an Alexa Skill as a Lambda Function before proceeding. This SDK addresses some of the steps documented here for you, but you should be familiar with the entire process.

The samples directory provides example usage.

The Alexa struct is the initial interface point with the SDK. Alexa must be initialized first. The struct is defined as:

type Alexa struct {
    ApplicationID       string
    RequestHandler      RequestHandler
    IgnoreApplicationID bool
    IgnoreTimestamp     bool
}

The ApplicationID must match the ApplicationID defined in the Alexa Skills

The RequestHandler is an interface that must be implemented, and is called to handle requests.

IgnoreApplicationID and IgnoreTimestamp should be used during debugging to test with hard-coded requests.

Requests from Alexa should be passed into the Alexa.ProcessRequest method.

func (alexa *Alexa) ProcessRequest(context context.Context, requestEnv *RequestEnvelope) (*ResponseEnvelope, error)

This method takes the incoming request and validates it, and the calls the appropriate callback methods on the RequestHandler interface implementation.

The ResponseEnvelope is returned and can be converted to JSON to be passed back to the Alexa skill.

RequestHandler interface is defined as:

type RequestHandler interface {
	OnSessionStarted(context.Context, *Request, *Session, *Context, *Response) error
	OnLaunch(context.Context, *Request, *Session, *Context, *Response) error
	OnIntent(context.Context, *Request, *Session, *Context, *Response) error
	OnSessionEnded(context.Context, *Request, *Session, *Context, *Response) error
}

For a summary of these methods, please see the Handling Requests Sent By Alexa documentation.

You can directly manipulate the Response struct, but it is not initialized by default and use of the connivence methods is recommended.

These methods include:

func (r *Response) SetSimpleCard(title string, content string)
func (r *Response) SetStandardCard(title string, text string, smallImageURL string, largeImageURL string)
func (r *Response) SetLinkAccountCard()
func (r *Response) SetOutputText(text string)
func (r *Response) SetOutputSSML(ssml string)
func (r *Response) SetRepromptText(text string)
func (r *Response) SetRepromptSSML(ssml string)

And more. These methods handle initializing any required struts within the Response struct as well as setting all required fields.

samples

HelloWorld

Limitations

This version does not support use as a standalone web server as it does not implement any of the HTTPS validation. It was developed to be used as an AWS Lambda function using AWS Labda Go support.

# Packages

No description provided by the author

# Variables

ErrRequestEnvelopeNil reports that the request envelope was nil there might be edge case which causes panic if for whatever reason this object is empty.

# Structs

Alexa defines the primary interface to use to create an Alexa request handler.
AudioItem contains an audio Stream definition for playback.
AudioPlayerDirective contains device level instructions on how to handle the response.
Card contains the data displayed to the user by the Alexa app.
Context contains the context data from the Alexa Request.
DialogDirective contains directives for use in Dialog prompts.
Image provides URL(s) to the image to display in resposne to the request.
Intent contains the data about the Alexa Intent requested.
IntentSlot contains the data for one Slot.
IntentSlotValue contains the value or values of a slot.
OutputSpeech contains the data the defines what Alexa should say to the user.
Reprompt contains data about whether Alexa should prompt the user for more data.
Request contains the data in the request within the main request.
RequestEnvelope contains the data passed from Alexa to the request handler.
Resolutions contain the (optional) ID of a slot.
Response contains the body of the response.
ResponseEnvelope contains the Response and additional attributes.
Session contains the session data from the Alexa request.
Stream contains instructions on playing an audio stream.

# Interfaces

RequestHandler defines the interface that must be implemented to handle Alexa Requests.