Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot Read Context in Dialogflow Fulfillment (Suddenly Undefined)

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:

Intent

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?

like image 649
phngs Avatar asked Mar 07 '19 09:03

phngs


People also ask

How do you use fulfillment Dialogflow?

Enable fulfillment responseNavigate to the Dialogflow console and click Intents. Click Schedule Appointment Intent. Scroll down to Fulfillment and turn on Enable webhook call for the intent.

What is Dialogflow fulfillment?

When you enable fulfillment for an intent, Dialogflow responds to that intent by calling a service that you define. For example, if an end-user wants to schedule a haircut on Friday, your service can check your database and respond to the end-user with availability information for Friday.

How do I call intent in fulfillment in Dialogflow?

You can call an intent directly without any prompt to user with the help of events . From the fulfillment, you can invoke an event with the help of followupEventInput . Just make sure to give correct name of event under your intent in Dialogflow console.

What is input context in Dialogflow?

Input and output contexts are applied to intents. They work together to control conversation flow: Output contexts control active contexts. When an intent is matched, any configured output contexts for that intent become active. Input contexts control intent matching.


2 Answers

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"

like image 102
Gian Maria Pandolfi Avatar answered Oct 19 '22 05:10

Gian Maria Pandolfi


I solved the problem by turning off "Beta features" enter image description here

like image 2
Илья Хоришко Avatar answered Oct 19 '22 05:10

Илья Хоришко