{
  "name": "Ofertas Whatsapp",
  "nodes": [
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "f3e2783e-aa27-4e82-8e12-cff93dbe2daa",
              "leftValue": "={{ $json['Id Pasta Imagem'] }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            },
            {
              "id": "4f839458-bc32-4dca-8f25-bf7e0e9e0e66",
              "leftValue": "={{ $json.Estoque }}",
              "rightValue": 0,
              "operator": {
                "type": "number",
                "operation": "gt"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "186b5c6e-72fe-415c-85e6-362c3c0c8fcf",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1720,
        360
      ]
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1T4N9AIasMHvkYdqf2wH4bXGkOVbPCox4b0x9hL3fRqg",
          "mode": "list",
          "cachedResultName": "Grupos N8N",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1T4N9AIasMHvkYdqf2wH4bXGkOVbPCox4b0x9hL3fRqg/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Grupos",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1T4N9AIasMHvkYdqf2wH4bXGkOVbPCox4b0x9hL3fRqg/edit#gid=0"
        },
        "options": {}
      },
      "id": "e52c44df-22b8-43cd-98ff-0fb3acdab0df",
      "name": "Grupos",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        3120,
        340
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "YWenq5p5xoiGfNR3",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {},
      "id": "11c8e85f-67fc-49e9-a4ff-d0d262c6092a",
      "name": "Wait1",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        1920,
        560
      ],
      "webhookId": "5e97b9a5-f4da-4fb3-99bb-b3cb3ac973eb"
    },
    {
      "parameters": {},
      "id": "a169c922-1322-4942-9a33-ed2f2fc7cb41",
      "name": "Wait3",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        3960,
        360
      ],
      "webhookId": "f511c2bb-37f6-4df3-845b-4e9f5b35d519"
    },
    {
      "parameters": {
        "fieldToSplitOut": "Id",
        "options": {}
      },
      "id": "6af126b4-3c05-4dbd-8391-51dcd8049228",
      "name": "Split Out",
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        3340,
        340
      ]
    },
    {
      "parameters": {
        "options": {}
      },
      "id": "a5c2007e-41ba-4efd-b4ce-93e820a2b73b",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        3560,
        340
      ]
    },
    {
      "parameters": {
        "amount": 15
      },
      "id": "a95fd7bc-8f9d-4d86-a69d-796d8f5a9c9f",
      "name": "Wait",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        4360,
        360
      ],
      "webhookId": "78436438-18be-433c-9bad-f8dc0433383c"
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 8
            },
            {
              "triggerAtHour": 17
            }
          ]
        }
      },
      "id": "71cadc58-689c-48e6-8128-80fd186ada0c",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        800,
        360
      ]
    },
    {
      "parameters": {
        "jsCode": "// Função para gerar um número aleatório entre min e max\nfunction getRandomInt(min, max) {\n    min = Math.ceil(min);\n    max = Math.floor(max);\n    return Math.floor(Math.random() * (max - min + 1)) + min; // Inclui ambos os limites\n}\n\n// Gera um número aleatório entre 1 e 100\nvar  randomNumber = getRandomInt(1, $input.first().json.quantProdutos);\n\n// Retorna o número gerado como parte do output\nreturn [{ json: { randomNumber } }];"
      },
      "id": "7767527a-1a1f-4983-a5a9-072a0fb33d22",
      "name": "Code",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1260,
        360
      ]
    },
    {
      "parameters": {
        "modelId": {
          "__rl": true,
          "value": "gpt-4o-mini-2024-07-18",
          "mode": "list",
          "cachedResultName": "GPT-4O-MINI-2024-07-18"
        },
        "messages": {
          "values": [
            {
              "content": "=Faça um anúncio breve para ser postado em grupo de whatsapp. Abaixo está o valor de venda.\nO valor de venda é esse: {{ $('If').item.json['Menor Valor de Venda'] }};\n\nUse como base o texto a seguir: \n####\n{{ $json.mensagem }}\n####\nSua resposta deve ser somente a mensagem que será usada diretamente no whatsapp. Use emojis e criatividade no anúncio.\n"
            }
          ]
        },
        "options": {}
      },
      "id": "00e3d9ab-d353-4ee0-a0a1-89817bd32933",
      "name": "OpenAI",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.6,
      "position": [
        2120,
        340
      ],
      "credentials": {
        "openAiApi": {
          "id": "Oo8FUOo9UEEn46xn",
          "name": "OpenAi Conexão"
        }
      }
    },
    {
      "parameters": {
        "resource": "fileFolder",
        "queryString": "={{ $('BuscaProduto').item.json['Id Pasta Imagem'] }}",
        "limit": 1,
        "filter": {},
        "options": {}
      },
      "id": "4611cc66-1750-4d45-86c6-48963b451089",
      "name": "ProcuraDiretorio",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        2520,
        340
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "8nPjC0ZiSNWXRcgj",
          "name": "Google Drive Conexão"
        }
      }
    },
    {
      "parameters": {
        "operation": "download",
        "fileId": {
          "__rl": true,
          "value": "={{ $json.id }}",
          "mode": "id"
        },
        "options": {}
      },
      "id": "8c25be8d-3dfe-4f9c-bb16-74cd7b616f28",
      "name": "Download",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        2740,
        340
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "8nPjC0ZiSNWXRcgj",
          "name": "Google Drive Conexão"
        }
      }
    },
    {
      "parameters": {
        "operation": "binaryToPropery",
        "options": {}
      },
      "id": "0d41d0f4-4ded-4b81-b6c6-2e1fef03b182",
      "name": "Convert2Base64",
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [
        2940,
        340
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://url/message/sendMedia/instancia",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{ $('Variaveis').item.json.apiKey }}"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "mediatype",
              "value": "image"
            },
            {
              "name": "media",
              "value": "={{ $('Convert2Base64').item.json.data }}"
            },
            {
              "name": "mimetype",
              "value": "image/jpeg"
            },
            {
              "name": "number",
              "value": "={{ $('Grupos').item.json.Id }}"
            }
          ]
        },
        "options": {}
      },
      "id": "a3465875-9bce-412d-adf0-57ed3efddcfe",
      "name": "EnviaImagem",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        3780,
        360
      ],
      "retryOnFail": true,
      "waitBetweenTries": 5000,
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://url/message/sendText/instancia",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{ $('Variaveis').item.json.apiKey }}"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "number",
              "value": "={{ $('Grupos').item.json.Id }}"
            },
            {
              "name": "text",
              "value": "={{ $('OpenAI').item.json.message.content }}"
            }
          ]
        },
        "options": {}
      },
      "id": "07230107-533d-488e-8434-a409cdc2470b",
      "name": "Enviatexto",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        4160,
        360
      ],
      "retryOnFail": true,
      "waitBetweenTries": 5000,
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "262fa94c-0bd4-4941-990e-62a232a3470e",
              "name": "quantProdutos",
              "value": 29,
              "type": "number"
            },
            {
              "id": "5cf393fe-640e-4e89-b376-64914fec326c",
              "name": "apiKey",
              "value": "SUAKEY",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "669884fc-5560-46fd-8912-fa7486cfec82",
      "name": "Variaveis",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1040,
        360
      ]
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1rAJrodx1ApFLKxVygLAO8DUtAMuwhV8PdC3uthr9Sls",
          "mode": "list",
          "cachedResultName": "Estoque N8N",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1rAJrodx1ApFLKxVygLAO8DUtAMuwhV8PdC3uthr9Sls/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Produtos",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1rAJrodx1ApFLKxVygLAO8DUtAMuwhV8PdC3uthr9Sls/edit#gid=0"
        },
        "filtersUI": {
          "values": [
            {
              "lookupColumn": "ID",
              "lookupValue": "={{ $json.randomNumber }}"
            }
          ]
        },
        "options": {
          "returnFirstMatch": true
        }
      },
      "id": "2754157f-3c6f-4ca7-a4a1-7279de25633d",
      "name": "BuscaProduto",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        1500,
        360
      ],
      "retryOnFail": true,
      "waitBetweenTries": 5000,
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "YWenq5p5xoiGfNR3",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "f3770301-eeba-4022-a439-8e0a4f0aa76a",
              "name": "mensagem",
              "value": "=*Pronta Entrega - Somente Venda*\n\n*{{ $('BuscaProduto').item.json['Descrição'].trim() }}* - Por {{ $json['Menor Valor de Venda'] }}\n\nEnvio saindo de *Curitiba* pelo Melhor Envios",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "535db5a0-15c3-45b4-8eb6-10c1df2330f6",
      "name": "ModeloMensagem",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1940,
        340
      ]
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        3780,
        160
      ],
      "id": "b7ddd78b-0de3-4886-9fb7-cd6a532c5462",
      "name": "No Operation, do nothing"
    }
  ],
  "pinData": {},
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "ModeloMensagem",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Grupos": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait1": {
      "main": [
        [
          {
            "node": "Variaveis",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait3": {
      "main": [
        [
          {
            "node": "Enviatexto",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "EnviaImagem",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Variaveis",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code": {
      "main": [
        [
          {
            "node": "BuscaProduto",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI": {
      "main": [
        [
          {
            "node": "ProcuraDiretorio",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ProcuraDiretorio": {
      "main": [
        [
          {
            "node": "Download",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download": {
      "main": [
        [
          {
            "node": "Convert2Base64",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert2Base64": {
      "main": [
        [
          {
            "node": "Grupos",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "EnviaImagem": {
      "main": [
        [
          {
            "node": "Wait3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Enviatexto": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Variaveis": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "BuscaProduto": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ModeloMensagem": {
      "main": [
        [
          {
            "node": "OpenAI",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "1edeae0b-4e9a-40a7-b046-8c11c95cb4b7",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "c4c7e3e169971e7879cf5656c76cde093980d47b7b10790e6489dfee65fcc6d4"
  },
  "id": "JwdupCg4zGSn05vD",
  "tags": []
}