Skip to main content

Exact Keyword Match

Expected Outcome

  1. When user types the question (e.g. How much time do you need to build a WhatsApp chatbot?), the FAQ module will scan the entire data source to see if there is an exact match in the keyword group(s).
Example of FAQ Chatbot Data source
Example of FAQ Chatbot Data source
  1. Once matched with an FAQ entry, the chatbot will display the answer of the corresponding entry. (In this case, a text response.)
Example of FAQ Chatbot
Example of FAQ Chatbot

FAQ Data Source Format

Example of FAQ Chatbot Data source
Example of FAQ Chatbot Data source

The basic data source format should in be .CSV file format and includes the following items:

ItemsDescriptionRequired Since
Language"Language" refers to the language of this FAQ entryLevel 1.1
CategoryThe categories refer to the option displayed on the Category filtering question.Level 3.1
Category PriorityCategory Priority refers to the positional priority (Lower the value, higher the position) of the option displayed on the Category filtering questionLevel 3.1
Question ID“Question ID” is a unique identifier for each entry.Level 1.1
Question“Question” is for your own reference at this stage. It is a standard sample question you expect the users to ask. For instance, “What is the price for Product A?”

However, if you categorize your FAQs and display them in the form of a list (on WOZTELL Web Chat only), a set of filtering questions (WhatsApp) or in a carousel (Facebook), then the “Question” you have set will be displayed to allow the users to choose from.
Level 1.2
Analytics CategoryAnalytics Category refers to the unique analytics label for each FAQ entry.Level 2.2
Analytics IDAnalytics ID refers to the analytics category for each FAQ entry.Level 2.2
Keyword GroupThe keyword groups consist of keywords to be searched/matched with user input. You can input multiple variations/synonyms of the keyword. For instance, if you expect users to ask about your product’s pricing, putting “pricing”, “price” or “cost” into the data source will make sense. The format will be [“pricing”,”price”,”cost”]. The words between quotation marks share an “OR” relationship.

You may also set multiple keywords per entry. The relationship between different keyword groups is “AND”. This means that the user's input must match all keyword groups of an entry in order for the chatbot to reply with the corresponding answer. With more keyword groups per entry, you provide more context to the system. (However, this also means that this entry is harder to trigger.)

For example, if the user is asking about "What is the price for Product A?", you may set up keyword group 1 as [“Product A”] & keyword group 2 as [“price”]. You may do the same for Product B, Product C…Product N. Then, each chatbot answer will be replying to a specific product.
Level 1.1
Intent"Intent" refers to the trained intent of an NLP engine on Google Dialogflow or Microsoft LUISLevel 2.3
Type“Type” is the type of message responses of your answer. For this standard procedure, the type: "Text", "Image", "Video", "GIF", "File", "Audio" & "Redirect" are supported. Please make sure you have the correct type.Level 1.1
Text“Text” is the chatbot textual answer of the FAQ entry.Level 1.1
URL“URL” refers to the multimedia link for the “Image”, “Video”, “GIF”, “File” & “Audio”.Level 1.1
Preview"Preview" refers to the link preview on WhatsApp text response. Set "TRUE" to display the preview.Level 1.1
Caption"Caption" refers to the caption text of a WhatsApp image. Please make sure "URL" is filled with an image link before inputting the caption.Level 1.1
treeID"treeID" refers to the tree that WOZTELL should redirect user to. Please make sure "*Redirect" is chosen for message type.Level 2.1
compositeID"compositeID" refers to the compositeID of the tree node that WOZTELL should redirect user to. You may locate this information in here of a tree node. Please make sure "*Redirect" is chosen for message type.Level 2.1

You may download the sample FAQ data source in .CSV here.

tip

Please note that format of quotation marks in the datasource must be " ", otherwise, the keyword group will not display as expected.


Sample Tree Structure

Tree Structure of FAQ Chatbot with Exact Keyword Match
Tree Structure of FAQ Chatbot with Exact Keyword Match

Create a New Data Source

  1. Head to “Data Source” and select “+ New Data Source”.
Add a New Data Source
Add a New Data Source
  1. Name your new Data Source.
Name the New Data Source
Name the New Data Source
  1. Import your .CSV file by choosing the file, toggle on “Replace” & “Parse JSON”. You may download the sample FAQ data source in .CSV here.
tip

Remember to toggle on "Parse JSON” in order to avoid possible error.

Import the Data Source File
Import the Data Source File
tip

Toggle to "Append" if you want to add additional entries only; toggle to "replace" if you want to replace the whole data source.

  1. Copy the “Data Source ID” and save it for latter use in “collectionName” in the code later.
