{
  "name": "Chatbot de Facebook Messenger para Captura de Leads",
  "flow": [
    {
      "id": 1,
      "module": "facebook-pages:watchMessages",
      "version": 1,
      "parameters": {
        "pageId": "{{FACEBOOK_PAGE_ID}}",
        "limit": 10
      },
      "mapper": {},
      "metadata": {
        "designer": { "x": 0, "y": 0 },
        "restore": {},
        "expect": [
          { "name": "pageId", "type": "text", "label": "Page ID" }
        ]
      }
    },
    {
      "id": 2,
      "module": "util:TextParser",
      "version": 1,
      "parameters": {},
      "mapper": {
        "text": "{{1.message}}",
        "pattern": "(precio|costo|horario|ubicación|dirección|catálogo|disponible)"
      },
      "metadata": {
        "designer": { "x": 300, "y": 0 },
        "restore": {},
        "expect": [
          { "name": "text", "type": "text", "label": "Text" },
          { "name": "pattern", "type": "text", "label": "Pattern" }
        ]
      }
    },
    {
      "id": 3,
      "module": "builtin:BasicRouter",
      "version": 1,
      "parameters": {},
      "mapper": {},
      "routes": [
        {
          "label": "Precios",
          "filter": { "conditions": [{ "a": "{{2.match}}", "o": "text:contains", "b": "precio" }] },
          "flow": [4]
        },
        {
          "label": "Horarios",
          "filter": { "conditions": [{ "a": "{{2.match}}", "o": "text:contains", "b": "horario" }] },
          "flow": [5]
        },
        {
          "label": "Registro Lead",
          "flow": [6]
        }
      ],
      "metadata": {
        "designer": { "x": 600, "y": 0 },
        "restore": {},
        "expect": []
      }
    },
    {
      "id": 4,
      "module": "http:ActionSendData",
      "version": 3,
      "parameters": {},
      "mapper": {
        "url": "https://graph.facebook.com/v18.0/me/messages",
        "method": "POST",
        "headers": [
          { "name": "Authorization", "value": "Bearer {{FACEBOOK_PAGE_TOKEN}}" }
        ],
        "body": "{\"recipient\":{\"id\":\"{{1.senderId}}\"},\"message\":{\"text\":\"¡Hola! Gracias por tu interés. 📋 Te comparto nuestro catálogo de precios: {{LINK_CATALOGO}}\\n\\n¿Te gustaría recibir una cotización personalizada?\"}}"
      },
      "metadata": {
        "designer": { "x": 900, "y": -200 },
        "restore": {},
        "expect": [
          { "name": "url", "type": "url", "label": "URL" },
          { "name": "method", "type": "select", "label": "Method" }
        ]
      }
    },
    {
      "id": 5,
      "module": "http:ActionSendData",
      "version": 3,
      "parameters": {},
      "mapper": {
        "url": "https://graph.facebook.com/v18.0/me/messages",
        "method": "POST",
        "headers": [
          { "name": "Authorization", "value": "Bearer {{FACEBOOK_PAGE_TOKEN}}" }
        ],
        "body": "{\"recipient\":{\"id\":\"{{1.senderId}}\"},\"message\":{\"text\":\"🕐 Nuestros horarios de atención:\\n\\nLunes a Viernes: 9:00 AM - 6:00 PM\\nSábados: 9:00 AM - 1:00 PM\\nDomingos: Cerrado\\n\\n¿En qué más te podemos ayudar?\"}}"
      },
      "metadata": {
        "designer": { "x": 900, "y": 0 },
        "restore": {},
        "expect": [
          { "name": "url", "type": "url", "label": "URL" },
          { "name": "method", "type": "select", "label": "Method" }
        ]
      }
    },
    {
      "id": 6,
      "module": "google-sheets:addRow",
      "version": 2,
      "parameters": {
        "spreadsheetId": "{{SPREADSHEET_ID}}",
        "sheetId": "Leads Messenger",
        "includeHeaders": true
      },
      "mapper": {
        "values": {
          "0": "{{1.senderName}}",
          "1": "{{1.senderId}}",
          "2": "{{1.message}}",
          "3": "{{formatDate(now; \"YYYY-MM-DD HH:mm:ss\")}}",
          "4": "Facebook Messenger",
          "5": "{{2.match}}"
        }
      },
      "filter": {
        "name": "No duplicados",
        "conditions": [
          { "a": "{{1.senderId}}", "o": "text:notEqual", "b": "{{previousSenderId}}" }
        ]
      },
      "metadata": {
        "designer": { "x": 900, "y": 200 },
        "restore": {
          "spreadsheetId": { "label": "Leads de Messenger" },
          "sheetId": { "label": "Leads Messenger" }
        },
        "expect": [
          { "name": "spreadsheetId", "type": "text", "label": "Spreadsheet ID" },
          { "name": "sheetId", "type": "text", "label": "Sheet Name" }
        ]
      }
    }
  ],
  "metadata": {
    "instant": true,
    "version": 1,
    "scenario": {
      "roundtrips": 1,
      "maxErrors": 3,
      "autoCommit": true,
      "autoCommitTriggerLast": true,
      "sequential": false
    },
    "designer": {
      "orphans": []
    },
    "zone": "us1.make.com"
  }
}