qnabot-on-aws icon indicating copy to clipboard operation
qnabot-on-aws copied to clipboard

Adding handlebars code invisibly to all answers

Open tommcgee57 opened this issue 4 years ago • 4 comments

I'd like to add an automatic counter to our QnA bot, so that after users ask 7 questions, they get a message that they've reached their limit.

Something like this code probably could do what I need;:

{{#ifCond UserInfo.InteractionCount  '>' 6}}
  You have asked {{UserInfo.InteractionCount}} questions.
{{/ifCond}}

but I don't think copying-and-pasting this code into each and every question in the bot is the right way to do it. How would I apply this globally? I'd like to avoid a steep learning curve, I just want to add this one function!

tommcgee57 avatar Aug 24 '20 19:08 tommcgee57

Hi @tommcgee57 - Interesting.. I don't have a tidy answer for you right now, but this might be something we could improve.. Your options include:

  1. adding the handlebars to every answer (just what you said you didn't want to do, and i can understand why!)
  2. add a preprocesisng lambda function to implement this logic.. The ability to add a preprocessing lambda is an 'undocumented feature'.. Create a new Lambda function - eg QNA-PreprocessFunction' just as though it were a Lambda Hook (ie it receives and returns an event object). Open the Fulfillment Lambda in the AWS Lambda console and set a new Lambda environment variable called LAMBDA_PREPROCESS to name of your new function. Now when each request is processed by the bot, it will call your new Lambda before doing moch else, and your new lambda can implement logic to check the req.userinfo.InteractionCount value in the event and if it exceeds your thershold, then modify req.question to point to a QiD that will return your count exceeded message. (Note: The code to call LAMBDA_PROPROCESS is in file /aws-ai-qna-bot/lambda/fulfillment/lib/middleware/2_preprocess.js)
  3. modify QnABot Source code to add support for configurable general purpose preprocessing logic that could be used for this kind of use case. Then send us a Pull Request, and we'll validate and include it in the next release. That would be a great feature to have.
  4. wait for us to implement (3) in an upcoming release.. I'll add this to our backlog.. it would be a generally usefuly capability to have, but can't promise an ETA.

rstrahan avatar Aug 25 '20 22:08 rstrahan

Robert,

Thanks for your thoughtful reply. Permissions are one of the things that I always bang my head against the wall on when using AWS, and this might be another instance. When I create a new Lambda function, it asks for a role to base permissions on. I set it to the existing role for the fulfillment Lambda, then added the environmental variable as outlined in your message. The function code for the new Lambda is the one that comes right out of the box,

exports.handler = async (event) => { // TODO implement const response = { statusCode: 200, body: JSON.stringify('Hello from Lambda!'), }; return response; };

But now questions are responded to properly in the content designer screen, but the client URL only gives me “Sorry, I was unable to process your message. Try again later,” in response to the same questions. The CloudWatch logs showed one missing permission, which I added.

I know this it way outside the scope of your role here, so I don’t expect a solution. AWS permissions are Kryptonite.

Thanks again.

Tom

From: Robert [email protected] Sent: Tuesday, August 25, 2020 6:41 PM To: aws-samples/aws-ai-qna-bot [email protected] Cc: Thomas A McGee [email protected]; Mention [email protected] Subject: Re: [aws-samples/aws-ai-qna-bot] Adding handlebars code invisibly to all answers (#219)

Hi @tommcgee57https://nam05.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ftommcgee57&data=02%7C01%7CThomas.McGee%40shu.edu%7C1de55e92cf4a4c8b3c2e08d84947eae5%7C51f07c2253b744dfb97ca13261d71075%7C1%7C0%7C637339920534773966&sdata=0rxa%2FEn%2F%2Fo1fI7D50rL%2FbeAT0ytBLWr6t2jppOMZKCs%3D&reserved=0 - Interesting.. I don't have a tidy answer for you right now, but this might be something we could improve.. Your options include:

  1. adding the handlebars to every answer (just what you said you didn't want to do, and i can understand why!)
  2. add a preprocesisng lambda function to implement this logic.. The ability to add a preprocessing lambda is an 'undocumented feature'.. Create a new Lambda function - eg QNA-PreprocessFunction' just as though it were a Lambda Hook (ie it receives and returns an event object). Open the Fulfillment Lambda in the AWS Lambda console and set a new Lambda environment variable called LAMBDA_PREPROCESS to name of your new function. Now when each request is processed by the bot, it will call your new Lambda before doing moch else, and your new lambda can implement logic to check the req.userinfo.InteractionCount value in the event and if it exceeds your thershold, then modify req.question to point to a QiD that will return your count exceeded message. (Note: The code to call LAMBDA_PROPROCESS is in file /aws-ai-qna-bot/lambda/fulfillment/lib/middleware/2_preprocess.js)
  3. modify QnABot Source code to add support for configurable general purpose preprocessing logic that could be used for this kind of use case. Then send us a Pull Request, and we'll validate and include it in the next release. That would be a great feature to have.
  4. wait for us to implement (3) in an upcoming release.. I'll add this to our backlog.. it would be a generally usefuly capability to have, but can't promise an ETA.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://nam05.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Faws-samples%2Faws-ai-qna-bot%2Fissues%2F219%23issuecomment-680304429&data=02%7C01%7CThomas.McGee%40shu.edu%7C1de55e92cf4a4c8b3c2e08d84947eae5%7C51f07c2253b744dfb97ca13261d71075%7C1%7C0%7C637339920534783966&sdata=YcA6oXcJ38KicdTwUpgVlBwi6WvBUtEZmyPVhoRy8nU%3D&reserved=0, or unsubscribehttps://nam05.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAABMXW3P3EN6X2IGAGZZDOLSCQ4XDANCNFSM4QJ3IS2A&data=02%7C01%7CThomas.McGee%40shu.edu%7C1de55e92cf4a4c8b3c2e08d84947eae5%7C51f07c2253b744dfb97ca13261d71075%7C1%7C0%7C637339920534793961&sdata=g9JHfiaUnITNHVjhC0ydY6Pr92bXiKXi2EmnPIJr4Jg%3D&reserved=0. ** WARNING: This email originated from outside of Seton Hall University. Do not click links or open attachments unless you recognize the sender and know the content is safe. **

tommcgee57 avatar Aug 28 '20 18:08 tommcgee57

Hm. Out of the box adding a generic Lambda function just broke the bot. It wasn’t able to process any questions.

I went back and removed the new environmental variable from the bot, but it still doesn’t understand the questions. It definitely did before!

Is there some rebuild step that’s necessary (other than the one in the content designer)?

TIA,

Tom

From: Robert [email protected] Sent: Tuesday, August 25, 2020 6:41 PM To: aws-samples/aws-ai-qna-bot [email protected] Cc: Thomas A McGee [email protected]; Mention [email protected] Subject: Re: [aws-samples/aws-ai-qna-bot] Adding handlebars code invisibly to all answers (#219)

Hi @tommcgee57https://nam05.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ftommcgee57&data=02%7C01%7CThomas.McGee%40shu.edu%7C1de55e92cf4a4c8b3c2e08d84947eae5%7C51f07c2253b744dfb97ca13261d71075%7C1%7C0%7C637339920534773966&sdata=0rxa%2FEn%2F%2Fo1fI7D50rL%2FbeAT0ytBLWr6t2jppOMZKCs%3D&reserved=0 - Interesting.. I don't have a tidy answer for you right now, but this might be something we could improve.. Your options include:

  1. adding the handlebars to every answer (just what you said you didn't want to do, and i can understand why!)
  2. add a preprocesisng lambda function to implement this logic.. The ability to add a preprocessing lambda is an 'undocumented feature'.. Create a new Lambda function - eg QNA-PreprocessFunction' just as though it were a Lambda Hook (ie it receives and returns an event object). Open the Fulfillment Lambda in the AWS Lambda console and set a new Lambda environment variable called LAMBDA_PREPROCESS to name of your new function. Now when each request is processed by the bot, it will call your new Lambda before doing moch else, and your new lambda can implement logic to check the req.userinfo.InteractionCount value in the event and if it exceeds your thershold, then modify req.question to point to a QiD that will return your count exceeded message. (Note: The code to call LAMBDA_PROPROCESS is in file /aws-ai-qna-bot/lambda/fulfillment/lib/middleware/2_preprocess.js)
  3. modify QnABot Source code to add support for configurable general purpose preprocessing logic that could be used for this kind of use case. Then send us a Pull Request, and we'll validate and include it in the next release. That would be a great feature to have.
  4. wait for us to implement (3) in an upcoming release.. I'll add this to our backlog.. it would be a generally usefuly capability to have, but can't promise an ETA.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://nam05.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Faws-samples%2Faws-ai-qna-bot%2Fissues%2F219%23issuecomment-680304429&data=02%7C01%7CThomas.McGee%40shu.edu%7C1de55e92cf4a4c8b3c2e08d84947eae5%7C51f07c2253b744dfb97ca13261d71075%7C1%7C0%7C637339920534783966&sdata=YcA6oXcJ38KicdTwUpgVlBwi6WvBUtEZmyPVhoRy8nU%3D&reserved=0, or unsubscribehttps://nam05.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAABMXW3P3EN6X2IGAGZZDOLSCQ4XDANCNFSM4QJ3IS2A&data=02%7C01%7CThomas.McGee%40shu.edu%7C1de55e92cf4a4c8b3c2e08d84947eae5%7C51f07c2253b744dfb97ca13261d71075%7C1%7C0%7C637339920534793961&sdata=g9JHfiaUnITNHVjhC0ydY6Pr92bXiKXi2EmnPIJr4Jg%3D&reserved=0. ** WARNING: This email originated from outside of Seton Hall University. Do not click links or open attachments unless you recognize the sender and know the content is safe. **

tommcgee57 avatar Sep 09 '20 15:09 tommcgee57

Thomas A McGee would like to recall the message, "[aws-samples/aws-ai-qna-bot] Adding handlebars code invisibly to all answers (#219)".

tommcgee57 avatar Sep 09 '20 15:09 tommcgee57