aws-solutions / qnabot-on-aws

AWS QnABot is a multi-channel, multi-language conversational interface (chatbot) that responds to your customer's questions, answers, and feedback. The solution allows you to deploy a fully functional chatbot across multiple channels including chat, voice, SMS and Amazon Alexa.
https://aws.amazon.com/solutions/implementations/aws-qnabot
Apache License 2.0
391 stars 251 forks source link

Specialty bot routing fixes, Lex Intent state fixes, handlebar processing of SSML injects "\n" into response. #726

Closed bobpskier closed 3 months ago

bobpskier commented 4 months ago

Issue #, if available: 674

Description of changes:

A couple of fixes are addressed in this pull request.

a) fix LexV2 lambda return templates (lambda/fulfillment/lib/middleware/lex.js) for elicitIntent (getV2ElicitTemplate) dialogCodeHook (getV2DialogCodeHookResponseTemplate) to return state and slots as part of intent structure.

b) fix processing of SSML in handlebars.js (lambda/es-proxy-layer/lib/handlebars.js) such that new lines (\n) are not injected as part of template processing. Designer UI allows the creation of a response for SSML using handlebar syntax where new lines are allowed in the template and cause handlebars to inject a "\n" in the response which causes Lex V2 to return an invalid audio/ogg stream.

c) Integrate original lexv2 bug fixes from first PR for speciltyBotRouter.js and implement additional fixes as necessary. Address the following merge and feature issues:

specialtyBotRouter.js will throw an exception as LexV2 will sometimes not return an intent as expected at lexv2response.sessionState.intent. The revised code is not handling this condition.

specialtyBotRouter.js will throw an exception in getDialogState() for the same undefined lexv2response.sessionState.intent.

bot router termination is not preserving the last message from the specialty bot in endUseOfSpecialtyBot().

both markdown and ssml responses from a target qnabot (specialtyBot) are merged into the the botRouter response. 

merging of specialty bot session attributes for supervisory bot response does not handle special cases for "appContext" and "qnabotcontext" when the specialty bot is another QnaBot.

The matching QID's answer/markdown which initiated bot routing is not provided to the user. The original answer is ignored when it should be prepended as part the response message when bot routing starts.

The superivsory bot does not terminate bot routing when the specialty LexV2 bot reaches fulfillment or is closed. Incorrect states are being checked. Note that a specialty QnABot (also LexV2) target is a special case where bot routing should not be terminated when fulfillment is reached as each answer represents a fulfilled state. A specialty QnABot requires special processing to terminate bot routing either through a defined session attribute or by the user entering the termination phrase.

getRespCard() is incorrectly defining several attributes that should be left undefined. One example is an image url in the response card. When an image url is defined in the response card as an empty string which the present code is setting, the LexV2 service handling the fulfillment response from the supervisory bot will return an error and the UI will display an error.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

abhirpat commented 3 months ago

Hi @bobpskier , this issue should be addressed with the latest release v6.0.0. Please refer to CHANGELOG for additional details about this release. Thank You!