{
  "name": "FlowPantry - Facebook/Instagram Lead Ads: instant text and email",
  "nodes": [
    {
      "id": "fbc4742a-13a1-4af7-a982-8969784774a6",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        300
      ],
      "parameters": {
        "httpMethod": "POST",
        "path": "meta-lead",
        "responseMode": "onReceived",
        "options": {}
      },
      "webhookId": "782793e8-5d25-49e6-8d43-2a784e437bff"
    },
    {
      "id": "803b8cd4-6748-465d-8d49-e3246b87e8c1",
      "name": "Normalize lead",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        240,
        300
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "return $input.all().map(i=>{const b=i.json.body||i.json;return {json:{name:(b.name||'there').split(' ')[0],phone:b.phone,email:b.email,source:b.source||'web form',message:b.message||''}}}).filter(i=>i.json.phone);"
      }
    },
    {
      "id": "e45e00f0-4770-47cf-ab95-24fc2317d872",
      "name": "Text the lead",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        480,
        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.name}}, it's {{$env.BUSINESS_NAME}}. Thanks for your interest! When's a good time for a quick call? Reply STOP to opt out."
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "42274d95-53f7-4d68-8b16-c450c38b1a64",
      "name": "Welcome email",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        720,
        300
      ],
      "parameters": {
        "method": "POST",
        "url": "https://api.resend.com/emails",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({from: $env.FROM_EMAIL, to: $('Normalize lead').item.json.email, subject: 'Thanks for reaching out to '+$env.BUSINESS_NAME, html: '<p>Hi '+$('Normalize lead').item.json.name+',</p><p>Thanks for your interest. Book a time here: '+$env.BOOKING_URL+'</p>'}) }}",
        "options": {}
      }
    },
    {
      "id": "f884e111-30f7-4b31-81e9-09ff8a4abcd9",
      "name": "Log to CRM",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        960,
        300
      ],
      "parameters": {
        "method": "POST",
        "url": "={{$env.CRM_WEBHOOK_URL}}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($('Normalize lead').item.json) }}",
        "options": {}
      }
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Normalize lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize lead": {
      "main": [
        [
          {
            "node": "Text the lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Text the lead": {
      "main": [
        [
          {
            "node": "Welcome email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Welcome email": {
      "main": [
        [
          {
            "node": "Log to CRM",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}