我正在尝试使用以下示例https://github.com/actions-on-google/actionssdk-say-number-nodejs设置助理应用。我可以看到助手应用程序端点工作正常,因为我在代码中找回了我配置的响应。 但当我回复MAIN intent的问题时,对话没有达到我的API 。
I found few places within 7.8 miles
未从我的API发送。我错过了什么吗?我修改了代码,使其成为使用express.js的nodejs app。
以下是代码
# index.js
'use strict';
process.env.DEBUG = 'actions-on-google:*';
const ActionsSdkApp = require('actions-on-google').ActionsSdkApp;
const express = require('express');
var bodyParser = require('body-parser');
// Constants
// App
const expressApp = express();
expressApp.use(bodyParser.urlencoded({ extended: true }));
expressApp.use(bodyParser.json());
var port = process.env.PORT || 5000; // set our port
const HOST = '0.0.0.0';
var router = express.Router();
const NO_INPUTS = [
'I didn\'t hear that.',
'If you\'re still there, say that again.',
'We can stop here. See you soon.'
];
function process_request(request, response) {
//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);
}
}
let actionMap = new Map();
actionMap.set(app.StandardIntents.MAIN, mainIntent);
actionMap.set(app.StandardIntents.TEXT, rawInput);
app.handleRequest(actionMap);
};
router.get('/googleBot', function(req, res) {
console.log("received a get request");
process_request(req, res)
});
router.post('/googleBot', function(req, res) {
console.log("received a post request");
process_request(req, res)
});
expressApp.use('/', router);
expressApp.listen(port, HOST);
//console.log(`Running on http://${HOST}:${PORT}`);
这是action.json
# action.json
{
"actions": [
{
"description": "Default Welcome Intent",
"name": "MAIN",
"fulfillment": {
"conversationName": "conversation_1"
},
"intent": {
"name": "actions.intent.MAIN"
}
}
],
"conversations": {
"conversation_1": {
"name": "conversation_1",
"url": "https://<myownsite>.xyz/googleBot",
"fulfillmentApiVersion": 2
}
}
}
我正在运行带有node index.js
的node.js,并且我将其反向代理到https://<myownsite>.xyz/googleBot
,当我发出Curl请求时,它工作得很好。
请求
curl -X POST -H "Content-Type: application/json" -H "Google-Actions-API-Version: 2" https://mysitexxx.com/googleBot -d '{"user":{"userId":"<hidden for obvious reasons>","locale":"en-US","lastSeen":"2017-12-11T09:22:58Z"},"conversation":{"conversationId":"1512984211990","type":"NEW"},"inputs":[{"intent":"actions.intent.TEXT","rawInputs":[{"inputType":"KEYBOARD","query":"12"}]}],"surface":{"capabilities":[{"name":"actions.capability.AUDIO_OUTPUT"},{"name":"actions.capability.SCREEN_OUTPUT"}]},"isInSandbox":true,"availableSurfaces":[{"capabilities":[{"name":"actions.capability.AUDIO_OUTPUT"},{"name":"actions.capability.SCREEN_OUTPUT"}]}]}'
当我使用Curl时,我回复说“你说12”。
响应
{"conversationToken":"{\"state\":null,\"data\":{}}","expectUserResponse":true,"expectedInputs":[{"inputPrompt":{"initialPrompts":[{"ssml":"<speak>You said, <say-as interpret-as=\"ordinal\">12</say-as></speak>"}],"noInputPrompts":[{"ssml":"I didn't hear that."},{"ssml":"If you're still there, say that again."},{"ssml":"We can stop here. See you soon."}]},"possibleIntents":[{"intent":"actions.intent.TEXT"}]}]}
所以,我在这里遗失了什么吗?
更新
以下是来自模拟器的请求和响应选项卡的信息(在右侧)
请求
{
"request": {
"conversationToken": "",
"debugLevel": 1,
"inputType": "KEYBOARD",
"locale": "en-US",
"mockLocation": {
"city": "Mountain View",
"coordinates": {
"latitude": 37.421980615353675,
"longitude": -122.08419799804688
},
"formattedAddress": "Googleplex, Mountain View, CA 94043, United States",
"zipCode": "94043"
},
"query": "Talk to my test app",
"surface": "PHONE"
},
"response": {},
"debug": {},
"errors": []
}
响应
this part is null; I don't see anything, but still simulator UI says "Hi! I can read out an ordinal number like 123. Speak or say a number."
UPDATE2
请求根据评论
中的要求,actions.intent.TEXT
张贴了欢迎消息
curl -X POST -H "Content-Type: application/json" -H "Google-Actions-API-Version: 2" https://mysitexyz.com/googleBot -d '{ "conversationToken": "{}", "expectUserResponse": true, "expectedInputs": [ { "inputPrompt": { "initialPrompts": [ { "textToSpeech": "<speak>Welcome</speak>" } ], "noInputPrompts": [] }, "possibleIntents": [ { "intent": "actions.intent.TEXT" } ], "speechBiasingHints": [ ] } ] }'
响应
Action Error: no matching intent handler for: null
主要意图请求。
curl -X POST -H "Content-Type: application/json" -H "Google-Actions-API-Version: 2" https://mysitezyx.com/googleBot -d '{"user":{"userId":"<hidden for obvious reasons>","locale":"en-US","lastSeen":"2017-12-11T09:22:58Z"},"conversation":{"conversationId":"1512984211990","type":"NEW"},"inputs":[{"intent":"actions.intent.MAIN","rawInputs":[{"inputType":"KEYBOARD","query":"Welcome"}]}],"surface":{"capabilities":[{"name":"actions.capability.AUDIO_OUTPUT"},{"name":"actions.capability.SCREEN_OUTPUT"}]},"isInSandbox":true,"availableSurfaces":[{"capabilities":[{"name":"actions.capability.AUDIO_OUTPUT"},{"name":"actions.capability.SCREEN_OUTPUT"}]}]}'
响应
{"conversationToken":"{\"state\":null,\"data\":{}}","expectUserResponse":true,"expectedInputs":[{"inputPrompt":{"initialPrompts":[{"ssml":"<speak>Hi! <break time=\"1\"/> I can read out an ordinal number like <say-as interpret-as=\"ordinal\">123</say-as>. Speak or say a number.</speak>"}],"noInputPrompts":[{"ssml":"I didn't hear that."},{"ssml":"If you're still there, say that again."},{"ssml":"We can stop here. See you soon."}]},"possibleIntents":[{"intent":"actions.intent.TEXT"}]}]}
答案 0 :(得分:1)
所以我重建你的情况我只是使用来自webstorm的nodejs express样板而不是你的代码。
我修复了一些问题,所以这个github工作正常:voice google home action boilerplate
如果您有疑问,请询问。
我只有欢迎意图而不是其他意图工作的唯一一点是当我创建了所有内容之后忘记点击谷歌动作控制台中的更改版本后我更新了action.json并运行gaction.exe: / p>
我修复后,我的服务器出现了很多错误500,直到我改变了行
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.buildInputPrompt(false, '<speak>Hi! <break time="1"/> ' +
'I can read out an ordinal like ' +
'<say-as interpret-as="ordinal">123</say-as>. Say a number.</speak>');
在此之后我不得不修复自己造成的一些错误,现在一切正常。
<强>更新强> 所以最后的问题是通过使用另一个谷歌帐户解决的。可能是一些谷歌云权限设置的原因。不完全确定。但是如果有些人遇到同样的问题,请查看您的权限并制定规则。
答案 1 :(得分:0)
经过几天的努力和帮助形成@shortQuestion,我们终于得出结论,这个问题是由于一些许可问题。事实证明我使用谷歌商业电子邮件,我们的管理员没有启用少量Activity Controls
,尤其是Web & App Activity
。只需打开https://myaccount.google.com/activitycontrols中的Web & App Activity
,然后让管理员启用网络&amp;您/所有需要访问助理测试的人的应用活动。
太糟糕了,谷歌没有在任何时候抛出这个错误。