dialogflow / dialogflow-fulfillment-nodejs

Dialogflow agent fulfillment library supporting v1&v2, 8 platforms, and text, card, image, suggestion, custom responses
Apache License 2.0
597 stars 281 forks source link

Wrong (empty) output context #260

Closed leocarmona closed 4 years ago

leocarmona commented 4 years ago

This is blocking me from submitting my app to production.

I have the following code to set an 'user' context in my fulfillment:

agent.context.set({ 'name': 'user', 'lifespan': 5, 'parameters': { 'username': username } });

In some devices (google assistant), when I try to get context using:

agent.context.get('user')

I receive an undefined (my context is not set)

So, I log:

console.log(JSON.stringfy(agent.context));

And I receive the following response:

{ "contexts":{ "-":{ "name":"-", "lifespan":4, "parameters":{ "username":"jfabro" } } } }

The context name is filled wrong with '-'.

This causes me to use an if like this:

var context = agent.context.get('user'); // This works in 90% of users

if (context == null || context == undefined) {
   context = agent.context.get('-'); // So, this works in some devices
}

How can I fix it?

My package.json:

{
  "name": "dialogflowFirebaseFulfillment",
  "description": "This is the default fulfillment for a Dialogflow agents using Cloud Functions for Firebase",
  "version": "0.0.1",
  "private": true,
  "license": "Apache Version 2.0",
  "author": "Google Inc.",
  "engines": {
    "node": "8"
  },
  "scripts": {
    "start": "firebase serve --only functions:dialogflowFirebaseFulfillment",
    "deploy": "firebase deploy --only functions:dialogflowFirebaseFulfillment"
  },
  "dependencies": {
    "actions-on-google": "^2.7.1",
    "firebase-admin": "^8.1.0",
    "firebase-functions": "^3.0.1",
    "dialogflow": "^0.10.1",
    "dialogflow-fulfillment": "^0.6.1"
  }
}
leocarmona commented 4 years ago

I found a workaround in https://github.com/dialogflow/dialogflow-fulfillment-nodejs/issues/187