{
  "id": "qbCAZbU6AXojolG4",
  "name": "Facebook Lead Qualification with AI",
  "tags": [],
  "nodes": [
    {
      "id": "4a4c481a-e26d-4f29-9206-d5ce09f56762",
      "name": "Setup Guide",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        800,
        448
      ],
      "parameters": {
        "width": 704,
        "height": 880,
        "content": "## Qualify and Book leads Instantly with Eleven Labs and Cal\n\n### How it works\nAs soon as a new lead fills out your form through facebook ads, the data gets sent to n8n immediately and saved to Supabase. Then an outbound call gets triggered instantly to qualify the lead and book a meeting if applicable. As soon as this step is completed, a slack and email notification is sent to the team\n\n\n### Requirements\n1. Facebook Account: Includes facebook ads account, business page, Facebook leads form\n2. Eleven labs Account\n3. Cal Account\n4. Supabase Account\n5. Slack Account\n6. Gmail Account\n\n\n### Set up steps\n1. Download and import workflow into n8n\n2. Add credentials for Facebook, Eleven Labs, Cal, Supabase, Slack and Gmail\n3. Run workflow node by node and edit accordingly including facebook form, supabase, eleven labs, slack and Gmail\n\n\n### Who this is for\nThis is for any business running facebook ads and wants to qualify leads and book appointment with qualified leads using voice agents."
      },
      "typeVersion": 1
    },
    {
      "id": "5ffe8eb9-712d-46e6-aa0d-54f244177888",
      "name": "Workflow A Header",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1744,
        416
      ],
      "parameters": {
        "color": 4,
        "width": 1316,
        "height": 264,
        "content": "## Workflow A: Lead Intake & Outbound Call Trigger\n\nFires real-time when a new Facebook lead arrives. Saves the lead, then initiates an AI voice call within seconds."
      },
      "typeVersion": 1
    },
    {
      "id": "154a032a-70f4-40e2-b3f8-e3d0aebc8f34",
      "name": "Facebook Lead Ads",
      "type": "n8n-nodes-base.facebookLeadAdsTrigger",
      "position": [
        1824,
        496
      ],
      "parameters": {
        "form": {
          "__rl": true,
          "mode": "list",
          "value": "__YOUR_FB_FORM_ID__",
          "cachedResultName": "__YOUR_FB_FORM_NAME__"
        },
        "page": {
          "__rl": true,
          "mode": "list",
          "value": "__YOUR_FB_PAGE_ID__",
          "cachedResultUrl": "__YOUR_FB_PAGE_URL__",
          "cachedResultName": "__YOUR_FB_PAGE_NAME__"
        },
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "b7555e27-9e5f-405e-a284-4fb5bebed775",
      "name": "Format Lead Data",
      "type": "n8n-nodes-base.set",
      "position": [
        2048,
        496
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "1",
              "name": "fb_lead_id",
              "type": "string",
              "value": "={{ $json.id }}"
            },
            {
              "id": "2",
              "name": "full_name",
              "type": "string",
              "value": "={{ $json.data.full_name }}"
            },
            {
              "id": "3",
              "name": "email",
              "type": "string",
              "value": "={{ $json.data.email }}"
            },
            {
              "id": "4",
              "name": "phone",
              "type": "string",
              "value": "={{ $json.data.phone_number }}"
            },
            {
              "id": "5",
              "name": "company_name",
              "type": "string",
              "value": "={{ $json.data.company_name }}"
            },
            {
              "id": "6",
              "name": "status",
              "type": "string",
              "value": "new"
            },
            {
              "id": "7",
              "name": "fb_form_id",
              "type": "string",
              "value": "={{ $json.form_id }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "4822165e-a351-4f54-b051-69e409a20cb6",
      "name": "Insert Lead",
      "type": "n8n-nodes-base.supabase",
      "position": [
        2256,
        496
      ],
      "parameters": {
        "tableId": "leads",
        "dataToSend": "autoMapInputData"
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "904cab84-6343-4c1a-bcd5-32c61a50da0f",
      "name": "Trigger ElevenLabs Call",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2464,
        496
      ],
      "parameters": {
        "url": "https://api.elevenlabs.io/v1/convai/twilio/outbound-call",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"agent_id\": \"__YOUR_ELEVENLABS_AGENT_ID__\",\n  \"agent_phone_number_id\": \"__YOUR_ELEVENLABS_PHONE_NUMBER_ID__\",\n  \"to_number\": \"{{ $('Facebook Lead Ads').item.json.data.phone_number }}\",\n  \"conversation_initiation_client_data\": {\n    \"dynamic_variables\": {\n      \"full_name\": \"{{ $('Facebook Lead Ads').item.json.data.full_name }}\",\n      \"company_name\": \"{{ $('Facebook Lead Ads').item.json.data.company_name }}\",\n      \"email\": \"{{ $('Facebook Lead Ads').item.json.data.email }}\"\n    }\n  }\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "typeVersion": 4.4
    },
    {
      "id": "cd80ecb3-8975-4bb8-97f2-75d8692ae970",
      "name": "Save Call ID",
      "type": "n8n-nodes-base.supabase",
      "position": [
        2672,
        496
      ],
      "parameters": {
        "filters": {
          "conditions": [
            {
              "keyName": "=fb_lead_id",
              "keyValue": "={{ $('Facebook Lead Ads').item.json.id }}",
              "condition": "eq"
            }
          ]
        },
        "tableId": "leads",
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": "call_id",
              "fieldValue": "={{ $json.conversation_id }}"
            },
            {
              "fieldId": "call_status",
              "fieldValue": "in_progress"
            },
            {
              "fieldId": "status",
              "fieldValue": "calling"
            },
            {
              "fieldId": "call_started_at",
              "fieldValue": "={{ new Date().toISOString() }}"
            }
          ]
        },
        "operation": "update"
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "4d20cca7-b2f6-4a48-a545-fb62f2959f8f",
      "name": "Workflow B Header",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1744,
        752
      ],
      "parameters": {
        "color": 3,
        "width": 1884,
        "height": 700,
        "content": "## Workflow B: Post-Call Analysis & Team Notification\n\n1. Listens for post-call webhook from ElevenLabs\n2. Extracts call analysis (qualification, booking, transcript, summary)\n3. Updates the lead row with full call data\n4. Branches based on appointment booking outcome\n5. Sends rich Slack message + Email notification with summary and transcript"
      },
      "typeVersion": 1
    },
    {
      "id": "b59240f6-076e-4871-b7c4-b4b2da69dc3d",
      "name": "ElevenLabs Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        1824,
        1024
      ],
      "parameters": {
        "path": "elevenlabs-call-complete",
        "options": {
          "rawBody": true,
          "responseCode": {
            "values": {}
          }
        },
        "httpMethod": "POST"
      },
      "typeVersion": 2.1
    },
    {
      "id": "aef74189-b1e8-4987-8a37-4591cecd203c",
      "name": "Extract Call Data",
      "type": "n8n-nodes-base.set",
      "position": [
        2032,
        1024
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "f1",
              "name": "conversation_id",
              "type": "string",
              "value": "={{ $json.body.data.conversation_id }}"
            },
            {
              "id": "f2",
              "name": "call_sid",
              "type": "string",
              "value": "={{ $json.body.data.metadata.phone_call.call_sid }}"
            },
            {
              "id": "f3",
              "name": "phone_called",
              "type": "string",
              "value": "={{ $json.body.data.metadata.phone_call.external_number }}"
            },
            {
              "id": "f4",
              "name": "call_duration_secs",
              "type": "number",
              "value": "={{ $json.body.data.metadata.call_duration_secs }}"
            },
            {
              "id": "f5",
              "name": "call_terminate_reason",
              "type": "string",
              "value": "={{ $json.body.data.metadata.termination_reason }}"
            },
            {
              "id": "f6",
              "name": "call_successful",
              "type": "string",
              "value": "={{ $json.body.data.analysis.call_successful }}"
            },
            {
              "id": "f7",
              "name": "call_summary_title",
              "type": "string",
              "value": "={{ $json.body.data.analysis.call_summary_title }}"
            },
            {
              "id": "f8",
              "name": "call_summary",
              "type": "string",
              "value": "={{ $json.body.data.analysis.transcript_summary }}"
            },
            {
              "id": "f9",
              "name": "qualification_status",
              "type": "string",
              "value": "={{ $json.body.data.analysis.data_collection_results.qualification_status.value }}"
            },
            {
              "id": "f10",
              "name": "appointment_booked",
              "type": "string",
              "value": "={{ $json.body.data.analysis.evaluation_criteria_results.appointment_booked.result }}"
            },
            {
              "id": "f11",
              "name": "lead_qualified_result",
              "type": "string",
              "value": "={{ $json.body.data.analysis.evaluation_criteria_results.lead_qualified.result }}"
            },
            {
              "id": "f12",
              "name": "lead_name",
              "type": "string",
              "value": "={{ $json.body.data.conversation_initiation_client_data.dynamic_variables.full_name }}"
            },
            {
              "id": "f13",
              "name": "lead_email",
              "type": "string",
              "value": "={{ $json.body.data.conversation_initiation_client_data.dynamic_variables.email }}"
            },
            {
              "id": "f14",
              "name": "lead_company",
              "type": "string",
              "value": "={{ $json.body.data.conversation_initiation_client_data.dynamic_variables.company_name }}"
            },
            {
              "id": "f15",
              "name": "call_started_at",
              "type": "string",
              "value": "={{ new Date($json.body.data.metadata.start_time_unix_secs * 1000).toISOString() }}"
            },
            {
              "id": "f16",
              "name": "call_ended_at",
              "type": "string",
              "value": "={{ new Date(($json.body.data.metadata.start_time_unix_secs + $json.body.data.metadata.call_duration_secs) * 1000).toISOString() }}"
            },
            {
              "id": "f17",
              "name": "transcript_text",
              "type": "string",
              "value": "={{ $json.body.data.transcript.map(t => t.role.toUpperCase() + ': ' + t.message).join('\\n\\n') }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "35b51efd-daf4-4179-90f0-4879fc7e498b",
      "name": "Update Lead Row",
      "type": "n8n-nodes-base.supabase",
      "position": [
        2240,
        1024
      ],
      "parameters": {
        "filters": {
          "conditions": [
            {
              "keyName": "call_id",
              "keyValue": "={{ $json.conversation_id }}",
              "condition": "eq"
            }
          ]
        },
        "tableId": "leads",
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": "call_status",
              "fieldValue": "completed"
            },
            {
              "fieldId": "status",
              "fieldValue": "={{ $json.appointment_booked === 'success' ? 'booked' : ($json.qualification_status === 'qualified' ? 'qualified' : 'reviewed') }}"
            },
            {
              "fieldId": "call_started_at",
              "fieldValue": "={{ $json.call_started_at }}"
            },
            {
              "fieldId": "call_ended_at",
              "fieldValue": "={{ $json.call_ended_at }}"
            },
            {
              "fieldId": "call_duration_seconds",
              "fieldValue": "={{ $json.call_duration_secs }}"
            },
            {
              "fieldId": "transcript",
              "fieldValue": "={{ $json.transcript_text }}"
            },
            {
              "fieldId": "call_summary",
              "fieldValue": "={{ $json.call_summary }}"
            },
            {
              "fieldId": "sales_qualified",
              "fieldValue": "={{ $json.qualification_status }}"
            },
            {
              "fieldId": "appointment_booked",
              "fieldValue": "={{ $json.appointment_booked }}"
            },
            {
              "fieldId": "call_terminate_reason",
              "fieldValue": "={{ $json.call_terminate_reason }}"
            },
            {
              "fieldId": "call_successful",
              "fieldValue": "={{ $json.call_successful }}"
            }
          ]
        },
        "operation": "update"
      },
      "typeVersion": 1
    },
    {
      "id": "4dfc9cca-07fc-4762-b791-526158481826",
      "name": "Appointment Booked?",
      "type": "n8n-nodes-base.switch",
      "position": [
        2448,
        1024
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "Appointment Booked",
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "cond-booked",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('Extract Call Data').item.json.appointment_booked }}",
                    "rightValue": "success"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "No Appointment Booked",
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "cond-not-booked",
                    "operator": {
                      "type": "string",
                      "operation": "notEquals"
                    },
                    "leftValue": "={{ $('Extract Call Data').item.json.appointment_booked }}",
                    "rightValue": "success"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.4
    },
    {
      "id": "c8cb31f0-a197-43f0-ac0c-5b0b95bc53be",
      "name": "Slack: Booked",
      "type": "n8n-nodes-base.slack",
      "position": [
        2672,
        912
      ],
      "parameters": {
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "__YOUR_SLACK_CHANNEL_ID__",
          "cachedResultName": "__YOUR_SLACK_CHANNEL_NAME__"
        },
        "otherOptions": {}
      },
      "typeVersion": 2.4
    },
    {
      "id": "0365830d-cebf-435b-8c4d-5a47c008b6e7",
      "name": "Slack: Not Booked",
      "type": "n8n-nodes-base.slack",
      "position": [
        2672,
        1136
      ],
      "parameters": {
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "__YOUR_SLACK_CHANNEL_ID__",
          "cachedResultName": "__YOUR_SLACK_CHANNEL_NAME__"
        },
        "otherOptions": {}
      },
      "typeVersion": 2.4
    },
    {
      "id": "bd5eadda-2a61-41aa-a10b-8c3140ab1007",
      "name": "Email: Booked",
      "type": "n8n-nodes-base.gmail",
      "position": [
        2880,
        912
      ],
      "parameters": {
        "sendTo": "__YOUR_NOTIFICATION_EMAIL__",
        "message": "=<h2>\ud83c\udf89 Discovery Call Booked</h2>\n<table style=\"border-collapse: collapse; width: 100%;\">\n  <tr><td style=\"padding: 4px 12px 4px 0;\"><strong>Lead:</strong></td><td>{{ $('Extract Call Data').item.json.lead_name }}</td></tr>\n  <tr><td style=\"padding: 4px 12px 4px 0;\"><strong>Company:</strong></td><td>{{ $('Extract Call Data').item.json.lead_company }}</td></tr>\n  <tr><td style=\"padding: 4px 12px 4px 0;\"><strong>Email:</strong></td><td>{{ $('Extract Call Data').item.json.lead_email }}</td></tr>\n  <tr><td style=\"padding: 4px 12px 4px 0;\"><strong>Phone:</strong></td><td>{{ $('Extract Call Data').item.json.phone_called }}</td></tr>\n  <tr><td style=\"padding: 4px 12px 4px 0;\"><strong>Qualification:</strong></td><td>{{ $('Extract Call Data').item.json.qualification_status }}</td></tr>\n  <tr><td style=\"padding: 4px 12px 4px 0;\"><strong>Call Duration:</strong></td><td>{{ $('Extract Call Data').item.json.call_duration_secs }} seconds</td></tr>\n  <tr><td style=\"padding: 4px 12px 4px 0;\"><strong>Call Outcome:</strong></td><td>{{ $('Extract Call Data').item.json.call_successful }}</td></tr>\n</table>\n<h3>Call Summary</h3>\n<p>{{ $('Extract Call Data').item.json.call_summary }}</p>\n<h3>Full Transcript</h3>\n<pre style=\"background: #f5f5f5; padding: 12px; border-radius: 4px; white-space: pre-wrap;\">{{ $('Extract Call Data').item.json.transcript_text }}</pre>\n<hr>\n<p style=\"color: #888; font-size: 12px;\">Conversation ID: {{ $('Extract Call Data').item.json.conversation_id }}</p>",
        "options": {
          "appendAttribution": false
        },
        "subject": "=\ud83c\udf89 {{ $('Extract Call Data').item.json.lead_name }} ({{ $('Extract Call Data').item.json.lead_company }}) \u2014 Discovery Call Booked"
      },
      "typeVersion": 2.2
    },
    {
      "id": "7cf76862-7bb5-4a07-bdd5-b1048fe2154a",
      "name": "Email: Not Booked",
      "type": "n8n-nodes-base.gmail",
      "position": [
        2880,
        1136
      ],
      "parameters": {
        "sendTo": "__YOUR_NOTIFICATION_EMAIL__",
        "message": "=<h2>{{ $('Extract Call Data').item.json.qualification_status === 'qualified' ? '\ud83d\udd25 Hot Lead \u2014 Follow Up Today' : '\ud83d\udccb Call Completed' }}</h2>\n<table style=\"border-collapse: collapse; width: 100%;\">\n  <tr><td style=\"padding: 4px 12px 4px 0;\"><strong>Lead:</strong></td><td>{{ $('Extract Call Data').item.json.lead_name }}</td></tr>\n  <tr><td style=\"padding: 4px 12px 4px 0;\"><strong>Company:</strong></td><td>{{ $('Extract Call Data').item.json.lead_company }}</td></tr>\n  <tr><td style=\"padding: 4px 12px 4px 0;\"><strong>Email:</strong></td><td>{{ $('Extract Call Data').item.json.lead_email }}</td></tr>\n  <tr><td style=\"padding: 4px 12px 4px 0;\"><strong>Phone:</strong></td><td>{{ $('Extract Call Data').item.json.phone_called }}</td></tr>\n  <tr><td style=\"padding: 4px 12px 4px 0;\"><strong>Qualification:</strong></td><td>{{ $('Extract Call Data').item.json.qualification_status }}</td></tr>\n  <tr><td style=\"padding: 4px 12px 4px 0;\"><strong>Appointment Booked:</strong></td><td>No</td></tr>\n  <tr><td style=\"padding: 4px 12px 4px 0;\"><strong>Call Duration:</strong></td><td>{{ $('Extract Call Data').item.json.call_duration_secs }} seconds</td></tr>\n  <tr><td style=\"padding: 4px 12px 4px 0;\"><strong>Call Outcome:</strong></td><td>{{ $('Extract Call Data').item.json.call_successful }}</td></tr>\n  <tr><td style=\"padding: 4px 12px 4px 0;\"><strong>Termination Reason:</strong></td><td>{{ $('Extract Call Data').item.json.call_terminate_reason }}</td></tr>\n</table>\n<h3>Call Summary</h3>\n<p>{{ $('Extract Call Data').item.json.call_summary }}</p>\n<h3>Full Transcript</h3>\n<pre style=\"background: #f5f5f5; padding: 12px; border-radius: 4px; white-space: pre-wrap;\">{{ $('Extract Call Data').item.json.transcript_text }}</pre>\n<hr>\n<p style=\"color: #888; font-size: 12px;\">Conversation ID: {{ $('Extract Call Data').item.json.conversation_id }}</p>",
        "options": {
          "appendAttribution": false
        },
        "subject": "={{ $('Extract Call Data').item.json.qualification_status === 'qualified' ? '\ud83d\udd25 Hot Lead \u2014 ' : 'Call Completed \u2014 ' }}{{ $('Extract Call Data').item.json.lead_name }} ({{ $('Extract Call Data').item.json.lead_company }})"
      },
      "typeVersion": 2.2
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "executionOrder": "v1"
  },
  "versionId": "034d2a01-b128-4e41-99df-6caae7eca272",
  "connections": {
    "Insert Lead": {
      "main": [
        [
          {
            "node": "Trigger ElevenLabs Call",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Slack: Booked": {
      "main": [
        [
          {
            "node": "Email: Booked",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Lead Row": {
      "main": [
        [
          {
            "node": "Appointment Booked?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Lead Data": {
      "main": [
        [
          {
            "node": "Insert Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Call Data": {
      "main": [
        [
          {
            "node": "Update Lead Row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Facebook Lead Ads": {
      "main": [
        [
          {
            "node": "Format Lead Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Slack: Not Booked": {
      "main": [
        [
          {
            "node": "Email: Not Booked",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ElevenLabs Webhook": {
      "main": [
        [
          {
            "node": "Extract Call Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Appointment Booked?": {
      "main": [
        [
          {
            "node": "Slack: Booked",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Slack: Not Booked",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Trigger ElevenLabs Call": {
      "main": [
        [
          {
            "node": "Save Call ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}