{
  "name": "FlowPantry - Win back customers inactive for 90 days",
  "nodes": [
    {
      "id": "5b32219f-0f83-4d6b-9b5c-703ca9bfb942",
      "name": "Schedule",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        300
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "weeks",
              "triggerAtDay": [
                1
              ],
              "triggerAtHour": 10
            }
          ]
        }
      }
    },
    {
      "id": "bb03600c-6a2b-4b8e-b4ac-d009e8b95e45",
      "name": "Get customers",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        240,
        300
      ],
      "parameters": {
        "url": "={{$env.CUSTOMERS_URL}}",
        "options": {}
      }
    },
    {
      "id": "2e0a8d15-38a6-4b83-8415-bb52397bbcc5",
      "name": "Inactive 90-120 days, opted in",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        480,
        300
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const out=[];for(const i of $input.all()){const cs=Array.isArray(i.json)?i.json:(i.json.customers||[i.json]);for(const c of cs){const d=(Date.now()-new Date(c.last_visit))/864e5;if(d>=90&&d<120&&c.phone&&c.sms_marketing_opt_in===true)out.push({json:{...c,first:(c.name||'there').split(' ')[0]}});}}return out;"
      }
    },
    {
      "id": "b1e6789b-a2bd-4b3b-9ba1-dbffa444e880",
      "name": "Send win-back offer",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        720,
        300
      ],
      "parameters": {
        "method": "POST",
        "url": "=https://api.twilio.com/2010-04-01/Accounts/{{$env.TWILIO_ACCOUNT_SID}}/Messages.json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBasicAuth",
        "sendBody": true,
        "contentType": "form-urlencoded",
        "bodyParameters": {
          "parameters": [
            {
              "name": "To",
              "value": "={{$json.phone}}"
            },
            {
              "name": "From",
              "value": "={{$env.TWILIO_FROM_NUMBER}}"
            },
            {
              "name": "Body",
              "value": "=Hi {{$json.first}}, we miss you at {{$env.BUSINESS_NAME}}! {{$env.OFFER}}. Book: {{$env.BOOKING_URL}} Reply STOP to opt out."
            }
          ]
        },
        "options": {}
      }
    }
  ],
  "connections": {
    "Schedule": {
      "main": [
        [
          {
            "node": "Get customers",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get customers": {
      "main": [
        [
          {
            "node": "Inactive 90-120 days, opted in",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Inactive 90-120 days, opted in": {
      "main": [
        [
          {
            "node": "Send win-back offer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}