dialogflow-es - 在 DialogFlow 中添加对知识库的附加链接响应
问题描述
借助 DialogFlow 中的知识库,您可以上传基本的常见问题解答。第一列是问题,第二列是答案。通常我们需要让答案提供额外的链接。例如,“你的问题的答案是否定的,菠萝不适合做披萨”。更多信息
我想提供的是答案,后面是丰富的响应链接。由于电子表格中不能有第三列来添加链接,我怎样才能干净地做到这一点?当然,我可以将链接作为答案文本的一部分,但这并不那么漂亮。
我能够复制这个问题,然后提供一个链接作为第二个答案(即 $Knowledge.Answer(2)),但是有些答案没有链接,我不能让它成为有条件的。
我假设我可以在 Fulfillment 中执行此操作,但我不确定可以返回答案 ($Knowledge.Answer(1)) 的实际代码,然后有条件地添加带有链接的丰富响应。
解决方案
我终于解决了。
首先,我在回答中使用了一些分隔符(这里只是“Z$Z”)。
例如,在 csv 文件中,我将以下内容放在第二列中:
你的问题的答案是否定的,菠萝不吃披萨$Z$更多信息$Z$https://www.mashed.com/183299/the-most-controversial-pizza-toppings-explained/
这样,当我得到满足时,我就可以解析答案。这是代码的一部分:
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
// save off the answer to parse
let answer = JSON.stringify(request.body.queryResult.fulfillmentText);
function faqHandler(agent) {
let answerAlt = answer.slice(1,-1); // remove first and last double quote
let answerParse = answerAlt.split("Z$Z"); // parse the answer
if( answerParse.length == 1) {
// no links
agent.add(answerParse[0].toString());
} else {
// display the content with the text and links
// you can use different ways here to display but you have access to
// the answer, title, and url as follows
// answerParse[0].toString(), answerParse[1].toString(), answerParse[1].toString()
}
}
...
intentMap.set('Knowledge.KnowledgeBase.ID_OF_KNOWLEDGEBASE',faqHandler);
推荐阅读
- apache-camel - 在 http4-component 范围内完成交换
- javascript - 如何从对象数组创建的 html 列表中删除逗号?
- r - 重复代码,需要帮助创建函数格式并在数据框中创建新列
- javascript - 在 ReactJS 中合并相同的键
- depth-first-search - llist out of index range。我的代码所属的实际问题请参考以下链接
- arrays - C中的全数组长度
- html - html的所有其他页面的页眉和页脚合并
- python - 安装深度学习框架(Caffe)时遇到错误
- reactjs - 导入反应给出这个错误';' 预期.ts(1005)
- authentication - 登录时使用令牌真的是无状态的吗?