Bot Gmail layer: n8n webhooks to direct API, 2026-06-09¶
Justin asked to verify capture + coordinator + remote-bridge can do tasks/Notion/automations/Google. Verification found the bots' ENTIRE Gmail layer dead: all 12 email tools in scripts/forge_telegram_inbox_brain.py call n8n webhooks that return Error in workflow on real payloads (apply-label is fully unregistered). Same root cause as the morning-report regression fixed earlier today (commit c6994f8): the 2026-04-30 Google migration moved auth off n8n.
Decision¶
Port the Gmail layer to the Gmail API directly via forge_google_user.user_token() (the canonical helper per reference_agent_integrations). Scopes already cover everything (gmail.modify, gmail.send, gmail.settings.basic, drive). Calendar tools already use the direct GCal client and work; Notion webhooks (notion-query-database, notion-create-page, notion-update-page) verified alive today and stay on n8n.
Tasks¶
scripts/forge_gmail.py, new shared module (single source of truth):search,get_message(recursive MIME walk, text/plain preferred),get_thread,modify(batchModify),archive,clear,star,mark_read,apply_label(find-or-create),list_drafts,create_draft,delete_draft,unsubscribe_info(List-Unsubscribe header, RFC 8058 one-click POST when offered),block_sender(filter: from sender to Trash). Fail loud; no silent excepts.- Rewire the 12
tool_*email functions inforge_telegram_inbox_brain.pyto forge_gmail, keeping return-string shapes. Fix the latent truncated-id trap: stop printingid[:8](same class as the calendar event-id truncation bug); print full message ids. tool_email_to_taskreuses the new search; Notion side unchanged.- Add Drive tools (gap: bots had zero Drive access):
tool_search_drive+tool_read_drive_filewrapping the gdrive subsystem; register in the tool schema. - Verify live: search/read/thread on real mail (both accounts), reversible mutations (star+unstar, draft create+delete, archive+restore), filter create+delete. Restart capture + coordinator one at a time.
- Commit; update
reference_email_workflows+ n8n state memory to mark email webhooks retired.
Pre-approved by Justin in-session ("make sure they are able to do... gmail"); plan recorded for the record per /feature-plan.
[Claude Code, forge-audit session]