Reputation: 67
I was trying to add Multiple Responses for AWS Lex using AWS Lambda Functions but I am facing this error.
But I am stuck at the message
An error has occurred: Invalid Lambda Response: Received invalid response from Lambda: Can not construct instance of Message, problem: contentType must not be null at [Source: {"dialogAction": {"type": "ConfirmIntent", "message": {"messages": [{"contentType": "PlainText", "group": 1, "content": "Hello"}, {"contentType": "PlainText", "group": 2, "content": "My"}, {"contentType": "PlainText", "group": 3, "content": "Friend"}]}, "intentName": "CardsI", "slots": {"CardsB": null}}}; line: 1, column: 252]
In Lambda Function we are using the following code for printing multiple responses
return {
"dialogAction": {
"type": "ConfirmIntent",
"message": {
"messages": [{
"contentType": "PlainText",
"group": 1,
"content": "Hello"
},
{
"contentType": "PlainText",
"group": 2,
"content": "My"
},
{
"contentType": "PlainText",
"group": 3,
"content": "Friend"
}
]
},
"intentName": "CardsI",
"slots": {
"CardsB": ""
}
}
}
We even went through the documentations such as
https://docs.aws.amazon.com/lex/latest/dg/howitworks-manage-prompts.html#message-groups
https://docs.aws.amazon.com/lex/latest/dg/context-mgmt.html#special-response
but we still are facing issue. Any help ?
Upvotes: 4
Views: 3540
Reputation: 41
I had the same problem, The docs don't suggest anything. But when inspecting the network response from the lex we can see that in case of multiple messages the array of messages passed in as a string, not as an object.
The response from the lambda should be in the below format.
return {
"dialogAction": {
"type": "ConfirmIntent",
"message": {
"contentType": "CustomPayload",
"content": "{\"messages\":[{\"type\":\"PlainText\",\"group\":1,\"value\":\"Hello\"},{\"type\":\"PlainText\",\"group\":2,\"value\":\"Hey\"}]}"
},
"intentName": "CardsI",
"slots": {
"CardsB": null
}
}
Upvotes: 3
Reputation: 1509
You can do the following things to add multiple response from Amazon lambda to your amazon lex.
You can add session attribute in the response from your lambda function.
{
"dialogState": "Fulfilled",
"intentName": "myIntent",
"message": "Hi",
"messageFormat": "PlainText",
"responseCard": null,
"sessionAttributes": {
"sessionAttribute1": "FirstAttribute",
"SessionAttribute2": "secondAttribute"
},
"slotToElicit": null,
"slots": {
"customerId": "1419"
}
}
These SessionAttributes can be returned from your lambda function to lex and it can be customized as per your need.
Hope it Helps!
Upvotes: 0
Reputation: 3287
A few things I suggest trying:
contentType
in the message
object, because of the error you are receiving.messages
as an escaped JSON object, so escape the quotation marks and wrap all of messages
in { }
. message
needs contentType
and content
so try setting the escaped JSON object (messages
) in content
messages
, use value
for the text instead of content
The docs are a little vague with the exact format when putting it all together. I've done all of the above in my suggestion below, but one or two may be all that's necessary. So try some combinations.
return {
"dialogAction": {
"type": "ConfirmIntent",
"message": {
"contentType": "PlainText",
"content":{
\"messages\": [{
\"contentType\": \"PlainText\",
\"group\": 1,
\"value\": \"Hello\"
},
{
\"contentType\": \"PlainText\",
\"group\": 2,
\"value\": \"My\"
},
{
\"contentType\": \"PlainText\",
\"group\": 3,
\"value\": \"Friend\"
}
]}
},
"intentName": "CardsI",
"slots": {
"CardsB": null
}
}
}
Upvotes: 0