使用 Dialogflow 的Node Fulfillment SDK,我认为可以以编程方式设置和删除上下文,并从其中提取参数。
我正在尝试收集多个参数的值,它们可以通过多次传递来实现相同的意图。以下代码在意图处理程序中运行:
contextParams = agent.context.get("seek-create-params-context").parameters;
currentParams = agent.parameters;
// merge will look for required params from both current and context
newParameters = merge(currentParams, contextParams);
agent.context.set({
name: "seek-create-params-context",
lifespan: 1,
parameters: newParameters
});
它提取在先前交互中传入的参数,将其与新可用的参数合并,并使用新的可用参数集重置上下文。
但是,现在,在每次传递中,“seek-create-params-context”不包含newParameters
上次发送的内容。他们确实根据上下文解决了正确的意图。我究竟做错了什么?
我是否需要摆弄 Dialogflow 的 UI 来发送上下文参数?
基于真实日志的示例交互(删除了不相关的参数):
/*
First pass:
User msg doesn't contain any of params `value` or `product`
*/
// agent.parameters:
{}
// agent.context.get('seeking-params-expense-create').parameters:
undefined
// outgoing 'seeking-params-expense-create' params (lifespan 1)
{ value: '', product: '' }
/*
Second pass:
So far, so good.
Next pass, we receive `value`, but not `product`.
*/
// agent.parameters:
{ value: 50, product: '' }
// agent.context.get('seeking-params-expense-create').parameters:
{
'value.original': '50',
'product.original': '',
value: 50,
product: ''
}
// outgoing 'seeking-params-expense-create' params (lifespan 1):
{ value: 50, product: '' }
/*
Third pass:
This time, we want to use `value` from context since we
stored in last pass and seek `product` from user.
User only supplies `product` this time.
*/
// agent.parameters:
{ value: '', product: 'MRT' }
// agent.context.get('seeking-params-expense-create').parameters:
{
'value.original': '',
'product.original': '',
product: 'MRT',
value: ''
}
// outgoing 'seeking-params-expense-create' params (lifespan 1):
{ value: '', product: 'MRT' }