The open-source AI receptionist for businesses. Answers every call, books the appointment and hands over to a person when needed. You own the code and the data.
TypeScript ai-receptionistanswering-serviceappointment-bookinglivekitlocal-firstmcpopen-sourceself-hostedsiptelephonytypescriptvoice-agentvoice-ai
Gmail app: request userinfo.email spelled out, as in the Data Access list (PR 2038)
Tim Gutberlet15b324814a02
diff --git a/apps/api/test/mail-connections.test.ts b/apps/api/test/mail-connections.test.tsindex 2cb45093..83d4df25 100644--- a/apps/api/test/mail-connections.test.ts+++ b/apps/api/test/mail-connections.test.ts@@ -28,7 +28,7 @@ async function inRollback(body: (tx: Tx) => Promise<void>) {})}-const READ = 'openid email https://www.googleapis.com/auth/gmail.readonly'+const READ = 'openid https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/gmail.readonly'const MAILBOX = '[email protected]'/** A Gmail account in memory: OAuth that hands out numbered tokens, and a mailbox with one message. */diff --git a/docs/architecture.md b/docs/architecture.mdindex 029368c8..cfd18b81 100644--- a/docs/architecture.md+++ b/docs/architecture.md@@ -483,7 +483,7 @@ REST routes outside the registry: `/v1/admin/*` need `instance:admin`; `/v1/shap- Why: the business's support mail shows the common requests, how support answers them and what it needs to know, so the assistant can answer the same requests on the phone. This step only connects mailboxes, read only; reading and analysing the mail comes later. Connecting stores no mail.- Settings › Integrations › Gmail and › Outlook (cards `gmail` and `outlook-mail`, category Email, one per provider with its logo; the old `#integrations/support-email` address goes to Gmail): an owner or admin connects Gmail or Microsoft 365 (`mail.connectStart`, `mail.connectFinish`, `mail.disconnect`; permission `settings:write`, a confirmed email, not while impersonating). A workspace may connect several mailboxes; the same account connected again updates its one row.- OAuth apps: Gmail has an OAuth app of its own (provider `google_mail`, Server admin › Providers › Gmail API: client ID and secret, `GOOGLE_MAIL_CLIENT_ID`/`GOOGLE_MAIL_CLIENT_SECRET`), never the sign-in and calendar app: `gmail.readonly` is a restricted scope (Google verification plus a yearly CASA security assessment for a public app), so the sign-in app's consent screen and verification stay as they are. Linedesk Cloud publishes the Gmail app unverified until it passes Google's verification and CASA: any Google account can connect after Google's "unverified app" warning, at most 100 accounts over the app's life (testing mode would need each account on a test list and ends a grant after 7 days). Microsoft uses the sign-in app (`MICROSOFT_*`) with the delegated permission `Mail.Read` added (no assessment).-- Scopes: Google `openid email gmail.readonly`; Microsoft `openid email offline_access User.Read Mail.Read`. Nothing that sends, changes or deletes mail. A grant without the read scope or without a refresh token is refused and revoked.+- Scopes: Google `openid userinfo.email gmail.readonly` (spelled out as in the Google Cloud Data Access list: Google's verification wants a string-for-string match); Microsoft `openid email offline_access User.Read Mail.Read`. Nothing that sends, changes or deletes mail. A grant without the read scope or without a refresh token is refused and revoked.- Flow as the calendar's: state (32 random bytes, `mail_oauth_states`) bound to member, provider and workspace, single use, 10 minutes; PKCE S256; the provider returns to `GET /v1/mail/callback/<provider>`, which runs `mail.connectFinish` (code and state redacted in the command log) and redirects to the provider's card, `#integrations/gmail?mail=connected` or `#integrations/outlook-mail?…`, or `?mail=error&reason=<code>` (codes `mailConnectErrors` in `packages/actions/src/mail.ts`, worded by the web app; never server text). Before storing, one message is listed to prove the access works (for Gmail also that the Gmail API is on in the app's project; when not, the app gets a provider failure in Server admin).- Storage: `mail_connections` (provider, account email, status, who connected it; synced, workspace-filtered) and `mail_credentials` (never synced; access and refresh token AES-256-GCM with `SECRETS_KEY` under slots `mail.<connection id>.access|refresh`; re-encrypted by the key rotation). Tokens with less than a minute left are refreshed on use (Microsoft's new refresh token replaces the old); a refused refresh marks the mailbox `needs_reconnect`. `mail.disconnect` deletes the mailbox and its tokens, then revokes the grant at Google unless another workspace holds the same account (Google withdraws the account's whole grant; Microsoft has no per-app revoke). A member who leaves takes the mailboxes they connected with them (`mail_dropped` in the audit log).- Adapters: `packages/mail` (Gmail API v1, Microsoft Graph; plain fetch, list and read only, spam, trash and drafts left out, bodies as plain text). `mailboxFor` in `apps/api/src/mail-connections.ts` gives the adapter of a workspace's mailbox to the analysis.diff --git a/packages/mail/src/google.ts b/packages/mail/src/google.tsindex 1038c689..0d542d9c 100644--- a/packages/mail/src/google.ts+++ b/packages/mail/src/google.ts@@ -24,8 +24,15 @@ const TOKEN = 'https://oauth2.googleapis.com/token'const REVOKE = 'https://oauth2.googleapis.com/revoke'const USERINFO = 'https://openidconnect.googleapis.com/v1/userinfo'-/** The account's address and read-only mail. Never send, modify or Drive. */-export const GMAIL_SCOPES = ['openid', 'email', 'https://www.googleapis.com/auth/gmail.readonly'] as const+/**+ * The account's address and read-only mail. Never send, modify or Drive. Spelled as Google Cloud's Data Access list+ * names them (`email` is short for `userinfo.email`): Google's verification wants a string-for-string match.+ */+export const GMAIL_SCOPES = [+ 'openid',+ 'https://www.googleapis.com/auth/userinfo.email',+ 'https://www.googleapis.com/auth/gmail.readonly',+] as constconst RATE_LIMITED = new Set(['rateLimitExceeded',diff --git a/packages/mail/src/mail.test.ts b/packages/mail/src/mail.test.tsindex def7d0ca..c45b5f7e 100644--- a/packages/mail/src/mail.test.ts+++ b/packages/mail/src/mail.test.ts@@ -361,7 +361,9 @@ describe('Gmail', () => {codeChallenge: 'c',}),)- expect(url.searchParams.get('scope')).toBe('openid email https://www.googleapis.com/auth/gmail.readonly')+ expect(url.searchParams.get('scope')).toBe(+ 'openid https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/gmail.readonly',+ )expect(url.searchParams.get('access_type')).toBe('offline')expect(oauth.grantsMailRead('openid https://www.googleapis.com/auth/userinfo.email')).toBe(false)expect(oauth.grantsMailRead('openid https://www.googleapis.com/auth/gmail.readonly')).toBe(true)