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?

- 517
- 4
- 19
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'});

- 370
- 2
- 10
-
2Thank you very much, that looks just like what I am looking for. Unfortunately in the Firebase Console it creates the following error: Firebase config variables are not available. Please use the latest version of the Firebase CLI to deploy this function. – Basti Nov 03 '17 at 13:28
-
Did you run `npm install firebase-admin`? – Akshay Gohil Nov 03 '17 at 13:31
-
No I didn't, it's already in the packages.json file under dependencies: "firebase-admin": "^4.2.1", – Basti Nov 03 '17 at 13:32
-
Try running the npm install and then deploy your function code. – Akshay Gohil Nov 03 '17 at 13:55
-
Sorry, I am really new to Dialogflow&Firebase but where do I run this? I don't see any Consoles in Dialogflow – Basti Nov 03 '17 at 13:57
-
4@AkshayGohil - The key point is that he's using the built-in Firebase Functions that he can edit as part of Dialogflow. This is a relatively new feature where simple functions can be written and edited as part of a Dialogflow project. I would have expected this to work, but I could see that the configuration component of Firebase Functions might be hardcoded, so some of the resources that firebase-admin is looking for aren't there. – Prisoner Nov 03 '17 at 14:10
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

- 49,922
- 7
- 53
- 105
-
Okay thank you very much! Do you recommend any good beginner tutorials for that? I looked into the firebase docs for the past 30 Minutes now but I think I don't really understand the concept. So I can host my Actions for free on the Firebase Servers? But where do I upload my projects? – Basti Nov 03 '17 at 14:50
-
I've added a link to a codelab that goes over deploying things to Firebase Functions directly (although it doesn't cover using the database as part of the project. Yes, you would be uploading your projects to Firebase. – Prisoner Nov 03 '17 at 15:02
-
Thanks! But there's one small problem: In the Tutorial it says, the link that is used for the Webhook can be found in the Firebase CLI Logs. But where do I find them? It should look something like this: https://us-central1-
.cloudfunctions.net/factsAboutGoogle. I tried inserting my app-id but when I am testing it it always says "My test app isn't responding right now. Try again soon." What can I do? – Basti Nov 03 '17 at 17:41 -
Are you following the directions about deploying from the command line? If so, you may want to open a new question and post the output from your deployment and possibly the logs. If not... you may want to start a new question describing how you're trying to do it. – Prisoner Nov 03 '17 at 17:48