Actions-on-Google : TypeError: assistant.getContextArgument is not a function
Actions-on-Google : TypeError: assistant.getContextArgument is not a function
我的节点代码有一些问题。
我正在使用 api.ai、node.js 和 Heroku 上的 Webhook 在 google 上构建一个动作。
问题是我想脱离上下文进行论证,但我只得到错误。
当我使用 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)");
}
最后是我的 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)
今日讲座:
阅读发行说明
此功能从 8 天开始就包含在内,我没有使用最新的 Node.js 客户端库。
;)
https://developers.google.com/actions/tools/nodejs-client-library#release_notes
我的节点代码有一些问题。 我正在使用 api.ai、node.js 和 Heroku 上的 Webhook 在 google 上构建一个动作。
问题是我想脱离上下文进行论证,但我只得到错误。
当我使用 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)");
}
最后是我的 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)
今日讲座:
阅读发行说明 此功能从 8 天开始就包含在内,我没有使用最新的 Node.js 客户端库。
;)
https://developers.google.com/actions/tools/nodejs-client-library#release_notes