Gmail

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

Setup

    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.

    For more advanced use cases, you can manually configure the integration.

    Step 1. Create a Google Cloud Platform project

    Log in 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.

    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:

    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

    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.

    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.

    Copy the service account email address 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.

    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.

    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.

    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.

    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://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. 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.

    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.

    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.

    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 to interact with your Gmail inbox. This allows you to manage threads, drafts, attachments, and other data associated with your inbox.


    Limitations

    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

    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.


    Cards

    Change Message Labels

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

    inputobject

    Create Draft

    Creates a new draft with the specified email content.

    inputobject
    outputobject

    Create Label

    Creates a new label in the user's mailbox.

    inputobject
    outputobject

    Delete Draft

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

    inputobject

    Delete Label

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

    inputobject

    Delete Message

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

    inputobject

    Get Draft

    Gets the specified draft by its ID.

    inputobject
    outputobject

    Get Label

    Gets the specified label by its ID.

    inputobject
    outputobject

    Get Message Attachment

    Gets the specified message attachment by its ID.

    inputobject
    outputobject

    Get Message Attachment From Mail

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

    inputobject
    outputobject

    Get Thread

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

    inputobject
    outputobject

    List Drafts

    Lists all drafts in the user's mailbox.

    outputobject

    List Labels

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

    outputobject

    List Threads

    Lists all email threads in the user's mailbox.

    outputobject

    Send Draft

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

    inputobject
    outputobject

    Trash Message

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

    inputobject

    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.

    inputobject

    Untrash Message

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

    inputobject

    Untrash Thread

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

    inputobject

    Update Draft

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

    inputobject
    outputobject

    Update Label

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

    inputobject
    outputobject

    Triggers