{
  "name": "AI WhatsApp Assistant for Humanized Replies",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "7bbf1baf-4b61-4dd8-bfe1-be0ccc1bf64f",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        -80,
        0
      ],
      "id": "112cfd90-a043-4e81-92b4-6a0522331443",
      "name": "Webhook"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "09f48a87-a7cf-42de-9294-4f9e68a2f27c",
              "name": "content_type",
              "value": "={{ $json.body.content_type }}",
              "type": "string"
            },
            {
              "id": "3dbdb649-b864-45af-a31b-5528d6c33cce",
              "name": "content_text",
              "value": "={{ $json.body.content }}",
              "type": "string"
            },
            {
              "id": "30a69cf4-fac8-40ab-b35a-c66b7a68f3d8",
              "name": "status",
              "value": "={{ $json.body.conversation.messages[0].status }}",
              "type": "string"
            },
            {
              "id": "ab626022-db93-4691-9e72-a219fedff2b6",
              "name": "sender_type",
              "value": "={{ $json.body.conversation.messages[0].sender_type }}",
              "type": "string"
            },
            {
              "id": "6bdea5ea-40c0-4c71-9115-cb2ce87d5b21",
              "name": "cliente_name",
              "value": "={{ $json.body.conversation.meta.sender.name }}",
              "type": "string"
            },
            {
              "id": "64a0946f-b3ab-402c-b1f6-5eda3ac4a21e",
              "name": "identifier",
              "value": "={{ $json.body.conversation.meta.sender.identifier }}",
              "type": "string"
            },
            {
              "id": "d07ca2db-7a83-4df9-8134-afec06cca28a",
              "name": "message_type",
              "value": "={{ $json.body.message_type }}",
              "type": "string"
            },
            {
              "id": "5860f566-6890-4e52-a76d-aff7572dd8cb",
              "name": "source",
              "value": "={{ $json.body.source_id }}",
              "type": "string"
            },
            {
              "id": "423d5c38-2c96-413c-9736-340246fbb25f",
              "name": "",
              "value": "",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        320,
        0
      ],
      "id": "3ef508e7-90c1-4217-9c6f-2f4cb8d6a48f",
      "name": "setData"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.content_text }}",
        "options": {
          "systemMessage": "Voc\u00ea \u00e9 uma assistente pessoal, responda as d\u00favidas de forma clara, simples e objetiva."
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.9,
      "position": [
        1140,
        0
      ],
      "id": "7c12c870-dcd6-4064-b663-eb9b89b4ebc3",
      "name": "AI Agent"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {
          "maxTokens": 300
        }
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        840,
        260
      ],
      "id": "07a44aa5-2158-4fad-a530-13ac96400ddb",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $json.identifier }}",
        "contextWindowLength": 50
      },
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [
        1140,
        300
      ],
      "id": "21844bb8-b258-4805-91df-a251f25f2dfa",
      "name": "Simple Memory"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://evolution.ggnocode.com/message/sendText/eduarda-teste-1",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "number",
              "value": "={{ $item(\"0\").$node[\"setData\"].json[\"identifier\"] }}"
            },
            {
              "name": "text",
              "value": "={{ $json.output }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1340,
        -500
      ],
      "id": "64d6aade-a200-466c-9ea4-ab943f3b6bdc",
      "name": "HTTP Request19",
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Whatsapp message to be splitted and formated: {{ $json.output }}",
        "hasOutputParser": true,
        "messages": {
          "messageValues": [
            {
              "message": "=Sua tarefa \u00e9 dividir a mensagem do usu\u00e1rio em partes compreens\u00edveis, naturais e humanizadas.\n\nReescreva ou quebre o texto em blocos pequenos e coesos, como se estivesse escrevendo uma conversa entre humanos.\n\nMantenha o tom informal, claro e emp\u00e1tico.\n\nEvite quebras mec\u00e2nicas ou rob\u00f3ticas.\n\nUse pontua\u00e7\u00e3o adequada para representar pausas naturais (v\u00edrgulas, retic\u00eancias, travess\u00f5es...).\n\nQuando necess\u00e1rio, adicione pequenas palavras de liga\u00e7\u00e3o que tornem o texto mais fluido, como \u201cent\u00e3o\u201d, \u201cbom\u201d, \u201colha\u201d, \u201cs\u00f3 pra te explicar\u201d, etc.\n\nNunca altere o sentido original da mensagem.\n\nPreserve g\u00edrias, emojis ou linguagem informal, se houver.\n\nExemplo de sa\u00edda esperada:\nMensagem original:\nOi, tudo bem? Preciso de ajuda com uma automa\u00e7\u00e3o no n8n. Estou tentando pegar dados de uma API mas est\u00e1 dando erro.\n\nMensagem transformada:\nOi, tudo certo?\n\nEnt\u00e3o, t\u00f4 precisando de uma m\u00e3o aqui com uma automa\u00e7\u00e3o no n8n.\n\nT\u00f4 tentando puxar dados de uma API... mas t\u00e1 rolando um erro.\n\nSempre se pergunte: \"Se eu estivesse explicando isso pra algu\u00e9m no WhatsApp, como eu falaria?\"\n\n### Jamais separe uma mensagem vazia.\n\n### Certifique-se de que a resposta siga exatamente essa estrutura abaixo, deixando somente entre '*' para negrito e nunca fugindo das demais regras de markdown do whatsapp:\n\t\t\t- *negrito* (substitua '**' por '*')\n\t\t\t- _it\u00e1lico_.(extremamente raro)\n            - `link` (usar sempre em todos os links)\n\nTudo o que for link, pode colocar entre \"`\", ou seja, na seguinte formata\u00e7\u00e3o: `www.link.com.br`\n"
            }
          ]
        }
      },
      "id": "b5a162e2-9011-4490-81d9-f6cfa7a0eb48",
      "name": "Parser  Chain",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.4,
      "position": [
        1620,
        40
      ]
    },
    {
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"messages\": {\n      \"type\": \"array\",\n      \"items\": {\n        \"type\": \"string\"\n      }\n    }\n  },\n  \"required\": [\"messages\"]\n}"
      },
      "id": "97bda638-5c3f-4ca0-8712-36a7020985dd",
      "name": "OutputParser1",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.2,
      "position": [
        1840,
        400
      ]
    },
    {
      "parameters": {},
      "id": "e4b96224-0506-4fad-9674-ed633e4ada7e",
      "name": "no.op",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        2960,
        460
      ]
    },
    {
      "parameters": {
        "options": {}
      },
      "id": "2532ce66-8177-48c5-8e44-af9201eb23a0",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        2240,
        40
      ]
    },
    {
      "parameters": {
        "amount": 1.2
      },
      "id": "04449e4f-5f72-42bd-9023-b3eefe588e24",
      "name": "1,2s1",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        2780,
        320
      ]
    },
    {
      "parameters": {
        "fieldToSplitOut": "output.messages",
        "options": {
          "destinationFieldName": "output"
        }
      },
      "id": "134d4a90-35c1-4a2f-9fa3-ae33ac53c5b6",
      "name": "Segmentos1",
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        2000,
        40
      ]
    },
    {
      "parameters": {
        "model": "gpt-4o",
        "options": {}
      },
      "id": "e0bbe618-c82c-43b3-921a-6d3f39eea97e",
      "name": "OpenAI",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1,
      "position": [
        1600,
        420
      ],
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "content": "## RESSPOSTA CLIENTE",
        "height": 1000,
        "width": 1640,
        "color": 6
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1500,
        -260
      ],
      "typeVersion": 1,
      "id": "c208f39f-cebf-49d0-9ce9-2d5db560780d",
      "name": "Sticky Note6"
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.message_type }}",
                    "rightValue": "outgoing",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "id": "5f4fc838-5202-486e-90c7-9cb2d10208a2"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Mensagem Enviada"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "eb450fc1-b44d-48f4-bad7-7762e5747621",
                    "leftValue": "={{ $json.message_type }}",
                    "rightValue": "incoming",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Mensagem Recebida"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        560,
        0
      ],
      "id": "7c3088b6-15d0-47c9-9395-cbb61fc96cc2",
      "name": "Switch"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        780,
        -220
      ],
      "id": "384525fb-fdbd-4e8b-bcff-611b192d164d",
      "name": "No Operation, do nothing"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://evolution.ggnocode.com/message/sendText/eduarda-teste-1",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "number",
              "value": "={{ $item(\"0\").$node[\"setData\"].json[\"identifier\"] }}"
            },
            {
              "name": "text",
              "value": "={{ $json.output }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        2600,
        240
      ],
      "id": "8e424b53-bc1b-41c8-9962-56ada20a48c1",
      "name": "HTTP Request",
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "onError": "continueRegularOutput"
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "setData",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "setData": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "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": "Parser  Chain",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parser  Chain": {
      "main": [
        [
          {
            "node": "Segmentos1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OutputParser1": {
      "ai_outputParser": [
        [
          {
            "node": "Parser  Chain",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "no.op": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "1,2s1": {
      "main": [
        [
          {
            "node": "no.op",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Segmentos1": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI": {
      "ai_languageModel": [
        [
          {
            "node": "Parser  Chain",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "1,2s1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "39e1d324-8c4d-47f7-8c42-ee5bd105755d",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "rv4OUQnms2JYf3cb",
  "tags": []
}