Skip to content

Latest commit

 

History

History
31 lines (24 loc) · 874 Bytes

README_Lex.md

File metadata and controls

31 lines (24 loc) · 874 Bytes

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.)

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
}