Closed tkashi closed 1 year ago
@tkashi Looks like a change in 5.2.0 for the file lambda/fulfillment/lib/middleware/lex.js is causing the problem. Since you've cloned the repo you might try the following change for lines 468 to 482 and then update your stack.
if (!isConnectClient(request)){
let imageResponseCardV2 = buildImageResponseCardV2(response);
if(imageResponseCardV2) {
let imgUrlLength = imageResponseCardV2.imageUrl ? imageResponseCardV2.imageUrl.length : 0;
if(imgUrlLength > 250){
qnabot.log("ResponseCard Image URL length is greater than the max limit (250 chars). Client is LexWebUI. Sending ResponseCard as session attribute rather than as Lex ImageresponseCard to avoid hitting the Lex URL length limit.")
} else {
out.messages[out.messages.length] = {
"contentType": "ImageResponseCard",
"imageResponseCard": imageResponseCardV2
};
}
}
}
Hi @bobpskier, thanks for your quick response! Yes, actually the below code defining imgUrlLength
works for me, which looks almost same as your suggestion (though I'm not sure this is the perfect correction).
let imgUrlLength = _.get(imageResponseCardV2, "imageUrl", []).length
@tkashi The important part is to set imgUrlLength to 0 if it does not exist. The lodash mechanism above will work as well, however, the default should be an empty string "" vs an empty array []. Both will work as they produce a length of 0. However, the expected value of imageUrl is a string.
Thank you @tkashi , @bobpskier , and @greengangsta!. We are currently working on a patch release and will include the fix in the release.
Released as of v5.2.1, thanks all!
Describe the bug In the designer, we can define an image url and Lex buttons in a question's response card. When we create a question with only set buttons fields without image url one, we will get no response when we ask the question in the client.
The implementation in the below code at v5.2.0 assumes that an image urls exists in a response card, which produces a type error ("Cannot read property 'length' of undefined"). However, in the older versions, this was not true. https://github.com/aws-solutions/qnabot-on-aws/blob/771b4b465266c19fb863a38c2aa0cd80bf665e96/lambda/fulfillment/lib/middleware/lex.js#L471
To Reproduce Steps to reproduce the behavior.
We can also see an error log in the CW logs of the FulfillmentLambda function.
Expected behavior A clear and concise description of what you expected to happen.
We can define a question only with buttons, but without a card image url.
Please complete the following information about the solution:
To get the version of the solution, you can look at the description of the created CloudFormation stack. For example, "(SO0189) QnABot [...] v0.0.1".
Screenshots If applicable, add screenshots to help explain your problem (please DO NOT include sensitive information).
Additional context Add any other context about the problem here.