{
  "name": "responde mensajes, comentarios y likes de facebook e instagram",
  "nodes": [
    {
      "parameters": {
        "promptType": "define",
        "text": "saluda amablemente",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3,
      "position": [
        -224,
        224
      ],
      "id": "28f1fcd2-c958-49e5-bdaf-6283538db40a",
      "name": "AI Agent"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        -304,
        464
      ],
      "id": "7d746728-51cd-4a44-992b-4adf56a220ea",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "id": "iSBDcbhdsYlhBBbV",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $json.body.entry[0].messaging[0].recipient.id }}"
      },
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [
        -32,
        464
      ],
      "id": "025d0daf-0d7f-46ef-8f82-f555e7ab37cd",
      "name": "Simple Memory",
      "disabled": true
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "31eb1d4e-acf8-415b-b5c0-501424e310c3",
              "leftValue": "={{ $json.body.entry[0].messaging[0].message.is_echo }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        -512,
        208
      ],
      "id": "5baf62e2-bbc5-4a02-9300-da3b2693e99e",
      "name": "If"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        -192,
        -48
      ],
      "id": "4b1443f2-fa52-45fc-b9eb-7af24588d882",
      "name": "No Operation, do nothing"
    },
    {
      "parameters": {
        "url": "=https://ux-flow.com/api/get-token?page_id={{ $('Webhook').item.json.body.entry[0].unified_page_id }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "x-api-key",
              "value": "TU_APIKEY_AQUI"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        128,
        224
      ],
      "id": "7c490cd3-be35-4f7d-b957-d14f871cc5c1",
      "name": "Obtener Token de Acceso"
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "leftValue": "={{ $('Webhook').item.json.body.object }}",
                    "rightValue": "page",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "id": "8cd317d8-17ed-4d9b-ae82-e0e2ae16be93"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "facebook"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "d6d6a7de-ecd8-4fd8-bcd9-db366fd74123",
                    "leftValue": "={{ $('Webhook').item.json.body.object }}",
                    "rightValue": "instagram",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "instagram"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        320,
        224
      ],
      "id": "d362ac97-b81d-4d39-bec9-159e4bab9246",
      "name": "Switch1"
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "leftValue": "={{ $('Webhook').item.json.body.entry[0].changes[0].field }}",
                    "rightValue": "feed",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "id": "9c833da1-6530-4734-93e2-86c0fac9d219"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "comentario"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "da2c7d00-6ac7-4a11-ab16-17dc25ea13f2",
                    "leftValue": "={{ $('Webhook').item.json.body.entry[0].messaging[0].message.text }}",
                    "rightValue": "={{ $('Webhook').item.json.body.entry[0].messaging[0].message.text }}",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "mensaje"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        608,
        48
      ],
      "id": "86b0f26d-a7da-4f5e-991a-f1e313c50d4e",
      "name": "Switch"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://graph.facebook.com/v20.0/me/messages?access_token={{ $('Obtener Token de Acceso').item.json.page_access_token }}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{\n{\n  \"messaging_type\": \"RESPONSE\",\n  \"recipient\": {\n    \"id\": $('Webhook').item.json.body.entry[0].messaging[0].sender.id\n  },\n  \"message\": {\n    \"text\": $('AI Agent').item.json.output\n  }\n}\n}}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        944,
        144
      ],
      "id": "64116316-06ca-4a15-a7e1-6585fa891648",
      "name": "Enviar Mensaje a Facebook3"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://graph.facebook.com/v20.0/{{ $('Webhook').item.json.body.entry[0].changes[0].value.comment_id }}/comments?access_token={{ $('Obtener Token de Acceso').item.json.page_access_token }}\n",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "message",
              "value": "={{ $('AI Agent').item.json.output }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        944,
        -48
      ],
      "id": "fb66a8fc-ccfb-452e-bd86-fddad2328318",
      "name": "Responder Comentario"
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "leftValue": "={{ $('Webhook').item.json.body.entry[0].changes[0].field }}",
                    "rightValue": "comments",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "id": "9c833da1-6530-4734-93e2-86c0fac9d219"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "comentario"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "da2c7d00-6ac7-4a11-ab16-17dc25ea13f2",
                    "leftValue": "={{ $('Webhook').item.json.body.entry[0].messaging[0].message.text }}",
                    "rightValue": "={{ $('Webhook').item.json.body.entry[0].messaging[0].message.text }}",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "mensaje"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        640,
        464
      ],
      "id": "154540b8-ae0b-4ca0-bc57-cd2a9d766971",
      "name": "Switch2"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://graph.facebook.com/v24.0/{{ $('Webhook').item.json.body.entry[0].changes[0].value.id }}/replies?access_token={{ $('Obtener Token de Acceso').item.json.page_access_token }}",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "message",
              "value": "={{ $('AI Agent').item.json.output }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        960,
        384
      ],
      "id": "3ef980fb-ca87-40c3-bb88-2e574de05844",
      "name": "Responder Comentario1"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://graph.facebook.com/v20.0/me/messages?access_token={{ $('Obtener Token de Acceso').item.json.page_access_token }}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{\n{\n  \"messaging_type\": \"RESPONSE\",\n  \"recipient\": {\n    \"id\": $('Webhook').item.json.body.entry[0].messaging[0].sender.id\n  },\n  \"message\": {\n    \"text\": $('AI Agent').item.json.output\n  }\n}\n}}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        960,
        592
      ],
      "id": "42d02f60-8e22-4d0b-bce6-f1e1f8dbff10",
      "name": "Enviar Mensaje a Instagram"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://graph.facebook.com/v24.0/{{ $('Webhook').item.json.body.entry[0].changes[0].value.comment_id }}/likes?access_token={{ $('Obtener Token de Acceso').item.json.page_access_token }}\n\n",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        1200,
        -48
      ],
      "id": "d8c785bc-f27a-43b3-a0a5-b59c43fd4dbc",
      "name": "Like Facebook"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://graph.facebook.com/v24.0/{{ $('Webhook').item.json.body.entry[0].changes[0].value.from.id }}/likes?access_token={{ $('Obtener Token de Acceso').item.json.page_access_token }}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        1216,
        384
      ],
      "id": "798ff84b-520b-49ab-a3d6-8d58a6400e4f",
      "name": "Like Instagram",
      "disabled": true
    },
    {
      "parameters": {
        "content": "\nCOLOCA TU WEBHOOK",
        "height": 80
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -784,
        224
      ],
      "typeVersion": 1,
      "id": "5640b94b-77d9-49da-a7d1-3c192312a901",
      "name": "Sticky Note"
    }
  ],
  "pinData": {},
  "connections": {
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Obtener Token de Acceso",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Obtener Token de Acceso": {
      "main": [
        [
          {
            "node": "Switch1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch1": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Switch2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Responder Comentario",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Enviar Mensaje a Facebook3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch2": {
      "main": [
        [
          {
            "node": "Responder Comentario1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Enviar Mensaje a Instagram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Responder Comentario": {
      "main": [
        [
          {
            "node": "Like Facebook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Responder Comentario1": {
      "main": [
        [
          {
            "node": "Like Instagram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "availableInMCP": false
  },
  "versionId": "54b7120d-aa87-40e7-845e-d89a9645e26a",
  "meta": {
    "instanceId": "db3b5789c10d5042a081c13e67258a0bb6e02117fde0f0039b6b0b1d873d3f99"
  },
  "id": "aBKHYWNBh1lvS8vM",
  "tags": []
}
