First of all, I tell if you are beginner then follow this link before reaching here
Before getting start actions development using firebase cli you need some steps to keep in mind
The following tools must be in your environment:
- An IDE/text editor of your choice, such as WebStorm, Atom, visual studio code.
- A terminal to run shell commands with NodeJS, npm, and git installed.
- A web browser, such as Chrome.
- An account on GitHub.com. (You can create one for free.)
We make our first google actions Fact actions. You can find the sample code below
Sample fact action code link:- Google fact action
Now get started with Firebase CLI
Step 1: Install Firebase command line interface (CLI)
The Firebase Command Line Interface (CLI) will allow you to deploy your Actions project to Cloud Functions.
To install or upgrade the CLI run the following npm command:
npm -g install firebase-tools Tip:- Doesn't work? You may need to change npm permissions.
To verify that the CLI has been installed correctly, open a terminal and run:
firebase --version Tip:- Make sure the version of the Firebase CLI is above 3.5.0 so that it has all the latest features required for Cloud Functions. If not, run npm install -g firebase-tools to upgrade as shown above.
Authorize the Firebase CLI by running:
Step 2: Setup for local development
Before setting up for local development you need to keep in mind some Key terms
- Cloud Functions for Firebase: A service provided by Google that lets you run your webhook code in a managed environment on the cloud. You use the Firebase CLI (command-line interface) tools to deploy your webhook to Google Cloud Functions.
Why develop your Actions locally?
In contrast to using the Dialogflow inline editor, you can use a local machine, which gives you more control over your programming and deployment environment. This provides several advantages:
- A locally-developed webhook supports a much larger suite of Actions on Google features.
- You are not restricted to only one webhook implementation file (
- Developing in a local environment also lets you follow software engineering best practices, such as using version control, for your Actions project.
Download your base files
Before starting development you need to download required Facts repositories
git clone https://github.com/actions-on-google/dialogflow-facts-about-google-nodejs
In order to test the Action that you’ll build for this project, you need to enable the necessary permissions.
- Go to the ‘Activity Controls’ page (https://myaccount.google.com/activitycontrols).
- Sign in with your Google account, if you have not already done so.
- Ensure that the following permissions are enabled:
- Web & App Activity
- Device Information
- Voice & Audio Activity
Step 3: Setup your project and agent
Next, you’ll need to set up the Actions project and the Dialogflow agent for your fact action
If you’ve already completed the MAKE YOUR FIRST GOOGLE ACTION FOR GOOGLE ASSISTANT.
Then do following
- Go directly to the Dialogflow console.
- Navigate to Fulfillment.
- Disable Inline Editor.
- Click Save.
If you’re starting from scratch, do the following:
- Open the Actions Console.
- Click on Add/import project.
- Type in a Project name, like “world facts”. This name is for your own internal reference; later on, you can set an external name for your project.
- Click Create Project.
- Rather than pick a category, click Skip on the upper-right corner.
- Click Build > Actions in the left nav.
- Click Add your first Action.
- On the Custom intent dialog, click Build to launch the Dialogflow console.
- Click Create.
- Click the gear icon on the left navigation.
- Click Export and Import.
- Click Restore From Zip.
- Upload the FactsAboutGoogle.zip file.
- Type “RESTORE” and click the Restore button.
- Click Done
Step 4: Deploy your fulfillment
Now that your Actions project and Dialogflow agent are ready, do the following to deploy your local
index.js file using the Firebase Functions CLI:
firebase use <PROJECT_ID>
for finding project id see the below picture
Run the following command in the terminal to install dependencies.
Run the following command to deploy your webhook to firebase
Note:- If you see an error message that says “An unexpected error has occurred from the CLI.”, try running the command
firebase deploy again.
Step 5: Setup the URL in dialogflow
Now you need to update your Dialogflow agent to use your webhook for fulfillment. To do so, follow these steps:
- Open the Dialogflow console (you can close the Firebase console if you’d like).
- Navigate to Fulfillment on the left navigation.
- Enable Webhook.
- Paste the URL you copied from the Firebase dashboard if it doesn’t already appear.
- Click Save.
Note:- You get your webhook url after deploying your code to firebase function sucessfully.