我的节点代码有一些问题。我正在使用 api.ai、node.js 和 Heroku 上的 webhook 构建一个 action-on-google。
问题是我想在上下文中使用 Argument,但我只会得到错误。
当我使用getContexts时没有问题,正如您在日志中看到的那样
let input = assistant.getContexts();
当我尝试getContext或getContextArgumet时,我得到一个类型错误。
let input2 = assistant.getContextArgument("csearch", "query");
我查看了文档、github 和示例,但我不知道我的代码到底出了什么问题。参数的名称应该没问题(与json比较),功能也应该没问题https://developers.google.com/actions/reference/ApiAiAssistant#getContextArgument
我希望有人可以简短地看一下。
所以,首先,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"
}
如您所见,我的 webhook 抛出了一个错误。但是看看上下文。这是我想要得到的数据。
我的node.js 代码片段
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)");
}
最后是我的日志:
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)