{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "d7294494-3464-4ee4-a5bc-e262c2fa395e",
      "name": "Workflow Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2064,
        -1680
      ],
      "parameters": {
        "color": 3,
        "width": 460,
        "height": 428,
        "content": "## Missed Call \u2192 SMS Recovery + Re-engagement\n\n**How it works:**\n1. Triggered by `call.missed` event from Aloware webhook\n2. Extracts caller data (phone, name, contact ID)\n3. Sends immediate \"sorry we missed you\" SMS\n4. Waits 2 hours\n5. Looks up contact to check if they replied\n6. No reply \u2192 sends follow-up SMS + enrolls in re-engagement sequence\n7. Already replied \u2192 no further action\n\n**Setup:**\n- Set n8n Variables: `ALOWARE_API_TOKEN`, `ALOWARE_LINE_PHONE`, `ALOWARE_REENGAGEMENT_SEQUENCE_ID`, `COMPANY_NAME`\n- In Aloware Admin \u2192 Webhooks, add `call.missed` event pointing to this webhook URL"
      },
      "typeVersion": 1
    },
    {
      "id": "e782da3a-3d75-466f-87c9-43c5ec250e5a",
      "name": "Instant Recovery",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2640,
        -1360
      ],
      "parameters": {
        "color": 5,
        "width": 676,
        "height": 324,
        "content": "### \u26a1 Instant SMS Recovery"
      },
      "typeVersion": 1
    },
    {
      "id": "19d2a722-c2ea-4ab3-a83b-4dcea1928268",
      "name": "2h Follow-up Check",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3328,
        -1360
      ],
      "parameters": {
        "color": 4,
        "width": 644,
        "height": 324,
        "content": "### \u23f0 Wait & Check Response"
      },
      "typeVersion": 1
    },
    {
      "id": "3d864366-835d-486f-9132-599db655d825",
      "name": "Re-engagement",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4000,
        -1456
      ],
      "parameters": {
        "color": 6,
        "width": 480,
        "height": 420,
        "content": "### \ud83d\udd04 Follow-up & Re-engage"
      },
      "typeVersion": 1
    },
    {
      "id": "f5c5c48f-e199-4822-91e9-6b7bb1c85245",
      "name": "Aloware: Missed Call Event",
      "type": "n8n-nodes-base.webhook",
      "position": [
        2704,
        -1248
      ],
      "parameters": {
        "path": "aloware-missed-call",
        "options": {},
        "httpMethod": "POST"
      },
      "typeVersion": 2
    },
    {
      "id": "b4a761c4-fcf6-4597-b945-d385f943712f",
      "name": "Extract Caller Data",
      "type": "n8n-nodes-base.set",
      "position": [
        2928,
        -1248
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "a001",
              "name": "callerPhone",
              "type": "string",
              "value": "={{ $json.body?.from || $json.from || $json.caller_id || $json.contact_phone || $json.phone || '' }}"
            },
            {
              "id": "a002",
              "name": "callerName",
              "type": "string",
              "value": "={{ $json.body?.contact_name || $json.contact_name || $json.caller_name || 'there' }}"
            },
            {
              "id": "a003",
              "name": "contactId",
              "type": "string",
              "value": "={{ $json.body?.contact_id || $json.contact_id || '' }}"
            },
            {
              "id": "a004",
              "name": "missedAt",
              "type": "string",
              "value": "={{ $json.body?.created_at || $json.created_at || $now.toISO() }}"
            },
            {
              "id": "a005",
              "name": "lineName",
              "type": "string",
              "value": "={{ $json.body?.line_name || $json.line_name || $vars.COMPANY_NAME || 'us' }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "c550dec6-b9a0-4d29-9bd5-d872b308be6a",
      "name": "Aloware: Send Missed-Call SMS",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3152,
        -1248
      ],
      "parameters": {
        "url": "https://app.aloware.com/api/v1/webhook/sms-gateway/send",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "api_token",
              "value": "={{ $vars.ALOWARE_API_TOKEN }}"
            },
            {
              "name": "from",
              "value": "={{ $vars.ALOWARE_LINE_PHONE }}"
            },
            {
              "name": "to",
              "value": "={{ $json.callerPhone }}"
            },
            {
              "name": "message",
              "value": "=Hi {{ $json.callerName }}, sorry we missed your call! We'd love to connect. Reply YES to schedule a callback, or call us back anytime at {{ $vars.ALOWARE_LINE_PHONE }}. \u2014 {{ $json.lineName }}"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "ab1e2e83-3421-4da1-baa4-db1a1b4e307a",
      "name": "Wait 2 Hours",
      "type": "n8n-nodes-base.wait",
      "position": [
        3360,
        -1248
      ],
      "parameters": {
        "unit": "hours",
        "amount": 2
      },
      "typeVersion": 1.1
    },
    {
      "id": "93e0e984-2ef4-4564-b53f-ed4cc248119e",
      "name": "Aloware: Lookup Contact Status",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3584,
        -1248
      ],
      "parameters": {
        "url": "=https://app.aloware.com/api/v1/webhook/contact/phone-number?api_token={{ $vars.ALOWARE_API_TOKEN }}&phone_number={{ $('Extract Caller Data').item.json.callerPhone }}",
        "options": {}
      },
      "typeVersion": 4.2
    },
    {
      "id": "c81cfda9-0556-4186-8d2b-967c697c3745",
      "name": "Did Contact Reply?",
      "type": "n8n-nodes-base.if",
      "position": [
        3808,
        -1248
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": false,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "cond_001",
              "operator": {
                "type": "string",
                "operation": "after"
              },
              "leftValue": "={{ $json.data?.last_communication_at || $json.last_sms_at || '' }}",
              "rightValue": "={{ $('Extract Caller Data').item.json.missedAt }}"
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "79eaba9a-5db8-4a2c-8297-52eaefb2c375",
      "name": "Already Engaged \u2014 No Action",
      "type": "n8n-nodes-base.noOp",
      "position": [
        4176,
        -1392
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "5324770c-c5e4-4617-aedf-407d97ddb6c7",
      "name": "Aloware: Send Follow-up SMS",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        4080,
        -1216
      ],
      "parameters": {
        "url": "https://app.aloware.com/api/v1/webhook/sms-gateway/send",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "api_token",
              "value": "={{ $vars.ALOWARE_API_TOKEN }}"
            },
            {
              "name": "from",
              "value": "={{ $vars.ALOWARE_LINE_PHONE }}"
            },
            {
              "name": "to",
              "value": "={{ $('Extract Caller Data').item.json.callerPhone }}"
            },
            {
              "name": "message",
              "value": "=Hey {{ $('Extract Caller Data').item.json.callerName }}, just wanted to follow up \u2014 we still haven't connected! Is there a better time to reach you? Reply with a time or call {{ $vars.ALOWARE_LINE_PHONE }} anytime."
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "53c9391a-a880-402a-8da4-1f6dde5083df",
      "name": "Aloware: Enroll in Re-engagement Sequence",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        4288,
        -1216
      ],
      "parameters": {
        "url": "https://app.aloware.com/api/v1/webhook/sequence-enroll",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "api_token",
              "value": "={{ $vars.ALOWARE_API_TOKEN }}"
            },
            {
              "name": "sequence_id",
              "value": "={{ $vars.ALOWARE_REENGAGEMENT_SEQUENCE_ID }}"
            },
            {
              "name": "phone_number",
              "value": "={{ $('Extract Caller Data').item.json.callerPhone }}"
            },
            {
              "name": "source",
              "value": "n8n-missed-call-recovery"
            },
            {
              "name": "force_enroll",
              "value": "=false"
            }
          ]
        }
      },
      "typeVersion": 4.2
    }
  ],
  "connections": {
    "Wait 2 Hours": {
      "main": [
        [
          {
            "node": "Aloware: Lookup Contact Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Did Contact Reply?": {
      "main": [
        [
          {
            "node": "Already Engaged \u2014 No Action",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Aloware: Send Follow-up SMS",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Caller Data": {
      "main": [
        [
          {
            "node": "Aloware: Send Missed-Call SMS",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aloware: Missed Call Event": {
      "main": [
        [
          {
            "node": "Extract Caller Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aloware: Send Follow-up SMS": {
      "main": [
        [
          {
            "node": "Aloware: Enroll in Re-engagement Sequence",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aloware: Send Missed-Call SMS": {
      "main": [
        [
          {
            "node": "Wait 2 Hours",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aloware: Lookup Contact Status": {
      "main": [
        [
          {
            "node": "Did Contact Reply?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}