1

i have some problems with my node code. I am building an action-on-google with api.ai, node.js and a webhook on Heroku.

The problem is that I want to an Argument out of a context, but I only get errors.

When I use getContexts there is not problem as you can see in the logs

let input = assistant.getContexts();

When I try getContext or getContextArgumet i get a type error.

let input2 = assistant.getContextArgument("csearch", "query");

I looked at the documenation, github and examples, but I don't know what exactly is wrong with my code. The name of the parameters should be allright (compare with the json) and the functions should ok as well https://developers.google.com/actions/reference/ApiAiAssistant#getContextArgument

I hope someone could take a short look on it.


So, first of all, the JSON:

{
 "id": "c2519421-0a7a-466c-99dc-b5d84949a74f",
  "timestamp": "2017-04-19T15:54:04.627Z",
  "lang": "de",
  "result": {
    "source": "agent",
    "resolvedQuery": "ne",
    "action": "queryNext",
    "actionIncomplete": false,
    "parameters": {},
    "contexts": [
      {
        "name": "csearch",
        "parameters": {
          "query": "wurst",
          "query.original": "wurst"
        },
        "lifespan": 3
      },
      {
        "name": "cquery",
        "parameters": {
          "query": "wurst",
          "query.original": "wurst"
        },
        "lifespan": 5
      }
    ],
    "metadata": {
      "intentId": "e12d2e09-23fa-45ba-891d-5832f711b811",
      "webhookUsed": "true",
      "webhookForSlotFillingUsed": "false",
      "intentName": "recipe_search_next"
    },
    "fulfillment": {
      "speech": "Nächstes Rezept",
      "messages": [
        {
          "type": 0,
          "speech": "Nächstes Rezept"
        }
      ]
    },
    "score": 1
  },
  "status": {
    "code": 206,
    "errorType": "partial_content",
    "errorDetails": "Webhook call failed. Error: Webhook response was empty."
  },
  "sessionId": "5178e4a6-af77-4710-bafe-2908609225e3"
}

As you can see, my webhook throws an error. But take a look at contexts. This is the data I want to get.

My node.js code snippet

function placeholderFunction (assistant) {

    /// PLACEHOLDER FUNCTION TO TEST
    let input = assistant.getContexts();
    console.log("Die Ausgabe für den gesamten Kontext", input );
    let input2 = assistant.getContextArgument("csearch", "query");
    console.log("Die Ausgabe für den speziellen Kontext", input2 );

    assistant.tell("Placeholder - keine Fehler in der Response. (Siehe Logs für mehr)");
  }

And finally my log:

2017-04-19T15:45:51.366142+00:00 app[web.1]: Die Ausgabe für den gesamten Kontext [ { name: 'csearch',
2017-04-19T15:45:51.366144+00:00 app[web.1]:     parameters: { query: 'wurst', 'query.original': 'wurst' },
2017-04-19T15:45:51.366145+00:00 app[web.1]:     lifespan: 3 },
2017-04-19T15:45:51.366146+00:00 app[web.1]:   { name: 'cquery',
2017-04-19T15:45:51.366149+00:00 app[web.1]:     parameters: { query: 'wurst', 'query.original': 'wurst' },
2017-04-19T15:45:51.366150+00:00 app[web.1]:     lifespan: 5 } ]
2017-04-19T15:45:51.375981+00:00 app[web.1]: TypeError: assistant.getContextArgument is not a function
2017-04-19T15:45:51.375983+00:00 app[web.1]:     at placeholderFunction (/app/handle.js:33:28)
2017-04-19T15:45:51.375984+00:00 app[web.1]:     at ApiAiAssistant.invokeIntentHandler_ (/app/node_modules/actions-on-google/assistant.js:606:25)
2017-04-19T15:45:51.375985+00:00 app[web.1]:     at ApiAiAssistant.handleRequest (/app/node_modules/actions-on-google/assistant.js:335:27)
2017-04-19T15:45:51.375986+00:00 app[web.1]:     at handle (/app/handle.js:92:13)
2017-04-19T15:45:51.375986+00:00 app[web.1]:     at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2017-04-19T15:45:51.375987+00:00 app[web.1]:     at next (/app/node_modules/express/lib/router/route.js:137:13)
2017-04-19T15:45:51.375988+00:00 app[web.1]:     at Route.dispatch (/app/node_modules/express/lib/router/route.js:112:3)
2017-04-19T15:45:51.375989+00:00 app[web.1]:     at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2017-04-19T15:45:51.375989+00:00 app[web.1]:     at /app/node_modules/express/lib/router/index.js:281:22
2017-04-19T15:45:51.375990+00:00 app[web.1]:     at Function.process_params (/app/node_modules/express/lib/router/index.js:335:12)

1 Answers1

0

Lecture of the day:

READ THE RELEASE NOTES This function are included since 8 days and i did not use the newest Node.js Client Library.

;)

https://developers.google.com/actions/tools/nodejs-client-library#release_notes