简体   繁体   English

使用Google Home和NodeJS设置一个非常简单的“开启设备”功能?

[英]Setting up a very simple “turn on device” with Google Home and NodeJS?

So far I've found plenty of guides online that shows how to set up a NodeJS backend, that Dialogflow can talk to. 到目前为止,我已经在网上找到了大量指南,这些指南显示了如何设置Dialogflow可以与之对话的NodeJS后端。 However, Dialogflow was previously API.AI and all the old guides are basically wrong now. 但是,Dialogflow以前是API.AI,现在所有旧指南基本上都是错误的。

When I try to do this: 当我尝试这样做时:

require('actions-on-google').ApiAiAssistant

It will tell me: 它会告诉我:

Importing the class name ApiAiAssistant is DEPRECATED , use DialogflowApp 导入类名ApiAiAssistant为DEPRECATED ,请使用DialogflowApp

But even changing ApiAiAssistant to DialogflowApp won't work. 但是,即使将ApiAiAssistant更改为DialogflowApp也行不通。 Here's an example of some Action: https://github.com/greenido/bitcoin-info-action/ 这是一些操作的示例: https : //github.com/greenido/bitcoin-info-action/

As you can see, it has not been updated in a long time, nor does the code actually work (even if I import the intents and so on into Dialogflow). 如您所见,它已经很长时间没有更新了,代码也没有真正起作用(即使我将意图等导入了Dialogflow)。

What I basically want: Give Google Home parameters (like turn on TV which would take TV as a parameter) and handle that in my NodeJS backend. 我基本上想要的是:提供Google Home参数(例如turn on TV ,它将TV作为参数)并在我的NodeJS后端中处理它。 How would I do something like that? 我该怎么做? It can be with or without Dialogflow. 可以有或没有Dialogflow。

Also, is it even possible to say Hey Google, turn on TV ? 此外,甚至可以说Hey Google, turn on TV吗? So far all examples I've seen it like Hey Google, launch MY_ACTION or Hey Google, ask MY_ACTION to INTENT which is slow and annoying. 到目前为止,我见过的所有示例都像Hey Google, launch MY_ACTIONHey Google, ask MY_ACTION to INTENT这很Hey Google, ask MY_ACTION to INTENT

Got some updated code. 得到了一些更新的代码。 Works fine with the DialogflowApp: 与DialogflowApp配合良好:

const fs = require("fs");
const express = require("express");
const https = require("https");
const bodyParser = require("body-parser");
const Assistant = require('actions-on-google').DialogflowApp;

const app = express();
app.use(bodyParser.json());

const options = {
    cert: fs.readFileSync("./cert.pem"),
    key: fs.readFileSync("./key.pem"),
    ca: fs.readFileSync("./chain.pem")
};

app.post("/google", (req, res) => {
    const assistant = new Assistant({ request: req, response: res });
    let device = assistant.getArgument("device");
    assistant.tell("Turning on " + device);
});

app.listen(5004);
https.createServer(options, app).listen(5005);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM