Dialogflow context suddenly undefined

2019-06-25 04:54发布

问题:

We built a Dialogflow agent using google cloud functions as webhook which worked properly until yesterday evening. At that time I exported the agent and reimported it later on and it worked for a while.

What stopped working is that agent.context.get('...'); (also agent.getContext('...')) does return undefined even if the context is set according to the UI and raw API response.

As an example I have an intent which has a required slot shop, webhook for slot filling enabled. When I test the agent, the intent named info is matched correctly and also the context info_dialog_params_store seems to be there:

And here is part of the output context according to the raw API response:

"outputContexts": [
      {
        "name": "projects/MYAGENTNAME/agent/sessions/0b753e8e-b377-587b-3db6-3c8dc898879b/contexts/info_dialog_params_store",
        "lifespanCount": 1,
        "parameters": {
          "store": "",
          "store.original": "",
          "kpi": "counts",
          "date_or_period": "",
          "kpi.original": "trafico",
          "date_or_period.original": ""
        }
      }

In the webhook I mapped the intent correctly to a js function:

let intentMap = new Map();
intentMap.set('info', info);
agent.handleRequest(intentMap);

And the first line of the info function looks like:

function info(agent) {
    store_context = agent.context.get('info_dialog_params_store');
}

Which returns

TypeError: Cannot read property 'get' of undefined
    at info (/user_code/index.js:207:36)
    at WebhookClient.handleRequest (/user_code/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:303:44)
    at exports.dialogflowFirebaseFulfillment.functions.https.onRequest (/user_code/index.js:382:9)
    at cloudFunction (/user_code/node_modules/firebase-functions/lib/providers/https.js:57:9)
    at /var/tmp/worker/worker.js:762:7
    at /var/tmp/worker/worker.js:745:11
    at _combinedTickCallback (internal/process/next_tick.js:73:7)
    at process._tickDomainCallback (internal/process/next_tick.js:128:9)

I am quite sure that I did not change anything which could affect the proper functioning of agent, except some refactoring.

I also tried the beta functions activated as well as deactivated as I read that there can be issues with environments, but that did not change anything.

Anyone knows in which direction I can investigate further?

回答1:

I had the same issue, I resolved it updating dialogflow-fulfillment in package.json:

from "dialogflow-fulfillment": "^0.5.0" to "dialogflow-fulfillment": "^0.6.0"



回答2:

Actually I could fix it by the following 'magic' steps:

  • Copied my original function to a text file
  • Copy and pasted the original example code into the GUI fulfillment code editor (Code on GitHub)
  • Deployed the function
  • Created a minimal example for my info function:
function info(agent) {
    store_context = agent.context.get('info_dialog_params_store');
}
  • Tested it, and it worked
  • Copied back my original code
  • Everything was fine again