Skip to main content

Google Drive and Gmail in chats

With the Google Workspace connector, the people of your company can:

  • Attach a Google Drive file to a chat. The file is posted as a card with its title, its type, a link that opens it in Google Drive and a hint that says who can open it. Before the file is sent, the sender sees that hint and can change the sharing in Google Drive first.
  • Send a chat message or a whole thread by e-mail from their own Gmail. The mail is plain text: an optional note from the sender, then each message with the sender's name and time (UTC). Files show their name. The mail appears in the sender's Sent folder.

Every user connects their own Google account. MonoPbx never uses one person's account for another, and an administrator cannot read anyone's Drive or mail through it.

What MonoPbx can access​

AccessWhyWhat it cannot do
Google Drive, read only (drive.readonly)Find the user's files by name or link, and read who a file is shared withDownload, change, share or delete files
Google Drive, files the app created (drive.file)Save to Google Drive of a file in a chat: it becomes a new file in the user's DriveSee, change or delete any other file of the user's Drive
Gmail, send only (gmail.send)Send the e-mail the user writesRead, search or delete mail

The access tokens are stored sealed with your company's key. No screen or API answer returns them, and they never appear in logs. When a user disconnects, or when you remove the connector, MonoPbx asks Google to revoke the tokens and then deletes them.

Set it up​

1. Create the Google app (once per PBX)​

The person who runs your PBX does this in the Google Cloud console:

  1. Create a project (or use an existing one) and enable the Google Drive API and the Gmail API.
  2. Open OAuth consent screen. For a Google Workspace organisation, choose Internal, so only your own users can connect. Add the scopes .../auth/drive.readonly, .../auth/drive.file and .../auth/gmail.send.
  3. Open Credentials > Create credentials > OAuth client ID, type Web application. Add the redirect URI https://pbx.example.com/chat/google/callback (your console address).
  4. Note the client ID and client secret.
  5. Add the app to the OAuth providers file of the PBX (MPBX_INTEGRATIONS_OAUTH_FILE). The endpoints and scopes come with MonoPbx, so the entry only needs:
[
{
"connector": "google_workspace",
"client_id": "1234567890-example.apps.googleusercontent.com",
"redirect_uri": "https://pbx.example.com/chat/google/callback"
}
]

Put the client secret in the environment variable MPBX_INTEGRATIONS_OAUTH_SECRET_GOOGLE_WORKSPACE instead of the file, and restart MonoPbx.

note

An External consent screen that is not published works only for the test users you list in Google. To let anyone outside your organisation connect, Google must review the app first.

2. Turn it on for your company​

  1. Open Admin > Settings > Integrations > Integrations and install Google Workspace. It needs no password or key.

  2. Two switches are on by default:

    • Attach Google Drive files in chats
    • Send chat messages by e-mail with Gmail

    Turn one off to hide that action for everyone in the company.

3. Each user connects their account​

In Chat, open + > Google Drive (or Send by e-mail under a message) and choose Connect Google account. Google asks the user to allow the access. Then the browser returns to the chat.

The mobile app uses the same connection, and it can connect it too: Connect Google account in the Drive or e-mail sheet of a chat, or Me > Account > Google account, opens Google's sign-in in the phone's browser. The browser comes back to the web console's callback page, so a user who is not signed in to the console there signs in first. When the user returns to the app it shows the account as connected.

Who can open a file​

The hint on the card comes from the file's sharing settings in Google Drive:

HintMeaning
Anyone with the link can open itThe link is public
People in example.com with the link can open itThe link works for your Google Workspace domain
Only people it is shared with can open itOthers see Request access in Google Drive
Only you can open itThe file is not shared. Share it before you send it
Recipients need access to the fileGoogle did not show the sharing settings to the sender

MonoPbx does not change the sharing of a file. Use Change sharing in Google Drive in the dialog.

Disconnect​

A user disconnects their own account in the Google Drive dialog of the chat (Disconnect Google account), in the app under Me > Account > Google account (Disconnect), or in their Google account settings (Security > Third-party apps). Removing the Google Workspace connector disconnects every user of the company.

Troubleshooting​

MessageWhat to do
Connect your Google accountThe user has not connected yet, or disconnected.
Google refused your connectionThe user changed their password, revoked the access in Google, or the app lost a scope. Connect again.
Save to Google Drive asks to connect againThe account was connected before saving to Drive was offered, so Google has not granted drive.file yet. Connect again once and accept the new permission. If your providers file lists its own scopes, add https://www.googleapis.com/auth/drive.file there.
Your company turned this offAn administrator turned the switch off in the connector.
No file foundThe user's Google account cannot see the file, or the link is not a Google Drive or Docs link.

Sending an e-mail is recorded in the audit log with the chat and the number of recipients, but not the addresses or the text.

API​

CallWho
GET /api/v1/chat/google: whether it is set up, whether you are connected, and the company's switchesAny signed-in user
POST /api/v1/integrations/installs/{id}/oauth/me/start: connect your own accountAny signed-in user
DELETE /api/v1/integrations/installs/{id}/oauth/me: disconnect your own accountAny signed-in user
GET /api/v1/chat/google/drive/files?q=: find files of your Drive (words of the name, or a pasted link)Any signed-in user
POST /api/v1/chat/rooms/{id}/messages/{message_id}/email: send a message or its thread by e-mailMembers of the chat

A Drive file is attached by sending an ordinary message card whose title links to the file (see Chat webhooks and rich messages).