Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d1b960
commit a7e2cdf
Showing
2 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
``` |