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
You will need:
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 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
- A Google account
- Access to Google Cloud Console
Step 1. Create a Google Cloud Platform project
Log in to Google Cloud Console with your Gmail account.
Step 2. Enable the Gmail API
Step 3. Configure the OAuth consent screen
Step 4. Create OAuth credentials
Step 5. Create a service account
Step 6. Create a Pub/Sub topic
Step 7. Grant publish rights on the Pub/Sub topic
From the topic list, find the topic you created earlier. Then, select the triple-dot ⋮ button on the right.
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.
Step 9. Create a Pub/Sub subscription
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.
Enter the shared secret you generated earlier in the Audience field.
Although this field is marked optional in Google Console, it’s required for the integration to work properly.
Step 10. Authorize the OAuth application
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_IDReplace 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.
After completing the authorization, you will be redirected to botpress.com. Don’t 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.
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 11. Configure the integration in Botpress
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.
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
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 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.
inputobjectCreate Draft
Creates a new draft with the specified email content.
inputobjectoutputobjectCreate Label
Creates a new label in the user's mailbox.
inputobjectoutputobjectDelete Draft
Immediately and permanently deletes the specified draft. This operation cannot be undone.
inputobjectDelete Label
Immediately and permanently deletes the specified label. Messages and threads are not deleted, they simply lose this label.
inputobjectDelete Message
Immediately and permanently deletes the specified message using its ID. This operation cannot be undone. Prefer messages.trash instead
inputobjectGet Draft
Gets the specified draft by its ID.
inputobjectoutputobjectGet Label
Gets the specified label by its ID.
inputobjectoutputobjectGet Message Attachment
Gets the specified message attachment by its ID.
inputobjectoutputobjectGet Message Attachment From Mail
Gets the first attachment from a message by automatically finding the attachment ID from the message.
inputobjectoutputobjectGet Thread
Gets the specified thread by its ID, including all messages in the thread.
inputobjectoutputobjectList Drafts
Lists all drafts in the user's mailbox.
outputobjectList Labels
Lists all labels in the user's mailbox, including system labels and user-created labels.
outputobjectList Threads
Lists all email threads in the user's mailbox.
outputobjectSend Draft
Sends the specified draft. The draft will be deleted after being sent.
inputobjectoutputobjectTrash Message
Moves the specified message to the trash. The message can be restored from the trash using untrashMessage.
inputobjectTrash 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.
inputobjectUntrash Message
Removes the specified message from the trash and restores it to the inbox.
inputobjectUntrash Thread
Removes the specified thread from the trash. All messages in the thread will be restored.
inputobjectUpdate Draft
Replaces a draft's content with the new email content provided.
inputobjectoutputobjectUpdate Label
Updates the specified label with new properties like name or color.
inputobjectoutputobject