1

我们如何使用 DialogFlow Fulfillment 库更新参数值?我编写了一个辅助方法来访问代理的上下文并循环更新值,但这似乎不起作用:

export const dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
    const wbhc = new WebhookClient({ request, response });

    function testIntentHandler(agent: any) {
        const date = agent.parameters['date'];
        const datePeriod = agent.parameters['date-period'];

        if (date && !datePeriod) {
            setDialogFlowParameter('date-period', {
                startDate: date,
                endDate: date
            }, agent.context);
        }

        agent.add("I've set the value");
    }

    // Run the proper function handler based on the matched Dialogflow intent name
    const intentMap = new Map();
    intentMap.set('TestIntent', testIntentHandler);
    wbhc.handleRequest(intentMap);
});

function setDialogFlowParameter(param: string, val: any, context: any) {
    const contexts = context.contexts;
    const keys = Object.keys(contexts);

    for (const key of keys) {
        const c = context.get(key);
        c.parameters[param] = val;
        context.set(key, c.lifespan, c.parameters);
    }
}

请注意,这个问题集中在 NodeJS dialogflow-fulfillment 库上,经过数小时的搜索,我找不到答案。

4

1 回答 1

1

您是否在 Dialogflow 控制台的“诊断信息”中查看了 FULFILLMENT RESPONSE 选项卡的输出上下文属性?使用 agent.context.set() 方法并更新参数值后,您应该能够看到那里的值。

于 2019-02-21T08:14:47.823 回答