{
  "name": "FlowPantry - Missed-call text-back",
  "nodes": [
    {
      "id": "55a526ec-b7a4-411b-b1b4-ba89204e9507",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        300
      ],
      "parameters": {
        "httpMethod": "POST",
        "path": "missed-call",
        "responseMode": "onReceived",
        "options": {}
      },
      "webhookId": "4ff42fee-7f9a-421a-946e-65ad92db7bc8"
    },
    {
      "id": "7722bf01-c8bc-4b47-bbd1-7a080dd67420",
      "name": "Only missed calls",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        240,
        300
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "return $input.all().filter(i=>{const b=i.json.body||i.json;return ['no-answer','busy','failed'].includes(b.CallStatus)||b.CallDuration==='0';}).map(i=>{const b=i.json.body||i.json;return {json:{phone:b.From}}});"
      }
    },
    {
      "id": "54c88887-d795-4573-8fab-b7679f2e7d04",
      "name": "Text caller back",
      "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": "=Sorry we missed your call at {{$env.BUSINESS_NAME}}! How can we help? Reply here or book: {{$env.BOOKING_URL}}. Reply STOP to opt out."
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "0352dad0-d40d-4d46-89a6-2e65c24603b6",
      "name": "Alert owner",
      "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": "={{$env.OWNER_PHONE}}"
            },
            {
              "name": "From",
              "value": "={{$env.TWILIO_FROM_NUMBER}}"
            },
            {
              "name": "Body",
              "value": "=Missed call from {{$('Only missed calls').item.json.phone}}. Auto-text sent."
            }
          ]
        },
        "options": {}
      }
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Only missed calls",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Only missed calls": {
      "main": [
        [
          {
            "node": "Text caller back",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Text caller back": {
      "main": [
        [
          {
            "node": "Alert owner",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}