{
  "id": "M6fAvs6tknDULQm9",
  "meta": {
    "builderVariant": "mcp",
    "aiBuilderAssisted": true
  },
  "name": "Turn client emails into CRM updates and next actions with Gemini",
  "tags": [],
  "nodes": [
    {
      "id": "91fac9e7-3361-44f5-bd7b-4c5ccb707e3d",
      "name": "Watch Sales Inbox",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        48,
        48
      ],
      "parameters": {
        "simple": false,
        "filters": {
          "q": "label:sales",
          "readStatus": "unread"
        },
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.4
    },
    {
      "id": "c28b81f4-853c-4546-b531-4f87dcc48107",
      "name": "Extract Deal Update with Gemini",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "onError": "continueRegularOutput",
      "position": [
        304,
        48
      ],
      "parameters": {
        "text": "=You are a sales operations analyst. Read this client email and extract a CRM update as JSON. Infer the company and contact from the sender. stage must be one of: qualification, proposal, negotiation, closed_won, closed_lost. sentiment: positive, neutral or negative. risk: low, medium or high - high when the client mentions competitors, budget cuts, delays or dissatisfaction. next_action must be a concrete task, owner is \"us\" or \"client\", and due_date in YYYY-MM-DD if a deadline is mentioned (resolve relative dates like Friday). Also draft a short reply. Never invent commitments that are not in the email.\n\nFrom: {{ $json.from }}\nSubject: {{ $json.subject }}\nEmail:\n{{ $json.text }}",
        "batching": {},
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.9
    },
    {
      "id": "d3774a33-87b1-4e35-b7d1-651f71f759ac",
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        272,
        208
      ],
      "parameters": {
        "options": {
          "temperature": 0.1
        },
        "modelName": "models/gemini-3.1-flash-lite"
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "e75a111b-fb10-4a7b-bb85-6f028cbeca1e",
      "name": "Deal Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        496,
        208
      ],
      "parameters": {
        "jsonSchemaExample": "{\"company\":\"Acme Ltd\",\"contact_name\":\"Jane\",\"stage\":\"negotiation\",\"sentiment\":\"neutral\",\"summary\":\"Client likes the proposal but pushes back on price\",\"objections\":[\"Price is too high\"],\"next_action\":\"Send a revised quote\",\"owner\":\"us\",\"due_date\":\"2026-07-24\",\"risk\":\"medium\",\"suggested_reply\":\"Hi Jane, thanks for the quick feedback...\"}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "fe7fc5ee-06a6-4897-85ac-a39184533845",
      "name": "Shape Deal Update",
      "type": "n8n-nodes-base.code",
      "position": [
        688,
        48
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const e = $('Watch Sales Inbox').item.json;\nconst d = $json.output || {};\nconst join = function (x) { return Array.isArray(x) ? x.join('; ') : (x || ''); };\nreturn {\n  clientEmail: e.from || '',\n  threadId: e.threadId || '',\n  subject: e.subject || '',\n  company: d.company || e.from || '',\n  contactName: d.contact_name || '',\n  stage: String(d.stage || 'qualification').toLowerCase(),\n  sentiment: String(d.sentiment || 'neutral').toLowerCase(),\n  risk: String(d.risk || 'low').toLowerCase(),\n  summary: d.summary || '',\n  objections: join(d.objections),\n  nextAction: d.next_action || 'Review the email',\n  owner: d.owner || 'us',\n  dueDate: d.due_date || '',\n  suggestedReply: d.suggested_reply || ''\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "4ce8e7d0-2647-4d2d-8fa1-934dee972da4",
      "name": "Update CRM Row",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        896,
        48
      ],
      "parameters": {
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultName": "Deals"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultName": "Select your spreadsheet"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "62da0a83-a070-4cbf-a52c-c2b859694107",
      "name": "Log Next Action",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1104,
        48
      ],
      "parameters": {
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultName": "Tasks"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultName": "Select your spreadsheet"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "81f7f105-e6b3-41e8-b3a3-f9f361560905",
      "name": "Draft Follow-up Reply",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1296,
        48
      ],
      "parameters": {
        "message": "={{ $(\"Shape Deal Update\").item.json.suggestedReply }}",
        "options": {
          "sendTo": "={{ $(\"Shape Deal Update\").item.json.clientEmail }}",
          "threadId": "={{ $(\"Shape Deal Update\").item.json.threadId }}"
        },
        "subject": "={{ \"Re: \" + $(\"Shape Deal Update\").item.json.subject }}",
        "resource": "draft"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "93ac088d-22f1-4c4c-8c99-660866006bf6",
      "name": "Route by Deal Risk",
      "type": "n8n-nodes-base.switch",
      "position": [
        1552,
        32
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "version": 1,
                  "leftValue": "",
                  "caseSensitive": false,
                  "typeValidation": "loose"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $(\"Shape Deal Update\").item.json.risk }}",
                    "rightValue": "high"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 1,
                  "leftValue": "",
                  "caseSensitive": false,
                  "typeValidation": "loose"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $(\"Shape Deal Update\").item.json.stage }}",
                    "rightValue": "closed_won"
                  }
                ]
              }
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra",
          "renameFallbackOutput": "Normal"
        }
      },
      "typeVersion": 3.2
    },
    {
      "id": "5b284e3e-cbc5-4ba5-8297-5a7b684b11c9",
      "name": "Alert Deal at Risk",
      "type": "n8n-nodes-base.slack",
      "position": [
        1824,
        16
      ],
      "parameters": {
        "text": "=*:warning: Deal at risk: {{ $(\"Shape Deal Update\").item.json.company }}*\n*Stage:* {{ $(\"Shape Deal Update\").item.json.stage }} | *Sentiment:* {{ $(\"Shape Deal Update\").item.json.sentiment }}\n*Objections:* {{ $(\"Shape Deal Update\").item.json.objections }}\n*Next action:* {{ $(\"Shape Deal Update\").item.json.nextAction }} (owner: {{ $(\"Shape Deal Update\").item.json.owner }})\nA draft reply is ready in Gmail.",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultName": "#sales"
        },
        "otherOptions": {},
        "authentication": "oAuth2"
      },
      "credentials": {
        "slackOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.5
    },
    {
      "id": "b997c8d4-a6ca-4e80-8e6a-a6f97d886263",
      "name": "Announce Closed Won",
      "type": "n8n-nodes-base.slack",
      "position": [
        1824,
        208
      ],
      "parameters": {
        "text": "=*:tada: Deal won: {{ $(\"Shape Deal Update\").item.json.company }}*\n{{ $(\"Shape Deal Update\").item.json.summary }}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultName": "#sales"
        },
        "otherOptions": {},
        "authentication": "oAuth2"
      },
      "credentials": {
        "slackOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.5
    },
    {
      "id": "d4a674f3-eb13-45ff-b9dd-2e2896088744",
      "name": "Mark Email Processed",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1824,
        384
      ],
      "parameters": {
        "messageId": "={{ $(\"Watch Sales Inbox\").item.json.id }}",
        "operation": "markAsRead"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "19668b9e-8b7e-4f95-a929-ac60a4314826",
      "name": "Overview Sticky",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -464,
        -112
      ],
      "parameters": {
        "width": 440,
        "height": 820,
        "content": "## Turn client emails into CRM updates and next actions with Gemini\n\n### How it works\nSales reps update the CRM last, if at all, so pipeline data is always stale. This template does it from the emails themselves. Every new message in your sales inbox is read by a Basic LLM Chain with Google Gemini, which extracts the company, contact, deal stage, sentiment, the objections raised, a concrete next action with an owner and due date, a risk rating, and a suggested reply - without inventing commitments the client never made. The CRM row is upserted by client email so each company keeps one live record, the next action is logged as a task, and a draft reply is prepared in the original Gmail thread. A Switch then alerts the sales channel when a deal is flagged at risk and celebrates closed-won deals, and every processed email is marked read.\n\n### Setup\n1. Connect Gmail, Google Gemini (PaLM) API, Google Sheets and Slack.\n2. Label your sales emails and point the sheets at your Deals and Tasks tabs.\n3. Pick the Slack channel for alerts.\n\n### Customization tips\nSwap Sheets for HubSpot or Pipedrive, or auto-send low-risk replies."
      },
      "typeVersion": 1
    },
    {
      "id": "eff3b280-fd2c-4a25-933c-e45d80b88c3a",
      "name": "S1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        -112
      ],
      "parameters": {
        "color": 7,
        "width": 620,
        "height": 652,
        "content": "## 1. Read the email (Basic LLM Chain)\nGemini extracts stage, sentiment, objections, next action, owner, due date, risk and a draft reply."
      },
      "typeVersion": 1
    },
    {
      "id": "0d92b4e0-f49e-4372-9905-a28c3224a628",
      "name": "S2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        640,
        -112
      ],
      "parameters": {
        "color": 7,
        "width": 800,
        "height": 652,
        "content": "## 2. Update the CRM & prepare the follow-up\nUpsert the deal row by client email, log the next action as a task, and draft the reply in the original thread."
      },
      "typeVersion": 1
    },
    {
      "id": "20809d64-8b8f-41d3-b3fa-ee17c0293625",
      "name": "S3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1456,
        -112
      ],
      "parameters": {
        "color": 7,
        "width": 660,
        "height": 652,
        "content": "## 3. Escalate & close the loop\nAt-risk deals alert sales, closed-won deals are celebrated, and every email is marked processed."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "availableInMCP": true,
    "executionOrder": "v1"
  },
  "versionId": "8012883c-635a-4c79-a36a-68a99603b10a",
  "nodeGroups": [],
  "connections": {
    "Deal Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Extract Deal Update with Gemini",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Update CRM Row": {
      "main": [
        [
          {
            "node": "Log Next Action",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Next Action": {
      "main": [
        [
          {
            "node": "Draft Follow-up Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Shape Deal Update": {
      "main": [
        [
          {
            "node": "Update CRM Row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Watch Sales Inbox": {
      "main": [
        [
          {
            "node": "Extract Deal Update with Gemini",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route by Deal Risk": {
      "main": [
        [
          {
            "node": "Alert Deal at Risk",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Announce Closed Won",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Mark Email Processed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Draft Follow-up Reply": {
      "main": [
        [
          {
            "node": "Route by Deal Risk",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Extract Deal Update with Gemini",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Extract Deal Update with Gemini": {
      "main": [
        [
          {
            "node": "Shape Deal Update",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}