Integrating Handlebars templates - QnABot on AWS

Integrating Handlebars templates

This solution supports the Handlebars simple templating language in your answers (including in the markdown and SSML fields) which allows you to include variable substitution and conditional elements. Use the following procedure to integrate Handlebars.

  1. From the content designer, choose Add.

    1. Enter ID: Handlebars.001

    2. Enter question: What is my interaction count?

    3. Enter answer: So far, you have interacted with me {{UserInfo.InteractionCount}} times.

  2. Save the new item.

  3. Use the web UI, or any Alexa device to say, “What is my interaction count?” to your chatbot, and listen to it respond.

  4. Ask a few more questions, and then ask “What is my interaction count?” again. Notice that the value has increased.

  5. From the content designer, edit item Handlebars.001

  6. Modify the answer to:

    So far, you have interacted with me {{UserInfo.InteractionCount}} times. {{#ifCond UserInfo.TimeSinceLastInteraction '>' 60}} It’s over a minute since I heard from you last.. I almost fell asleep! {{else}} Keep those questions coming fast.. It’s been {{UserInfo.TimeSinceLastInteraction}} seconds since your last interaction. {{/ifCond}}
  7. Use the web UI, or Alexa, to interact with the chatbot again. Wait over a minute between interactions and observe the conditional answer in action.

There’s a lot more that you can do with Handlebars, such as randomly selecting content from a list, setting and accessing session attributes, and generating Amazon S3 presigned URLs. For more information see the Handlebars section in the GitHub repository.