【发布时间】:2017-11-29 13:16:18
【问题描述】:
我想向我的 Google Home 添加自定义投射功能。到目前为止,我所做的是使用此页面中的 Dialogflow 的教程:https://developers.google.com/actions/dialogflow/first-app
然后我发现了一个关于将视频投射到 Chromecast 的存储库,仅来自 PC 而不是来自 Google Home:https://github.com/googlecast/CastHelloVideo-chrome/blob/master/helloVideos.js
然后我尝试将两者结合起来。到目前为止,我只尝试连接到我的 Chromecast,但每次都会收到此错误:
API Version 2: Failed to parse JSON response string with 'INVALID_ARGUMENT' error: ": Cannot find field.".
我完成了教程,所以我没有更改 Dialogflow 上的任何内容,只更改了 index.js 文件。
这是我的文件:
'use strict';
process.env.DEBUG = 'actions-on-google:*';
const App = require('actions-on-google').DialogflowApp;
const functions = require('firebase-functions');
// a. the action name from the make_name Dialogflow intent
const NAME_ACTION = 'game_cast';
// b. the parameters that are parsed from the make_name intent
const COLOR_ARGUMENT = 'color';
const NUMBER_ARGUMENT = 'number';
exports.gameCast = functions.https.onRequest((request, response) => {
const app = new App({request, response});
console.log('Request headers: ' + JSON.stringify(request.headers));
console.log('Request body: ' + JSON.stringify(request.body));
// c. The function that generates the silly name
function gameCast (app) {
let number = app.getArgument(NUMBER_ARGUMENT);
let color = app.getArgument(COLOR_ARGUMENT);
// app.tell('Alright, your silly name is ' +
// color + ' ' + number +
// '! I hope you like it. See you next time.');
launchApp();
}
// d. build an action map, which maps intent names to functions
let actionMap = new Map();
actionMap.set(NAME_ACTION, gameCast);
app.handleRequest(actionMap);
});
gameCast 函数中的 launchApp() 函数调用将连接到我的 Chromecast。此外,我添加了 helloVideos.js 的全部内容,因此不会有任何 launchApp() 可能使用的缺失函数。 (这里我没有包含我的原始文件,因为文件 helloVideos.js 有 617 行代码。)
任何建议将不胜感激!谢谢!
【问题讨论】:
-
必须尝试这个SO post中的建议答案?
标签: javascript node.js chromecast