A PoV on Zero-Maintenance QnA Chatbot

Tanmoy Sengupta
Voice Tech Podcast
Published in
8 min readJul 21, 2019

Introduction

According to a forecast by Juniper Research, organizations in different sectors such as banking, finance, healthcare, travel, retail, e-commerce etc. are expected to achieve cost savings of over $8 billion per annum by 2022, thanks to use of chatbots. The rise in the maturity of chatbot applications along with machine learning has created a new angle to approach personalized and engaging customer experiences. Chatbots represent the ultimate culmination of content accessibility and personalization effort.

However, a major drawback of the existing approach of bot development is that it works in silos and not integrated with the content management system (CMS). Hence the same content needs to be created or written twice, once for the CMS and then for the bot (to train it with the knowledgebase from the content). This defeats the “Create Once, Publish Everywhere” principle for content distribution, and also creates additional operational overhead. Additionally, the bot needs to be retrained with the latest content every time there is change in content.

To address these problems, we first need to make the content “single-source” in the CMS, and then integrate the chatbot platform with the CMS, so that the latest content flows automatically from the CMS to the bot. When we single-source the content this way, the content becomes ready for other interaction channels like Interactive Voice Response (IVR), Augmented Reality (AR) and Virtual Reality (VR).

This blog proposes a solution to the above problems via real time content integration between the CMS and an informational chatbot (e.g. QnA/FAQ chatbot). That is, whenever new QnA or FAQ content is created or updated or deleted in the CMS, the latest content (knowledgebase for the bot) is automatically pushed to the bot platform. The QnA bot is then automatically trained with the content and can respond to the customer queries with the latest content via the client channel (e.g. web chat, text/SMS, Skype, Messenger, etc.). This solution completely eliminates the time-consuming manual process of retraining and republishing a QnA bot whenever its underlying knowledgebase is changed in the CMS, thus eliminating maintenance overhead and saving time and cost for the Enterprise.

A reference architecture and detailed implementation of the proposed solution will also be discussed in detail.

Solution Overview

The below diagram is a pictorial representation of the solution.

Fig. 1: Block Diagram of the Proposed QnA Chatbot Solution

· The solution leverages the “webhook” support offered by most modern CMS platforms, in some form or other (e.g. Event I/O based webhooks in Adobe Experience Manager, webhooks on events such as updating/publishing contents in Episerver and Kentico CMS, and so on).

· The webhook receiver can be any function which subscribes or listens to the webhook and gets executed as soon the webhook URL posts the latest content data from the CMS. A typical example of such function is the Serverless “Function as a Service (FaaS)” provided by all major cloud platforms, such as Lambda Functions in AWS and Functions in Microsoft Azure.

· The function processes this data to generate the training data appropriate for the bot. The data format may differ from Bot platform to platform (e.g. JSON file for Amazon Lex and TSV/Excel for Microsoft QnA Maker). The function then programmatically retrains and republishes the Bot by using the Bot SDK or Bot development API.

· This way, the bot remains auto-synced the with the latest QnA knowledgebase from the CMS and hence the QnA bot client can respond to any new or updated questions as soon as they are added/modified in the CMS. It makes the bot truly maintenance-free in respect to updating the knowledgebase, retraining and republishing to make it remain in sync with the underlying content source.

Reference Architecture

Fig. 2: Architecture Diagram of the Reference Implementation of the “Zero-Maintenance” Chatbot Solution

The reference architecture of the solution is based on the following building blocks:

Kentico Cloud:

This is the CMS platform which stores the QnA knowledgebase as question and answer pairs. It publishes a Webhook URL for the event of QnA content publish after the content is changed (e.g. QnA pairs are modified or deleted or new QnAs added).

Microsoft Azure Logic App:

This is the Serverless service acting as the Webhook receiver. Azure logic app is typically used for creating workflows and writing some built-in logic such as condition checking but it does not support custom logic. The logic app listens to HTTP requests and checks if the posted URL is for the publish event of the appropriate content from the CMS.

Azure Function:

This is another Serverless service from Azure which supports custom coding in C#, JavaScript, etc. The function is invoked by the Logic App to execute custom C# code programmatically train and publish the latest QnA content data (obtained from the Webhook) to a Microsoft QnA Maker knowledgebase.

Microsoft QnA Maker:

This is part of Microsoft Cognitive Services to create, train and publish QnA knowledgebase from various sources like a TSV/Excel/Word/PDF file containing questions and answers and even from an FAQ page URL. The Azure Function calls the programming API of QnA Maker to replace the old knowledgebase with latest content, and then train and publish the new QnA knowledgebase.

Azure Bot Service:

It is the Bot service from Azure and it leverages the updated knowledgebase from QnA Maker API to create the QnA bot.

Bot Client:

This is a web-embedded chatbot client (built on HTML, CSS and jQuery), which basically calls the Bot Service to respond to user’s queries.

Build better voice apps. Get more articles & interviews from voice technology experts at voicetechpodcast.com

Reference Implementation

A step by step implementation of the solution based on the above reference architecture is described below.

1. Create Microsoft Azure and Kentico Cloud accounts if not already present (trial subscription/account will do).

