{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Send a Daily Sales Report to WhatsApp from Google Sheets with MoltFlow",
  "tags": [
    {
      "name": "whatsapp"
    },
    {
      "name": "google sheets"
    },
    {
      "name": "sales"
    },
    {
      "name": "moltflow"
    },
    {
      "name": "reports"
    },
    {
      "name": "daily"
    }
  ],
  "nodes": [
    {
      "id": "l1000001-0000-4000-0c00-000000000010",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -40,
        -300
      ],
      "parameters": {
        "color": 4,
        "width": 400,
        "height": 300,
        "content": "## Daily Sales Report \u2192 WhatsApp\nGet a daily WhatsApp summary of your sales data from Google Sheets, powered by [MoltFlow](https://molt.waiflow.app).\n\n**How it works:**\n1. Runs every day at 6 PM\n2. Reads today's sales from Google Sheets\n3. Calculates total revenue, order count, and top product\n4. Sends a formatted summary to your WhatsApp"
      },
      "typeVersion": 1
    },
    {
      "id": "l1000001-0000-4000-0c00-000000000011",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        420,
        -300
      ],
      "parameters": {
        "color": 5,
        "width": 400,
        "height": 250,
        "content": "## Setup (5 min)\n1. Create a [MoltFlow account](https://molt.waiflow.app) and connect WhatsApp\n2. Create a Google Sheet with columns: **Date**, **Product**, **Amount**, **Customer**\n3. Connect Google Sheets OAuth2 credential\n4. Paste your Sheet URL in the Google Sheets node\n5. Set `YOUR_SESSION_ID` and `YOUR_PHONE` in the Build Report node\n6. Add MoltFlow API Key: Header Auth \u2192 `X-API-Key`"
      },
      "typeVersion": 1
    },
    {
      "id": "l1000001-0000-4000-0c00-000000000001",
      "name": "Every Day 6 PM",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        0,
        0
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 18 * * *"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "l1000001-0000-4000-0c00-000000000002",
      "name": "Read Sales Data",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        220,
        0
      ],
      "parameters": {
        "options": {},
        "operation": "read",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "Sales"
        },
        "documentId": {
          "__rl": true,
          "mode": "url",
          "value": "YOUR_GOOGLE_SHEET_URL"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "l1000001-0000-4000-0c00-000000000003",
      "name": "Build Report",
      "type": "n8n-nodes-base.code",
      "position": [
        440,
        0
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const SESSION_ID = 'YOUR_SESSION_ID';\nconst MY_PHONE = 'YOUR_PHONE';\n\nconst rows = $input.all();\nconst today = new Date().toISOString().split('T')[0];\n\nconst todaySales = rows.filter(r => {\n  const d = r.json.Date || r.json.date || '';\n  return d.startsWith(today);\n});\n\nif (todaySales.length === 0) {\n  const message = `Daily Sales Report (${today})\\n\\nNo sales recorded today.`;\n  return [{ json: { session_id: SESSION_ID, chat_id: MY_PHONE + '@c.us', message } }];\n}\n\nlet totalRevenue = 0;\nconst productCounts = {};\n\nfor (const sale of todaySales) {\n  const amount = parseFloat(sale.json.Amount || sale.json.amount || 0);\n  const product = sale.json.Product || sale.json.product || 'Unknown';\n  totalRevenue += amount;\n  productCounts[product] = (productCounts[product] || 0) + 1;\n}\n\nconst topProduct = Object.entries(productCounts)\n  .sort((a, b) => b[1] - a[1])[0];\n\nconst message = `Daily Sales Report (${today})\\n\\nOrders: ${todaySales.length}\\nRevenue: $${totalRevenue.toFixed(2)}\\nTop product: ${topProduct[0]} (${topProduct[1]} sold)\\n\\nKeep it up!`;\n\nreturn [{\n  json: {\n    session_id: SESSION_ID,\n    chat_id: MY_PHONE + '@c.us',\n    message: message\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "l1000001-0000-4000-0c00-000000000004",
      "name": "Send Report via WhatsApp",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        660,
        0
      ],
      "parameters": {
        "url": "https://apiv2.waiflow.app/api/v2/messages/send",
        "method": "POST",
        "options": {},
        "jsonBody": "={{ JSON.stringify({ session_id: $json.session_id, chat_id: $json.chat_id, message: $json.message }) }}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "l1000001-0000-4000-0c00-000000000005",
      "name": "Done",
      "type": "n8n-nodes-base.code",
      "position": [
        880,
        0
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "return [{ json: { status: 'report_sent', timestamp: new Date().toISOString() } }];"
      },
      "typeVersion": 2
    }
  ],
  "settings": {
    "executionOrder": "v1"
  },
  "connections": {
    "Build Report": {
      "main": [
        [
          {
            "node": "Send Report via WhatsApp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Every Day 6 PM": {
      "main": [
        [
          {
            "node": "Read Sales Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Sales Data": {
      "main": [
        [
          {
            "node": "Build Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Report via WhatsApp": {
      "main": [
        [
          {
            "node": "Done",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}