Using Dialogflow's Node Fulfillment SDK, I thought one could programmatically set and delete contexts, and extract parameters from within them.
I'm trying to collect values for multiple parameters, and they can come in on multiple passes to the same intent. The following code runs within the intent handler:
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
});
It extracts the params that were passed in on the previous interaction, merges it with the newly available params, and reset the context with the new set of available params.
However, right now, on each pass, "seek-create-params-context" doesn't contain what was sent out in newParameters
the previous time. They do resolve to the correct intent based on the context.
What am I doing wrong?
Do I need to fiddle with Dialogflow's UI at all to send context params?
An example interaction based on real logs (irrelevant params removed):
/*
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' }