How to use Firebase Database in Google Actions?

Viewed 2607

I'm new to programming Actions for Google Home/Assistant. I have been using the Inline-Editor under Fulfilment lately and it works fine. Now I want to start using the Firebase DB. As it says const functions = require('firebase-functions'); in the first lines of the Inline Editor I am assuming, that the Database is ready to use? If so, how do I access it?

2 Answers

You can use the Google Realtime Database package firebase-admin

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

And to set a value in the database ref.set({yourKey: 'value'});

Although Dialogflow uses Firebase Functions to let you do inline code-editing, it doesn't sound like it is a full-fledged Firebase environment. There may be APIs on the back-end that are not setup.

The Dialogflow In-line Fulfillment is meant for simple logic testing and simple operations.

Fortunately - it isn't difficult to take that code and expand it into code that you write... and still host on Firebase Functions! See https://firebase.google.com/docs/functions/get-started for the tools you'll need to install to get started.

For a more extensive tutorial about writing Firebase Functions that work with Dialogflow and getting started with Firebase Functions, you can take a look at the codelab from Google at https://codelabs.developers.google.com/codelabs/assistant-dialogflow-nodejs/index.html

Related