We'll show you how to set up your environment to locally test and develop with the Google Cloud Functions local emulator and to deploy to Google Cloud Functions for production hosting.
Set up local fulfillment
When developing, it's very useful to have a local fulfillment server so you can quickly deploy code changes and test them. However, because your app is deployed to the web, you must use a tool like ngrok to expose the fulfillment server to the internet. Here's our recommended environment for developing fulfillment locally:
Cloud Functions local emulator - The emulator lets you deploy a Cloud Function locally for quick testing.
ngrok - This tool creates an externally addressable URL (API.AI requires this) for a local development server. This lets you test your fulfillment logic with API.AI without having to deploy to a production Google Cloud Function.
Node.js - Node.js is our preferred development language, and our samples and client library are Node.js based. You'll also install the Google Cloud Functions local emulator with the Node Package Manager (
To set up your environment:
- Download and install Node.js.
Install the Google Cloud local emulator:
npm install -g @google-cloud/functions-emulator
Download and install ngrok. Ngrok is a single file binary, so wherever you unpack it to, it's convenient to add that directory to your system path.
Install the sample dependencies for the Node.js fulfillment, where
<cloud_function_dir>is the directory that contains your fulfillment (for example, the directory that contains your
cd <cloud_function_dir> npm install
Run the following commands to deploy the function.
cd <cloud_function_dir> functions start functions deploy cloudFunctionName --trigger-http
The output of the commands displays a table of information. Make note of the URL specified by the Resource row. You'll need the port and path of that URL. For example, if the resource row shows:
the port is
8010and the path is
ngrokwith the port specified by the Resource URL:
<ngrok-dir>/ngrok http <port>
Your fulfillment URL is the ngrok hostname appended with the path of the Resource URL. For example:
In API.AI's left navigation, click Fulfillment and enter the fulfillment URL in the URL field.
Set up production fulfillment
- Download and install Node.js.
Set up and initialize the Firebase CLI. If the following command fails with an
EACCESerror, you may need to change npm permissions.
npm install -g firebase-tools
Authenticate the firebase tool with your Google account:
Associate the firebase tool with your Actions project:
firebase use PROJECT_ID
Get the fulfillment dependencies and deploy the fulfillment:
cd <<cloud_function_dir>>/functions npm install firebase deploy --only functions
The deployment takes a few minites. Once completed, you'll see output similar to the following. You'll need the Function URL to enter in API.AI.
✔ Deploy complete!
Project Console: https://console.firebase.google.com/project/factsapp-abb1d/overview Function URL (factsAboutGoogle): https://us-central1-factsapp-abb1d.cloudfunctions.net/factsAboutGoogle
In API.AI's left navigation, click Fulfillment, move the ENABLED slider to the right, and enter the Function URL in the URL field. For example, if your project ID is
factsapp-abb1d, your API.AI fulfillment setting might look like this screenshot.