This sample demonstrates how to create an appointment setting agent for the Business Messages platform using Dialogflow and the Business Messages Node.js client library.
This sample runs on the Google App Engine.
See the Google App Engine (https://cloud.google.com/appengine/docs/nodejs/) standard environment documentation for more detailed instructions.
The documentation for the Business Messages API can be found here.
You must have the following software installed on your machine:
- Google Cloud SDK (aka gcloud)
- Node.js - version 10 or above
- Register with Business Messages.
- Once registered, follow the instructions to enable the APIs for your project.
This sample application uses a service account key file to authenticate the Business Messages API calls for your registered Google Cloud project. You must download a service account key and configure it for the sample.
To download a service account key and configure it for the sample, follow the instructions below.
-
Open Google Cloud Console with your Business Messages Google account and make sure you select the project that you registered for Business Messages with.
-
Create a service account.
-
Navigate to Credentials.
-
Click Create service account.
-
For Service account name, enter your agent's name, then click Create.
-
For Select a role, choose Project > Editor, then click Continue.
-
Under Create key, choose JSON, then click Create.
Your browser downloads the service account key. Store it in a secure location.
-
Click Done.
-
Copy the JSON credentials file into this sample's /resources folder and rename it to "bm-agent-service-account-credentials.json".
-
- Open the Create an agent guide and follow the instructions to create a Business Messages agent.
-
Open Dialogflow Console with your Google account and create a new Dialogflow agent.
-
After the agent is created, click the great icon next to the name of your agent in the left navigation.
-
Click the Service Account email field. This will open the Service accounts page within the Google Cloud Console.
-
Download a service account key.
-
Click the three dots for see the overflow menu for the existing service account in the table.
-
Click Create key.
-
One the dialog that opens, click Create to download the service account key.
-
Copy the JSON credentials file into this sample's /resources folder and rename it to "df-agent-service-account-credentials.json".
-
-
Go back to the Dialogflow Console and from the agent configuration page, click Export and Import.
-
Click the RESTORE FROM ZIP button and select the zip file within this samples root directory called dialogflow-appointmentbot.zip.
-
Once the Dialogflow agent is imported, click Fulfillment from the left navigation.
-
Under Webhook, click the Disabled toggle onto Enabled and enter https://PROJECT_ID.appspot.com/fulfillment/dfCallback in the URL field. Replace PROJECT_ID with the Google Cloud project you created and registered with Business Messages.
-
Click SAVE at the bottom of this page.
-
Open the views/index.ejs file from the samples route directory.
-
Locate the Chat now anchor link and update the href value to your agent's test URL. You can retrieve your agent's test URL by issuing a GET request via Business Communications API for your agent.
-
In a terminal, navigate to this sample's root directory.
-
Run the following commands:
gcloud config set project PROJECT_ID
Where PROJECT_ID is the project ID for the project you created when you registered for Business Messages.
gcloud app deploy
-
On your mobile device, use the test business URL associated with the Business Messages agent you created. Open a conversation with your agent and follow the prompts to book an appointment.
See the Test an agent guide if you need help retrieving your test business URL.