Skip to content

Instantly share code, notes, and snippets.

@arienmalec
Created March 4, 2018 06:46
Show Gist options
  • Select an option

  • Save arienmalec/a07fe00ebd4a34eafe0913150fa5a444 to your computer and use it in GitHub Desktop.

Select an option

Save arienmalec/a07fe00ebd4a34eafe0913150fa5a444 to your computer and use it in GitHub Desktop.
AWS Lambda with Alexa skill response
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)
}
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