Dialogflow-fulfillment-nodejs: agent.context.set(contextobj) is not updating the existing context by the same name

Created on 2 Nov 2018  路  3Comments  路  Source: dialogflow/dialogflow-fulfillment-nodejs

I have an Google Action based on DialogFlow fulfillment, it had one issue related to the issue #149 and to resolve it i updated this project to its latest release.

Seems like context api is updated and i tried to use as suggested in various issues. The context is set the first time i set the object like

     const ctx = {
      "lifespan": 5,
      "name": "mycontext",
      "parameters":  {
        a: 1,
        b: 2,
        score: 0,
      }
    };
    agent.context.set(ctx);

Since i have a conversational action, where the context is updated until the action is complete, the next time i set the context similar to above is not updating the context.

I tried deleting the context and setting again too like

agent.context.delete("mycontext");
agent.context.set(ctx);

Its not working as the version 0.5.0 anymore.

My current dependencies are

"dependencies": {
    "actions-on-google": "^2.4.1",
    "firebase-admin": "^5.13.1",
    "firebase-functions": "^2.0.2",
    "dialogflow": "^0.6.0",
    "dialogflow-fulfillment": "^0.6.1"
  }

please suggest a solution

Most helpful comment

Why can't it take integers? Previously it could and it's not that much different from a string.

All 3 comments

Your parameters need to be strings, you can see more about this in our docs. Yes you'll need to use the latest dialogflow-fulfillment dependency version, "0.6.1".

agent.context.set({
  'name':'context-name',
  'lifespan': 5,
  'parameters':{
    'parameter-name':'parameter-value'
    }
});

Why can't it take integers? Previously it could and it's not that much different from a string.

0

I found the only workaround to reassign a new context object via context.set(ctx). Then it worked.

  //update context to show full menu
  let context = agent.context.get('user_data');
  if (!context) throw "User_data context ius nod defined in PreferrenceAdd"

  let context2 = new Object();
  context2 = {'name': 'user_data', 'lifespan': 40, 
  'parameters': context.parameters}; 
  console.log("ctx: = " + JSON.stringify(context2));
  context2.parameters.new = false;
  context2.parameters.refresh = true;
  agent.context.set(context2);
Was this page helpful?
0 / 5 - 0 ratings