Skip to content

Conversation

@joysl
Copy link

@joysl joysl commented Jan 20, 2026

  • Add LexV2Event and LexV2Response structures
  • Add support for Kendra integration and sub-slot elicitation
  • Include test fixtures and example usage
  • Add implementation documentation

Issue #, if available: #518

Description of changes:

This PR adds complete Amazon Lex V2 event support to aws-lambda-go, including:

  • LexV2Event and LexV2Response structures for Lambda integration
  • Support for interpretations with NLU confidence scores
  • KendraSearchIntent response handling
  • Sub-slot elicitation for hierarchical slot collection
  • Slot elicitation style configuration
  • Runtime hints and active contexts
  • Comprehensive test coverage with example usage and test fixtures
  • Implementation documentation

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

- Add LexV2Event and LexV2Response structures
- Add support for Kendra integration and sub-slot elicitation
- Include test fixtures and example usage
- Add implementation documentation
@codecov-commenter
Copy link

codecov-commenter commented Jan 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.94%. Comparing base (9dac8a5) to head (ea8f66c).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

MessageVersion: "1.0",
InvocationSource: "FulfillmentCodeHook",
InputMode: "Text",
SessionID: "session-123",
Copy link

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.

Copy link
Author

@joysl joysl Jan 21, 2026

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
image

// https://docs.aws.amazon.com/lexv2/latest/dg/lambda-input-format.html
type LexV2Event struct {
MessageVersion string `json:"messageVersion"`
InvocationSource string `json:"invocationSource"`
Copy link

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"
)
Suggested change
InvocationSource string `json:"invocationSource"`
InvocationSource LexInvocationSource `json:"invocationSource"`

type LexV2Event struct {
MessageVersion string `json:"messageVersion"`
InvocationSource string `json:"invocationSource"`
InputMode string `json:"inputMode"`
Copy link

@aaiezza aaiezza Jan 21, 2026

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"
)
Suggested change
InputMode string `json:"inputMode"`
InputMode InputMode `json:"inputMode"`

Copy link
Author

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"`
Copy link

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:

Suggested change
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.

Copy link

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.

Copy link
Author

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants