From 044197f0c506bc82db83fdf6ff9e2ae6c30a1f55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Turhan=20Co=C5=9Fkun?= Date: Wed, 20 Feb 2019 20:11:59 +0100 Subject: [PATCH] Add AWS Lex event example (#170) --- events/README_Lex.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 events/README_Lex.md diff --git a/events/README_Lex.md b/events/README_Lex.md new file mode 100644 index 00000000..abcc07aa --- /dev/null +++ b/events/README_Lex.md @@ -0,0 +1,31 @@ + +# Sample Function + +The following is a sample class and Lambda function that receives Amazon Lex event data as input, writes some of the record data to CloudWatch Logs, and responds back to Lex. (Note that by default anything written to Console will be logged as CloudWatch Logs events.) + +```go +import ( + "context" + "fmt" + + "github.com/aws/aws-lambda-go/events" +) + +func Handler(ctx context.Context, event events.LexEvent) (*lex.LexResponse, error) { + fmt.Printf("Received an input from Amazon Lex. Current Intent: %s", event.CurrentIntent.Name) + + messageContent := "Hello from AWS Lambda!" + + return &LexResponse{ + SessionAttributes: event.SessionAttributes, + DialogAction: events.LexDialogAction{ + Type: "Close", + Message: map[string]string{ + "content": messageContent, + "contentType": "PlainText", + }, + FulfillmentState: "Fulfilled", + }, + }, nil +} +```