Save Data Source ID
Save Data Source ID

Create a Tree Node for FAQ Module

  1. Head to a tree and create a tree node for the FAQ module.

  2. Create a pre-action (this is for handling the exact keyword matching logic) in this tree node with the following code (Remember to apply the Data Source ID to collectionName in the code):

Create Pre-actions
Create Pre-actions
return new Promise((resolve, reject) => {
console.log("in Save FAQ temp ans")
let text = this.messageEvent.data.text
text = text.replace(/\r\n|\r|\n/g, "")
text = text.replace(/(\/|\.|\*|\?|\+)/g, "")

function genKeywordsRegex(keywords, text) {
// return "/(" + keywords.join("|") + ")/i.test('" + text + "')"
let regex = new RegExp("(" + keywords.join("|") + ")", "i")
return regex.test(text)
}

this.fetchDataFromDataSource({ channel: this.channel, collectionName: "enter the Data Source ID here", filter: {} }).then((result) => {
console.log("length", result.length);
const ans = result.filter((doc) => {
if (this.lodash.isArray(doc["Keyword Group 1"]) && this.lodash.get(doc, "Keyword Group 1.length") && this.lodash.isArray(doc["Keyword Group 2"]) && this.lodash.get(doc, "Keyword Group 2.length") && this.lodash.isArray(doc["Keyword Group 3"]) && this.lodash.get(doc, "Keyword Group 3.length") ) {
const regex1 = genKeywordsRegex(doc["Keyword Group 1"], text)
const regex2 = genKeywordsRegex(doc["Keyword Group 2"], text)
const regex3 = genKeywordsRegex(doc["Keyword Group 3"], text)
console.log("current doc (3 keyword group)", doc["Question ID"])
return regex1 && regex2 && regex3
} else if (this.lodash.isArray(doc["Keyword Group 1"]) && this.lodash.get(doc, "Keyword Group 1.length") && this.lodash.isArray(doc["Keyword Group 2"]) && this.lodash.get(doc, "Keyword Group 2.length")) {
const regex1 = genKeywordsRegex(doc["Keyword Group 1"], text)
const regex2 = genKeywordsRegex(doc["Keyword Group 2"], text)
console.log("current doc (2 keyword group)", doc["Question ID"])
return regex1 && regex2
} else if (this.lodash.isArray(doc["Keyword Group 1"]) && this.lodash.get(doc, "Keyword Group 1.length")) {
const regex1 = genKeywordsRegex(doc["Keyword Group 1"], text)
console.log("current doc (1 keyword group)", doc["Question ID"])
return regex1
} else {
return false
}
})
console.log("ans", ans)
this.lodash.set(this.member, "botMeta.tempData.faqAns", [])
this.lodash.set(this.member, "botMeta.tempData.faqAns", ans)
// this.member.botMeta.tempData.faqAns = ans
resolve({ member: this.member })
})
})

  1. Create a transformed response in “Advanced” in this tree node for displaying the chatbot answer based on the matched entry with the following code:
Transform Response
Transform Response
 return new Promise((resolve, reject) => {
console.log("in FAQ Keyword")
let ans = this.member.botMeta.tempData.faqAns || []
console.log("ans", ans)
if (ans.length >= 1) {
let response = {}
switch (ans[0].Type) {
case "Text":
response.type = "TEXT"
response.text = ans[0].Text
if (ans[0].Preview === true || ans[0].Preview === "TRUE") {
response.preview_url = true
}
break
case "Image":
case "Image_Text":
response.type = "IMAGE"
response.url = ans[0].URL
response.text = ans[0].Caption
break
case "Video":
case "GIF":
case "File":
response.type = "FILE"
response.url = ans[0].URL
response.text = ans[0].Caption
response.filename = ans[0]["File Name"]
break
case "Audio":
response.type = "AUDIO"
response.url = ans[0].URL
break
default:
response = null
break;
}
resolve(response)
} else {
resolve({
type: "TEXT",
text: "Sorry, we don't have the answer for you at the moment. You may try to ask us in another way or reach our support team at hello@sanuker.com."
})
}

}

)

Create a Global Node for FAQ Module

  1. Create a global node for triggering the FAQ module in the same tree.

  2. Create a trigger in the global node with a pre-defined trigger as “Any Text”.

Create Trigger
Create Trigger
Create Any Text Trigger
Create Any Text Trigger
  1. Toggle on redirect to the FAQ tree node you created and save this global node.
Redirect to FAQ Tree Node
Redirect to FAQ Tree Node
  1. Test your chatbot and see if you can get the expected outcome!