{
  "name": "Discord",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "42e803ae-8aee-4b1c-858a-6c6d3fbb6230",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [
        -464,
        112
      ],
      "id": "52d47c40-63c3-4d17-ab86-d0e19a9ca911",
      "name": "Webhook",
      "webhookId": "42e803ae-8aee-4b1c-858a-6c6d3fbb6230"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $('Webhook').item.json.body.message }}",
"options": {
          "systemMessage": "────────────────────────────────────────────────────────────────\nBASE DE DATOS - IMPORTANTE\n────────────────────────────────────────────────────────────────\n\nUsa la herramienta 'MySQL Tool' para buscar información.\n\nTabla: knowledge_base\nBase de datos: lastwar_mysql\n\nEjemplos de consultas:\n- SELECT * FROM knowledge_base WHERE topic='Heroes' LIMIT 10\n- SELECT * FROM knowledge_base WHERE entity_name LIKE '%Mason%' LIMIT 5\n- SELECT * FROM knowledge_base WHERE topic='General' LIMIT 10\n\n────────────────────────────────────────────────────────────────\nREGLAS\n────────────────────────────────────────────────────────────────\n\n1. NUNCA inventes información - usa solo datos de MySQL\n2. Si no hay resultados, dice \"No encontré información\"\n3. Los héroes reales incluyen: Mason, Murphy, Kimberly, Blade, Shadow Marshall, Striker Carlie, Thunder Tesla, etc.\n\n────────────────────────────────────────────────────────────────\nIDIOMA\n────────────────────────────────────────────────────────────────\n\n- ESCRIBE en el mismo idioma que el usuario\n- Si el usuario escribe en português, responde en português\n- Si el usuario escribe en inglés, responde en inglés"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 2.2,
      "position": [
        176,
        0
      ],
      "id": "52957df8-1036-40f9-84bf-c1411780aa05",
      "name": "AI Agent"
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $('Webhook').item.json.body.user_id }}",
        "contextWindowLength": 10
      },
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [
        176,
        208
      ],
      "id": "eb69403c-6ccd-4ea0-8840-b58dbb06c156",
      "name": "Simple Memory"
    },
    {
      "parameters": {
        "jsCode": "const maxLen = 4000;\nlet inputText = $input.first().json.output || $input.first().json.text || '';\n\nif (!inputText || inputText.length <= maxLen) {\n  return [{ json: { text_chunk: inputText } }];\n}\n\nconst chunks = [];\nlet currentPos = 0;\n\nwhile (currentPos < inputText.length) {\n  let chunk = inputText.substring(currentPos, currentPos + maxLen);\n  let lastNewline = chunk.lastIndexOf('\\n');\n\n  if (lastNewline !== -1 && currentPos + maxLen < inputText.length) {\n    chunk = inputText.substring(currentPos, currentPos + lastNewline + 1);\n    currentPos += lastNewline + 1;\n  } else {\n    currentPos += maxLen;\n  }\n  chunks.push({ json: { text_chunk: chunk } });\n}\n\nreturn chunks;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        496,
        0
      ],
      "id": "54cb88eb-9980-4966-965c-98f6f32dbc7d",
      "name": "Dividir"
    },
    {
      "parameters": {
        "description": "Eres un asistente interno especializado en Last War Survival Game."
      },
      "type": "@n8n/n8n-nodes-langchain.toolThink",
      "typeVersion": 1.1,
      "position": [
        288,
        208
      ],
      "id": "7632a9ee-8f28-4089-9dfc-aad2c36e738b",
      "name": "Think"
    },
    {
      "parameters": {
        "mode": "chooseBranch",
        "useDataOfInput": 2
      },
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [
        0,
        0
      ],
      "id": "0f2fa41b-a2b1-435c-a11b-7dd085914225",
      "name": "Merge"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": []
        },
        "includeOtherFields": true,
        "options": {
          "ignoreConversionErrors": true
        }
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -208,
        16
      ],
      "id": "817d5af2-1a3f-469a-94c3-d387f073c90d",
      "name": "Edit Fields"
    },
    {
      "parameters": {
        "resource": "message",
        "guildId": {
          "__rl": true,
          "value": "1385792757980987523",
          "mode": "list",
          "cachedResultName": "El servidor de Pruebas web",
          "cachedResultUrl": "https://discord.com/channels/1385792757980987523"
        },
        "channelId": {
          "__rl": true,
          "value": "1471360653896847402",
          "mode": "list",
          "cachedResultName": "general",
          "cachedResultUrl": "https://discord.com/channels/1385792757980987523/1471360653896847402"
        },
        "content": "={{ $json.body.message }}",
        "options": {}
      },
      "type": "n8n-nodes-base.discord",
      "typeVersion": 2,
      "position": [
        -240,
        224
      ],
      "id": "98ef93b5-bc6b-4a7a-99a2-801e932f1047",
      "name": "Send a message",
      "webhookId": "0bbbede1-c843-4188-8e3e-00effe69ff6e",
      "credentials": {
        "discordBotApi": {
          "id": "5CsYocisvR0L2b4A",
          "name": "Discord Bot account"
        }
      }
    },
    {
      "parameters": {
        "resource": "message",
        "guildId": {
          "__rl": true,
          "value": "1385792757980987523",
          "mode": "list",
          "cachedResultName": "El servidor de Pruebas web",
          "cachedResultUrl": "https://discord.com/channels/1385792757980987523"
        },
        "channelId": {
          "__rl": true,
          "value": "1471360653896847402",
          "mode": "list",
          "cachedResultName": "general",
          "cachedResultUrl": "https://discord.com/channels/1385792757980987523/1471360653896847402"
        },
        "content": "={{ $json.text_chunk }}",
        "options": {}
      },
      "type": "n8n-nodes-base.discord",
      "typeVersion": 2,
      "position": [
        672,
        0
      ],
      "id": "ca5b0946-6083-4bae-ac8e-7c4509049363",
      "name": "Send a message1",
      "webhookId": "b517e733-400b-40ce-ad0d-c7fbc36f3b5c",
      "credentials": {
        "discordBotApi": {
          "id": "5CsYocisvR0L2b4A",
          "name": "Discord Bot account"
        }
      }
    },
    {
      "parameters": {
        "operation": "select",
        "table": {
          "__rl": true,
          "value": "knowledge_base",
          "mode": "name"
        },
        "options": {
          "limit": 10
        }
      },
      "type": "n8n-nodes-base.mySqlTool",
      "typeVersion": 2.5,
      "position": [
        384,
        256
      ],
      "id": "8ce4bcc7-f4e3-43b7-9b15-fc849eb99b5c",
      "name": "MySQL Tool",
      "credentials": {
        "mySql": {
          "id": "GxTgZPkOMennctva",
          "name": "MySQL account"
        }
      }
    },
    {
      "parameters": {
        "model": "llama-3.3-70b-versatile",
        "options": {
          "temperature": 0.1
        }
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatGroq",
      "typeVersion": 1,
      "position": [
        16,
        224
      ],
      "id": "0aca1a17-b9a8-40bc-a087-77731df514dc",
      "name": "Groq Chat Model",
      "credentials": {
        "groqApi": {
          "id": "MMphZipiXwg84ObQ",
          "name": "Groq account"
        }
      }
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "typeVersion": 1,
      "position": [
        144,
        384
      ],
      "id": "f1f54ecd-6938-4218-a912-d51451c2f2d5",
      "name": "Google Gemini Chat Model",
      "credentials": {
        "googlePalmApi": {
          "id": "qsNvxBK1JwvqckgL",
          "name": "Google Gemini(PaLM) Api account"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          },
          {
            "node": "Send a message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Dividir",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Dividir": {
      "main": [
        [
          {
            "node": "Send a message1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Think": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
"Edit Fields": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "MySQL Tool": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Groq Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        []
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": ""
  },
  "id": "",
  "tags": []
}
