diff --git a/integrations/integration-guides/gmail.mdx b/integrations/integration-guides/gmail.mdx index f5c17da2..b8862fa9 100644 --- a/integrations/integration-guides/gmail.mdx +++ b/integrations/integration-guides/gmail.mdx @@ -21,153 +21,285 @@ The Gmail integration allows your bot to chat with users via your Gmail address. ## 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 set up the integration using [manual configuration](#manual-configuration). - - {/* ### Automatic configuration with OAuth - - To set up the Gmail integration using OAuth, click the authorization button and follow the on-screen instructions to connect your Botpress bot 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 don't recommend using personal Gmail accounts** for this integration. You should set up a service account and use this account to authorize the connection. - - #### Configuring the integration in Botpress - - 1. Authorize the Gmail integration by clicking the authorization button. - 2. Follow the on-screen instructions to connect your Botpress bot to Gmail. - 3. Once the connection is established, you can save the configuration and enable the integration. */} - - - - - You will need: - - - A [Gmail account](https://accounts.google.com/lifecycle/steps/signup/name?dsh=S488568382:1750873665808135&flowEntry=SignUp&flowName=GlifWebSignIn&ifkv=AdBytiOTk616W0u9QbXQoFbPYoR1Qt9WGXLoe9KHjswYWHiW2YTuLodd-4Obm8grx6EQIpFLKcluuQ&TL=ALgCv6xtJQTT14EXPydgMeNRTVl3Q1ie-kqOs_0vn7uPY_I47_GueZAXRwuHK72t&continue=https://accounts.google.com/ManageAccount?nc%3D1) - - - ### Step 1. Create a Google Cloud Platform project - - 1. Login to [Google Cloud Console](https://console.cloud.google.com/) with your Gmail account. - 2. Select **Select a project** dropdown in the top navigation. Then, select **New Project**. - 3. Follow the on-screen instructions to create the new project. - - ### Step 2. Enable the Gmail API - - 1. In Google Cloud Console, navigate to the *APIs & Services* section. - 2. Select **Library** from the left sidebar. - 3. Search for **Gmail API** and select the result. - 4. Select **Enable** to enable the Gmail API for your project. - - ### Step 3. Configure the OAuth consent screen - - 1. In Google Cloud Console, navigate to the **APIs & Services** section. - 2. Select **OAuth consent screen** in the left sidebar. - 3. Select **Get Started** and fill out the **App Information** section. Then, select *Next*. - 4. Under **Audience**, select **External** - 5. Fill in the other required sections, then select **Create**. - 6. Navigate to the **Data Access** tab, then select **Add or remove scopes**. - 7. Under `Manually add scopes`, enter the following: + + + You will need: + + - A [published bot](/get-started/quick-start) + - A [Google account](https://accounts.google.com/) + + + + + 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 **Authorize Gmail**. + + + Follow the instructions to connect Botpress to your Google account. + + + + + When using basic configuration, 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 don't recommend using personal Gmail accounts** for this integration. You should set up a [service account](https://docs.cloud.google.com/iam/docs/service-account-overview) and use that account to authorize the connection. + + + + For more advanced use cases, you can manually configure the integration. + + + You will need: + + - A [published bot](/get-started/quick-start) + - A [Google account](https://accounts.google.com/) + - Access to [Google Cloud Console](https://console.cloud.google.com/) + + + ### Step 1. Create a Google Cloud Platform project + + + + Log in to [Google Cloud Console](https://console.cloud.google.com/) 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: ```plaintext https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile - https://www.googleapis.com/auth/gmail.readonly + https://mail.google.com/ https://www.googleapis.com/auth/gmail.send ``` - - 8. Select **Add to table**, then **Update**. - 9. Select **Save** at the bottom of the screen. - 10. Navigate to the **Audience** tab. Under **Test users**, select ** + Add users**. - 11. Add an email address for testing the app, then select **Save**. - - ### Step 4. Create OAuth credentials - - 1. In Google Cloud Console, navigate to the **APIs & Services** section. - 2. Select **Credentials** in the left sidebar. - 3. Select **Create credentials**, then **OAuth client ID**. - 4. Select **Web application** as the application type. - 5. Enter a name for the OAuth client ID. - 6. Under **Authorized redirect URIs**, enter `https://botpress.com`. - 7. Select **Add URI**, then **Create**. - 8. Copy the **Client ID** and **Client secret** for use in the next steps. + + + 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 - - 1. In Google Cloud Console, navigate to the **IAM & Admin** section. - 2. Select **Service accounts** in the left sidebar. - 3. Select **Create service account**. - 4. Enter a name for the service account. Then, select **Done**. + + + + ### 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. - - 6. Copy the service account email address for use in the next steps. + + + 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 - - 1. In Google Cloud Console, search for and navigate to the **Pub/Sub** section. - 2. Select **Topics** in the left sidebar. - 3. Select **Create topic**. - 4. Enter a name for the topic in the **Topic ID** field. - 5. Uncheck the **Add default subscription** checkbox. Leave the other options unchanged. - 7. Select **Create** to create the topic. - 8. Copy the **Topic name** for use in the next steps. + + + + ### 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 - - 1. In Google Cloud Console, search for and navigate to the **Pub/Sub** section. - 2. Select **Topics** in the left sidebar. - 3. From the topic list, find the topic you created earlier. Then, select the triple-dot button on the right. - 4. Select **View permissions** from the dropdown menu. - 5. Select **Add principal**. - 6. Under **Add principals**, enter `gmail-api-push@system.gserviceaccount.com`. + + + + ### 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. + + - 7. Under **Assign roles**, select `Pub/Sub Publisher`. - 8. Select **Save** to grant publish rights to the service account. - - ### Step 8. Generate a shared secret + ### Step 8. Generate a shared secret - 1. 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. + + + 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](https://bitwarden.com/password-generator/) to create a secure string. - - 2. Copy this string for use in the next steps. - - ### Step 9. Create a Pub/Sub subscription - - 1. In **Google Cloud Console**, search for and navigate to the **Pub/Sub** section. - 2. Select **Subscriptions** in the left sidebar. - 3. Select **Create subscription**. - 4. Enter a name for the subscription in the **Subscription ID** field. - 5. Select the topic you created earlier from the topic dropdown. - 6. Under **Delivery type**, select **Push**. - 7. 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. + + + 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: @@ -181,76 +313,128 @@ Due to the sensitive nature of email communication, the Gmail integration requir in the **Endpoint URL** field. - - 8. Check the **Enable authentication** checkbox. - 9. Select the service account email address you created earlier in the **Service account** field. - 10. Enter the shared secret you generated earlier in the `Audience` field. - 11. Under **Expiration period**, select **Never expire**. - 12. Under **Acknowledgement deadline**, enter 60 seconds. - 13. Under **Retry policy**, select **Retry after exponential backoff delay**. Set the minimum backoff to 60 seconds and the maximum backoff to 600 seconds. - 14. Select **Create** to create the subscription. - - ### Step 10. Authorize the OAuth application - - 1. On Gmail, log in to the Google account you want to use with the Gmail integration. - 2. 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= - ` + + + 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. - Make sure to add your OAuth **Client ID** from [Step 4](#step-4-create-oauth-credentials) to the end of the URL. For example, if your OAuth client ID is `abcd`, the URL should end with `&client_id=abcd`. + Although this field is marked optional in Google Console, it's required for the integration to work properly. + + + 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://mail.google.com/%20https://www.googleapis.com/auth/gmail.send&access_type=offline&prompt=consent&redirect_uri=https://botpress.com&client_id=YOUR_CLIENT_ID + ``` + + Replace `YOUR_CLIENT_ID` with your OAuth **Client ID** from [Step 4](#step-4-create-oauth-credentials). For example, if your OAuth client ID is `abcd`, the URL should end with `&client_id=abcd`. - 3. Follow the on-screen instructions to authorize the OAuth application with your personal Gmail account. + + + 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](https://botpress.com). Don't close this page. - - 4. 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. + + + 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. - 5. You can now safely close this page. - - ### Step 11. Configure the integration in Botpress - - 1. In Botpress Studio, select **Explore Hub** in the upper-right corner. - 2. Search for the **Gmail** integration, then select **Install Integration**. - 3. In the Configuration menu, select **Configure manually with your own GCP App**. - 4. Fill in the required fields with all the information you saved from the previous steps. + + If you update any scopes, you need to generate a new authorization code and add it to the integration's configuration in Botpress Studio. The previous authorization code won't have the correct scope permissions. + + + + 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](#step-10-authorize-the-oauth-application). - - 10. Select **Save Configuration**. If no error message is displayed, the integration was successfully configured. - + + + Select **Save Configuration**. If no error message is displayed, the integration was successfully configured. + + + --- +## Using the integration + +Once you’ve successfully configured the integration, the email address you provided will begin responding to all incoming messages as your bot. If this is your desired behaviour, no additional setup is required. + +You can also use the integration's [Cards](#cards) to interact with your Gmail inbox. This allows you to manage threads, drafts, attachments, and other data associated with your inbox. + +--- + ## Limitations - - 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 bot adheres to these limitations to maintain optimal performance and reliability. - - More details are available in the [Gmail API documentation](https://developers.google.com/gmail/api/reference/quota). - + + 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 bot adheres to these limitations to maintain optimal performance and reliability. + + More details are available in the [Gmail API documentation](https://developers.google.com/gmail/api/reference/quota). + +--- + ## Cards