dialogflow-es - 使用履行向后续意图添加回退的问题
问题描述
我们正在用 mysql 制作一个聊天机器人。我们想为每个意图做一个后备,但它不起作用。
我们看到了这个视频(youtube)并应用了它。但它在后续意图中不起作用。
代码
└>Code_Ship
这是我们的意图结构。
即使添加了否定答案而不是 Code_Ship 中的期望答案,也会重复来自 Code_Ship 的问题。
这种方法不起作用,所以我正在修改 index.js 文件以实现。
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
const mysql = require('mysql');
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
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));
function welcome(agent) {
agent.add(`Welcome to my agent!`);
}
function fallback(agent) {
agent.add(`I didn't understand`);
agent.add(`I'm sorry, can you try again?`);
}
function queryShipCode(connection){
return new Promise((resolve,reject)=>{
connection.query('SELECT *FROM ShipCode',(error,results,fields)=>{
resolve(results);
});
});
}
function handleCode(agent){
agent.setContext({
name: 'first-call',
lifespan: 2,
});
}
function handleCode_Ship(agent){
agent.getContext('first-call');
const ShipCode_shipname = agent.parameters.shipname;
return connectToDatabase()
.then(connection => {
return queryShipCode(connection)
.then(result => {
console.log(result);
result.map(ShipCode => {
if(ShipCode_shipname === ShipCode.name){
agent.add(`ShipCode : ${ShipCode.code} , ShipName : ${ShipCode.name}`);
}else if(ShipCode_shipname !== ShipCode.name){
agent.add(`Sorry. I didn't understand.`);
}
});
connection.end();
});
});
}
这些是我们代码的一部分。
我不能尝试使用agent.add( Sorry. I didn't understand.
); 在 handleCode_Ship() 中。我不能使用这种方法(否则)?
我们不擅长对话流。请告诉我们。
解决方案
推荐阅读
- xml - 定位标签 MESSAGE_RECORD/InsertChange/Bonglinjer/Bonglinje/sumDiscountedPrice/BelopFelt
- sublime-text-plugin - 处理文件夹中的每个视图/文件
- docker - 未通过 ZAP API 扫描 docker 映像进行身份验证
- reactjs - 如何在 Ant 设计 React 中使用地图动态呈现选项卡
- java - 如何在不暂停 GUI 的情况下在命令之前添加延迟 - JAVA
- next.js - 我可以在路由器返回 Next.js 后执行回调函数吗?
- javascript - 如何在反应式中使用剪贴板?
- python - 玛雅脚本选择一个频道?
- javascript - 等待 fs.promises 列表
- git - windows下通过cmd独立调用git-credential-manager-core.exe?