> ## Documentation Index
> Fetch the complete documentation index at: https://botpress.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Gmail

{/* vale on */}

[Open in Hub](https://studio.botpress.cloud/home?exploreHub=1\&hubItemId=intver_01KMZAHQQ8YSB2DRVR1B6YXNCN)
*v1.0.7*

The Gmail integration allows your bot to chat with users via your Gmail address.

> [!CAUTION]
>
> 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

> [tab] Basic configuration
>
> > [!NOTE]
> >
> > You will need:
> >
> > * A [published bot](https://botpress.com/docs/get-started/quick-start.md)
> > * A [Google account](https://accounts.google.com/)
>
> **Step 1**
>
> In Botpress Studio, select **Explore Hub** in the upper-right corner.
>
> **Step 2**
>
> Search for the **Gmail** integration, then select **Install Integration**.
>
> **Step 3**
>
> In the **Configuration** menu, select **Authorize Gmail**.
>
> **Step 4**
>
> Follow the instructions to connect Botpress to your Google account.
>
> > [!NOTE]
> >
> > 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.

> [tab] Manual configuration
>
> For more advanced use cases, you can manually configure the integration.
>
> > [!NOTE]
> >
> > You will need:
> >
> > * A [published bot](https://botpress.com/docs/get-started/quick-start.md)
> > * 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
>
> **Step 1**
>
> Log in to [Google Cloud Console](https://console.cloud.google.com/) with your Gmail account.
>
> **Step 2**
>
> Select **Select a project** dropdown in the top navigation. Then, select **New Project**.
>
> **Step 3**
>
> Follow the on-screen instructions to create the new project.
>
> ### Step 2. Enable the Gmail API
>
> **Step 1**
>
> In Google Cloud Console, navigate to the **APIs & Services** section.
>
> **Step 2**
>
> Select **Library** from the left sidebar.
>
> **Step 3**
>
> Search for **Gmail API** and select the result.
>
> **Step 4**
>
> Select **Enable** to enable the Gmail API for your project.
>
> ### Step 3. Configure the OAuth consent screen
>
> **Step 1**
>
> In Google Cloud Console, navigate to the **APIs & Services** section.
>
> **Step 2**
>
> Select **OAuth consent screen** in the left sidebar.
>
> **Step 3**
>
> Select **Get Started** and fill out the **App Information** section. Then, select **Next**.
>
> **Step 4**
>
> Under **Audience**, select **External**.
>
> **Step 5**
>
> Fill in the other required sections, then select **Create**.
>
> **Step 6**
>
> Navigate to the **Data Access** tab, then select **Add or remove scopes**.
>
> **Step 7**
>
> Under **Manually add scopes**, enter the following:
>
> ```plaintext theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
> https://www.googleapis.com/auth/userinfo.email
> https://www.googleapis.com/auth/userinfo.profile
> https://mail.google.com/
> https://www.googleapis.com/auth/gmail.send
> ```
>
> **Step 8**
>
> Select **Add to table**, then **Update**.
>
> **Step 9**
>
> Select **Save** at the bottom of the screen.
>
> **Step 10**
>
> Navigate to the **Audience** tab. Under **Test users**, select **+ Add users**.
>
> **Step 11**
>
> Add an email address for testing the app, then select **Save**.
>
> ### Step 4. Create OAuth credentials
>
> **Step 1**
>
> In Google Cloud Console, navigate to the **APIs & Services** section.
>
> **Step 2**
>
> Select **Credentials** in the left sidebar.
>
> **Step 3**
>
> Select **Create credentials**, then **OAuth client ID**.
>
> **Step 4**
>
> Select **Web application** as the application type.
>
> **Step 5**
>
> Enter a name for the OAuth client ID.
>
> **Step 6**
>
> Under **Authorized redirect URIs**, enter `https://botpress.com`.
>
> **Step 7**
>
> Select **Add URI**, then **Create**.
>
> **Step 8**
>
> Copy the **Client ID** and **Client secret** for use in the next steps.
>
> > [!NOTE]
> >
> > The client ID is the string that ends with `.apps.googleusercontent.com`.
>
> ### Step 5. Create a service account
>
> **Step 1**
>
> In Google Cloud Console, navigate to the **IAM & Admin** section.
>
> **Step 2**
>
> Select **Service accounts** in the left sidebar.
>
> **Step 3**
>
> Select **Create service account**.
>
> **Step 4**
>
> Enter a name for the service account. Then, select **Done**.
>
> > [!NOTE]
> >
> > You don't need to grant any roles to the service account, as it will only be used to sign webhook events.
>
> **Step 5**
>
> Copy the service account email address for use in the next steps.
>
> > [!TIP]
> >
> > The service account email address is the string that ends with `.gserviceaccount.com`.
>
> ### Step 6. Create a Pub/Sub topic
>
> **Step 1**
>
> In Google Cloud Console, search for and navigate to the **Pub/Sub** section.
>
> **Step 2**
>
> Select **Topics** in the left sidebar.
>
> **Step 3**
>
> Select **Create topic**.
>
> **Step 4**
>
> Enter a name for the topic in the **Topic ID** field.
>
> **Step 5**
>
> Uncheck the **Add default subscription** checkbox. Leave the other options unchanged.
>
> **Step 6**
>
> Select **Create** to create the topic.
>
> **Step 7**
>
> Copy the **Topic name** for use in the next steps.
>
> > [!NOTE]
> >
> > The topic name is the string that starts with `projects/`.
>
> ### Step 7. Grant publish rights on the Pub/Sub topic
>
> **Step 1**
>
> In Google Cloud Console, search for and navigate to the **Pub/Sub** section.
>
> **Step 2**
>
> Select **Topics** in the left sidebar.
>
> **Step 3**
>
> From the topic list, find the topic you created earlier. Then, select the triple-dot <kbd>⋮</kbd> button on the right.
>
> **Step 4**
>
> Select **View permissions** from the dropdown menu.
>
> **Step 5**
>
> Select **Add principal**.
>
> **Step 6**
>
> Under **Add principals**, enter `gmail-api-push@system.gserviceaccount.com`.
>
> > [!NOTE]
> >
> > This service account is managed by Google and is used to push events to Pub/Sub.
>
> **Step 7**
>
> Under **Assign roles**, select `Pub/Sub Publisher`.
>
> **Step 8**
>
> Select **Save** to grant publish rights to the service account.
>
> ### Step 8. Generate a shared secret
>
> **Step 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.
>
> > [!TIP]
> >
> > You can use an [online password generator](https://bitwarden.com/password-generator/) to create a secure string.
>
> **Step 2**
>
> Copy this string for use in the next steps.
>
> ### Step 9. Create a Pub/Sub subscription
>
> **Step 1**
>
> In Google Cloud Console, search for and navigate to the **Pub/Sub** section.
>
> **Step 2**
>
> Select **Subscriptions** in the left sidebar.
>
> **Step 3**
>
> Select **Create subscription**.
>
> **Step 4**
>
> Enter a name for the subscription in the **Subscription ID** field.
>
> **Step 5**
>
> Select the topic you created earlier from the topic dropdown.
>
> **Step 6**
>
> Under **Delivery type**, select **Push**.
>
> **Step 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.
>
> > [!TIP]
> >
> > 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.
>
> **Step 8**
>
> Check the **Enable authentication** checkbox.
>
> **Step 9**
>
> Select the service account email address you created earlier in the **Service account** field.
>
> **Step 10**
>
> Enter the shared secret you generated earlier in the **Audience** field.
>
> > [!NOTE]
> >
> > Although this field is marked optional in Google Console, it's required for the integration to work properly.
>
> **Step 11**
>
> Under **Expiration period**, select **Never expire**.
>
> **Step 12**
>
> Under **Acknowledgement deadline**, enter 60 seconds.
>
> **Step 13**
>
> Under **Retry policy**, select **Retry after exponential backoff delay**. Set the minimum backoff to 60 seconds and the maximum backoff to 600 seconds.
>
> **Step 14**
>
> Select **Create** to create the subscription.
>
> ### Step 10. Authorize the OAuth application
>
> **Step 1**
>
> On Gmail, log in to the Google account you want to use with the Gmail integration.
>
> **Step 2**
>
> 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`.
>
> **Step 3**
>
> Follow the on-screen instructions to authorize the OAuth application with your personal Gmail account.
>
> > [!WARNING]
> >
> > After completing the authorization, you will be redirected to [botpress.com](https://botpress.com). Don't close this page.
>
> **Step 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.
>
> > [!TIP]
> >
> > If you have difficulty finding the authorization code in the URL, you can use online tools like [https://semalt.tools/en/url-parser](https://semalt.tools/en/url-parser) or [https://parseurlonline.com](https://parseurlonline.com).
>
> > [!NOTE]
> >
> > 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.
>
> **Step 5**
>
> You can now safely close this page.
>
> ### Step 11. Configure the integration in Botpress
>
> **Step 1**
>
> In Botpress Studio, select **Explore Hub** in the upper-right corner.
>
> **Step 2**
>
> Search for the **Gmail** integration, then select **Install Integration**.
>
> **Step 3**
>
> In the **Configuration** menu, select **Configure manually with your own GCP App**.
>
> **Step 4**
>
> Fill in the required fields with all the information you saved from the previous steps.
>
> > [!WARNING]
> >
> > 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).
>
> **Step 5**
>
> 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

> [accordion] 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.

> [accordion] 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 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

{/* vale off */}

Here's a reference for all [Cards](https://botpress.com/docs/studio/concepts/cards/introduction.md) available with the integration:

### Change Message Labels

Modifies the labels on the specified message by adding or removing label IDs.

**input** `object`

**id** `string` *required*

The ID of the message to modify.

**addLabelIds** `array`

A list of IDs of labels to add to this message.

**removeLabelIds** `array`

A list of IDs of labels to remove from this message.

**output** `object`

This Card has no output.

### Create Draft

Creates a new draft with the specified email content.

**input** `object`

**to** `string` *required*

The recipient email address.

**subject** `string` *required*

The subject of the email.

**body** `string` *required*

The body content of the email.

**output** `object`

**id** `string`

The immutable ID of the created draft.

**message** `object`

The message content of the draft.

**id** `string`

The ID of the message.

**threadId** `string`

The ID of the thread.

### Create Label

Creates a new label in the user's mailbox.

**input** `object`

**name** `string` *required*

The display name of the label to create.

**output** `object`

**id** `string`

The immutable ID of the created label.

**name** `string`

The display name of the label.

**type** `string`

The owner type for the label (system or user).

### Delete Draft

Immediately and permanently deletes the specified draft. This operation cannot be undone.

**input** `object`

**id** `string` *required*

The ID of the draft to delete.

**output** `object`

This Card has no output.

### Delete Label

Immediately and permanently deletes the specified label. Messages and threads are not deleted, they simply lose this label.

**input** `object`

**id** `string` *required*

The ID of the label to delete.

**output** `object`

This Card has no output.

### Delete Message

Immediately and permanently deletes the specified message using its ID. This operation cannot be undone. Prefer messages.trash instead

**input** `object`

**id** `string` *required*

The ID of the message to delete.

**output** `object`

This Card has no output.

### Get Draft

Gets the specified draft by its ID.

**input** `object`

**id** `string` *required*

The ID of the draft to retrieve.

**output** `object`

**id** `string`

The immutable ID of the draft.

**message** `object`

The message content of the draft.

**id** `string`

The ID of the message.

**threadId** `string`

The ID of the thread.

**labelIds** `array`

List of label IDs applied to the draft message.

**snippet** `string`

A short part of the message text.

### Get Label

Gets the specified label by its ID.

**input** `object`

**id** `string` *required*

The ID of the label to retrieve.

**output** `object`

**id** `string`

The immutable ID of the label.

**name** `string`

The display name of the label.

**type** `string`

The owner type for the label (system or user).

**messageListVisibility** `string`

The visibility of messages with this label in the message list.

**labelListVisibility** `string`

The visibility of the label in the label list.

**messagesTotal** `number`

The total number of messages with the label.

**messagesUnread** `number`

The number of unread messages with the label.

**threadsTotal** `number`

The total number of threads with the label.

**threadsUnread** `number`

The number of unread threads with the label.

**color** `object`

The color to assign to the label.

**backgroundColor** `string`

The background color.

**textColor** `string`

The text color.

### Get Message Attachment

Gets the specified message attachment by its ID.

**input** `object`

**messageId** `string` *required*

The ID of the message containing the attachment.

**attachmentId** `string` *required*

The ID of the attachment to retrieve.

**output** `object`

**attachment** `object` *required*

The attachment retrieved from the message.

**size** `number | null`

**data** `string | null`

**attachmentId** `string | null`

### Get Message Attachment From Mail

Gets the first attachment from a message by automatically finding the attachment ID from the message.

**input** `object`

**messageId** `string` *required*

The ID of the message containing the attachment.

**output** `object`

**attachment** `object` *required*

The attachment retrieved from the message.

**size** `number | null`

**data** `string | null`

**attachmentId** `string | null`

### Get Thread

Gets the specified thread by its ID, including all messages in the thread.

**input** `object`

**id** `string` *required*

The ID of the thread to retrieve.

**output** `object`

**id** `string`

The unique ID of the thread.

**snippet** `string`

A short part of the message text.

**historyId** `string`

The history ID of the thread.

**messages** `array`

The list of messages in the thread.

**array item properties**

**id** `string`

The ID of the message.

**threadId** `string`

The ID of the thread the message belongs to.

**labelIds** `array`

List of label IDs applied to this message.

**snippet** `string`

A short part of the message text.

### List Drafts

Lists all drafts in the user's mailbox.

**input** `object`

This Card has no input fields.

**output** `object`

**drafts** `array`

List of drafts.

**array item properties**

**id** `string`

The immutable ID of the draft.

**message** `object`

The message content of the draft.

**id** `string`

The ID of the message contained in the draft.

**threadId** `string`

The ID of the thread the draft belongs to.

**resultSizeEstimate** `number`

Estimated total number of results.

### List Labels

Lists all labels in the user's mailbox, including system labels and user-created labels.

**input** `object`

This Card has no input fields.

**output** `object`

**labels** `array`

List of labels.

**array item properties**

**id** `string`

The immutable ID of the label.

**name** `string`

The display name of the label.

**type** `string`

The owner type for the label (system or user).

### List Threads

Lists all email threads in the user's mailbox.

**input** `object`

This Card has no input fields.

**output** `object`

**threads** `array`

List of threads in the mailbox.

**array item properties**

**id** `string`

The unique ID of the thread.

**snippet** `string`

A short part of the message text.

**historyId** `string`

The history ID of the thread.

**resultSizeEstimate** `number`

Estimated total number of results.

### Send Draft

Sends the specified draft. The draft will be deleted after being sent.

**input** `object`

**id** `string` *required*

The ID of the draft to send.

**output** `object`

**id** `string`

The ID of the sent message.

**threadId** `string`

The ID of the thread the message belongs to.

**labelIds** `array`

List of label IDs applied to the sent message.

### Trash Message

Moves the specified message to the trash. The message can be restored from the trash using untrashMessage.

**input** `object`

**id** `string` *required*

The ID of the message to trash.

**output** `object`

This Card has no output.

### Trash Thread

Moves the specified thread to the trash. All messages in the thread will be moved to trash. The thread can be restored using untrashThread.

**input** `object`

**id** `string` *required*

The ID of the thread to trash.

**output** `object`

This Card has no output.

### Untrash Message

Removes the specified message from the trash and restores it to the inbox.

**input** `object`

**id** `string` *required*

The ID of the message to untrash.

**output** `object`

This Card has no output.

### Untrash Thread

Removes the specified thread from the trash. All messages in the thread will be restored.

**input** `object`

**id** `string` *required*

The ID of the thread to restore from trash.

**output** `object`

This Card has no output.

### Update Draft

Replaces a draft's content with the new email content provided.

**input** `object`

**id** `string` *required*

The ID of the draft to update.

**to** `string` *required*

The recipient email address.

**subject** `string` *required*

The subject of the email.

**body** `string` *required*

The body content of the email.

**output** `object`

**id** `string`

The immutable ID of the updated draft.

**message** `object`

The message content of the draft.

**id** `string`

The ID of the message.

**threadId** `string`

The ID of the thread.

### Update Label

Updates the specified label with new properties like name or color.

**input** `object`

**id** `string` *required*

The ID of the label to update.

**name** `string`

The new display name for the label.

**backgroundColor** `string`

The background color as hex string (e.g., #ffffff).

**textColor** `string`

The text color as hex string (e.g., #000000).

**output** `object`

**id** `string`

The immutable ID of the label.

**name** `string`

The display name of the label.

**type** `string`

The owner type for the label (system or user).

**color** `object`

The color assigned to the label.

**backgroundColor** `string`

The background color.

**textColor** `string`

The text color.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.