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

How to use Firebase Database in Google Actions?

我是 Google Home/Assistant 的 Action 编程新手。 我最近一直在 Fulfillment 下使用内联编辑器,它运行良好。现在我想开始使用 Firebase DB。 正如我假设的内联编辑器的第一行中所说的 const functions = require('firebase-functions');,数据库可以使用了吗? 如果有,我该如何访问它?

您可以使用 Google Realtime Database package firebase-admin

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

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

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

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

幸运的是 - 获取该代码并将其扩展为您编写的代码并不难......并且仍然托管在 Firebase Functions 上!请参阅 https://firebase.google.com/docs/functions/get-started 以了解开始前需要安装的工具。

有关编写与 Dialogflow 一起使用的 Firebase Functions 和 Firebase Functions 入门的更广泛的教程,您可以查看来自 Google https://codelabs.developers.google.com/codelabs/assistant-dialogflow-nodejs/index.html

的代码实验室