{
  "name": "Send AI-powered post-purchase emails and WhatsApp messages from PostgreSQL to Google Sheets with Groq",
  "nodes": [
    {
      "id": "63be4def-1ce6-43e6-a6de-4b1283fd1dae",
      "name": "Postgres Trigger1",
      "type": "n8n-nodes-base.postgresTrigger",
      "position": [
        13040,
        4528
      ]
    },
    {
      "id": "89ce4316-a1b8-45b4-823b-c184d6acff19",
      "name": "Execute a SQL query2",
      "type": "n8n-nodes-base.postgres",
      "position": [
        13264,
        4528
      ]
    },
    {
      "id": "fa93aa96-d0fb-4b0d-b766-fe95411e5743",
      "name": "Loop Over Items1",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        13472,
        4528
      ]
    },
    {
      "id": "3f1cee2b-d3f2-4ad3-bf50-c115a467d3ea",
      "name": "Execute a SQL query3",
      "type": "n8n-nodes-base.postgres",
      "position": [
        13680,
        4624
      ]
    },
    {
      "id": "3643ff66-e420-4868-8893-f8040b3714a8",
      "name": "AI Agent1",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        13920,
        4480
      ]
    },
    {
      "id": "b92f6fd8-98f8-4242-9ec7-e4f183f7ecb7",
      "name": "Groq Chat Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatGroq",
      "position": [
        13872,
        4752
      ]
    },
    {
      "id": "c6fc472c-f9c6-4a3b-a20b-95859a0630a1",
      "name": "Format AI response1",
      "type": "n8n-nodes-base.code",
      "position": [
        14448,
        4608
      ]
    },
    {
      "id": "bc784680-1b27-42bd-b553-6ad60ada94fb",
      "name": "Send a message1",
      "type": "n8n-nodes-base.gmail",
      "position": [
        14688,
        4496
      ]
    },
    {
      "id": "5d01369c-4182-41f4-b091-ba615c696eca",
      "name": "Merge1",
      "type": "n8n-nodes-base.merge",
      "position": [
        14256,
        4608
      ]
    },
    {
      "id": "a4b2e316-6580-4407-b72e-4b21107cb36c",
      "name": "Send message1",
      "type": "n8n-nodes-base.whatsApp",
      "position": [
        14688,
        4736
      ]
    },
    {
      "id": "ed63fad4-21f7-46bd-a69a-f07eb00013ee",
      "name": "Edit Fields1",
      "type": "n8n-nodes-base.set",
      "position": [
        14912,
        4608
      ]
    },
    {
      "id": "d345eaf3-d79a-4fde-b3a2-9b9f94e6ff28",
      "name": "Append row in sheet1",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        15136,
        4736
      ]
    },
    {
      "id": "30e7d44b-1300-4796-9218-b0015298978e",
      "name": "Wait1",
      "type": "n8n-nodes-base.wait",
      "position": [
        15392,
        4736
      ]
    },
    {
      "id": "fdd7b7cf-7f9c-4760-a539-4cb3231d05e5",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        12368,
        4032
      ],
      "parameters": {
        "width": 656,
        "height": 928,
        "content": "## AI-Powered Post-Purchase Journey (Email + WhatsApp Automation)\n\nAutomatically sends AI-generated post-purchase messages when an order is marked **completed**. The workflow personalizes communicatio"
      }
    },
    {
      "id": "9fd7bdb5-95b8-45da-8977-61a187f5399c",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        13040,
        4032
      ],
      "parameters": {
        "width": 1360,
        "height": 928,
        "content": "## Step 1: Fetch & Prepare Orders\nDetect completed orders, loop safely through them, and retrieve full customer, product, and payment details. Send structured data to the AI Agent.\n"
      }
    },
    {
      "id": "e395e6ae-bd6a-4621-9867-d7096776c6e1",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        14416,
        4032
      ],
      "parameters": {
        "width": 1200,
        "height": 928,
        "content": "## Step 2: Send Messages & Log Data\nFormat AI output for Email and WhatsApp, send messages via connected channels, flag delivery status, and log post-purchase communication into Google Sheets.\n"
      }
    }
  ],
  "connections": {
    "Wait1": {
      "main": [
        [
          {
            "node": "Loop Over Items1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge1": {
      "main": [
        [
          {
            "node": "Format AI response1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent1": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields1": {
      "main": [
        [
          {
            "node": "Append row in sheet1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send message1": {
      "main": [
        [
          {
            "node": "Edit Fields1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send a message1": {
      "main": [
        [
          {
            "node": "Edit Fields1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Groq Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent1",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items1": {
      "main": [
        [],
        [
          {
            "node": "Execute a SQL query3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Postgres Trigger1": {
      "main": [
        [
          {
            "node": "Execute a SQL query2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format AI response1": {
      "main": [
        [
          {
            "node": "Send a message1",
            "type": "main",
            "index": 0
          },
          {
            "node": "Send message1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append row in sheet1": {
      "main": [
        [
          {
            "node": "Wait1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Execute a SQL query2": {
      "main": [
        [
          {
            "node": "Loop Over Items1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Execute a SQL query3": {
      "main": [
        [
          {
            "node": "AI Agent1",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge1",
            "type": "main",
            "index": 1
          }
        ]
      ]
    }
  }
}