-
Notifications
You must be signed in to change notification settings - Fork 574
feat: add Amazon Lex V2 event support (#518) #615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Add LexV2Event and LexV2Response structures - Add support for Kendra integration and sub-slot elicitation - Include test fixtures and example usage - Add implementation documentation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #615 +/- ##
=======================================
Coverage 74.94% 74.94%
=======================================
Files 36 36
Lines 1401 1401
=======================================
Hits 1050 1050
Misses 273 273
Partials 78 78 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
events/example_lexv2_test.go
Outdated
| MessageVersion: "1.0", | ||
| InvocationSource: "FulfillmentCodeHook", | ||
| InputMode: "Text", | ||
| SessionID: "session-123", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does Lex allow non-UUID session IDs? If not, we could replace this with a placeholder value that would represent something legal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lex V2 accepts any string for sessionId, I'll update this in the next commit to be similar to a UUID format https://docs.aws.amazon.com/lexv2/latest/dg/lambda-input-format.html

| // https://docs.aws.amazon.com/lexv2/latest/dg/lambda-input-format.html | ||
| type LexV2Event struct { | ||
| MessageVersion string `json:"messageVersion"` | ||
| InvocationSource string `json:"invocationSource"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would recommend a data type for InvocationSource:
// InvocationSource represents the source of the invocation within the Lex Bot lifecycle.
type LexInvocationSource string
const (
LexInvocationSourceDialogCodeHook InvocationSource = "DialogCodeHook"
LexInvocationSourceFulfillmentCodeHook InvocationSource = "FulfillmentCodeHook"
)| InvocationSource string `json:"invocationSource"` | |
| InvocationSource LexInvocationSource `json:"invocationSource"` |
| type LexV2Event struct { | ||
| MessageVersion string `json:"messageVersion"` | ||
| InvocationSource string `json:"invocationSource"` | ||
| InputMode string `json:"inputMode"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would recommend a data type for InputMode:
// InputMode represents the mode of innput from the user.
type InputMode string
const (
InputModeText InputMode = "Text"
InputModeVoice InputMode = "Voice"
InputModeDTMF InputMode = "DTMF"
)| InputMode string `json:"inputMode"` | |
| InputMode InputMode `json:"inputMode"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
intentionally kept these as plain string types to match the pattern used throughout the aws-lambda-go events library (see lex.go, cognito.go, apigw.go)
AWS can add new enum values without requiring library updates. Developers are pointed to the official AWS docs for valid values if they want to add type-safe constants in their own code.
https://docs.aws.amazon.com/lexv2/latest/dg/lambda-input-format.html
https://docs.aws.amazon.com/lexv2/latest/dg/lambda-response-format.html
This approach keeps the library minimal while remaining flexible as AWS evolves the service.
| InputMode string `json:"inputMode"` | ||
| ResponseContentType string `json:"responseContentType"` | ||
| SessionID string `json:"sessionId"` | ||
| InputTranscript string `json:"inputTranscript,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The LexV2Event struct is missing the optional InvocationLabel:
| InputTranscript string `json:"inputTranscript,omitempty"` | |
| InputTranscript string `json:"inputTranscript"` | |
| InvocationLabel *string `json:"invocationLabel,omitempty"` |
The documentation does not describes this field as optional, but testing has shown that the field is optional, so it can be represented as a string pointer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is InputTranscript actually optional? If so, it could be a pointer, so that the json struct tag omitempty, results in a nil value instead of a default empty string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks will add InvocationLabel in next commit
InputTranscript: The documentation not explicitly mark inputTranscript as required. However, I'm keeping it as a regular string with omitempty because it represents user input and is present in all standard DialogCodeHook and FulfillmentCodeHook invocations. It's a core field fundamental to Lex's operation. Making it a pointer would incorrectly signal it's rarely used, when it's present in nearly every event. The omitempty tag handles edge cases where it might be absent. While the docs don't say "required" verbatim, the field's purpose and typical usage patterns indicate it's a standard field rather than optional.
- Add InvocationLabel field as optional pointer - Update sessionId examples to use UUID format for realism - Keep InputTranscript as string (core field, present in standard invocations)
Issue #, if available: #518
Description of changes:
This PR adds complete Amazon Lex V2 event support to aws-lambda-go, including:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.