我正在使用内联编辑器中提供的默认 dialogflow 代码,基于 dialogflow-fulfillment ^0.5.0 来整理通过几个后续意图给出的所有参数。我有一个设置,其中后续意图提出问题,从而产生一个包含所有问题的最终意图。
从对话流控制台内的先前意图中提取数据以包含在响应中将仅使用即 #order-cream-followup.chocolate-type
从以前的意图或 $quantity
获取参数从当前意图获取参数。但同时 agent.parameters['quantity']
像 $quantity
,我找不到相当于 #order-cream-followup.chocolate-type
的方法在对话流实现中
抱歉,如果这是一个明显的答案,我会在各种不同的文档中迷失方向,这些文档通常在 google 上进行。
我的代码:(目前只是在添加代码来处理推送数据之前登录到控制台)
// See https://github.com/dialogflow/dialogflow-fulfillment-nodejs
// for Dialogflow fulfillment library docs, samples, and to report issues
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
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 placeOrder(agent) {
console.log('placing order:');
console.log(agent.context.get('order-cream-followup').parameters['choctype']);
agent.add('Thanks ' + agent.parameters['name'] + ', please collect your order from the window.');
}
// Run the proper function handler based on the matched Dialogflow intent name
let intentMap = new Map();
intentMap.set('order - cream - marshmallow - check - yes - name - submit', placeOrder);
agent.handleRequest(intentMap);
});
最佳答案
要获得仍处于事件状态的上下文(即 - 它的 lifespanCount
尚未达到 0),您可以使用 agent.context.get()
.所以你的例子看起来像
agent.context.get('order-cream-followup').params['chocolate-type']
(这是在库的 0.6.0 版中引入的。)
但是……这要求上下文仍然有效。如果您使用 Followup Intents(可能会变得困惑),则生命周期最初仅设置为 2,因此它们可能已过期。
你应该做两件事:
关于dialogflow-es - 在 dialogflow-fulfillment 中访问先前的跟进意图参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53156526/