Learn how to host your Alexa Skills and Google Actions on Google Cloud with Cloud Functions and Firebase (Google Cloud Firestore) as your database.
- Google Cloud Functions
- Google Firestore
Google Cloud is the cloud computing service by Google. It provides a variety of cloud services, including Cloud Functions (a serverless compute service) and Firestore (the NoQSL database service by Firebase).
In this tutorial, you will go through the steps needed to host your Alexa Skills and Google Actions on Google Cloud by using Cloud Functions for your code, and Firestore for storing user specific data.
Find the Docs here: Hosting: Google Cloud Functions.
In this section, you will go through the necessary steps to host your voice app's code on Google Cloud Functions:
The only change you have to make to your project to be able to host on Google Cloud Functions, will be made inside your
package.json file. Instead of using
Lambda, you have to use
For that, first replace
GoogleCloudFunction at the
require statement at the top of the file:
After that, replace the code snipped at the bottom, where it says
AWS Lambda with the following piece:
package.json file, you have to change value of the
main option, which specifies the entry point to your program, from
First of all, you have to create a Cloud Function. For that, select
Cloud Functions at the navigation menu of the Google Cloud Console:
You will be prompted to enable the Cloud Functions API as well as to create a new function, which will route you to the following form:
memory allocated settings can be left untouched, but I would recommend to change the
Node.js 8 to allow the use of
Also, instead of using the
Inline editor, select the
ZIP upload option. You can generate a
bundle.zip file to upload by using the following command in your Jovo project:
You also need to specify a
Stage bucket, which you have to create, if you don't have one already, that will be used to store your code:
Last but not least, change the
Function to execute to
The filled form should look like this:
Create and lean back, as this will take a minute or two.
After your function was created, you will be redirected to the landing page of
Google Cloud Functions. Now select the toogle on the left of your function, and select
After that, add the
allUsers member with the
Cloud Functions Invoker role:
Now, click on your function's name to get to its details page:
On the landing page of your function, you can find the
Trigger section, where you will be able to find the URL, that you can use as the endpoint for each platform your voice app supports:
Find the Docs here: Database: Firestore.
Now that you have your code running on Google Cloud Functions, you can't rely on the default database integration (FileDB) anymore.
Instead, we are going to use Google Cloud Firestore, the NoSQL database by Firebase. An alternative could also be Google Cloud Datastore, which is also supported by Jovo. You can find the Docs for Google Cloud Datastore here.
Learn how to use Firestore to store user data in the following steps.
Open up the Firebase Console and select
Select the project you created earlier on and press
After your project was added, select
Database to be routed to Firestore:
On there, select
Stay with the
locked mode option and press
After that, your database should be created.
To access the database, you have to authenticate yourself, for which you need add a service account. To create one, go to your project settings:
On there, switch to the
Service Accounts tab:
At the bottom of the page, you will find the
Generate new private key button, which will download a
JSON file that you will need later on:
For now you're done here, but eep the tab open, since you will need it in a minute.
To use Firestore in your project, you will need the
After that go to your
app.js file and import as well as enable it:
Last but not least, you have to configure the plugin. For that you will need the database url, which you can find on the tab you left open, as well as the
JSON file you downloaded a minute ago:
JSON file inside your project's
src folder and add the following to your
That's it. Your project will now use Firestore as its database.