Skip to content

Commit

Permalink
Updated README files
Browse files Browse the repository at this point in the history
  • Loading branch information
ericdaugherty committed Mar 4, 2017
1 parent 9d1b960 commit a7e2cdf
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 1 deletion.
79 changes: 78 additions & 1 deletion README.md
@@ -1,5 +1,82 @@
# ericdaugherty/alexa-skills-kit-golang

Port of the alexa-skills-kit in golang.
alexa-skills-kit-golang is a lightweight port of the Amazon [alexa-skills-kit-java](https://github.com/amzn/alexa-skills-kit-java)
SDK and Samples.

[![License][badge-license]](LICENSE)

## Usage

This explanation assumes familiarity with with AWS Documentation. Please
review [Developing an Alexa Skill as a Lambda Function](https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/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.

This SDK was designed to be used as an AWS Lambda function via the [eawsy lambda shim](https://github.com/eawsy/aws-lambda-go-shim).

The samples directory provides example usage, including a Makefile.

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

```Go
type Alexa struct {
ApplicationID string
RequestHandler RequestHandler
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.

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

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

```Go
func (alexa *Alexa) ProcessRequest(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:
```Go
type RequestHandler interface {
OnSessionStarted(*Request, *Session, *Response) error
OnLaunch(*Request, *Session, *Response) error
OnIntent(*Request, *Session, *Response) error
OnSessionEnded(*Request, *Session, *Response) error
}
```

For a summary of these methods, please see the [Handling Reqeusts Sent By Alexa](https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/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:
```Go
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](https://github.com/ericaugherty/alexa-skills-kit-golang/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 the [eawsy lambda shim](https://github.com/eawsy/aws-lambda-go-shim) The samples
utilize this library.
35 changes: 35 additions & 0 deletions samples/helloworld/README.md
@@ -0,0 +1,35 @@
# HelloWorld Sample

This SDK was designed to be used as an AWS Lambda function via the [eawsy lambda shim](https://github.com/eawsy/aws-lambda-go-shim). Please review their
documentation and install the necessary dependencies if you will be deploying
this sample to AWS Lambda.

This also assumes you have the [Amazon AWS CLI](https://aws.amazon.com/cli/) installed and configured.

First, create an Alexa Skill following the instructions described in the [Java HelloWorld Sample](https://github.com/amzn/alexa-skills-kit-java/tree/master/samples/src/main/java/helloworld)

Second, compile the sample using the included Makefile

```
make all
```

Then, create a new Lambda function using the AWS CLI:

```
aws lambda create-function \
--role arn:aws:iam::AWS_ACCOUNT_NUMBER:role/lambda_basic_execution \
--function-name HelloWorld \
--zip-file fileb://package.zip \
--runtime python2.7 \
--handler handler.Handle
```

You can now test the HelloWorld skill via an Echo attached to your Amazon account or using the Amazon Alexa Console.

Once the lambda function is created, you can use the make file to build and
update your function.

```
make all push
```

0 comments on commit a7e2cdf

Please sign in to comment.