从过去的意图访问参数 Dialogflow Fulfillment
Access parameters from past intents Dialogflow Fulfillment
Intent example 1 Intent example 2 我正在尝试从过去的意图中访问不同的参数,但使用此代码它只会获取最后一个参数。最后一个触发 fulfillment 的 intent 是 'Dias20',它只会得到参数 'Dias20',其他的会报错 --> 'undefined'。我已经尝试了一切来检索上下文,然后是参数,但没有办法。这是一个树型对话,其中每个意图都有一个后续意图,输入上下文是最后一个意图并输出当前意图。
function CalcularScore(agent)
{
//coger los parametros
//var contextIn = agent.getContext('resp-followup');
const respiracion = agent.contexts['resp-followup'].parameters.Respiracion;
//const respiracion = agent.parameters.Respiracion;
const fiebre = agent.parameters.Fiebre;
const muco = agent.parameters.Muco;
const muscular = agent.parameters.Muscular;
const gastro = agent.parameters.Gastro;
const dias20 = agent.parameters.Dias20;
agent.add('tu score es: ' + respiracion );
}
根据您提供的信息,这可能有效:
let params = agent.getContext("resp-followup").parameters;
let respiracion = params.Respiracion;
如果这不起作用,请尝试像这样在先前的意图实现中设置上下文:
agent.setContext({ name: 'context_name', lifespan: 5, parameters: { param_name: agent.parameters.Respiracion}});
然后:
let params = agent.getContext("context_name").parameters;
let respiracion = params.param_name;
注意:将 context_name 和 param_name 替换为您喜欢的任何内容。此外,如果您愿意,可以根据以后需要数据的意图数量来延长寿命。
Intent example 1 Intent example 2 我正在尝试从过去的意图中访问不同的参数,但使用此代码它只会获取最后一个参数。最后一个触发 fulfillment 的 intent 是 'Dias20',它只会得到参数 'Dias20',其他的会报错 --> 'undefined'。我已经尝试了一切来检索上下文,然后是参数,但没有办法。这是一个树型对话,其中每个意图都有一个后续意图,输入上下文是最后一个意图并输出当前意图。
function CalcularScore(agent)
{
//coger los parametros
//var contextIn = agent.getContext('resp-followup');
const respiracion = agent.contexts['resp-followup'].parameters.Respiracion;
//const respiracion = agent.parameters.Respiracion;
const fiebre = agent.parameters.Fiebre;
const muco = agent.parameters.Muco;
const muscular = agent.parameters.Muscular;
const gastro = agent.parameters.Gastro;
const dias20 = agent.parameters.Dias20;
agent.add('tu score es: ' + respiracion );
}
根据您提供的信息,这可能有效:
let params = agent.getContext("resp-followup").parameters;
let respiracion = params.Respiracion;
如果这不起作用,请尝试像这样在先前的意图实现中设置上下文:
agent.setContext({ name: 'context_name', lifespan: 5, parameters: { param_name: agent.parameters.Respiracion}});
然后:
let params = agent.getContext("context_name").parameters;
let respiracion = params.param_name;
注意:将 context_name 和 param_name 替换为您喜欢的任何内容。此外,如果您愿意,可以根据以后需要数据的意图数量来延长寿命。