{
  "name": "CRM \u2014 Sequences prospection",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 8 * * *"
            }
          ]
        }
      },
      "id": "a1b2c3d4-0201-4000-8000-000000000001",
      "name": "Tous les jours a 8h",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "={{ $vars.CRM_BASE_URL }}/api/n8n/sequences/actions-dues",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "x-n8n-secret",
              "value": "={{ $vars.CRM_N8N_SECRET }}"
            }
          ]
        },
        "options": {}
      },
      "id": "a1b2c3d4-0201-4000-8000-000000000002",
      "name": "GET Actions dues",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        220,
        0
      ]
    },
    {
      "parameters": {
        "fieldToSplitOut": "actionsDues",
        "options": {}
      },
      "id": "a1b2c3d4-0201-4000-8000-000000000003",
      "name": "Split actions",
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        440,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "return $input.all().filter(item => item.json.etapeCourante?.action === 'tache');"
      },
      "id": "a1b2c3d4-0201-4000-8000-000000000010",
      "name": "Filtrer taches",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        660,
        -200
      ]
    },
    {
      "parameters": {
        "jsCode": "return $input.all().filter(item => item.json.etapeCourante?.action === 'email_ia');"
      },
      "id": "a1b2c3d4-0201-4000-8000-000000000011",
      "name": "Filtrer emails",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        660,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "return $input.all().filter(item => item.json.etapeCourante?.action === 'auto_perdu');"
      },
      "id": "a1b2c3d4-0201-4000-8000-000000000012",
      "name": "Filtrer auto perdu",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        660,
        200
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $vars.CRM_BASE_URL }}/api/n8n/taches",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "x-n8n-secret",
              "value": "={{ $vars.CRM_N8N_SECRET }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"titre\": \"[Seq] {{ $json.etapeCourante.titre }} - {{ $json.clientNom }}\",\n  \"clientId\": \"{{ $json.clientId }}\",\n  \"type\": \"{{ $json.etapeCourante.type ?? 'ADMIN' }}\",\n  \"priorite\": \"normale\",\n  \"sourceAuto\": \"n8n_sequence\"\n}",
        "options": {}
      },
      "id": "a1b2c3d4-0201-4000-8000-000000000004",
      "name": "Creer tache sequence",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        880,
        -200
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $vars.CRM_BASE_URL }}/api/n8n/sequences",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "x-n8n-secret",
              "value": "={{ $vars.CRM_N8N_SECRET }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"inscriptionId\": \"{{ $json.inscriptionId }}\",\n  \"etapeIndex\": {{ $json.etapeActuelle }}\n}",
        "options": {}
      },
      "id": "a1b2c3d4-0201-4000-8000-000000000005",
      "name": "Avancer sequence tache",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1100,
        -200
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "a1",
              "name": "prompt",
              "value": "={{ $json.etapeCourante.prompt }}",
              "type": "string"
            },
            {
              "id": "a2",
              "name": "clientNom",
              "value": "={{ $json.clientNom }}",
              "type": "string"
            },
            {
              "id": "a3",
              "name": "clientEmail",
              "value": "={{ $json.clientEmail }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "a1b2c3d4-0201-4000-8000-000000000006",
      "name": "Preparer donnees email",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        880,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $vars.CRM_BASE_URL }}/api/n8n/sequences",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "x-n8n-secret",
              "value": "={{ $vars.CRM_N8N_SECRET }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"inscriptionId\": \"{{ $json.inscriptionId }}\",\n  \"etapeIndex\": {{ $json.etapeActuelle }},\n  \"emailSujet\": \"{{ $json.etapeCourante.titre }}\",\n  \"emailEnvoyeAt\": \"{{ new Date().toISOString() }}\"\n}",
        "options": {}
      },
      "id": "a1b2c3d4-0201-4000-8000-000000000007",
      "name": "Avancer sequence email",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1100,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $vars.CRM_BASE_URL }}/api/n8n/deals/mark-lost",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "x-n8n-secret",
              "value": "={{ $vars.CRM_N8N_SECRET }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"clientId\": \"{{ $json.clientId }}\",\n  \"motif\": \"{{ $json.etapeCourante.motif ?? 'Pas de reponse (sequence auto)' }}\"\n}",
        "options": {}
      },
      "id": "a1b2c3d4-0201-4000-8000-000000000008",
      "name": "Marquer deals perdus",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        880,
        200
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $vars.CRM_BASE_URL }}/api/n8n/sequences",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "x-n8n-secret",
              "value": "={{ $vars.CRM_N8N_SECRET }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"inscriptionId\": \"{{ $json.inscriptionId }}\",\n  \"etapeIndex\": {{ $json.etapeActuelle }}\n}",
        "options": {}
      },
      "id": "a1b2c3d4-0201-4000-8000-000000000009",
      "name": "Avancer sequence perdu",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1100,
        200
      ]
    }
  ],
  "connections": {
    "Tous les jours a 8h": {
      "main": [
        [
          {
            "node": "GET Actions dues",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GET Actions dues": {
      "main": [
        [
          {
            "node": "Split actions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split actions": {
      "main": [
        [
          {
            "node": "Filtrer taches",
            "type": "main",
            "index": 0
          },
          {
            "node": "Filtrer emails",
            "type": "main",
            "index": 0
          },
          {
            "node": "Filtrer auto perdu",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filtrer taches": {
      "main": [
        [
          {
            "node": "Creer tache sequence",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filtrer emails": {
      "main": [
        [
          {
            "node": "Preparer donnees email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filtrer auto perdu": {
      "main": [
        [
          {
            "node": "Marquer deals perdus",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Creer tache sequence": {
      "main": [
        [
          {
            "node": "Avancer sequence tache",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Preparer donnees email": {
      "main": [
        [
          {
            "node": "Avancer sequence email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Marquer deals perdus": {
      "main": [
        [
          {
            "node": "Avancer sequence perdu",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "tags": [
    {
      "name": "CRM Courtage"
    }
  ]
}