integrations/gmail/hub.md
Simplify your email communication and supercharge your chatbot with seamless integration between Botpress and Gmail. Experience the power of combining your AI-powered chatbot with the versatility of Gmail, empowering you to streamline workflows, automate tasks, and deliver exceptional customer experiences. Unlock a world of possibilities as your chatbot seamlessly interacts with your Gmail inbox, managing emails, composing messages, and executing actions with ease. Leverage Gmail's robust features, such as advanced search, labeling, and filtering, to efficiently organize and respond to emails. Elevate your chatbot's capabilities and revolutionize your email-based interactions with the Botpress and Gmail Integration.
Unfortunately, automatic configuration is temporarily unavailable.
We are currently in the process of getting our Gmail integration verified by Google. Once this verification is complete, you will be able to use the automatic configuration method to set up the Gmail integration with just a few clicks. Until then, you will need to create your own OAuth app by following the steps outlined in the Manual configuration with OAuth section below.
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 must configure the Gmail integration using OAuth.
To set up the Gmail integration using OAuth, click the authorization button and follow the on-screen instructions to connect your Botpress chatbot to Gmail.
When using this configuration mode, a Botpress-managed Gmail application will be used to connect to your Gmail account. However, actions taken by the bot will be attributed to the user who authorized the connection, rather than the application. For this reason, we do not recommend using personal Gmail accounts for this integration. You should set up a service account and use this account to authorize the connection.
To set up the Gmail integration manually, you must create a Google Cloud Platform project and enable the Gmail API. You will also need to create OAuth credentials, set up a Pub/Sub topic, and configure the integration in Botpress.
Select a resource dropdown in the top navigation bar and selecting New Project.APIs & Services section.Library in the left sidebar.Gmail API and click on the result.Enable button to enable the Gmail API for your project.In the Google Cloud Console, navigate to the APIs & Services section.
Click on OAuth consent screen in the left sidebar.
Select External as the user type and click the Create button.
Enter a name for your application and fill in the other required fields.
Click the Save and continue button.
Click the Add or remove scopes button.
Under Manually add scopes, enter the following:
https://www.googleapis.com/auth/userinfo.email
https://www.googleapis.com/auth/userinfo.profile
https://www.googleapis.com/auth/gmail.readonly
https://www.googleapis.com/auth/gmail.send
Click the Add to table button, followed by the Update button.
Click the Save and continue button.
Under Test users, enter the email address of the user you would like to use with the integration.
Click the Save and continue button again.
Click the Back to dashboard button.
APIs & Services section.Credentials in the left sidebar.Create credentials dropdown and select OAuth client ID.Web application as the application type.Authorized redirect URIs, enter https://botpress.com.Create button to create the OAuth client ID.The client ID is the string that ends with
.apps.googleusercontent.com.
IAM & Admin section.Service accounts in the left sidebar.Create service account button.Done button to create the service account.
There is no need to grant any roles to the service account, as it will only be used to sign webhook events.
The service account email address is the string that ends with
.gserviceaccount.com.
Pub/Sub section.Topics in the left sidebar.Create topic button.Topic ID field.Add default subscription checkbox.Create button to create the topic.The topic name is the string that starts with
projects/.
Pub/Sub section.Topics in the left sidebar.View permissions from the dropdown menu.Add principal button.Add principals, enter [email protected].
This service account is managed by Google and is used to push events to Pub/Sub.
Assign roles, select the role Pub/Sub Publisher.Save button to grant publish rights to the service account.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 tools like openssl or online password generators to create a secure string.
For example, you can generate a secure string using one the following commands:
# Using openssl:
openssl rand -hex 32
# Using nodejs:
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
# Using Python 3:
python3 -c "import secrets; print(secrets.token_hex(32))"
You may also use an online password generator to create a secure string:
Copy the shared secret for use in the next steps.
Pub/Sub section.Subscriptions in the left sidebar.Create subscription button.Subscription ID field.Topic dropdown.Delivery type, select Push.Endpoint URL field. To this URL, append ?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, the endpoint URL would behttps://webhook.botpress.cloud/57fcfb04-51fd-4381-909a-10e6ae53d310?shared_secret=your_shared_secret.
Enable authentication checkbox.Service account field.Audience field.Expiration period, select Never expire.Acknowledgement deadline, enter 60 seconds.Retry policy, select Retry after exponential backoff delay. Set the minimum backoff to 60 second and the maximum backoff to 600 seconds.Create button to create the subscription.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 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.
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 may use online tools such as https://semalt.tools/en/url-parser or https://parseurlonline.com.
You may now safely close this page.
Manual configuration mode in the Botpress integration settings.projects/.Unfortunately, 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 the
Authorizing the OAuth applicationsection. If the authorization code is not expired, it will be exchanged for a refresh token, which will be used to authenticate the integration.
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.
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.