首页 文章

我们可以使用Dialogflow的节点实现库以编程方式设置和删除上下文,而不涉及UI吗?

提问于
浏览
1

使用Dialogflow的Node Fulfillment SDK,我认为可以通过编程方式设置和删除上下文,并从中提取参数 .

我正在尝试收集多个参数的值,并且它们可以多次传递到同一个意图 . 以下代码在intent处理程序中运行:

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"不包含上一次_512391中发送的内容 . 他们确实根据上下文解决了正确的意图 . 我究竟做错了什么?

我是否需要使用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' }

1 回答

  • 2

    您没有显示您的Intent是什么,但看起来第二次和第三次传递都是由具有 valueproduct 参数的Intent触发的 .

    如果一个参数是由Intent指定的,它会将一些东西(可能是一个空字符串)传递给webhook .

    它还将在当时处于活动状态的每个Context中设置该参数,并将这些上下文传递给webhook . 即使Context以前有一个为该参数设置的值 .

    为了确保您的值不被当前Intent践踏,您应该将它们作为参数存储在Context中的任何Intent参数名称未使用的参数名称下 .

相关问题