Skip to main content

NLP for FAQ Chatbot

You can improve your FAQ chatbot's intelligence by integrating with natural language processing engines. If you do not have any idea on how to train the NLP engine or build a basic NLP chatbot, please check out these documentations: Google Dialogflow, LUIS & Basic NLP Chatbot Setup Procedure.

Please make sure you have input the "Intent" of the question entries correctly as reflected in your training agent/app from the NLP engine.


Expected Outcome

  1. WOZTELL will prioritize matching with an intent before escalating to keyword matching.
Example of FAQ Chatbot with NLP
Example of FAQ Chatbot with NLP
  1. In this way, when user types a sentence without matching any keywords in the FAQ data source, the system will still be able to send the user input to the NLP engine for analysis and finally, return the correct intent to WOZTELL for sending the corresponding response.
Matching Intent in FAQ Data Source
Matching Intent in FAQ Data Source

Sample Tree Structure

Tree Structure of FAQ Chatbot with NLP
Tree Structure of FAQ Chatbot with NLP

Create the 1st Tree Node - NLP Integration

  1. Before proceeding, you should have completed the level up to Step 2.1, Step 2.2 and the integration with Google Dialogflow or LUIS. You may edit the level four tree directly or duplicate a new tree.

  2. Create a tree node in the level four tree and rename is as "NLP Integration".

NLP Integration
NLP Integration
  1. Toggle on "NLP" and select the corresponding "Platform", "Integration" and "Locale" of your NLP integration.

  2. Save this tree node.


Create the 2nd Tree Node - Intents

  1. Select the tree node "NLP Integration" and add the next tree node.

  2. Rename it as "Intents".

  3. Create a trigger with the following sample code:

return this.messageEvent.type === "TEXT" && (this.messageEvent.dialogflow || this.messageEvent.luis)

NLP Trigger
NLP Trigger
  1. Create the pre-action for processing the intent in the FAQ data source below and rename it as "Handle Intents":
NLP Pre-action
NLP Pre-action
return new Promise(async (resolve, reject) => {
let dialogflowIntent = this.lodash.get(this.messageEvent, "dialogflow.intent.displayName")
console.log("Dialogflow Intent", dialogflowIntent)

const docs = await this.fetchDataFromDataSource({ channel: this.channel, collectionName: "Insert your Data Source ID here", filter: {} })
const ans = docs.filter((doc) => {
const datasourceIntent = this.lodash.get(doc, "Intent")
if (datasourceIntent === dialogflowIntent) {
console.log(datasourceIntent)
return doc
}
})
console.log("ans", ans)
this.lodash.set(this.member, "botMeta.tempData.faq", ans[0])
resolve({ member: this.member })
})
  1. Input the Data Source ID of the FAQ data source you have been using since here into the above code.
NLP Response
NLP Response
  1. Create the response for displaying the answer of the matched entry with the following code:
return new Promise(async (resolve, reject) => {
let result = this.member.botMeta.tempData.faq
let response = {}
console.log("response start", result)
if (result) {
switch (result.Type) {
case "Text":
response.type = "TEXT"
response.text = result.Text
if (result.Preview === true || result.Preview === "TRUE") {
response.preview_url = true
}
break
case "Image":
case "Image_Text":
response.type = "IMAGE"
response.url = result.URL
response.text = result.Caption
break
case "Video":
case "GIF":
case "File":
response.type = "FILE"
response.url = result.URL
response.text = result.Caption
response.filename = result["File Name"]
break
case "Audio":
response.type = "AUDIO"
response.url = result.URL
break
default:
response = null
break;
}
}
console.log("response", response)
resolve(response)
})
  1. Toggle on "Redirect" and paste the following code into the Advanced tab:
return new Promise((resolve) => {
let redirectAns = this.member.botMeta.tempData.faq
if (this.lodash.isEmpty(redirectAns)) {
resolve({
tree: this.node.tree,
nodeCompositeId: "Insert the FAQ Module node composite ID here",
runPreAction: true,
sendResponse: true,
runPostAction: true
})
}
})
Redirect to FAQ Module
Redirect to FAQ Module
  1. Input the node composite ID of the FAQ Module you have used to the above code. This is for redirecting to the FAQ Module in case there are no intents matched.

Edit the Global Node for FAQ Module

  1. Change the existing trigger with the following sample code:
return this.messageEvent.type === "TEXT" && this.messageEvent.dialogflow && !this.messageEvent.luis

No NLP Trigger
No NLP Trigger

First condition - Type Text:

  1. Toggle on Redirect and redirect to the NLP Integration tree node.
Redirect to NLP Integration
Redirect to NLP Integration
  1. Save the node. Test your chatbot and see if you can get the expected outcome.