Improve AI support email drafts with Gmail, OpenAI and PostgreSQL
Ready for 3.0What this workflow does
This AI workflow has 27 nodes and runs on a schedule (every 3 hours). Along the way it connects Postgres, Gmail, OpenAI Chat Model and OpenAI. It also calls api.openai.com over HTTP.
How it runs
Trigger: On a schedule (every 3 hours).
- 🗄️ DB - Get Last Watermark (Postgres): run a query
- ⚙️ Set Watermark (Code): runs custom JavaScript code
- 🗄️ DB - Start Run Log (Postgres): run a query
- ⚙️ Carry Run Context (Code): runs custom JavaScript code
- Gmail: get many
- 🔄 Loop - Sent Emails (Loop Over Items (Split in Batches)): loops over the items in batches
- 🗄️ DB - Complete Run Log (Postgres): run a query
- 📧 Gmail - Fetch Full Message (HTTP Request): calls an HTTP API
- ⚙️ Parse Full Message Body (Code): runs custom JavaScript code
- 🗄️ DB - Match Thread ID (Postgres): run a query
…plus 15 more steps. See the full node list below.
Services it uses
Other OpenAI + Gmail templates (1,623) · Other OpenAI + PostgreSQL templates (191) · Other Gmail + PostgreSQL templates (82)
HTTP calls to: api.openai.com
Before you upgrade to n8n 3.0
Nothing in this workflow is removed in n8n 3.0, so it should import and run after the upgrade.
- Code node: the task timeout drops from 300s to 60s. Test with a realistic data volume.
Nodes used (10)
- Schedule Trigger
n8n-nodes-base.scheduleTrigger - Postgres
n8n-nodes-base.postgres - Code
n8n-nodes-base.code - Gmail
n8n-nodes-base.gmail - Loop Over Items (Split in Batches)
n8n-nodes-base.splitInBatches - If
n8n-nodes-base.if - AI Agent
@n8n/n8n-nodes-langchain.agent - OpenAI Chat Model
@n8n/n8n-nodes-langchain.lmChatOpenAi - HTTP Request
n8n-nodes-base.httpRequest - OpenAI
@n8n/n8n-nodes-langchain.openAi
From the author
Self-learning feedback loop for AI customer support email drafts with Gmail, OpenAI and PostgreSQL Automatically compare AI-generated email drafts against what your support team actually sent, learn from the differences, and improve future drafts over time —…