【问题标题】:Access parameters from past intents Dialogflow Fulfillment从过去的意图访问参数 Dialogflow Fulfillment
【发布时间】:2020-03-31 10:23:28
【问题描述】:

Intent example 1 Intent example 2 我正在尝试从过去的意图中访问不同的参数,但是使用此代码它只会获取最后一个参数。触发实现的最后一个意图是“Dias20”,它只会获取参数“Dias20”,其他的会引发错误-->“未定义”。我已经尝试了一切来检索上下文,然后是参数,但没有办法。这是一个树型对话,其中每个意图都有一个后续意图,输入上下文是最后一个意图,并输出当前意图。

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 );

 }

【问题讨论】:

  • 虽然您将 Intent 描述为使用 Followup Intent,但如果您可以更新您的问题以包含确切 Intent 的屏幕截图以显示输入和输出上下文以及每个一。您在问题中提供的信息越多,我们为您提供帮助的机会就越大。有关更多指南,请参阅 How do I ask a good question

标签: node.js dialogflow-es


【解决方案1】:

根据您提供的信息,这可能会起作用:

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 替换为您喜欢的任何内容。此外,如果您愿意,您可以根据以后需要数据的意图数量来延长使用寿命。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多