dialogflow-fulfillment-nodejs icon indicating copy to clipboard operation
dialogflow-fulfillment-nodejs copied to clipboard

agent.getContext() and agent.context.get() both returning null

Open harshadabhanose opened this issue 5 years ago • 7 comments

We are using version ^0.6.1 of dialogflow-fulfillment-nodejs library in our Actions on Google app. During the development and internal testing, everything is working fine. However when we submitted the app for Google Review, the support team is experiencing issues and the bot exits the conversation. The logs show that the context object returned by agent.getContext() or agent.context.get() is null even though we could see that it's present in the request.body with active lifespan.

Below is the code that I have used to retrieve the context:

   `const sessionAttr = agent.getContext('session_attributes');
    agent.add(sessionAttr.parameters.jobDetails[9]);`

The exception in the log:

dialogflowFirebaseFulfillment 2u600gl7bqkl getContext is deprecated, migrate to context.get dialogflowFirebaseFulfillment 2u600gl7bqkl TypeError: Cannot read property 'parameters' of null at jobTitle (/srv/index.js:313:31) at WebhookClient.handleRequest (/srv/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:313:44) at exports.dialogflowFirebaseFulfillment.functions.https.onRequest (/srv/index.js:619:11) at cloudFunction (/srv/node_modules/firebase-functions/lib/providers/https.js:57:9) at /worker/worker.js:726:7 at /worker/worker.js:709:11 at _combinedTickCallback (internal/process/next_tick.js:132:7) at process._tickDomainCallback (internal/process/next_tick.js:219:9) dialogflowFirebaseFulfillment 2u600gl7bqkl undefined

Here is the request.body object for the same intent handler call - here we can see that context "session_attributes" is still active with lifespan of 49:

{ "name": "projects/new-recruitmentbot/agent/sessions/ABwppHHoIPs-VMhwPNN1MXgbvxvNt5kqQXiPPZKkAjeYFqa7y6DYDXEJwMAdHbiL_2g1HSlV4NRBfN_h7S9-iY2L/contexts/session_attributes", "lifespanCount": 49, "parameters": { ..., "jobDetails": [ "JD001", ... ], } }

Any help in identifying the issue and fixing it will be appreciated.

harshadabhanose avatar Jan 11 '19 14:01 harshadabhanose

Found this issue #187 - both may be related.

harshadabhanose avatar Jan 11 '19 17:01 harshadabhanose

Have you found a way to resolve the issue? I am facing the exact same problem independent of the environment. It just started being undefined from one moment to the other

(https://stackoverflow.com/questions/55039936/dialogflow-context-suddenly-undefined)

phngs avatar Mar 07 '19 15:03 phngs

I ended up using the older version of lib where agent.getContext() is working fine.

harshadabhanose avatar Mar 07 '19 17:03 harshadabhanose

I ended up using the older version of lib where agent.getContext() is working fine.

hey, I've tried changing versions in the package.json, cant get any to work. Which version did you roll back to?

acousticintel avatar Jul 15 '19 06:07 acousticintel

I ended up using the older version of lib where agent.getContext() is working fine.

hey, I've tried changing versions in the package.json, cant get any to work. Which version did you roll back to?

@acousticintel version ^0.5.0

harshadabhanose avatar Jul 15 '19 07:07 harshadabhanose

same problem here. either turn off the environment config in beta or get the contexts manually under agent.contexts

alexyoux avatar Dec 23 '19 21:12 alexyoux

Hello, I solved the problem by turning off "Beta features" image

ilKhr avatar Sep 19 '20 19:09 ilKhr