筛选常见问题
除了直接在常见问题聊天机器人中输入文本外,过滤问题还允许用户在预设流程中找到答案(类似于手机中的 IVRS)。 您可以将 FAQ 条目分类为 3(或更多)层,以便用户可以逐层选择类别,直到他们得到最终答案。
请确保您已输入“Category 1-3”和“Category 1-3 Priority”。 有关 FAQ 数据源格式的详细信息,请参阅此处.
预期结果?
- 用户经过3层过滤问题,最终得到过滤结果。
2.在后台,Stella根据FAQ数据源对这些问题进行排序。 Category 1-3 代表聊天机器人过滤问题 1-3 的选项。 选项的顺序基于Category 1-3 Priority。
FAQ 数据源格式
请参考一级程序 用于FAQ数据源格式。
动手实践
示例树结构
Create the 1st Tree Node - Category 1
创建第一个树节点 - 类别 1
在继续之前,您应该已经完成了 4.1 和 [4.2](https:// doc.stella.sanuker.com/docs/zh-CN/standard-procedures-FAQ-analytics/)(或 [4.3](https://doc.stella.sanuker.com/docs/zh-CN/standard-procedures-FAQ-nlp ) 可选) FAQ 程序。 您可以直接编辑四级树或复制一棵新树。
在四级树中创建一个树节点,并重命名为“Category 1”。
- 使用以下代码创建一个Pre-action,并将其重命名为“Save Category 1 Answers”。
return new Promise(async (resolve, reject) => {
try {
console.log("in Save Category 1 answers")
let result = await this.fetchDataFromDataSource({
collectionName: "Insert your Data Source ID here",
filter: {}
})
console.log("result", result)
result = this.lodash.uniqBy(result, "Category 1")
console.log("result", result)
result = this.lodash.reject(result, { "Category 1": "" })
console.log("result", result)
result = this.lodash.sortBy(result, "Category 1 Priority")
this.member.botMeta.tempData.currentAnswers = result.map(obj => obj["Category 1"])
this.member.botMeta.tempData.listLength = result.length
resolve({
member: this.member,
})
} catch (e) {
reject(e)
}
})
4.输入你从[一级]开始使用的FAQ数据源的数据源ID(https://doc.stella.sanuker.com/docs/zh-CN/standard-procedures-FAQ-tree- with-exact-keyword-match) 到上面的代码中。
- 在“Advanced”下创建一个Response,代码如下,重命名为“Category 1 Question”。
return new Promise((resolve) => {
let currentAnswers = this.member.botMeta.tempData.currentAnswers || []
let text = `Please input number to select🔢:\n`
currentAnswers.forEach((str, i) => {
let t = ""
switch (i + 1) {
case 1:
t = "1️⃣"
break
case 2:
t = "2️⃣"
break
case 3:
t = "3️⃣"
break
case 4:
t = "4️⃣"
break
case 5:
t = "5️⃣"
break
case 6:
t = "6️⃣"
break
case 7:
t = "7️⃣"
break
case 8:
t = "8️⃣"
break
case 9:
t = "9️⃣"
break
case 10:
t = "🔟️"
break
case 11:
t = "1️⃣1️⃣"
break
case 12:
t = "1️⃣2️⃣"
break
case 13:
t = "1️⃣3️⃣"
break
case 14:
t = "1️⃣4️⃣"
break
case 15:
t = "1️⃣5️⃣"
break
case 16:
t = "1️⃣6️⃣"
break
case 17:
t = "1️⃣7️⃣"
break
case 18:
t = "1️⃣8️⃣"
break
case 19:
t = "1️⃣9️⃣"
break
case 20:
t = "2️⃣0️⃣"
break
default:
}
text = `${text}\n${t} ${str}`
})
text = `${text}\n\nCan't find what you are looking for? Type keywords to ask Stella. You can also type *#* anytime to return to this menu.`
resolve({
type: "TEXT",
text,
})
})
6、可以编辑上面代码中text =
反引号内标注的过滤题内容(短信的页眉和页脚)。 ${text}
是指从 FAQ 数据源显示的类别 1 选项。
- 保存这个树节点。
创建第二个树节点 - 类别 2
- 选择 Category 1 树节点。 创建下一个树节点并将其重命名为“类别 2”。
- 使用以下条件和关系创建触发器:
第一个条件 - 输入文本:
this.messageEvent.type === "TEXT"
第二个条件 - 列表长度内的数字:
this.member.botMeta.tempData.listLength ? new RegExp("\\b" + [...Array(this.member.botMeta.tempData.listLength + 1).keys()].slice(1).join("\\b|\\b") + "\\b").test(this.messageEvent.data.text) : false
- 使用以下代码创建一个Pre-action,并将其重命名为“Save Category 1”。
return new Promise((resolve) => {
console.log("in Save FAQ Category 1")
if (/(\+)/i.test(this.messageEvent.data.text)) {
resolve()
} else {
let match = this.messageEvent.data.text.match(new RegExp("\\b" + [...Array(this.member.botMeta.tempData.listLength + 1).keys()].slice(1).join("\\b|\\b") + "\\b"))
let indexStr = match[0]
let index = parseInt(indexStr) - 1
let currentAnswers = this.member.botMeta.tempData.currentAnswers
let currentAnswer = currentAnswers[index]
this.member.botMeta.tempData.category1 = currentAnswer
resolve({ member: this.member })
}
})
- 使用以下代码创建第二个 Pre-action 并将其重命名为“Save Category 2 Answers”。
return new Promise(async (resolve, reject) => {
try {
console.log("in Save Category 2 Answers")
let result = await this.fetchDataFromDataSource({
collectionName: "Insert your Data Source ID here",
filter: {
"Category 1": this.member.botMeta.tempData.category1
}
})
console.log("result", result)
if (result.length === 1) {
this.member.displayAnswer = true
this.member.botMeta.tempData.faq = result[0]
resolve({ member: this.member })
} else {
result = this.lodash.uniqBy(result, "Category 2")
console.log("result", result)
result = this.lodash.reject(result, { "Category 2": "" })
console.log("result", result)
result = this.lodash.sortBy(result, "Category 2 Priority")
this.member.botMeta.tempData.currentAnswers = result.map(obj => obj["Category 2"])
this.member.botMeta.tempData.listLength = result.length
resolve({
member: this.member,
})
}
} catch (e) {
reject(e)
}
})
12.输入你从[一级]开始使用的FAQ数据源的数据源ID(https://doc.stella.sanuker.com/docs/zh-CN/standard-procedures-FAQ-tree-with-exact-keyword-match/#创建一个新的数据源) 到上面的代码中。
13.在“Advanced”下创建一个Response,代码如下,重命名为“Category 2 Question”。
return new Promise((resolve) => {
if (this.member.displayAnswer) {
resolve()
} else {
let currentAnswers = this.member.botMeta.tempData.currentAnswers || []
let text = `Do you want to know about ${this.member.botMeta.tempData.category1} ?\n`
currentAnswers.forEach((str, i) => {
let t = ""
switch (i + 1) {
case 1:
t = "1️⃣"
break
case 2:
t = "2️⃣"
break
case 3:
t = "3️⃣"
break
case 4:
t = "4️⃣"
break
case 5:
t = "5️⃣"
break
case 6:
t = "6️⃣"
break
case 7:
t = "7️⃣"
break
case 8:
t = "8️⃣"
break
case 9:
t = "9️⃣"
break
case 10:
t = "1️⃣0️⃣️"
break
case 11:
t = "1️⃣1️⃣"
break
case 12:
t = "1️⃣2️⃣"
break
case 13:
t = "1️⃣3️⃣"
break
case 14:
t = "1️⃣4️⃣"
break
case 15:
t = "1️⃣5️⃣"
break
case 16:
t = "1️⃣6️⃣"
break
case 17:
t = "1️⃣7️⃣"
break
case 18:
t = "1️⃣8️⃣"
break
case 19:
t = "1️⃣9️⃣"
break
case 20:
t = "2️⃣0️⃣"
break
default:
}
text = `${text}\n${t} ${str}`
})
text = `${text}\n\nCan't find what you are looking for? Type keywords to ask Stella. You can also type *#* anytime to return to this menu.`
resolve({
type: "TEXT",
text,
})
}
})
可以编辑上面代码中
text =
反引号内标注的过滤题内容(短信的页眉和页脚)。${text}
是指从 FAQ 数据源显示的类别 2 选项。${this.member.botMeta.tempData.category1}
显示用户选择的类别 1。切换“重定向”中的高级选项卡并粘贴以下代码:
return new Promise((resolve) => {
if (this.member.displayAnswer) {
resolve({
tree: this.node.tree,
nodeCompositeId: "Input the node composite ID of the filtering result tree node here",
runPreAction: false
})
} else {
resolve()
}
})
16.在上面输入过滤结果树节点的节点复合ID 代码。 您将能够在接下来的步骤中检索节点复合 ID。 记得稍后回来编辑。
- 保存这个树节点。
创建第三个树节点 - 类别 3
- 选择类别 2 树节点。 创建下一个树节点并将其重命名为“Category 3”。
- 使用您在 Step 9 树节点中创建的相同触发器。
- 使用以下代码创建一个Pre-action,并将其重命名为“Save Category 2”。
return new Promise((resolve) => {
console.log("in Save FAQ Category 2")
let match = this.messageEvent.data.text.match(new RegExp("\\b" + [...Array(this.member.botMeta.tempData.listLength + 1).keys()].slice(1).join("\\b|\\b") + "\\b"))
let indexStr = match[0]
let index = parseInt(indexStr) - 1
let currentAnswers = this.member.botMeta.tempData.currentAnswers
let currentAnswer = currentAnswers[index]
console.log("category2 ans", currentAnswer)
this.member.botMeta.tempData.category2 = currentAnswer
resolve({ member: this.member })
})
- 使用以下代码创建第三个 Pre-action 并将其重命名为“保存第 3 类答案”。
return new Promise(async (resolve, reject) => {
try {
console.log("in Save Category 3 Answers")
let result = await this.fetchDataFromDataSource({
collectionName: "Insert your Data Source ID here",
filter: {
"Category 1": this.member.botMeta.tempData.category1,
"Category 2": this.member.botMeta.tempData.category2,
}
})
console.log("result", result)
if (result.length === 1) {
this.member.displayAnswer = true
this.member.botMeta.tempData.faq = result[0]
resolve({ member: this.member })
} else {
result = this.lodash.uniqBy(result, "Category 3")
console.log("result", result)
result = this.lodash.reject(result, { "Category 3": "" })
console.log("result", result)
result = this.lodash.sortBy(result, "Category 3 Priority")
this.member.botMeta.tempData.currentAnswers = result.map(obj => obj["Category 3"])
this.member.botMeta.tempData.listLength = result.length
resolve({
member: this.member,
})
}
} catch (e) {
reject(e)
}
})
22.输入你从[一级]开始使用的FAQ数据源的数据源ID(https://doc.stella.sanuker.com/docs/en/standard-procedures-FAQ-tree-with-exact-keyword-match/#创建一个新的数据源) 到上面的代码中。
- 在“Advanced”下创建一个Response,代码如下,重命名为“Category 3 Question”。
return new Promise((resolve) => {
if (this.member.displayAnswer) {
resolve()
} else {
let currentAnswers = this.member.botMeta.tempData.currentAnswers || []
let text = `Do you want to know about ${this.member.botMeta.tempData.category2}?\n`
currentAnswers.forEach((str, i) => {
let t = ""
switch (i + 1) {
case 1:
t = "1️⃣"
break
case 2:
t = "2️⃣"
break
case 3:
t = "3️⃣"
break
case 4:
t = "4️⃣"
break
case 5:
t = "5️⃣"
break
case 6:
t = "6️⃣"
break
case 7:
t = "7️⃣"
break
case 8:
t = "8️⃣"
break
case 9:
t = "9️⃣"
break
case 10:
t = "1️⃣0️⃣️"
break
case 11:
t = "1️⃣1️⃣"
break
case 12:
t = "1️⃣2️⃣"
break
case 13:
t = "1️⃣3️⃣"
break
case 14:
t = "1️⃣4️⃣"
break
case 15:
t = "1️⃣5️⃣"
break
case 16:
t = "1️⃣6️⃣"
break
case 17:
t = "1️⃣7️⃣"
break
case 18:
t = "1️⃣8️⃣"
break
case 19:
t = "1️⃣9️⃣"
break
case 20:
t = "2️⃣0️⃣"
break
default:
}
text = `${text}\n${t} ${str}`
})
text = `${text}\n\nCan't find what you are looking for? Type keywords to ask Stella. You can also type *#* anytime to return to this menu.`
resolve({
type: "TEXT",
text,
})
}
})
24、可以编辑上面代码中text =
反引号内标注的过滤题内容(短信的页眉和页脚)。 ${text}
是指从 FAQ 数据源显示的 Category 3 选项。 ${this.member.botMeta.tempData.category2}
显示用户选择的类别 1。
- 切换“重定向”中的高级选项卡,并使用您在[步骤15](/docs/zh-CN/standard-procedures-FAQ-filtering-questions#创建第二棵树节点---类别2)。
26.在上面输入过滤结果树节点的节点复合ID代码。您将能够在接下来的步骤中检索节点复合 ID。记得稍后回来编辑。
- 保存这个树节点。
创建第四个树节点-过滤结果
- 选择 Category 3 树节点。 创建下一个树节点并将其重命名为“过滤结果”。
- 使用您在 Step 9 树节点中创建的相同触发器。
- 使用以下代码创建一个Pre-action,并将其重命名为“Save Category 3”。
return new Promise((resolve) => {
console.log("in Save FAQ Category 3")
let match = this.messageEvent.data.text.match(new RegExp("\\b" + [...Array(this.member.botMeta.tempData.listLength + 1).keys()].slice(1).join("\\b|\\b") + "\\b"))
let indexStr = match[0]
let index = parseInt(indexStr) - 1
let currentAnswers = this.member.botMeta.tempData.currentAnswers
let currentAnswer = currentAnswers[index]
this.member.botMeta.tempData.category3 = currentAnswer
resolve({ member: this.member })
})
- 使用以下代码创建第三个Pre-action,并将其重命名为“Save Filtering Result”。
return new Promise(async (resolve, reject) => {
try {
console.log("in Save Filtering Result")
let result = await this.fetchDataFromDataSource({
collectionName: "Insert your Data Source ID here"
filter: {
"Category 1": this.member.botMeta.tempData.category1,
"Category 2": this.member.botMeta.tempData.category2,
"Category 3": this.member.botMeta.tempData.category3,
}
})
console.log("result", result)
this.member.botMeta.tempData.faq = result[0]
resolve({
member: this.member,
})
} catch (e) {
reject(e)
}
})
32.输入你从[一级]开始使用的FAQ数据源的数据源ID(https://doc.stella.sanuker.com/docs/en/standard-procedures-FAQ-tree-with-exact-keyword-match/#创建一个新的数据源) 到上面的代码中。
33.在“Advanced”下创建一个Response,代码如下,重命名为“Show Selected Question Content”。
return new Promise((resolve, reject) => {
console.log("in Show Selected Question Content")
let result = this.member.botMeta.tempData.faq
console.log("result", result)
let response = {}
let type = result["Type"]
console.log("type", type)
switch (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":
case "Image with caption":
response.type = "IMAGE"
response.url = result.URL
response.text = result.Text
break
case "Video":
case "GIF":
case "File":
response.type = "FILE"
response.url = result.URL
response.text = result.Text
response.filename = result["File Name"]
break
case "Audio":
response.type = "AUDIO"
response.url = result.URL
break
case "Carousel":
response.type = "CAROUSEL"
response.carousel = [{
title: result.Text,
image_url: result.URL,
buttons: [{
type: "web_url",
title: result["Button title"],
url: result["Button url"],
}]
}]
break
case "Button":
response.type = "BUTTON"
response.text = result.Text,
response.buttons = [{
type: "web_url",
title: result["Button title"],
url: result["Button url"],
}]
break
default:
response = null
break;
}
console.log("response", response)
resolve(response)
})
- 保存并查看是否可以产生预期结果。