2. Create a new Content Type in the Kentico Cloud portal and add a Rich Text content element to it.

3. Add content item by writing QnA pairs (a question and its answer separated by a line break) to the content type. QnA pairs should be separated by two line breaks. Once done, publish the content on Kentico Cloud.

4. Each published content will have a Project ID which can be obtained from the Project Settings page. It will also have a content item name which is also called Codename.

5. The Content Delivery API for retrieving the published content would be of the following format:

https://deliver.kenticocloud.com/ + Project ID + Codename

6. Create a QnA Maker service on the Azure portal. Note down the Key and the base URL of the service (https://westus.api.cognitive.microsoft.com/qnamaker/v4.0).

[More details: https://docs.microsoft.com/en-us/azure/cognitive-services/qnamaker/how-to/set-up-qnamaker-service-azure]

7. Log in to the QnA Maker portal (www.qnamaker.ai) with your Microsoft credentials (same credentials used for Azure portal). Create an empty Knowledgebase (without adding any QnA pair) by specifying the Azure QnA Maker service name and publish the knowledgebase. Note down the sample HTTP request for QnA Maker service. This will be required to build the bot later.

[More details:

https://docs.microsoft.com/en-us/azure/cognitive-services/qnamaker/quickstarts/create-publish-knowledge-base]

8. Create an HTTP request based Azure Logic App on the Azure Portal. The webhook from Kentico Cloud project will trigger this Logic App. The JSON schema of the webhook POST request body will be like below:

{

“properties”: {

“data”: {

“properties”: {

“items”: {

“items”: {

“properties”: {

“codename”: {

“type”: “string”

},

“language”: {

“type”: “string”

},

“type”: {

“type”: “string”

}

},

“required”: [

“language”,

“codename”,

“type”

],

“type”: “object”

},

“type”: “array”

},

“taxonomies”: {

“items”: {

“properties”: {

“codename”: {

“type”: “string”

}

},

“required”: [

“codename”

],

“type”: “object”

},

“type”: “array”

}

},

“type”: “object”

},

“message”: {

“properties”: {

“api_name”: {

“type”: “string”

},

“id”: {

“type”: “string”

},

“operation”: {

“type”: “string”

},

“project_id”: {

“type”: “string”

},

“type”: {

“type”: “string”

}

},

“type”: “object”

}

},

“type”: “object”

}

9. Note down the incoming HTTP POST URL for the Logic App. This will be our Webhook URL.

10. Create a Webhook for the Kentico project from the project settings and use the above URL as the URL address for the webhook.

11. Add logic in the Logic App workflow to verify if the webhook was fired due to a content publish event on the Kentico Cloud and the content type was the same created in step 2. If yes, then it calls an Azure Function by HTTP POST with the Codename obtained from the webhook’s post data in the request body.

12. Create an HTTP trigger based Azure Function. This will be triggered by HTTP request from the Logic App and mainly performs the automation of chatbot with respect to auto-syncing and auto-training with latest QnAs.

i) The function first retrieves the Kentico Cloud content’s Codename from the request body.

Make sure to update the QnA Maker API subscription key, Kentico cloud Project ID and knowledge base ID.

ii) Then it calls the Kentico Cloud’s Content Delivery API (concatenating the Kentico host URI, project id, method (“items”) and item’s Codename to retrieve the latest content. Make sure to set the message header “X-KC-Wait-For-Loading-New-Content” to “true” in the request to force get latest content.

iii) Then it extracts the QnA from the content by parsing the result from the API call and creating appropriate JSON structure expected by the QnA Maker REST API for updating knowledgebase.

iv) Then it calls the QnA Maker REST API for updating knowledgebase with the JSON data containing latest QnA and next calls the API for publishing the knowledgebase.

13. Create an Azure Bot Service (Web App Bot) based on the QnA template, using the previously created QnA Maker service’s details in app settings.

14. From the Bot’s Channel settings on Azure portal, create a Web Chat channel and copy the bot embed code.

15. Create a sample HTML page as the host page for the web-embedded bot client. Use the bot embed code within an iframe in the HTML, which will be chatbot window for the end users.

16. Finally, to test the solution:

i) Launch the web chat client HTML page in browser.

ii) Type an existing question (with word rephrase keeping the meaning intact, if you want) from the FAQ content on Kentico Cloud in the chat window and hit Enter or send. The correct response appears in the chat window.

iii) Type an unknown question (not present in CMS) and hit Enter. Response says nor matching answer found.

iv) Add the same unknown question with its answer in the FAQ content on Kentico Cloud. Publish the changes.

v) On asking the newly added question on chat window, it now responds with appropriate answer from the CMS.

vi) Now explore further by modifying/deleting QnA on the CMS and same should immediately reflect on the chatbot client.

Caveats & Constraints

· The underlying CMS platform must support Webhooks or similar event-based pub-sub model. Otherwise, real time data syncing is not possible, and we need to resort to polling or scheduled job kind of solution to retrieve the latest content at certain intervals.

· Multimedia, such as images and videos, are not supported as part of QnAs.

· If the CMS has content from multiple languages, need to create a separate QnA Maker knowledgebase and service for each language.

--

--