/alexa-skills-kit-golang

GoLang port of the Amazon Alexa Skills Kit

Primary LanguageGoApache License 2.0Apache-2.0

ericdaugherty/alexa-skills-kit-golang

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

License

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, *Response) error
	OnLaunch(context.Context, *Request, *Session, *Response) error
	OnIntent(context.Context, *Request, *Session, *Response) error
	OnSessionEnded(context.Context, *Request, *Session, *Response) error
}

For a summary of these methods, please see the Handling Reqeusts 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.