我正在尝试使用actions-on-google
/ google-assistant-sdk
构建我的第一个应用,我想开始使用3个意图,MAIN,响应输入TEXT,以及HELP
用户可以随时打电话:
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
将Google Actions推送为:
gactions update --action_package action.json --project <YOUR_PROJECT_ID>
在测试助手here时,它以良好的方式启动,并重复我输入的号码,等待另一个号码,依此类推,但当我输入help
时,它会终止并且没有回应!
更新
我尝试了以下内容,但没有奏效:
actionMap.set("app.StandardIntents.HELP", helpHandler);
我应该期待该应用“你需要什么样的帮助?”当我输入/说“帮助”时,发生的事情只是重写它,就像它对任何其他数字一样。
答案 0 :(得分:2)
仅first message in a conversation支持非内置Intent。之后,虽然您可以将它们用于speech biasing,但您只会获得内置的TEXT
意图。
答案 1 :(得分:1)
您的actionMap正在寻找app.StandardIntents.HELP
,但它并不存在。您可以在GitHub仓库中查看所有the standard intents。
app.StandardIntents.MAIN
会返回另一个字符串,该字符串对应于&#34;&#39; actions.intent.MAIN&#39;&#34;。它不会读取您的action.json
并生成新的意图。因此,app.StandardIntents.HELP
实际上会返回undefined
并且永远不会被调用。
您的地图应使用字符串作为您的帮助意图,因为它不能作为app
对象中的常量使用。
actionMap.set("app.StandardIntents.HELP", helpHandler);
这可以解决您的问题。如果没有,请告诉我。