Overview
Add Gmail integration via Cloud Pub/Sub for email-triggered actions.
Push Notifications via Pub/Sub
Gmail uses Google Cloud Pub/Sub (not traditional webhooks):
Setup
- Create Pub/Sub topic
- Grant
gmail-api-push@system.gserviceaccount.com publish rights
- Call
users.watch() to start notifications
- Watch expires after 7 days (refresh daily)
Payload Structure
{
"message": {
"data": "base64_encoded_data",
"messageId": "xxx",
"publishTime": "2024-01-01T00:00:00Z"
},
"subscription": "projects/xxx/subscriptions/xxx"
}
Decoded Data
{
"emailAddress": "user@example.com",
"historyId": "123456789"
}
Polling via History API
Efficient incremental sync:
GET /gmail/v1/users/me/history?startHistoryId=xxx
- Filter by
historyTypes: messageAdded, labelAdded
- Store
historyId between polls
OAuth Scopes
gmail.readonly - Read only
gmail.modify - Read + modify labels
gmail.send - Send emails
Tasks
Use Cases
- Email Triggers: Process PR review request emails
- Digest: Summarize PR emails into daily digest
- Auto-Reply: Draft PR review responses
- Notifications: Email summaries of PR activity
Overview
Add Gmail integration via Cloud Pub/Sub for email-triggered actions.
Push Notifications via Pub/Sub
Gmail uses Google Cloud Pub/Sub (not traditional webhooks):
Setup
gmail-api-push@system.gserviceaccount.compublish rightsusers.watch()to start notificationsPayload Structure
{ "message": { "data": "base64_encoded_data", "messageId": "xxx", "publishTime": "2024-01-01T00:00:00Z" }, "subscription": "projects/xxx/subscriptions/xxx" }Decoded Data
{ "emailAddress": "user@example.com", "historyId": "123456789" }Polling via History API
Efficient incremental sync:
GET /gmail/v1/users/me/history?startHistoryId=xxxhistoryTypes:messageAdded,labelAddedhistoryIdbetween pollsOAuth Scopes
gmail.readonly- Read onlygmail.modify- Read + modify labelsgmail.send- Send emailsTasks
GmailPollerusing History APIUse Cases