Gmail
The Gmail integration allows your bot to chat with users via your Gmail address.
Once you’ve successfully configured the Gmail integration, the email address you provided will begin responding to all incoming emails as your bot. Please be aware of this behaviour before configuring the integration.
Setup
Due to the sensitive nature of email communication, the Gmail integration requires a secure connection between Botpress and Gmail. To establish this secure connection, you need to configure the Gmail integration using OAuth.
Automatic configuration is temporarily unavailable
The Gmail integration is currently undergoing a verification process by Google. This means the option to automatically configure your Gmail integration is temporarily unavailable.
You can still setup the integration using manual configuration.
Automatic configuration is temporarily unavailable
The Gmail integration is currently undergoing a verification process by Google. This means the option to automatically configure your Gmail integration is temporarily unavailable.
You can still setup the integration using manual configuration.
You will need:
Step 1. Create a Google Cloud Platform project
- Login to Google Cloud Console with your Gmail account.
- Select Select a project dropdown in the top navigation. Then, select New Project.
- Follow the on-screen instructions to create the new project.
Step 2. Enable the Gmail API
- In Google Cloud Console, navigate to the APIs & Services section.
- Select Library from the left sidebar.
- Search for Gmail API and select the result.
- Select Enable to enable the Gmail API for your project.
Step 3. Configure the OAuth consent screen
- In Google Cloud Console, navigate to the APIs & Services section.
- Select OAuth consent screen in the left sidebar.
- Select Get Started and fill out the App Information section. Then, select Next.
- Under Audience, select External
- Fill in the other required sections, then select Create.
- Navigate to the Data Access tab, then select Add or remove scopes.
- Under
Manually add scopes
, enter the following:
- Select Add to table, then Update.
- Select Save at the bottom of the screen.
- Navigate to the Audience tab. Under Test users, select ** + Add users**.
- Add an email address for testing the app, then select Save.
Step 4. Create OAuth credentials
- In Google Cloud Console, navigate to the APIs & Services section.
- Select Credentials in the left sidebar.
- Select Create credentials, then OAuth client ID.
- Select Web application as the application type.
- Enter a name for the OAuth client ID.
- Under Authorized redirect URIs, enter
https://botpress.com
. - Select Add URI, then Create.
- Copy the Client ID and Client secret for use in the next steps.
The client ID is the string that ends with .apps.googleusercontent.com
.
Step 5. Create a service account
- In Google Cloud Console, navigate to the IAM & Admin section.
- Select Service accounts in the left sidebar.
- Select Create service account.
- Enter a name for the service account. Then, select Done.
You don’t need to grant any roles to the service account, as it will only be used to sign webhook events.
- Copy the service account email address for use in the next steps.
The service account email address is the string that ends with .gserviceaccount.com
.
Step 6. Create a Pub/Sub topic
- In Google Cloud Console, search for and navigate to the Pub/Sub section.
- Select Topics in the left sidebar.
- Select Create topic.
- Enter a name for the topic in the Topic ID field.
- Uncheck the Add default subscription checkbox. Leave the other options unchanged.
- Select Create to create the topic.
- Copy the Topic name for use in the next steps.
The topic name is the string that starts with projects/
.
Step 7. Grant publish rights on the Pub/Sub topic
- In Google Cloud Console, search for and navigate to the Pub/Sub section.
- Select Topics in the left sidebar.
- From the topic list, find the topic you created earlier. Then, select the triple-dot ⋮ button on the right.
- Select View permissions from the dropdown menu.
- Select Add principal.
- Under Add principals, enter
gmail-api-push@system.gserviceaccount.com
.
This service account is managed by Google and is used to push events to Pub/Sub.
- Under Assign roles, select
Pub/Sub Publisher
. - Select Save to grant publish rights to the service account.
Step 8. Generate a shared secret
- Generate an alphanumeric string to use as a shared secret for signing Pub/Sub push events. We recommend using a string with at least 32 characters.
You can use an online password generator to create a secure string.
- Copy this string for use in the next steps.
Step 9. Create a Pub/Sub subscription
- In Google Cloud Console, search for and navigate to the Pub/Sub section.
- Select Subscriptions in the left sidebar.
- Select Create subscription.
- Enter a name for the subscription in the Subscription ID field.
- Select the topic you created earlier from the topic dropdown.
- Under Delivery type, select Push.
- Enter your integration’s Botpress-provided webhook URL in the Endpoint URL field. To this URL, add
?shared_secret=
, followed by the shared secret you generated earlier.
For example, if:
- Your integration’s webhook URL is:
https://webhook.botpress.cloud/57fcfb04-51fd-4381-909a-10e6ae53d310
- Your shared secret is
Ut5hzrxs7uV87mzCAKL3ztrzesWWBiNa
You would enter:
https://webhook.botpress.cloud/57fcfb04-51fd-4381-909a-10e6ae53d310?shared_secret=Ut5hzrxs7uV87mzCAKL3ztrzesWWBiNa
in the Endpoint URL field.
- Check the Enable authentication checkbox.
- Select the service account email address you created earlier in the Service account field.
- Enter the shared secret you generated earlier in the
Audience
field. - Under Expiration period, select Never expire.
- Under Acknowledgement deadline, enter 60 seconds.
- Under Retry policy, select Retry after exponential backoff delay. Set the minimum backoff to 60 seconds and the maximum backoff to 600 seconds.
- Select Create to create the subscription.
Step 10. Authorize the OAuth application
- On Gmail, log in to the Google account you want to use with the Gmail integration.
- Once logged in, go to the following URL in your browser:
https://accounts.google.com/o/oauth2/auth?response_type=code&scope=https://www.googleapis.com/auth/gmail.readonly%20https://www.googleapis.com/auth/gmail.send&access_type=offline&prompt=consent&redirect_uri=https://botpress.com&client_id=
Make sure to add your OAuth Client ID from Step 4 to the end of the URL. For example, if your OAuth client ID is abcd
, the URL should end with &client_id=abcd
.
- Follow the on-screen instructions to authorize the OAuth application with your personal Gmail account.
After completing the authorization, you will be redirected to botpress.com. Do not close this page.
- Copy the authorization code from the URL in your browser’s address bar. The authorization code is the string that appears after
code=
and before&scope=
in the URL.
If you have difficulty finding the authorization code in the URL, you can use online tools like https://semalt.tools/en/url-parser or https://parseurlonline.com.
- You can now safely close this page.
Step 11. Configure the integration in Botpress
- In Botpress Studio, select Explore Hub in the upper-right corner.
- Search for the Gmail integration, then select Install Integration.
- In the Configuration menu, select Configure manually with your own GCP App.
- Fill in the required fields with all the information you saved from the previous steps.
The authorization code is only valid for a short period of time. If the code has expired, you will need to repeat the steps outlined in Step 10.
- Select Save Configuration. If no error message is displayed, the integration was successfully configured.
Limitations
Costs
Costs
Botpress shall not be held responsible for any costs you may incur on the Google Cloud Platform while using the Gmail integration, should you choose to use the manual configuration mode. Ensure that you are aware of the costs associated with using the Gmail API and the Google Cloud Platform before using the manual configuration mode.
API limits
API limits
Standard Gmail API limitations apply to the Gmail integration in Botpress. These limitations include rate limits, message size restrictions, and other constraints imposed by the Gmail and Google Cloud platforms. Ensure that your chatbot adheres to these limitations to maintain optimal performance and reliability.
More details are available in the Gmail API documentation.