如何在Google Actions中使用Firebase数据库?

时间:2017-11-03 13:04:07

标签: dialogflow actions-on-google google-home

我是Google Home / Assistant的编程操作的新手。 我最近在Fulfillment下使用了Inline-Editor,它工作正常。现在我想开始使用Firebase DB。 正如我在假设的内联编辑器的第一行中所说const functions = require('firebase-functions');,数据库已准备就绪? 如果是这样,我该如何访问它?

2 个答案:

答案 0 :(得分:3)

您可以使用Google Realtime Databasefirebase-admin

const admin = require("firebase-admin");
admin.initializeApp(functions.config().firebase);
const db = admin.database();
const ref = db.ref("/");

并在数据库中设置一个值 ref.set({yourKey: 'value'});

答案 1 :(得分:3)

虽然Dialogflow使用Firebase功能让您进行内联代码编辑,但听起来并不像是一个成熟的Firebase环境。后端可能有API未设置。

Dialogflow In-line Fulfillment用于简单的逻辑测试和简单的操作。

幸运的是 - 将代码扩展为您编写的代码并不难,并且仍然是Firebase函数的主机!有关您开始安装所需的工具,请参阅https://firebase.google.com/docs/functions/get-started

有关编写与Dialogflow配合使用Firebase功能并开始使用Firebase功能的更广泛的教程,您可以在https://codelabs.developers.google.com/codelabs/assistant-dialogflow-nodejs/index.html

查看来自Google的codelab。