在 Dialogflow ES 中,如何将参数值从一个意图保存到另一个意图?
In Dialogflow ES, how to save parameter value from one intent to another?
我有一个意图“购买汽车”,我会询问一些基本信息,例如颜色、尺寸、地区。这些保存在参数中。然后我触发另一个名为“TriggerBot”的意图,它将调用我的后端进程以通过履行来履行订单。如何将参数信息从一个意图传递到另一个意图?
这里我定义了Buy-Car intent中的参数:
这里我定义了 TriggerBot 意图:
这是我的实现代码:
function TriggerBot(agent) {
console.log("Parameters: "+JSON.stringify(agent.parameters));
const color = agent.parameters.color;
const size = agent.parameters.size;
const region = agent.parameters.region;
}
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));
let intentMap = new Map();
intentMap.set('Default Welcome Intent', Welcome);
intentMap.set('Default Fallback Intent', Fallback);
intentMap.set('Trigger Bot', TriggerBot);
agent.handleRequest(intentMap);
}
在这种情况下一切都是未定义的,但是如果我只使用一个意图,它就可以正常工作。因此,当从一个意图转移到另一个意图时,价值会丢失。
在 Dialogflow ES 的意图之间传递参数主要有 3 种方式
You can use follow-up intents to automatically set contexts for pairs of intents. A follow-up intent is a child of its associated parent intent.
后续意图有助于跟踪对话中发生的事情。它们还可以帮助您在意图之间传递参数。
- 使用会话变量
声明一个叫做 session variable in each of your Dialogflow entry intents 的东西。
这有一个额外的好处,即即使对话出现意外转变,也能够在意图之间传递参数。
- 使用上下文
另一个 Whosebug 线程中描述了它 - How to save data between conversations in Dialogflow?。
此外,我认为您还可以在以下链接中找到一些其他信息
- Sending parameter value from one intent to another and assign it to parameter
- 3 ways to pass parameters between intents in Dialogflow ES
根据 PjoterS 的回答,我能够使用 Context 让它工作:
我首先在“Buy-Car”意图中设置输出上下文:
然后我在“TriggerBot”输入意图中得到它:
然后我访问处理程序中的值:
函数 TriggerBot(代理){
const color = agent.contexts[0].parameters.color;
常量大小 = agent.contexts[0].parameters.size;
const 区域 = agent.contexts[0].parameters.region;
}
我有一个意图“购买汽车”,我会询问一些基本信息,例如颜色、尺寸、地区。这些保存在参数中。然后我触发另一个名为“TriggerBot”的意图,它将调用我的后端进程以通过履行来履行订单。如何将参数信息从一个意图传递到另一个意图?
这里我定义了Buy-Car intent中的参数:
这里我定义了 TriggerBot 意图:
这是我的实现代码:
function TriggerBot(agent) {
console.log("Parameters: "+JSON.stringify(agent.parameters));
const color = agent.parameters.color;
const size = agent.parameters.size;
const region = agent.parameters.region;
}
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));
let intentMap = new Map();
intentMap.set('Default Welcome Intent', Welcome);
intentMap.set('Default Fallback Intent', Fallback);
intentMap.set('Trigger Bot', TriggerBot);
agent.handleRequest(intentMap);
}
在这种情况下一切都是未定义的,但是如果我只使用一个意图,它就可以正常工作。因此,当从一个意图转移到另一个意图时,价值会丢失。
在 Dialogflow ES 的意图之间传递参数主要有 3 种方式
You can use follow-up intents to automatically set contexts for pairs of intents. A follow-up intent is a child of its associated parent intent.
后续意图有助于跟踪对话中发生的事情。它们还可以帮助您在意图之间传递参数。
- 使用会话变量
声明一个叫做 session variable in each of your Dialogflow entry intents 的东西。
这有一个额外的好处,即即使对话出现意外转变,也能够在意图之间传递参数。
- 使用上下文
另一个 Whosebug 线程中描述了它 - How to save data between conversations in Dialogflow?。
此外,我认为您还可以在以下链接中找到一些其他信息
- Sending parameter value from one intent to another and assign it to parameter
- 3 ways to pass parameters between intents in Dialogflow ES
根据 PjoterS 的回答,我能够使用 Context 让它工作:
我首先在“Buy-Car”意图中设置输出上下文:
然后我在“TriggerBot”输入意图中得到它:
然后我访问处理程序中的值:
函数 TriggerBot(代理){ const color = agent.contexts[0].parameters.color; 常量大小 = agent.contexts[0].parameters.size; const 区域 = agent.contexts[0].parameters.region; }