只有2个意图工作“主”和“TEXT”
我想我建立第一个应用程序与actions-on-google
/google-assistant-sdk
,我想开始使用3个意图,主力,输入文字回应,HELP
,用户可以调用随时随地:只有2个意图工作“主”和“TEXT”
的action.json
是:
{
"actions": [
{
"description": "Default Welcome Intent",
"name": "MAIN",
"fulfillment": {
"conversationName": "conversation_1"
},
"intent": {
"name": "actions.intent.MAIN"
}
},
{
"description": "Help Intent",
"name": "Help",
"fulfillment": {
"conversationName": "conversation_1"
},
"intent": {
"name": "app.StandardIntents.HELP",
"trigger": {
"queryPatterns": [
"Help",
"HELP",
"help"
]
}
}
}
],
"conversations": {
"conversation_1": {
"name": "conversation_1",
"url": "https://us-central1-sillytest-16570.cloudfunctions.net/sayNumber",
"fulfillmentApiVersion": 2
}
}
}
的index.js
:
'use strict';
process.env.DEBUG = 'actions-on-google:*';
const ActionsSdkApp = require('actions-on-google').ActionsSdkApp;
const functions = require('firebase-functions');
const NO_INPUTS = [
'I didn\'t hear that.',
'If you\'re still there, say that again.',
'We can stop here. See you soon.'
];
exports.sayNumber = functions.https.onRequest((request, response) => {
const app = new ActionsSdkApp({request, response});
function mainIntent (app) {
console.log('mainIntent');
let inputPrompt = app.buildInputPrompt(true, '<speak>Hi! <break time="1"/> ' +
'I can read out an ordinal like ' +
'<say-as interpret-as="ordinal">123</say-as>. Say a number.</speak>', NO_INPUTS);
app.ask(inputPrompt);
}
function rawInput (app) {
console.log('rawInput');
if (app.getRawInput() === 'bye') {
app.tell('Goodbye!');
} else {
let inputPrompt = app.buildInputPrompt(true, '<speak>You said, <say-as interpret-as="ordinal">' +
app.getRawInput() + '</say-as></speak>', NO_INPUTS);
app.ask(inputPrompt);
}
}
function helpHandler (app) {
console.log('rawInput');
app.ask('<speak>What kind of help do you need?</speak>');
}
let actionMap = new Map();
actionMap.set(app.StandardIntents.MAIN, mainIntent);
actionMap.set(app.StandardIntents.TEXT, rawInput);
actionMap.set(app.StandardIntents.HELP, helpHandler);
app.handleRequest(actionMap);
});
我推firebase
为:
firebase deploy --only functions
,推动了谷歌的行动是:
gactions update --action_package action.json --project <YOUR_PROJECT_ID>
在测试助理here,它在一个很好的方式开始了,再说一遍,我输入号码,等待另一个号码等等,但是当我输入help
时,它终止并且没有响应!
UPDATE
我试过以下,但没有工作:“你需要什么样的帮助”
actionMap.set("app.StandardIntents.HELP", helpHandler);
我应该期待的应用当我输入/说出“帮助”时,但发生的事情只是重写它,就像它与任何其他号码一样。
你的ActionMap正在寻找app.StandardIntents.HELP
,但它不存在。您可以在GitHub库中查看所有the standard intents。
app.StandardIntents.MAIN
返回对应于“'actions.intent.MAIN'”的另一个字符串。它不会读取您的action.json
并生成新的意图。因此,app.StandardIntents.HELP
实际上返回undefined
并且永远不会被调用。
您的地图应该为您的帮助意图使用字符串,因为它不可用作为app
对象中的常量。
actionMap.set("app.StandardIntents.HELP", helpHandler);
这应该解决您的问题。让我知道如果它不。
没有工作,我更新了我的代码,以便数学运算100%,并提供了打印屏幕 –
这与订购有关吗?如果'TEXT'在'HELP'之前,它匹配所有文本情况,并且在当前情况下优先于帮助。如果行为尚未定义,也许最后放置TEXT会让它成为一种全面的方式。 –
:(没有改变 –
为什么helpHandler是一个'const'而不是像其他两个''函数? –
我正在使用它的ES6风格,它应该是相同的意思 –
@NickFelker为了避免任何混淆,我重新写它的正常方式。 –