{
  "name": "Iris",
  "nodes": [
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "2a6b79d7-6ff3-403a-a944-e3c0021ff63d",
              "leftValue": "={{ !!$json.jid }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        96,
        416
      ],
      "id": "f86e1f29-240f-4d68-a532-ffc3ec832173",
      "name": "\u00bfEsta registrado?"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT * \nFROM users u\nWHERE jid = '{{ $json.body.data.key.remoteJid }}';",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        -128,
        416
      ],
      "id": "30c7bec2-f093-476e-a5d3-1d91cccbec61",
      "name": "comprobar si un jid esta registrado",
      "alwaysOutputData": true,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "table": {
          "__rl": true,
          "value": "users",
          "mode": "list",
          "cachedResultName": "users"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "jid": "={{ $('mensaje de whatsapp').item.json.body.data.key.remoteJid }}"
          },
          "matchingColumns": [
            "id"
          ],
          "schema": [
            {
              "id": "email",
              "displayName": "email",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "name",
              "displayName": "name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "phone",
              "displayName": "phone",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "jid",
              "displayName": "jid",
              "required": true,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "conversation_token_limit",
              "displayName": "conversation_token_limit",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "verification_code",
              "displayName": "verification_code",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "is_verified",
              "displayName": "is_verified",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "boolean",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "verification_requested_at",
              "displayName": "verification_requested_at",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "dateTime",
              "canBeUsedToMatch": true,
              "removed": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        320,
        496
      ],
      "id": "2a71b1c2-0875-4e9e-9a6c-704b04e7f5ec",
      "name": "a\u00f1adir jid al sistema",
      "alwaysOutputData": true,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT name\nFROM users u\nWHERE jid = '{{ $('mensaje de whatsapp').item.json.body.data.key.remoteJid }}';",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        768,
        416
      ],
      "id": "85f0d8c3-6efc-4676-b943-d1ac13c580bc",
      "name": "comprobar si tiene un nombre asignado",
      "alwaysOutputData": true,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "workflowId": {
          "__rl": true,
          "value": "BXBLMLRPBiqSvBW6",
          "mode": "list",
          "cachedResultUrl": "/workflow/BXBLMLRPBiqSvBW6",
          "cachedResultName": "[Registro] Preguntar a la IA"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {
            "prompt": "Pregunta al usuario por su nombre. \n\nExtrae del mensaje el nombre del usuario. \n\nPuedes usar la herramienta de contexto para enterarte de la conversaci\u00f3n. \n\nSi no estas seguro de que hayas encontrado lo que es su nombre pregunta antes que guardar en la base de datos, tambi\u00e9n puedes preguntar para asegurarte de que esta correcto la eleccion que has hecho.\n\nDespu\u00e9s tiene que registrar el correo, as\u00ed que preguntaselo si ya tienes el nombre de usuario guardado correctamente en la base de datos",
            "mensaje": "={{ $('mensaje de whatsapp').item.json.body.data.message.conversation }}",
            "jid": "={{ $('mensaje de whatsapp').item.json.body.data.key.remoteJid }}"
          },
          "matchingColumns": [
            "mensaje"
          ],
          "schema": [
            {
              "id": "prompt",
              "displayName": "prompt",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string",
              "removed": false
            },
            {
              "id": "mensaje",
              "displayName": "mensaje",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string",
              "removed": false
            },
            {
              "id": "contexto",
              "displayName": "contexto",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string",
              "removed": false
            },
            {
              "id": "jid",
              "displayName": "jid",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string",
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": true
        },
        "options": {}
      },
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1.3,
      "position": [
        2112,
        704
      ],
      "id": "a90d834a-a7e9-4865-bf49-c2d7d8d52691",
      "name": "extraer nombre del mensaje"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "2a6b79d7-6ff3-403a-a944-e3c0021ff63d",
              "leftValue": "={{ !!$json.name }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        992,
        416
      ],
      "id": "8ef14301-fb39-48a5-9c82-d05de12e78a5",
      "name": "\u00bfTiene nombre?"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT email\nFROM users\nWHERE jid = '{{ $('mensaje de whatsapp').item.json.body.data.key.remoteJid }}';",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        1216,
        320
      ],
      "id": "dcc25790-ff45-48b0-8593-6f44749fc27d",
      "name": "comprobar si tiene un correo asignado",
      "alwaysOutputData": true,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "2a6b79d7-6ff3-403a-a944-e3c0021ff63d",
              "leftValue": "={{ !!$json.email }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1440,
        320
      ],
      "id": "ab3eb681-f8d9-4238-af50-55b88b28d2d6",
      "name": "\u00bfTiene email?"
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "iris",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [
        -352,
        416
      ],
      "id": "bb3427cc-8891-477b-9edf-872bdbaa1dd5",
      "name": "mensaje de whatsapp"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT is_verified\nFROM users\nWHERE jid = '{{ $('mensaje de whatsapp').item.json.body.data.key.remoteJid }}';",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        1664,
        224
      ],
      "id": "3f7a4c77-d67c-43c1-abea-4d01605d8ce0",
      "name": "comprobar si el correo esta verificado",
      "alwaysOutputData": true,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "2a6b79d7-6ff3-403a-a944-e3c0021ff63d",
              "leftValue": "={{ !!$json.is_verified }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1888,
        224
      ],
      "id": "fcbf7c30-966e-4245-b08d-07d5e9289e4f",
      "name": "\u00bfEst\u00e1 verificado?"
    },
    {
      "parameters": {
        "workflowId": {
          "__rl": true,
          "value": "BXBLMLRPBiqSvBW6",
          "mode": "list",
          "cachedResultUrl": "/workflow/BXBLMLRPBiqSvBW6",
          "cachedResultName": "[Registro] Preguntar a la IA"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {
            "prompt": "El usuario te ha enviado un c\u00f3digo de verificaci\u00f3n que se le ha enviado al correo, t\u00fa debes acceder a sus datos de usuario de la base de datos y comprobar que efectivamente el codigo es igual y correcto, si no es as\u00ed responde consecuentemente y di que es incorrecto.",
            "mensaje": "={{ $json.verification_code }}",
            "jid": "={{ $('mensaje de whatsapp').item.json.body.data.key.remoteJid }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "prompt",
              "displayName": "prompt",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string",
              "removed": false
            },
            {
              "id": "mensaje",
              "displayName": "mensaje",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string",
              "removed": false
            },
            {
              "id": "contexto",
              "displayName": "contexto",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string",
              "removed": false
            },
            {
              "id": "jid",
              "displayName": "jid",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string",
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": true
        },
        "options": {}
      },
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1.3,
      "position": [
        2320,
        320
      ],
      "id": "bbed4707-fc77-4e21-8d59-dee92b2889c2",
      "name": "comprobar si el codigo es correcto"
    },
    {
      "parameters": {
        "workflowId": {
          "__rl": true,
          "value": "gNadtkM0HahY774W",
          "mode": "list",
          "cachedResultUrl": "/workflow/gNadtkM0HahY774W",
          "cachedResultName": "flujo principal de iris"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {
            "mensaje": "={{ $('mensaje de whatsapp').item.json.body.data.message.conversation }}",
            "jid": "={{ $('mensaje de whatsapp').item.json.body.data.key.remoteJid }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "mensaje",
              "displayName": "mensaje",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string",
              "removed": false
            },
            {
              "id": "jid",
              "displayName": "jid",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string",
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": true
        },
        "options": {}
      },
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1.3,
      "position": [
        2496,
        128
      ],
      "id": "d6b18a34-30d4-4f17-a3f3-56b942b39537",
      "name": "flujo principal"
    },
    {
      "parameters": {
        "workflowId": {
          "__rl": true,
          "value": "GqjOsNpwcrrWKumD",
          "mode": "list",
          "cachedResultUrl": "/workflow/GqjOsNpwcrrWKumD",
          "cachedResultName": "enviar mensaje"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {
            "jid": "={{ $('mensaje de whatsapp').item.json.body.data.key.remoteJid }}",
            "mensaje": "={{ $json.output }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "jid",
              "displayName": "jid",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string",
              "removed": false
            },
            {
              "id": "mensaje",
              "displayName": "mensaje",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string",
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": true
        },
        "options": {}
      },
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1.3,
      "position": [
        2544,
        512
      ],
      "id": "3401cc51-ec03-48aa-bc92-df7f569116a8",
      "name": "Call 'enviar mensaje'"
    },
    {
      "parameters": {
        "workflowId": {
          "__rl": true,
          "value": "BXBLMLRPBiqSvBW6",
          "mode": "list",
          "cachedResultUrl": "/workflow/BXBLMLRPBiqSvBW6",
          "cachedResultName": "[Registro] Preguntar a la IA"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {
            "prompt": "Pregunta al usuario cu\u00e1l es su correo de la universidad. Cuando te responda extraes el correo y te aseguras de preguntarle \"entonces, para asegurarme, \u00bfes `example@alumnos.uneatlantico.es` tu correo? \"\n\nNO aceptes correos que no terminan en @alumnos.uneatlantico.es, ya que ser\u00e1n rechazados m\u00e1s adelante en el workflow.",
            "mensaje": "={{ $json.mensaje }}",
            "jid": "={{ $json.jid }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "prompt",
              "displayName": "prompt",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string",
              "removed": false
            },
            {
              "id": "mensaje",
              "displayName": "mensaje",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string",
              "removed": false
            },
            {
              "id": "contexto",
              "displayName": "contexto",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string",
              "removed": true
            },
            {
              "id": "jid",
              "displayName": "jid",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string",
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": true
        },
        "options": {}
      },
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1.3,
      "position": [
        2112,
        512
      ],
      "id": "6a3516d0-1210-4881-a8c3-1ff0211d7669",
      "name": "registrar email"
    }
  ],
  "connections": {
    "\u00bfEsta registrado?": {
      "main": [
        [
          {
            "node": "comprobar si tiene un nombre asignado",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "a\u00f1adir jid al sistema",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "comprobar si un jid esta registrado": {
      "main": [
        [
          {
            "node": "\u00bfEsta registrado?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "comprobar si tiene un nombre asignado": {
      "main": [
        [
          {
            "node": "\u00bfTiene nombre?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "a\u00f1adir jid al sistema": {
      "main": [
        [
          {
            "node": "comprobar si tiene un nombre asignado",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u00bfTiene nombre?": {
      "main": [
        [
          {
            "node": "comprobar si tiene un correo asignado",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "extraer nombre del mensaje",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "comprobar si tiene un correo asignado": {
      "main": [
        [
          {
            "node": "\u00bfTiene email?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u00bfTiene email?": {
      "main": [
        [
          {
            "node": "comprobar si el correo esta verificado",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "registrar email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "mensaje de whatsapp": {
      "main": [
        [
          {
            "node": "comprobar si un jid esta registrado",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "comprobar si el correo esta verificado": {
      "main": [
        [
          {
            "node": "\u00bfEst\u00e1 verificado?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u00bfEst\u00e1 verificado?": {
      "main": [
        [
          {
            "node": "flujo principal",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "comprobar si el codigo es correcto",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "extraer nombre del mensaje": {
      "main": [
        [
          {
            "node": "Call 'enviar mensaje'",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "comprobar si el codigo es correcto": {
      "main": [
        [
          {
            "node": "Call 'enviar mensaje'",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "registrar email": {
      "main": [
        [
          {
            "node": "Call 'enviar mensaje'",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "5abd21bb-c5ac-4860-a3b9-ece2dee849c6",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "kZcoVljZ3oPFcHJ6",
  "tags": []
}