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 V2 lambda event serialize issue #1248

Closed antonysamy931 closed 2 years ago

antonysamy931 commented 2 years ago

Describe the bug

Not able to deserialize event object in lambda handler. It throws following error tions options, ReadStack& state, T& value) at System.Text.Json.Serialization.Metadata.JsonPropertyInfo1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader) at System.Text.Json.Serialization.Converters.ObjectDefaultConverter1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value) at System.Text.Json.Serialization.JsonConverter1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value) at System.Text.Json.Serialization.JsonCollectionConverter2.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, TCollection& value) at System.Text.Json.Serialization.JsonConverter1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value) at System.Text.Json.Serialization.Metadata.JsonPropertyInfo1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader) Request object : { "sessionId": "042444039656365", "inputTranscript": "hi", "interpretations": [ { "intent": { "slots": {}, "confirmationState": "None", "name": "Welcome_Intent", "state": "InProgress" }, "nluConfidence": 1 }, { "intent": { "slots": {}, "confirmationState": "None", "name": "FallbackIntent", "state": "InProgress" } } ], "responseContentType": "text/plain; charset=utf-8", "invocationSource": "DialogCodeHook", "messageVersion": "1.0", "transcriptions": [ { "resolvedContext": { "intent": "Welcome_Intent" }, "transcription": "hi", "resolvedSlots": {}, "transcriptionConfidence": 1 } ], "sessionState": { "originatingRequestId": "f2837226-8607-4ae5-b62b-db506533871e", "intent": { "slots": {}, "confirmationState": "None", "name": "Welcome_Intent", "state": "InProgress" } }, "inputMode": "Text", "bot": { "aliasName": "TestBotAlias", "aliasId": "TSTALIASID", "name": "DP_botv2_research", "version": "DRAFT", "localeId": "en_US", "id": "HMKPH2BKSM" } }

Expected Behavior

LexV2Event object should be populated based on the request object.

Current Behavior

Throws de-serialization errors.

Reproduction Steps

  1. Create Lex v2 bot
  2. Create intent
  3. Test

Possible Solution

No response

Additional Information/Context

Error place image

nluConfidence is class type. In the request json nluConfidence is value type(integer). image

AWS .NET SDK and/or Package version used

Amazon.Lambda.Core : 2.1.0 Amazon.Lambda.LexV2Events : 1.0.0 Amazon.Lambda.Serialization.SystemTextJson : 2.3.0

Targeted .NET Platform

.Net 6

Operating System and version

windows 10

antonysamy931 commented 2 years ago

Request & response documentation for lex v2 https://docs.aws.amazon.com/lexv2/latest/dg/lambda.html#lambda-input-format

ashishdhingra commented 2 years ago

Hi @antonysamy931,

Good morning.

Thanks for reporting the issue. The LexV2 event classes have been modeled as per the documentation. If you refer API reference for Interpretation and ConfidenceScore types, the nluConfidence is a ConfidenceScore with the score value of type Double. The documentation link LexV2: Input event format also models this as:

"nluConfidence": {
                "score": number
            }

Please advise on how did you test end-to-end integration.

NOTE: There was some end-to-end testing done as part of PR https://github.com/aws/aws-lambda-dotnet/pull/1129 where TranscriptionConfidence was found to be of type double (instead of a nested class object) in LexV2Transcription class and this was confirmed (and documentation corrected) by the Lex team. Not sure if there is some change on the service side which models nluConfidence differently now.

Thanks, Ashish

antonysamy931 commented 2 years ago

Hi @ashishdhingra ,

I have created bot using lex version 2. Created c# lambda and map to lex fulfillment. Invoke request from lex to lambda, it throws parsing error.

ashishdhingra commented 2 years ago

Reproducible. Need to check with service team on this change since the Amazon.Lambda.LexV2Events followed the documentation and the scenario was tested successfully earlier.

Now the logged JSON is as follows:

{
    "sessionId": "139480602983606",
    "inputTranscript": "I need to make appintment",
    "interpretations": [
        {
            "intent": {
                "slots": {
                    "AppointmentType": null,
                    "Time": null,
                    "Date": null
                },
                "confirmationState": "None",
                "name": "MakeAppointment",
                "state": "InProgress"
            },
            "nluConfidence": 0.79
        },
        {
            "intent": {
                "slots": {},
                "confirmationState": "None",
                "name": "FallbackIntent",
                "state": "InProgress"
            }
        }
    ],
    "proposedNextState": {
        "intent": {
            "slots": {
                "AppointmentType": null,
                "Time": null,
                "Date": null
            },
            "confirmationState": "None",
            "name": "MakeAppointment",
            "state": "InProgress"
        },
        "dialogAction": {
            "slotToElicit": "AppointmentType",
            "type": "ElicitSlot"
        }
    },
    "responseContentType": "text/plain; charset=utf-8",
    "invocationSource": "DialogCodeHook",
    "messageVersion": "1.0",
    "transcriptions": [
        {
            "resolvedContext": {
                "intent": "MakeAppointment"
            },
            "transcription": "I need to make appintment",
            "resolvedSlots": {},
            "transcriptionConfidence": 1
        }
    ],
    "sessionState": {
        "intent": {
            "slots": {
                "AppointmentType": null,
                "Time": null,
                "Date": null
            },
            "confirmationState": "None",
            "name": "MakeAppointment",
            "state": "InProgress"
        },
        "originatingRequestId": "e0a249b8-87b7-402c-8f57-ac122ed78cf8"
    },
    "inputMode": "Text",
    "bot": {
        "aliasName": "TestBotAlias",
        "aliasId": "TSTALIASID",
        "name": "TestBot",
        "version": "DRAFT",
        "localeId": "en_US",
        "id": "V1HNK7EBLW"
    }
}

The nluConfidence NOW appears to be of type double (with value 0.79) instead of top level object with nested property score (which was the case during testing before the package release).

I'm not sure if this change is correct since the Lex V2 API documentation for Interpretation documents nluConfidence property as ConfidenceScore instead of a Number.

ashishdhingra commented 2 years ago

P69014723

ashishdhingra commented 2 years ago

Per service team, nluConfidence in case of Lambda input event is a double. They will get the documentation corrected. We would work to fix this in Amazon.Lambda.LexV2Events package.

ashishdhingra commented 2 years ago

This has been fixed in Amazon.Lambda.LexV2Events 1.0.1

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.