我们如何使用 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 库上,经过数小时的搜索,我找不到答案。