You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Feature Request: Add LexResolver for simplified intent routing
Description
Add a LexResolver class similar to APIGatewayRestResolver that enables decorator-based routing for Amazon Lex V2 Lambda functions. This simplifies handling different intents and event types in Lex bot fulfillment/dialog code hooks.
Use Case
fromaws_lambda_powertools.utilities.leximportLexResolverapp=LexResolver()
@app.fulfillment("OrderPizza")defhandle_order_pizza():
# Handle pizza order fulfillmentreturn {
"sessionAttributes": session_attributes,
"messages": [{
"contentType": "PlainText",
"content": "Your pizza order is confirmed"
}]
}
@app.dialog("CheckOrder")defhandle_check_order():
# Handle order status dialogpass
Proposed Features
Intent-based routing using decorators
Separate decorators for DialogCodeHook and FulfillmentCodeHook
Access to session attributes via resolver context
Type hints and response validation
Error handling with appropriate Lex response formats
Middleware support similar to APIGatewayRestResolver
Benefits
Reduces boilerplate code
Cleaner separation of concerns
Type-safe handling of Lex events
Consistent with existing Powertools patterns
Implementation Notes
Follow similar pattern to APIGatewayRestResolver
Support Lambda Powertools logger and tracer integration
Maintain compatibility with Lex V2 response formats
Solution/User Experience
Solution/User Experience
The LexResolver would provide a clean, intuitive API for routing Lex events:
fromaws_lambda_powertools.utilities.leximportLexResolverapp=LexResolver()
@app.fulfillment("OrderPizza")defhandle_pizza_order(session_attributes: dict):
return {
"sessionAttributes": {**session_attributes, "order_status": "confirmed"},
"messages": [{
"contentType": "PlainText",
"content": "Your pizza order is confirmed"
}]
}
@app.dialog("CheckDelivery", required_slots=["order_id"])defhandle_delivery_check(session_attributes: dict):
return {
"sessionAttributes": session_attributes,
"messages": [{
"contentType": "PlainText",
"content": f"Your delivery is on its way"
}]
}
deflambda_handler(event, context):
returnapp.resolve(event, context)
Hey @fakhtar ! Thank you for your feature request for a LexResolver. We appreciate your detailed suggestion and will evaluate it carefully in our next iterations. We'll get back to you soon or with any follow-up questions!
Use case
Feature Request: Add LexResolver for simplified intent routing
Description
Add a
LexResolver
class similar toAPIGatewayRestResolver
that enables decorator-based routing for Amazon Lex V2 Lambda functions. This simplifies handling different intents and event types in Lex bot fulfillment/dialog code hooks.Use Case
Proposed Features
Benefits
Implementation Notes
Solution/User Experience
Solution/User Experience
The LexResolver would provide a clean, intuitive API for routing Lex events:
Alternative solutions
Acknowledgment
The text was updated successfully, but these errors were encountered: