Created
March 4, 2018 06:46
-
-
Save arienmalec/a07fe00ebd4a34eafe0913150fa5a444 to your computer and use it in GitHub Desktop.
AWS Lambda with Alexa skill response
This file contains hidden or 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
| package main | |
| import ( | |
| "github.com/aws/aws-lambda-go/lambda" | |
| ) | |
| // Response contains the message for the world | |
| type Response struct { | |
| Version string `json:"version"` | |
| Body ResBody `json:"response"` | |
| } | |
| // ResBody is the actual body of the response | |
| type ResBody struct { | |
| OutputSpeech Payload ` json:"outputSpeech,omitempty"` | |
| ShouldEndSession bool `json:"shouldEndSession"` | |
| } | |
| // Payload ... | |
| type Payload struct { | |
| Type string `json:"type,omitempty"` | |
| Text string `json:"text,omitempty"` | |
| } | |
| // NewResponse builds a simple Alexa session response | |
| func NewResponse(speech string) Response { | |
| return Response{ | |
| Version: "1.0", | |
| Body: ResBody{ | |
| OutputSpeech: Payload{ | |
| Type: "PlainText", | |
| Text: speech, | |
| }, | |
| ShouldEndSession: true, | |
| }, | |
| } | |
| } | |
| // Handler is the lambda hander | |
| func Handler() (Response, error) { | |
| return NewResponse("Hello, World"), nil | |
| } | |
| func main() { | |
| lambda.Start(Handler) | |
| } |
This file contains hidden or 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
| AWSTemplateFormatVersion: '2010-09-09' | |
| Transform: AWS::Serverless-2016-10-31 | |
| Resources: | |
| HelloLambda: | |
| Type: AWS::Serverless::Function | |
| Properties: | |
| Handler: hello | |
| Runtime: go1.x | |
| CodeUri: ./deploy/hello.zip | |
| Environment: | |
| Variables: | |
| S3_BUCKET: hello_lambda | |
| Events: | |
| AlexaSkillEvent: | |
| Type: AlexaSkill |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment