Prerequisite setup

This prerequisite setup deploys the Echo Bot sample, a web application, to Google Cloud Platform. The Echo Bot defines a webhook URL, which you need to register as a partner with Business Messages.

This guide assumes that you haven't set up a GCP project for use with Business Messages.

Create a GCP project

You need a GCP project to deploy the sample code in App Engine.

  1. Open the Google Cloud Console Project Selector with your Business Messages Google account.
  2. Click Create Project and provide a Project name for your new project.
  3. Click Create.
  4. Note the Project number. You need to provide your project number when you register with Business Messages.

Create a service account

You need to create a service account to access the Business Messages and Business Communications APIs.

  1. Navigate to Credentials.
  2. Click + Create Credentials > Service account.
  3. For Service account name, enter an agent name (such as "bm-agent" or "echo-bot"), then click Create.
  4. Under Create key, choose JSON, then click Create.
  5. Click Done and save the JSON credentials file. Store the downloaded credentials in a secure location.

Deploy the web application to GCP

Business Messages forwards messages from your customers to a webhook in your infrastructure. For this guide, you will deploy a new web application to GCP with a webhook designed to process customer messages from Business Messages.

If you already have web infrastructure to leverage for receiving messages from Business Messages, you can create a new webhook on that web service to handle messages similar to the Echo Bot sample. See Receive messages for more details. For this guide, you will deploy the Echo Bot sample source code provided to obtain this webhook.

  1. Download and extract the Echo Bot Sample (Node.js, Java, Python)

  2. Copy your JSON credentials file created for the service account into the sample's resources folder and rename the credentials to "bm-agent-service-account-credentials.json". The path to this credentials file will depend on the sample you downloaded.

    Node.js

    ./bm-nodejs-echo-bot/resources/bm-agent-service-account-credentials.json
    

    Java

    ./bm-java-echo-bot/src/main/resources/bm-agent-service-account-credentials.json
    

    Python

    ./bm-python-echo-bot/resources/bm-agent-service-account-credentials.json
    
  3. In a terminal, navigate to the sample's root directory.

  4. Run the following commands in a terminal to deploy the sample:

    Node.js

    gcloud config set project PROJECT_ID
    gcloud app create
    gcloud app deploy
    

    PROJECT_ID is the project ID for the project you created in the Create a GCP project step above.

    Java

    gcloud config set project PROJECT_ID
    gcloud app create
    mvn appengine:deploy
    

    PROJECT_ID is the project ID for the project you created in the Create a GCP project step above.

    Python

    gcloud config set project PROJECT_ID
    gcloud app create
    gcloud app deploy
    

    PROJECT_ID is the project ID for the project you created in the Create a GCP project step above.

  5. Note the URL of the deployed application in the output of the last command:

    Deployed service [default] to [https://PROJECT_ID.appspot.com]

Register with Business Messages

Register as a partner with Business Messages. The form requests details that can associate your GCP Project with Business Messages.

Submit the form and wait for approval. You receive an email once Google registers your project, which can take up to three days.

Enable the APIs

Once you receive confirmation from Google that your project is registered with Business Messages, you must use two APIs to operate and manage Business Messages agents: the Business Messages API sends and receives messages while the Business Communications API creates and manages agents.

To enable the APIs:

  1. Open the Business Messages API in the Google Cloud Console.
  2. Click Enable.
  3. Open the Business Communications API in the Google Cloud Console.
  4. Click Enable.

Set your webhook

Now that the Business Messages and Business Communications API is enabled for your project, you must specify your webhook URL in order to start receiving messages.

  1. Open the Business Communications Developer Console and sign in with your Business Messages Google account.
  2. Click Account settings.
  3. Make sure the correct partner account is selected.
  4. Enter your Business Messages webhook URL.
  5. Click Save.

See Example: Update webhook URL to see how to configure your webhook with the Business Communication APIs.

Install and test oauth2l

oauth2l is used to securely connect with the Business Communications and Business Messages APIs. All curl requests in this site's documentation use oauth2l for authentication.

To install oauth2l with Python 3,

  1. Download oauth2l.

  2. Change the directory to "./oauth2l/python".

  3. Install oauth2l with the following command.

    sudo python setup.sh build && sudo python setup.py install
    
  4. Test that oauth2l can generate an authorization token.

    oauth2l header --json resources/bm-agent-service-account-credentials.json businesscommunications
    
  5. Verify that the output creates an authorization token of the form:

    Authorization: Bearer AUTHORIZATION_BEARER_TOKEN
    

There are other ways to install oauth2l for different operating systems. Regardless of the installation method you choose, ensure that you can generate an authorization token based on the service account JSON credentials before proceeding with this quickstart.

Next steps

Once you enable the APIs and set your webhook URL, you can create your first agent.