aws / aws-lambda-dotnet

Libraries, samples and tools to help .NET Core developers develop AWS Lambda functions.
Apache License 2.0
1.57k stars 478 forks source link

[AWS Lex] "null" values from Lex v2 Chatbot Request #1077

Closed omf-jnguyen closed 2 years ago

omf-jnguyen commented 2 years ago

Context

Description

Reproduction Steps

  1. Create a new .NET project using the "AWS Lambda Project (.NET Core - C#)" template with the "Order Flowers Chatbot" Blueprint.
  2. Log the lexEvent variable to CloudWatch within the FunctionHandler function: LambdaLogger.Log(JsonSerializer.Serialize(lexEvent));
  3. Publish the solution to AWS Lambda (default settings, arbitrary function name).
  4. Create a new Lex v2 Chatbot with the "Order Flowers Chatbot" Example.
  5. Configure the new chatbot to use the new lambda function you uploaded under Bot > Alias > Language.
  6. Under Intents > OrderFlowers > Fulfillment > Advanced Options, ensure "Use a Lambda function for fulfillment" is checked.
  7. Save the intent, build the bot, and test the conversation.
  8. An error should appear when attempting to fulfill the intent - when you check CloudWatch, the LexEvent body should appear with null values for fields such as CurrentIntent and SlotDetails.

Logs

Lex Invalid Lambda Response: Received error response from Lambda: Unhandled

CloudWatch

{
    "CurrentIntent": null,
    "SlotDetails": null,
    "Bot": {
        "Name": "OrderFlowersBot",
        "Alias": null,
        "Version": "DRAFT"
    },
    "UserId": null,
    "InputTranscript": "yes",
    "InvocationSource": "FulfillmentCodeHook",
    "OutputDialogMode": null,
    "MessageVersion": "1.0",
    "SessionAttributes": null,
    "RequestAttributes": null,
    "AlternativeIntents": null,
    "SentimentResponse": null,
    "RecentIntentSummaryView": null,
    "ActiveContexts": null
}

Environment

Resolution


This is a :bug: bug-report

ashishdhingra commented 2 years ago

Hi @omf-jnguyen,

Good afternoon.

Upon investigating further, looks like the Amazon Lex V2 could be having a different request/response format (reference Using an AWS Lambda function). Hence, this is not a bug, instead a new feature request to implement new POCO classes, perhaps better to be part of new project Amazon.Lambda.LexV2Events. While I cannot commit timeline by which this feature request can be implemented, feel free to contribute in the form of PR. You may take existing Amazon.Lambda.LexEvents project as a starting point and take guidance from Amazon Lex V2 API reference for model classes.

Thanks, Ashish

omf-jnguyen commented 2 years ago

Thanks for the swift reply @ashishdhingra - really appreciate the insight and guidance. Will follow-up with a PR in the near future then unless you guys beat me to it.

1bberto commented 2 years ago

Its related to the version! Lex V1: https://docs.aws.amazon.com/lex/latest/dg/lambda-input-response-format.html

And V2: https://docs.aws.amazon.com/lexv2/latest/dg/lambda.html#lambda-input-format

I`m facing the same issue!

omf-jnguyen commented 2 years ago

@1bberto - yup, realized that so I ended up implementing my own custom models based on v2. Now works like a charm for me!

Here's a gist in case anyone else wants to use them: https://gist.github.com/omf-jnguyen/dbd6cfebeb82780976038e1514a6ecb6

1bberto commented 2 years ago

@omf-jnguyen - nice! I think that ifs working like a charm that is totally fine then. the only thing that you don't need on your code are the attributes JsonPropertyName on your properties, I think that on the serialization the capitalization is not checked

ashishdhingra commented 2 years ago

Amazon.Lambda.LexV2Events 1.0.0 has been released.

github-actions[bot] commented 2 years ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.