feat(google-gmail): add TRIGGER binding for email received events#393
feat(google-gmail): add TRIGGER binding for email received events#393
Conversation
Implement the TRIGGER_LIST/TRIGGER_CONFIGURE tools and webhook ingestion for gmail.message.received, following the same patterns used by the GitHub and Slack MCPs. - Add trigger-store using createTriggers from @decocms/runtime/triggers - Add email-connection-map for routing Pub/Sub notifications to connections - Add webhook handler for POST /webhooks/gmail (Google Pub/Sub push) - Wire onChange to fetch user profile, map email→connectionId, and call users.watch() for push notification registration - Bump @decocms/runtime to 1.5.0, add @decocms/bindings ^1.4.0 Requires GMAIL_PUBSUB_TOPIC env var for push notification setup. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
2 issues found across 8 files
You’re at about 93% of the monthly review limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="google-gmail/server/lib/email-connection-map.ts">
<violation number="1" location="google-gmail/server/lib/email-connection-map.ts:7">
P1: Using an in-memory map for `email -> connectionId` breaks trigger delivery after restarts or in multi-instance deployments; store this mapping in shared persistent storage instead of process memory.</violation>
</file>
<file name="google-gmail/server/webhook.ts">
<violation number="1" location="google-gmail/server/webhook.ts:25">
P1: Webhook endpoint lacks authentication/verification, allowing forged notification events.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| * Populated during onChange when we fetch the user's Gmail profile. | ||
| */ | ||
|
|
||
| const emailMap = new Map<string, string>(); |
There was a problem hiding this comment.
P1: Using an in-memory map for email -> connectionId breaks trigger delivery after restarts or in multi-instance deployments; store this mapping in shared persistent storage instead of process memory.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At google-gmail/server/lib/email-connection-map.ts, line 7:
<comment>Using an in-memory map for `email -> connectionId` breaks trigger delivery after restarts or in multi-instance deployments; store this mapping in shared persistent storage instead of process memory.</comment>
<file context>
@@ -0,0 +1,23 @@
+ * Populated during onChange when we fetch the user's Gmail profile.
+ */
+
+const emailMap = new Map<string, string>();
+
+export function setEmailMapping(email: string, connectionId: string): void {
</file context>
| historyId: string; | ||
| } | ||
|
|
||
| export async function handleGmailWebhook(req: Request): Promise<Response> { |
There was a problem hiding this comment.
P1: Webhook endpoint lacks authentication/verification, allowing forged notification events.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At google-gmail/server/webhook.ts, line 25:
<comment>Webhook endpoint lacks authentication/verification, allowing forged notification events.</comment>
<file context>
@@ -0,0 +1,72 @@
+ historyId: string;
+}
+
+export async function handleGmailWebhook(req: Request): Promise<Response> {
+ let body: PubSubPushMessage;
+ try {
</file context>
Summary
gmail.message.receivedtrigger usingcreateTriggersfrom@decocms/runtime/triggers(same pattern as GitHub and Slack MCPs)POST /webhooks/gmailfor Google Pub/Sub push notificationsonChangeto fetch user profile, mapemail → connectionId, and callusers.watch()for push notification registration@decocms/runtimeto 1.5.0, add@decocms/bindings^1.4.0How it works
Infra requirements
gmail-api-push@system.gserviceaccount.comas Publisherhttps://<server>/webhooks/gmailGMAIL_PUBSUB_TOPICenv var (e.g.projects/my-project/topics/gmail-push)Test plan
bun run checkpasses (type-check)onChangelogs email mapping and watch registrationtriggers.notify()fires🤖 Generated with Claude Code
Summary by cubic
Adds a
gmail.message.receivedtrigger and a Pub/Sub webhook so automations fire when new Gmail messages arrive. Registers Gmail push notifications on connect and routes events to the correct connection.New Features
gmail.message.receivedviacreateTriggersfrom@decocms/runtime/triggers; expose TRIGGER_LIST/TRIGGER_CONFIGURE withtriggers.tools().POST /webhooks/gmailto ingest Google Pub/Sub push and calltriggers.notify().users.profile, mapemail → connectionId, and callusers.watch()(INBOX).StudioKVwhenMESH_URL/MESH_API_KEYare set.WATCH,STOP,HISTORY, andPROFILE.@decocms/runtimeto1.5.0; add@decocms/bindings^1.4.0.Migration
gmail-api-push@system.gserviceaccount.comas Publisher.https://<server>/webhooks/gmail.GMAIL_PUBSUB_TOPICto the topic path (e.g.projects/<project>/topics/<topic>).Written for commit 00bf3a5. Summary will update on new commits.