Fulfillment Hosting

You can use any web hosting platform that supports HTTPS to host your fulfillment. For your convenience, we provide a Node.js client library that parses requests and generates the necessary JSON payloads for responses.

If you don't already have a preferred hosting platform, we'll show you how to deploy to a production environment with Cloud Functions for Firebase with one of our samples. We also show you how to deploy a generic project with Google App Engine and Heroku.

Deploying to Cloud Functions for Firebase

When you create an Actions on Google project, a corresponding Firebase project is also created. This makes it easy to use Firebase products, such as Cloud Functions for Firebase, and all of our samples are built to support Cloud Functions for Firebase. We'll show you how to deploy fulfillment with one of our samples in the following sections.

Get the Facts About Google sample

We'll use our Facts About Google sample for this example. To get the sample, download and unzip the Facts about Google sample app from GitHub or clone the repository.

We'll refer to the sample app directory as <sample_dir>. The sample app contains a Dialogflow agent (<sample_dir>/FactsAboutGoogle.zip) and the corresponding fulfillment (sample_dir/functions/index.js), which you'll deploy to Cloud Functions for Firebase.

Deploy the fulfillment

  1. Download and install Node.js.
  2. Set up and initialize the Firebase CLI. If the following command fails with an EACCES error, you may need to change npm permissions.

    npm install -g firebase-tools
    
  3. Authenticate the firebase tool with your Google account:

    firebase login
    
  4. Associate the firebase tool with your Actions project:

    cd <sample_dir>/functions
    firebase use PROJECT_ID
    
  5. Get the fulfillment dependencies and deploy the fulfillment:

        cd <sample_dir>/functions
        npm install
        firebase deploy --only functions
    

    The deployment takes a few minutes. Once completed, you'll see output similar to the following. You'll need the Function URL to enter in Dialogflow.

    ✔  Deploy complete!
    Project Console: https://console.firebase.google.com/project/myprojectname-ab123/overview Function URL (factsAboutGoogle): https://us-central1-myprojectname-ab123.cloudfunctions.net/factsAboutGoogle

  6. If you're using Dialogflow: In Dialogflow's left navigation, click Fulfillment, move the ENABLED slider to the right, and enter the Function URL in the URL field. For example, your Dialogflow fulfillment setting might look like this screenshot.

  7. If you're using Actions SDK: Create an object inside the conversations object to declare your fulfillment in your action package:

    "conversations": {
      "myFulfillmentFunction": {
        "name": "myFulfillmentFunction",
        "url": "(factsAboutGoogle): https://us-central1-myprojectname-ab123.cloudfunctions.net/factsAboutGoogle"
      }
    }
    

Other hosting options

Deploying to Google App Engine

  1. Download Google Cloud SDK.
  2. Download and install Node.js.
  3. In the Cloud Platform Console, go to the Projects page and select or create a new project. This should be the project you are using for your actions.
  4. Enable billing for your project. See the console help center for more information. Note: Note the Project ID, since it is used for configuration and deployment.

  5. Initialize the Cloud SDK with the following command:

    gcloud init
    
  6. Run the following commands to configure your Google cloud project:

    gcloud config set project <project-id>
    
  7. Deploy fulfillment:

    cd <fulfillment-app-dir>
    gcloud app deploy
    

    You should see a long response from the gCloud CLI (it may take a few minutes) with the final portion looking similar to:

    Updating service [default]...done.
    Deployed service [default] to your-appengine-url.appspot.com
    
    You can read logs from the command line by running:
      $ gcloud app logs read
    
    To view your application in the web browser run:
      $ gcloud app browse
    

Deploying to Heroku

See the Heroku documentation for full instructions on setting up a project and deploying it.

  1. Sign up for a Heroku account if you don’t already have one.
  2. In your Heroku Apps list, click New > Create New App in the top right and specify an app name.
  3. Download the Heroku CLI. To ensure it works, run heroku --version.
  4. If your project is not already in a Git repo, initialize your project directory:

    cd git init

  5. Type heroku login and enter your credentials to log in to the Heroku CLI.

  6. Run heroku git:remote -a <HEROKU_APP_NAME> to register your remote Heroku project repository with your local Git project. If you already have a Git repo in your Heroku project, then clone the repo with heroku git:clone -a <HEROKU_APP_NAME>.
  7. Add and commit your files if you haven’t already, using git add . and git commit -am "Initial commit"
  8. Use git push heroku master to push your local app to Heroku
  9. Make sure you set your Heroku app’s URL, found in your app’s settings, as the fulfillment Webhook URL in the Fulfillment page of Dialogflow.
  10. You can view your projects logs using with heroku logs