Disparador Inteligente com Google Sheets
Shared 12/11/2025
2 views
Visual Workflow
JSON Code
{
"meta": {
"instanceId": "6052a1b29f061469e8139dae44556603650099c3365d7598798f132ae827fa1c"
},
"nodes": [
{
"id": "b0dfa033-a4af-46ea-ab93-d3897be0abc1",
"name": "Loop Over Items1",
"type": "n8n-nodes-base.splitInBatches",
"position": [
-368,
144
],
"parameters": {
"options": {}
},
"typeVersion": 3
},
{
"id": "4ed4da4e-2d62-47c5-834c-52bcf26af130",
"name": "Pegar lista de leads",
"type": "n8n-nodes-base.googleSheets",
"position": [
-576,
144
],
"parameters": {
"options": {},
"sheetName": {
"__rl": true,
"mode": "list",
"value": 1870596170,
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1es4TCZ7gYTZh2YX7pifixqyjTGxiXOug4WiRa-P72V4/edit#gid=1870596170",
"cachedResultName": "NUMEROS"
},
"documentId": {
"__rl": true,
"mode": "list",
"value": "1es4TCZ7gYTZh2YX7pifixqyjTGxiXOug4WiRa-P72V4",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1es4TCZ7gYTZh2YX7pifixqyjTGxiXOug4WiRa-P72V4/edit?usp=drivesdk",
"cachedResultName": "DISPARADOR INTELIGENTE"
}
},
"typeVersion": 4.3
},
{
"id": "ca509331-c3f1-4c39-8f09-5860ba0c9aca",
"name": "Pegar mensagem",
"type": "n8n-nodes-base.googleSheets",
"position": [
-960,
144
],
"parameters": {
"options": {},
"sheetName": {
"__rl": true,
"mode": "list",
"value": "gid=0",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1es4TCZ7gYTZh2YX7pifixqyjTGxiXOug4WiRa-P72V4/edit#gid=0",
"cachedResultName": "MENSAGEIRO"
},
"documentId": {
"__rl": true,
"mode": "list",
"value": "1es4TCZ7gYTZh2YX7pifixqyjTGxiXOug4WiRa-P72V4",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1es4TCZ7gYTZh2YX7pifixqyjTGxiXOug4WiRa-P72V4/edit?usp=drivesdk",
"cachedResultName": "DISPARADOR INTELIGENTE"
}
},
"typeVersion": 4.3
},
{
"id": "224a02a5-b09a-4846-bf5a-ae00b38635e3",
"name": "Delay",
"type": "n8n-nodes-base.wait",
"position": [
-1136,
432
],
"webhookId": "b10f2338-86d1-4a16-b45c-14513cad6551",
"parameters": {
"amount": "={{ $item(\"0\").$node[\"Gerar número\"].json[\"randomNumber\"] }}"
},
"typeVersion": 1.1
},
{
"id": "2db8a0c0-a4fa-4191-9f0e-9c0cd13f95d8",
"name": "Verificar Status",
"type": "n8n-nodes-base.if",
"position": [
0,
192
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 1,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "0c5f5f0f-7d04-439a-8b31-6e7ff7fd7345",
"operator": {
"type": "boolean",
"operation": "true",
"singleValue": true
},
"leftValue": "={{ $json.active }}",
"rightValue": "\"true\""
}
]
}
},
"typeVersion": 2
},
{
"id": "6471799c-2b0b-44e3-90ea-464e67b0ea41",
"name": "Enviar Mensagem 1",
"type": "n8n-nodes-base.httpRequest",
"onError": "continueRegularOutput",
"position": [
-80,
384
],
"parameters": {
"url": "={{ $('Dados').item.json.api_url }}/message/sendText/{{ $('Dados').item.json.api_instance1 }}",
"method": "POST",
"options": {
"allowUnauthorizedCerts": true
},
"jsonBody": "={\n \"number\": \"{{ $('Pegar lista de leads').item.json.tel }}\",\n \"text\": \"{{ $('OpenAI').item.json.message.content }}\"\n}",
"sendBody": true,
"sendHeaders": true,
"specifyBody": "json",
"headerParameters": {
"parameters": [
{
"name": "apikey",
"value": "={{ $('Dados').item.json.api_key1 }}"
},
{
"name": "Content-Type",
"value": "application/json"
}
]
}
},
"typeVersion": 4.1
},
{
"id": "56c1bf5e-a686-47fd-b3f5-7c5453b3b1c8",
"name": "Dados",
"type": "n8n-nodes-base.set",
"position": [
-1168,
144
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "2f32f35f-e985-47e0-be28-f6959d9844a9",
"name": "api_url",
"type": "string",
"value": "https://"
},
{
"id": "4291ce09-2085-4137-b13e-37949e349c36",
"name": "api_instance1",
"type": "string",
"value": ""
},
{
"id": "4331c9c5-4713-4c11-8c08-c703e2c63332",
"name": "api_key1",
"type": "string",
"value": ""
},
{
"id": "1e996931-5182-43c4-9c81-9c4804a3b03e",
"name": "api_instance2",
"type": "string",
"value": ""
},
{
"id": "a0ab772d-5123-4536-9caa-8c347d43af1c",
"name": "api_key2",
"type": "string",
"value": ""
}
]
}
},
"typeVersion": 3.3
},
{
"id": "997907a1-31c1-46bf-b96f-30df702ed7a4",
"name": "Enviar Mensagem 2",
"type": "n8n-nodes-base.httpRequest",
"onError": "continueRegularOutput",
"position": [
-80,
528
],
"parameters": {
"url": "={{ $('Dados').item.json.api_url }}/message/sendText/{{ $('Dados').item.json.api_instance2 }}",
"method": "POST",
"options": {
"allowUnauthorizedCerts": true
},
"jsonBody": "={\n \"number\": \"{{ $('Pegar lista de leads').item.json.tel }}\",\n \"text\": \"{{ $('OpenAI').item.json.message.content }}\"\n}",
"sendBody": true,
"sendHeaders": true,
"specifyBody": "json",
"headerParameters": {
"parameters": [
{
"name": "apikey",
"value": "={{ $('Dados').item.json.api_key2 }}"
},
{
"name": "Content-Type",
"value": "application/json"
}
]
}
},
"typeVersion": 4.1
},
{
"id": "90de324a-dd2d-48db-86d1-b91f625ae1a1",
"name": "Atualizar Status",
"type": "n8n-nodes-base.googleSheets",
"position": [
-768,
144
],
"parameters": {
"columns": {
"value": {
"STATUS": "Disparando",
"row_number": "={{ $('Pegar mensagem').item.json.row_number }}"
},
"schema": [
{
"id": "MENSAGEM",
"type": "string",
"display": true,
"removed": true,
"required": false,
"displayName": "MENSAGEM",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "STATUS",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "STATUS",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "row_number",
"type": "string",
"display": true,
"removed": false,
"readOnly": true,
"required": false,
"displayName": "row_number",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "defineBelow",
"matchingColumns": [
"row_number"
]
},
"options": {},
"operation": "update",
"sheetName": {
"__rl": true,
"mode": "list",
"value": "gid=0",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1es4TCZ7gYTZh2YX7pifixqyjTGxiXOug4WiRa-P72V4/edit#gid=0",
"cachedResultName": "MENSAGEIRO"
},
"documentId": {
"__rl": true,
"mode": "list",
"value": "1es4TCZ7gYTZh2YX7pifixqyjTGxiXOug4WiRa-P72V4",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1es4TCZ7gYTZh2YX7pifixqyjTGxiXOug4WiRa-P72V4/edit?usp=drivesdk",
"cachedResultName": "DISPARADOR INTELIGENTE"
}
},
"typeVersion": 4.3,
"alwaysOutputData": false
},
{
"id": "802e8704-b865-4c6c-ba72-d0108623e3a1",
"name": "Atualizar Status1",
"type": "n8n-nodes-base.googleSheets",
"position": [
0,
0
],
"parameters": {
"columns": {
"value": {
"STATUS": "Finalizado",
"row_number": "={{ $('Pegar mensagem').item.json.row_number }}"
},
"schema": [
{
"id": "MENSAGEM",
"type": "string",
"display": true,
"removed": true,
"required": false,
"displayName": "MENSAGEM",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "STATUS",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "STATUS",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "row_number",
"type": "string",
"display": true,
"removed": false,
"readOnly": true,
"required": false,
"displayName": "row_number",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "defineBelow",
"matchingColumns": [
"row_number"
]
},
"options": {},
"operation": "update",
"sheetName": {
"__rl": true,
"mode": "list",
"value": "gid=0",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1es4TCZ7gYTZh2YX7pifixqyjTGxiXOug4WiRa-P72V4/edit#gid=0",
"cachedResultName": "MENSAGEIRO"
},
"documentId": {
"__rl": true,
"mode": "list",
"value": "1es4TCZ7gYTZh2YX7pifixqyjTGxiXOug4WiRa-P72V4",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1es4TCZ7gYTZh2YX7pifixqyjTGxiXOug4WiRa-P72V4/edit?usp=drivesdk",
"cachedResultName": "DISPARADOR INTELIGENTE"
}
},
"typeVersion": 4.3,
"alwaysOutputData": false
},
{
"id": "f80235a6-fdb5-4471-86c4-c994de83212d",
"name": "Atualizar Active",
"type": "n8n-nodes-base.googleSheets",
"position": [
160,
528
],
"parameters": {
"columns": {
"value": {
"tel": "={{ $('Pegar lista de leads').item.json.tel }}",
"active": "true",
"row_number": "={{ $('Pegar lista de leads').item.json.row_number }}"
},
"schema": [
{
"id": "tel",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "tel",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "name",
"type": "string",
"display": true,
"removed": true,
"required": false,
"displayName": "name",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "active",
"type": "string",
"display": true,
"required": false,
"displayName": "active",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "row_number",
"type": "string",
"display": true,
"removed": false,
"readOnly": true,
"required": false,
"displayName": "row_number",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "defineBelow",
"matchingColumns": [
"row_number"
]
},
"options": {},
"operation": "update",
"sheetName": {
"__rl": true,
"mode": "list",
"value": 1870596170,
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1es4TCZ7gYTZh2YX7pifixqyjTGxiXOug4WiRa-P72V4/edit#gid=1870596170",
"cachedResultName": "NUMEROS"
},
"documentId": {
"__rl": true,
"mode": "list",
"value": "1es4TCZ7gYTZh2YX7pifixqyjTGxiXOug4WiRa-P72V4",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1es4TCZ7gYTZh2YX7pifixqyjTGxiXOug4WiRa-P72V4/edit?usp=drivesdk",
"cachedResultName": "DISPARADOR INTELIGENTE"
}
},
"typeVersion": 4.3,
"alwaysOutputData": false
},
{
"id": "3a623d79-04a3-4bf6-a075-a8a5cabb9470",
"name": "Gerar número",
"type": "n8n-nodes-base.code",
"position": [
-1344,
432
],
"parameters": {
"jsCode": "// Executa o código de geração do número aleatório\nconst min = 5;\nconst max = 10;\nconst randomNumber = Math.floor(Math.random() * (max - min + 1)) + min;\n\n// Retorna o valor em um array de objetos com a propriedade \"json\"\nreturn [\n {\n json: {\n randomNumber: randomNumber,\n },\n },\n];"
},
"typeVersion": 2
},
{
"id": "a779a9aa-dc6f-4233-8a01-064620dc2559",
"name": "Gerar número1",
"type": "n8n-nodes-base.code",
"position": [
-576,
432
],
"parameters": {
"jsCode": "randomNumber = Math.floor(Math.random() * 2) + 1;\n\nreturn [\n {\n json: {\n randomNumber: randomNumber\n }\n }\n]"
},
"typeVersion": 2
},
{
"id": "1eb6eae6-8d72-443b-813a-64125c8b88c4",
"name": "Switch",
"type": "n8n-nodes-base.switch",
"position": [
-368,
432
],
"parameters": {
"rules": {
"values": [
{
"outputKey": "Instancia 1",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"operator": {
"type": "number",
"operation": "equals"
},
"leftValue": "={{ $json.randomNumber }}",
"rightValue": 1
}
]
},
"renameOutput": true
},
{
"outputKey": "Instancia 2",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "f6145ca8-af77-489d-8abe-92f995e4e453",
"operator": {
"type": "number",
"operation": "equals"
},
"leftValue": "={{ $json.randomNumber }}",
"rightValue": 2
}
]
},
"renameOutput": true
}
]
},
"options": {}
},
"typeVersion": 3.2
},
{
"id": "8a66a182-3acf-4be4-9035-b73b5955bbae",
"name": "OpenAI",
"type": "@n8n/n8n-nodes-langchain.openAi",
"position": [
-928,
432
],
"parameters": {
"modelId": {
"__rl": true,
"mode": "list",
"value": "gpt-4o-mini",
"cachedResultName": "GPT-4O-MINI"
},
"options": {},
"messages": {
"values": [
{
"content": "=Crie uma variação do texto: \"{{ $('Pegar mensagem').item.json.MENSAGEM }}\". Sua resposta deve ser apenas o texto editado! Mantenha a informalidade."
}
]
}
},
"typeVersion": 1.6
},
{
"id": "be68ba16-3928-4e80-ad12-081a417f5830",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"position": [
-1360,
144
],
"webhookId": "b3385fc1-0b8c-4df6-be29-b0cfe92e3872",
"parameters": {
"path": "disparador-inteligente",
"options": {}
},
"typeVersion": 2
}
],
"pinData": {},
"connections": {
"Dados": {
"main": [
[
{
"node": "Pegar mensagem",
"type": "main",
"index": 0
}
]
]
},
"Delay": {
"main": [
[
{
"node": "OpenAI",
"type": "main",
"index": 0
}
]
]
},
"OpenAI": {
"main": [
[
{
"node": "Gerar número1",
"type": "main",
"index": 0
}
]
]
},
"Switch": {
"main": [
[
{
"node": "Enviar Mensagem 1",
"type": "main",
"index": 0
}
],
[
{
"node": "Enviar Mensagem 2",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "Dados",
"type": "main",
"index": 0
}
]
]
},
"Gerar número": {
"main": [
[
{
"node": "Delay",
"type": "main",
"index": 0
}
]
]
},
"Gerar número1": {
"main": [
[
{
"node": "Switch",
"type": "main",
"index": 0
}
]
]
},
"Pegar mensagem": {
"main": [
[
{
"node": "Atualizar Status",
"type": "main",
"index": 0
}
]
]
},
"Atualizar Active": {
"main": [
[
{
"node": "Loop Over Items1",
"type": "main",
"index": 0
}
]
]
},
"Atualizar Status": {
"main": [
[
{
"node": "Pegar lista de leads",
"type": "main",
"index": 0
}
]
]
},
"Loop Over Items1": {
"main": [
[
{
"node": "Atualizar Status1",
"type": "main",
"index": 0
}
],
[
{
"node": "Verificar Status",
"type": "main",
"index": 0
}
]
]
},
"Verificar Status": {
"main": [
[
{
"node": "Loop Over Items1",
"type": "main",
"index": 0
}
],
[
{
"node": "Gerar número",
"type": "main",
"index": 0
}
]
]
},
"Enviar Mensagem 1": {
"main": [
[
{
"node": "Atualizar Active",
"type": "main",
"index": 0
}
]
]
},
"Enviar Mensagem 2": {
"main": [
[
{
"node": "Atualizar Active",
"type": "main",
"index": 0
}
]
]
},
"Pegar lista de leads": {
"main": [
[
{
"node": "Loop Over Items1",
"type": "main",
"index": 0
}
]
]
}
}
}