{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Shopify Order Confirmation via WhatsApp with MoltFlow",
  "tags": [
    {
      "name": "whatsapp"
    },
    {
      "name": "shopify"
    },
    {
      "name": "e-commerce"
    },
    {
      "name": "moltflow"
    },
    {
      "name": "order confirmation"
    }
  ],
  "nodes": [
    {
      "id": "d1000001-0000-4000-d000-000000000010",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -40,
        -300
      ],
      "parameters": {
        "color": 4,
        "width": 400,
        "height": 300,
        "content": "## Shopify \u2192 WhatsApp Order Confirmation\nSend instant WhatsApp order confirmations when a customer places an order on your Shopify store, powered by [MoltFlow](https://molt.waiflow.app).\n\n**How it works:**\n1. Shopify sends an order webhook to n8n\n2. Customer details and order info are extracted\n3. A personalized WhatsApp confirmation is sent\n4. Result is logged for tracking"
      },
      "typeVersion": 1
    },
    {
      "id": "d1000001-0000-4000-d000-000000000011",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        420,
        -300
      ],
      "parameters": {
        "color": 5,
        "width": 400,
        "height": 270,
        "content": "## Setup (5 min)\n1. Create a [MoltFlow account](https://molt.waiflow.app) and connect WhatsApp\n2. Activate this workflow \u2014 copy the webhook URL\n3. In Shopify Admin \u2192 Settings \u2192 Notifications \u2192 Webhooks, add the n8n URL for **Order creation**\n4. Set `YOUR_SESSION_ID` in the Format Order node\n5. Add MoltFlow API Key: Header Auth \u2192 `X-API-Key`\n\n**Note:** Customer phone must include country code"
      },
      "typeVersion": 1
    },
    {
      "id": "d1000001-0000-4000-d000-000000000001",
      "name": "Shopify Order Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        0,
        0
      ],
      "parameters": {
        "path": "shopify-order",
        "options": {},
        "httpMethod": "POST"
      },
      "typeVersion": 2
    },
    {
      "id": "d1000001-0000-4000-d000-000000000002",
      "name": "Format Order Message",
      "type": "n8n-nodes-base.code",
      "position": [
        220,
        0
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const SESSION_ID = 'YOUR_SESSION_ID';\n\nconst order = $input.first().json.body || $input.first().json;\n\nconst customerName = order.customer\n  ? (order.customer.first_name + ' ' + (order.customer.last_name || '')).trim()\n  : 'Customer';\n\nconst phone = order.customer && order.customer.phone\n  ? order.customer.phone.replace(/[^0-9]/g, '')\n  : (order.billing_address && order.billing_address.phone\n    ? order.billing_address.phone.replace(/[^0-9]/g, '')\n    : '');\n\nif (!phone) {\n  return [{ json: { error: 'No phone number found', order_id: order.id || order.order_number } }];\n}\n\nconst orderNumber = order.order_number || order.name || order.id;\nconst total = order.total_price || '0.00';\nconst currency = order.currency || 'USD';\n\nconst items = (order.line_items || []).map(item =>\n  item.title + ' x' + item.quantity\n).join(', ');\n\nconst message = `Hi ${customerName}! Your order #${orderNumber} has been confirmed.\\n\\nItems: ${items}\\nTotal: ${currency} ${total}\\n\\nWe'll send you tracking details once your order ships. Thank you for your purchase!`;\n\nreturn [{\n  json: {\n    session_id: SESSION_ID,\n    chat_id: phone + '@c.us',\n    message: message,\n    customer_name: customerName,\n    order_number: orderNumber,\n    phone: phone\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "d1000001-0000-4000-d000-000000000003",
      "name": "Has Phone?",
      "type": "n8n-nodes-base.if",
      "position": [
        440,
        0
      ],
      "parameters": {
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "has-phone",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              },
              "leftValue": "={{ $json.phone }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "d1000001-0000-4000-d000-000000000004",
      "name": "Send WhatsApp Confirmation",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        660,
        -100
      ],
      "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": "d1000001-0000-4000-d000-000000000005",
      "name": "Log Success",
      "type": "n8n-nodes-base.code",
      "position": [
        880,
        -100
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const input = $input.first().json;\nreturn [{ json: {\n  status: 'sent',\n  customer: input.customer_name || $('Format Order Message').first().json.customer_name,\n  order: $('Format Order Message').first().json.order_number,\n  message_id: input.id || 'N/A'\n} }];"
      },
      "typeVersion": 2
    },
    {
      "id": "d1000001-0000-4000-d000-000000000006",
      "name": "No Phone - Skip",
      "type": "n8n-nodes-base.code",
      "position": [
        660,
        100
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "return [{ json: {\n  status: 'skipped',\n  reason: 'No phone number on order',\n  order: $('Format Order Message').first().json.order_number\n} }];"
      },
      "typeVersion": 2
    }
  ],
  "settings": {
    "executionOrder": "v1"
  },
  "connections": {
    "Has Phone?": {
      "main": [
        [
          {
            "node": "Send WhatsApp Confirmation",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Phone - Skip",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Order Message": {
      "main": [
        [
          {
            "node": "Has Phone?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Shopify Order Webhook": {
      "main": [
        [
          {
            "node": "Format Order Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send WhatsApp Confirmation": {
      "main": [
        [
          {
            "node": "Log Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}