1
votes

I have set up a bot in lex console that collects data from users such as the product/service that they are interested in and email-ID, Phone number etc. Now every time a visitor interacts with the bot I would want to receive an email with chat conversations.

I also created a lambda function that is triggered by lex fulfilment but i get this error on bot ui An error has occurred: Invalid Lambda Response: Received invalid response from Lambda: Can not construct instance of IntentResponse: no String-argument constructor/factory method to deserialize from String value

As per the documentation I have reconstructed a response and returning it.

import json

def lambda_handler(event, context):
    print(event)

    var1 = '''dialogAction": {
    "type": "close",
    "fulfillmentState": "fulfilled",
    "message": {
      "contentType": "PlainText or SSML or CustomPayload",
      "content": "Message to convey to the user. For example, What size pizza would you like?"
    },
    }
    }'''
    return(var1)

And here is what the error looks like:-

An error has occurred: Invalid Lambda Response: Received invalid response from Lambda: Can not construct instance of IntentResponse: no String-argument constructor/factory method to deserialize from String value ('"dialogAction": { "type": "close", "fulfillmentState": "fulfilled", "message": { "contentType": "PlainText or SSML or CustomPayload", "content": "Message to convey to the user. For example, What size pizza would you like?" }, } }') at [Source: "\"dialogAction\": {\n \"type\": \"close\",\n \"fulfillmentState\": \"fulfilled\",\n \"message\": {\n \"contentType\": \"PlainText or SSML or CustomPayload\",\n \"content\": \"Message to convey to the user. For example, What size pizza would you like?\"\n },\n }\n }"; line: 1, column: 1]
1

1 Answers

2
votes

You are incorrectly passing the response as a string. And by using the triple quotation marks ''', it is adding the line breaks \n which you can see in the error source, and you don't want those.

So try this, simply return the response as an object. I believe the callback function will automatically convert to JSON before delivering to Lex.

 var1 = {
    dialogAction": {
         "type": "close",
         "fulfillmentState": "fulfilled",
         "message": {
               "contentType": "PlainText or SSML or CustomPayload",
               "content": "Message to convey to the user. For example, What size pizza would you like?"
         },
    }
}
return var1