Exact Keyword Match
What is your Result?
- 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).
- Once matched with an FAQ entry, the chatbot will display the answer of the corresponding entry. (In this case, a text response.)
FAQ Data Source Format
The basic data source format should in be .CSV file format and includes the following items:
Items | Description | Required Since |
---|---|---|
Language | "Language" refers to the language of this FAQ entry | Level 1 |
Category 1-3 | The categories refer to the option displayed on the Category 1-3 filtering question. | Level 5 |
Category 1-3 Priority | Category Priority refers to the positional priority (Lower the value, higher the position) of the option displayed on the Category 1-3 filtering question | Level 5 |
Question ID | “Question ID” is a unique identifier for each entry. | Level 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 Stella 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 2 |
Analytics Category | Analytics Category refers to the unique analytics label for each FAQ entry. | Level 4.2 |
Analytics ID | Analytics ID refers to the analytics category for each FAQ entry. | Level 4.2 |
Keyword Group | The 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 |
Intent | "Intent" refers to the trained intent of an NLP engine on Google Dialogflow or Microsoft LUIS | Level 4.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 |
Text | “Text” is the chatbot textual answer of the FAQ entry. | Level 1 |
URL | “URL” refers to the multimedia link for the “Image”, “Video”, “GIF”, “File” & “Audio”. | Level 1 |
Preview | "Preview" refers to the link preview on WhatsApp text response. Set "TRUE" to display the preview. | Level 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 |
treeID | "treeID" refers to the tree that Stella should redirect user to. Please make sure "*Redirect" is chosen for message type. | Level 4.1 |
compositeID | "compositeID" refers to the compositeID of the tree node that Stella 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 4.1 |
You may download the sample FAQ data source in .CSV here.
Please note that format of quotation marks in the datasource must be " ", otherwise, the keyword group could not display as expected.
Getting Hands-on
Sample Tree Structure
Create a New Data Source
- Head to “Data Source” and select “+ New Data Source”.
- Name your new Data Source.
- Import your .CSV file by choosing the file, toggle on “Replace” & “Parse JSON”. You may download the sample FAQ data source in .CSV here.
Remember to toggle on "Parse JSON” in order to avoid possible error.
Toggle to "Append" if you want to add additional entries only; toggle to "replace" if you want to replace the whole data source.
- Copy the “Data Source ID” and save it for latter use in “collectionName” in the code later.
Create a Tree Node for FAQ Module
Head to a tree and create a tree node for the FAQ module.
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):
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({
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 })
})
})
- Create a transformed response in “Advanced” in this tree node for displaying the chatbot answer based on the matched entry with the following code:
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].Text
break
case "Video":
case "GIF":
case "File":
response.type = "FILE"
response.url = ans[0].URL
response.text = ans[0].Text
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
Create a global node for triggering the FAQ module in the same tree.
Set the Priority to "10" to make sure the global node can be triggered probably.
- Create a trigger in the global node with a pre-defined trigger as “Any Text”.
- Toggle on redirect to the FAQ tree node you created and save this global node.
Add Tree to Channels
Upon completion of the tree, head to "Channels".
Locate the channel you would like to deploy the tree, click "Edit".
Head to "Platform", and then "Tree Settings".
Select "+ New Tree", and pick the tree from the dropdown, remember to also select the global nodes. After that, select "Save" to complete adding the tree to channel.
Please remember to add trees to channel by repeating step 11-14 after building FAQ trees of other levels.
Check and see if you can produce the expected outcome.