{ "name": "Disparador 1.1", "nodes": [ { "parameters": { "rule": { "interval": [ { "field": "minutes", "minutesInterval": 1 } ] } }, "id": "b7b607b1-be24-42ef-8a18-ed7726559e3c", "name": "Schedule Trigger", "type": "n8n-nodes-base.scheduleTrigger", "typeVersion": 1, "position": [ -2180, 1040 ] }, { "parameters": { "conditions": { "dateTime": [ { "value1": "={{ $json.newDate }}", "operation": "before", "value2": "={{ $now }}" } ] } }, "id": "89e3bd15-bee5-4122-b65e-2f3499010ac5", "name": "Horario", "type": "n8n-nodes-base.if", "typeVersion": 1, "position": [ -1460, 1040 ] }, { "parameters": { "content": "# Buscando Campanhas", "height": 456.3958547081602, "width": 1221.218469617133 }, "id": "bd9e7aee-1ded-4415-8d29-2f2fe33d062f", "name": "Sticky Note5", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ -2231.8637163263666, 840 ] }, { "parameters": { "content": "# Disparador de Campanha para ChatWoot\n## Evolution API\n\n\nv 1.0.0", "height": 163.30528430133387, "width": 847.4993167412657, "color": 4 }, "id": "42ef079d-1bde-404f-8c23-dd44ee9865bb", "name": "Sticky Note10", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ -1940, 520 ] }, { "parameters": { "operation": "subtractFromDate", "magnitude": "={{ $json.scheduled_at }}", "timeUnit": "hours", "duration": 3, "options": { "includeInputFields": true } }, "id": "a73fbe32-0f10-4521-82c4-1c2dd9cd03d0", "name": "Altera fuso horário", "type": "n8n-nodes-base.dateTime", "typeVersion": 2, "position": [ -1640, 1040 ] }, { "parameters": { "keepOnlySet": true, "values": { "string": [ { "name": "chatwoot_url", "value": "https://suaurldochatwootaqui.com.br" }, { "name": "evolution_url", "value": "https://suaurldaevoaqui.com.br" }, { "name": "global_api_key", "value": "global api key da evolution" }, { "name": "instance_name", "value": "=Nome da caixa da Evo api" }, { "name": "chatwoot_token", "value": "=token da tenancia do chatwoot" } ], "number": [ { "name": "chatwoot_account_id", "value": "=id da tenancia" }, { "name": "recebe_relatorio", "value": 5511944446666 } ] }, "options": {} }, "id": "c9705aa1-ad1e-4a4b-8eab-0e054571cc90", "name": "Info_Base", "type": "n8n-nodes-base.set", "typeVersion": 2, "position": [ -2000, 1040 ] }, { "parameters": { "content": "# Busca contatos / Envia campanha\n", "height": 580.894584655091, "width": 5692.989846984048, "color": 3 }, "id": "d6b24fdc-329f-41ca-b8bf-11b7dddca8e7", "name": "Sticky Note", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ -160, 800 ] }, { "parameters": { "operation": "executeQuery", "query": "select * from campaigns c where campaign_type = 1 and status_envia = 0 LIMIT 1", "additionalFields": {} }, "id": "e77dac9b-88ff-42c8-9fd5-e6f34ddb2248", "name": "Buscar campanhas", "type": "n8n-nodes-base.postgres", "typeVersion": 1, "position": [ -1820, 1040 ], "credentials": { "postgres": { "id": "CbrIGpLnj1oilB4h", "name": "Chatwoot" } } }, { "parameters": {}, "id": "ab63de6e-3f45-4097-89d2-761c909374ad", "name": "Repetir ação", "type": "n8n-nodes-base.noOp", "typeVersion": 1, "position": [ 5320, 1160 ] }, { "parameters": { "jsCode": "// Este exemplo gera um tempo de espera aleatório entre 10 e 60 segundos\nconst minWait = 8; // Tempo mínimo de espera em segundos\nconst maxWait = 15; // Tempo máximo de espera em segundos\nconst randomWaitTime = Math.floor(Math.random() * (maxWait - minWait + 1)) + minWait;\n\nreturn [\n {\n json: {\n waitTime: randomWaitTime\n }\n }\n];\n" }, "id": "a0c63923-c2ee-45f5-9181-3bf41bc23ac6", "name": "Time Randon1", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 2460, 1060 ] }, { "parameters": { "amount": "={{ $json.waitTime }}" }, "id": "dd31e31c-cf93-437d-a180-ebe8b30cdfe3", "name": "Tempo de espera1", "type": "n8n-nodes-base.wait", "typeVersion": 1.1, "position": [ 2640, 1060 ], "webhookId": "2358ca39-ffd8-46cb-bad7-ebd4696ecffa" }, { "parameters": { "jsCode": "return items.map(item => {\n if (item.json.phone_number) {\n item.json.phone_number = item.json.phone_number.substring(1);\n }\n return item;\n});" }, "id": "311a0a1a-aff2-4e69-864e-d7561fe54f10", "name": "Limpa numero1", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 2100, 1060 ] }, { "parameters": { "operation": "executeQuery", "query": "SELECT c.*\nFROM contacts c\nJOIN taggings tg ON c.id = tg.taggable_id\nWHERE tg.tag_id = {{ $json.etiqueta }};", "options": {} }, "id": "39a7454f-b68b-4e6e-8921-6efad83f0ce4", "name": "Busca contatos", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, "position": [ -120, 1040 ], "credentials": { "postgres": { "id": "CbrIGpLnj1oilB4h", "name": "Chatwoot" } } }, { "parameters": { "conditions": { "string": [ { "value1": "={{ $('Buscar campanhas').item.json.campaign_type }}", "value2": "={{ 1 }}" } ] } }, "id": "8afdffc1-6a6a-4843-862a-0a9c44c5731a", "name": "IF6", "type": "n8n-nodes-base.if", "typeVersion": 1, "position": [ -840, 1000 ] }, { "parameters": { "fieldToSplitOut": "audience", "include": "allOtherFields", "options": {} }, "id": "f10d57aa-d1f8-4aee-aa7d-2dcb92e734f8", "name": "Item Lists1", "type": "n8n-nodes-base.itemLists", "typeVersion": 3, "position": [ -620, 1000 ] }, { "parameters": { "content": "# Trata mensagem", "height": 456.8892799239013, "width": 728.217926985971, "color": 2 }, "id": "db5186ce-bb30-45ed-9f22-0c6ac3791834", "name": "Sticky Note2", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ -940, 840 ] }, { "parameters": { "assignments": { "assignments": [ { "id": "de68590b-f364-42ca-96cb-f7a09d9c6395", "name": "numberdispara", "value": "={{ $json.phone_number }}", "type": "string" } ] }, "options": {} }, "id": "4a816d73-9fa1-455a-9888-991bd848c218", "name": "numero editado1", "type": "n8n-nodes-base.set", "typeVersion": 3.3, "position": [ 2280, 1060 ] }, { "parameters": { "options": {} }, "id": "c05b13bb-aef3-4d51-818e-98382fe73ed1", "name": "Loop Over Items", "type": "n8n-nodes-base.splitInBatches", "typeVersion": 3, "position": [ 360, 1020 ], "executeOnce": false, "alwaysOutputData": false, "retryOnFail": false, "notesInFlow": false }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict" }, "conditions": [ { "id": "d0205698-dcfd-4d3c-b6e3-dfd7209035c3", "leftValue": "={{ $json.limite_disparo }}", "rightValue": 1, "operator": { "type": "number", "operation": "gte" } } ], "combinator": "and" }, "options": {} }, "id": "8a7949fc-f79c-42bb-a3bb-227f3e57f2ef", "name": "If", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ 1660, 1060 ] }, { "parameters": { "operation": "executeQuery", "query": "SELECT limite_disparo\nFROM accounts\nWHERE id ={{ $('Info_Base').item.json.chatwoot_account_id }};", "options": { "queryReplacement": "={{ $('Info_Base').item.json.chatwoot_account_id }}" } }, "id": "2e98ff77-b019-4600-baec-c2523338e527", "name": "Conta Disparo", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, "position": [ 1500, 1060 ] }, { "parameters": { "content": "## Limita disparo Diario", "height": 264.9413594226407, "width": 653.3075078799386, "color": 4 }, "id": "73922bab-217c-4e68-8409-3dd13d2bfad9", "name": "Sticky Note1", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ 1160, 1000 ] }, { "parameters": { "content": "## Dispara Mensagem", "height": 260.06359305339754, "width": 911.0441675732073, "color": 4 }, "id": "09b7112e-aa7f-4023-bb63-f98e1223dad3", "name": "Sticky Note3", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ 1880, 1000 ] }, { "parameters": { "operation": "executeQuery", "query": "SELECT limite_disparo\nFROM accounts\nWHERE id ={{ $('Info_Base').item.json.chatwoot_account_id }};", "options": { "queryReplacement": "=" } }, "id": "e3fb8e9e-7970-4dde-a91f-aed1704bbcb8", "name": "Limitador", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, "position": [ 1180, 1060 ] }, { "parameters": { "content": "## Contabiliza falhas", "height": 211.13093154244973, "width": 374.41687218580967, "color": 2 }, "id": "424dafc2-2168-4f5c-ba29-e3c61e7045df", "name": "Sticky Note6", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ 3560, 820 ] }, { "parameters": { "content": "## Contabiliza envios", "height": 215.09474919455494, "width": 382.34450749002, "color": 2 }, "id": "35ff8c46-84f7-48e1-a010-afd28978ef34", "name": "Sticky Note7", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ 3560, 1060 ] }, { "parameters": { "operation": "executeQuery", "query": "SELECT falhou\nFROM campaigns\nWHERE id = {{ $('IF6').item.json.id }};", "options": { "queryReplacement": "=" } }, "id": "d80dbe98-b91a-4f4b-baa0-ccae712db90c", "name": "Busca falhas", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, "position": [ 3600, 880 ] }, { "parameters": { "operation": "executeQuery", "query": "UPDATE accounts\nSET limite_disparo ={{ $json.limite_disparo -1 }}\nWHERE id ={{ $('Info_Base').item.json.chatwoot_account_id }};", "options": {} }, "id": "401c6494-661e-473c-83cd-fd09cc1605fc", "name": "Subtrair", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, "position": [ 1340, 1060 ] }, { "parameters": { "operation": "executeQuery", "query": "UPDATE campaigns\nSET falhou = {{ $json.falhou +1 }}\nWHERE id = {{ $('IF6').item.json.id }};", "options": {} }, "id": "43ee417a-0ea2-471b-a159-6e8376d0fa0f", "name": "Adiciona falhas", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, "position": [ 3760, 880 ] }, { "parameters": { "operation": "executeQuery", "query": "SELECT enviou\nFROM campaigns\nWHERE id = {{ $('IF6').item.json.id }};", "options": {} }, "id": "bf895abe-142c-4770-a8f8-88e2782e6d62", "name": "Busca envios", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, "position": [ 3600, 1120 ] }, { "parameters": { "assignments": { "assignments": [ { "id": "cbb23691-dfc9-413f-b996-ba0515b0a902", "name": "etiqueta", "value": "={{ $('Buscar campanhas').item.json.audience[0].id }}", "type": "number" }, { "id": "7a194f32-e774-4d48-94ed-1e2c9b9fd025", "name": "msg.title", "value": "={{ $('Buscar campanhas').item.json.title }}", "type": "string" }, { "id": "4dc32df3-cc5a-4a9b-8dcd-2d3f8a50a6fd", "name": "msg.message", "value": "={{ $('Buscar campanhas').item.json.message }}", "type": "string" }, { "id": "3b2fef42-7655-4ebc-ac93-1a25f77cbec1", "name": "anexo", "value": "={{ $('IF6').item.json.message.split('&anexo=')[1].split('&')[0] }}", "type": "string" }, { "id": "66e5ac5e-5cef-4737-81d8-9457f8fb8536", "name": "nomecontato", "value": "={{ $json.message.match(/&nome/)[0] }}", "type": "string" } ] }, "options": {} }, "id": "d910bd7a-800c-4953-912f-8b38b34a6601", "name": "Campanha", "type": "n8n-nodes-base.set", "typeVersion": 3.3, "position": [ -420, 1000 ] }, { "parameters": { "content": "# Relatorio da campanha", "height": 260.9879652172832, "width": 449.5390080420451 }, "id": "836c7655-5241-4a7f-bdea-97bca3732ac9", "name": "Sticky Note8", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ 1000, 520 ] }, { "parameters": { "operation": "executeQuery", "query": "SELECT falhou, enviou\nFROM campaigns\nWHERE id = {{ $('IF6').item.json.id }};", "options": { "queryReplacement": "=" } }, "id": "44432510-df66-4213-a0bf-a01ba3c8fad8", "name": "Resumo relatorio", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, "position": [ 1040, 620 ], "credentials": { "postgres": { "id": "CbrIGpLnj1oilB4h", "name": "Chatwoot" } } }, { "parameters": { "method": "POST", "url": "={{ $('Info_Base').item.json.evolution_url }}/message/sendMedia/{{ $('Info_Base').item.json.instance_name }}", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "accept", "value": "application/json, text/plain, */*" }, { "name": "apikey", "value": "={{ $('Info_Base').item.json.global_api_key }}" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={\"number\":\"{{ $('numero editado1').item.json.numberdispara }}@s.whatsapp.net\",\"options\":{\"delay\":3000,\"presence\":\"composing\"},\"mediaMessage\":{\"mediatype\":\"image\",\"caption\":\"{{ $json.mensagem }}\",\"media\":\"{{ $json[\"anexo\"] }}\"}}", "options": {} }, "id": "bd42bbd8-fc85-4563-85f0-21b6919d4e79", "name": "Envia msg2", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, "position": [ 3360, 1120 ], "retryOnFail": false, "maxTries": 2, "waitBetweenTries": 2000, "executeOnce": true, "onError": "continueErrorOutput" }, { "parameters": { "method": "POST", "url": "={{ $('Info_Base').item.json.evolution_url }}/message/sendText/{{ $('Info_Base').item.json.instance_name }}", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "accept", "value": "application/json, text/plain, */*" }, { "name": "apikey", "value": "={{ $('Info_Base').item.json.global_api_key }}" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={\"number\":\"{{ $('numero editado1').item.json.numberdispara }}@s.whatsapp.net\",\"options\":{\"delay\":3000,\"presence\":\"composing\"},\"textMessage\":{\"text\":\"{{ $('Edita Mensagem').item.json.var_msg }}\"}} ", "options": {} }, "id": "b72e62e8-dd5d-41f8-8f7d-54176e5bed08", "name": "Envia msg", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, "position": [ 3280, 840 ], "retryOnFail": false, "maxTries": 2, "waitBetweenTries": 2000, "executeOnce": true, "onError": "continueErrorOutput" }, { "parameters": { "content": "# Limite exedido", "height": 253.00924578984532, "width": 421.4323377312729 }, "id": "3a862afa-9145-4364-9449-8fbfdc867fae", "name": "Sticky Note9", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ 1000, 220 ] }, { "parameters": { "method": "POST", "url": "={{ $('Info_Base').item.json.evolution_url }}/message/sendText/{{ $('Info_Base').item.json.instance_name }}", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "accept", "value": "application/json, text/plain, */*" }, { "name": "apikey", "value": "={{ $('Info_Base').item.json.global_api_key }}" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={\"number\":\"{{ $('Info_Base').item.json[\"recebe_relatorio\"] }}@s.whatsapp.net\",\"options\":{\"delay\":3000,\"presence\":\"composing\"},\"textMessage\":{\"text\":\"📢 Campanha *{{ $('Buscar campanhas').item.json.title }}* enviada com sucesso! 📢\\n\\n✔️ Total de envios: {{ $json[\"enviou\"] }}\\n❌ Número de falhas: {{ $json[\"falhou\"] }}\\n\\nObrigado por utilizar nossos serviços!\"}}", "options": {} }, "id": "919991c6-56ca-46f5-a039-aefc966e0008", "name": "Envia relatorio", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, "position": [ 1200, 620 ], "retryOnFail": false, "maxTries": 2, "waitBetweenTries": 2000, "executeOnce": true }, { "parameters": { "method": "POST", "url": "={{ $('Info_Base').item.json.evolution_url }}/message/sendText/{{ $('Info_Base').item.json.instance_name }}", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "accept", "value": "application/json, text/plain, */*" }, { "name": "apikey", "value": "={{ $('Info_Base').item.json.global_api_key }}" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={\"number\":\"{{ $('Info_Base').item.json[\"recebe_relatorio\"] }}@s.whatsapp.net\",\"options\":{\"delay\":3000,\"presence\":\"composing\"},\"textMessage\":{\"text\":\"⚠️ *Atenção!* Algumas mensagens da campanha podem não ter sido enviadas. ⚠️\\n\\n✔️ Total de envios: {{ $json[\"enviou\"] }}\\n❌ Número de falhas: {{ $json[\"falhou\"] }}\\n\\nO limite de disparos diários foi excedido. Por favor, verifique os envios ou entre em contato com o suporte para mais informações.\\n\\nObrigado pela compreensão!\"}}", "options": {} }, "id": "d4e9f5d2-73c4-4464-952f-859a6083f434", "name": "Envia relatorio1", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, "position": [ 1200, 300 ], "retryOnFail": false, "maxTries": 2, "waitBetweenTries": 2000, "executeOnce": true }, { "parameters": { "operation": "executeQuery", "query": "=UPDATE campaigns SET status_envia = 1 WHERE id = {{ $json.id }}", "additionalFields": {} }, "id": "c67ab37d-c2f6-4513-b86d-a7e8f7cb711e", "name": "Update Campanha", "type": "n8n-nodes-base.postgres", "typeVersion": 1, "position": [ -1160, 900 ], "alwaysOutputData": true }, { "parameters": { "assignments": { "assignments": [ { "id": "fbca67eb-842d-47de-a989-c1879a8141bc", "name": "phone_number", "value": "={{ $('Loop Over Items').item.json.phone_number }}", "type": "string" } ] }, "options": {} }, "id": "c8688917-7a0b-4262-aeec-f8f44507f296", "name": "contato1", "type": "n8n-nodes-base.set", "typeVersion": 3.3, "position": [ 1940, 1060 ] }, { "parameters": { "operation": "executeQuery", "query": "UPDATE campaigns\nSET enviou = {{ $json.enviou +1 }}\nWHERE id = {{ $('IF6').item.json.id }};", "options": {} }, "id": "8740937f-39ec-4fca-b9be-adf7c6b90079", "name": "Adiciona envios", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, "position": [ 3760, 1120 ] }, { "parameters": { "content": "## Sem Anexo", "height": 199.63817652105178, "width": 313.99126283929667 }, "id": "b0c4684e-0fd8-4eb3-b826-2899bb7c27c6", "name": "Sticky Note4", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ 3180, 800 ] }, { "parameters": { "content": "## Com Anexo", "height": 216.81471968017428, "width": 313.99126283929667 }, "id": "bf6ffbe7-698d-436f-b33e-e667a1c28c1a", "name": "Sticky Note11", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ 3180, 1060 ] }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict" }, "conditions": [ { "id": "daf39b75-a974-426f-a6f7-197497d2fa94", "leftValue": "={{ $('Campanha').item.json.anexo }}", "rightValue": "", "operator": { "type": "string", "operation": "empty", "singleValue": true } } ], "combinator": "and" }, "options": {} }, "id": "f1bfef90-791f-4984-8ac8-9cb66361ddaa", "name": "If1", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ 2860, 1060 ] }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict" }, "conditions": [ { "id": "ebbe2797-49a1-47e7-9c54-161ff02dfa49", "leftValue": "={{ $('Campanha').item.json.nomecontato }}", "rightValue": "", "operator": { "type": "string", "operation": "empty", "singleValue": true } } ], "combinator": "and" }, "options": {} }, "id": "526a6680-e405-4d55-a2c4-c25969f381b2", "name": "If2", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ 560, 1040 ] }, { "parameters": { "assignments": { "assignments": [ { "id": "a588a036-88bc-4bc2-aefa-a2c0b9af2000", "name": "var_msg", "value": "={{ $('IF6').item.json.message.split('&nome').join($json.name) }}", "type": "string" } ] }, "options": {} }, "id": "8038d40c-2245-4fcf-9c91-2dcd8d4d2eb9", "name": "Edita Mensagem", "type": "n8n-nodes-base.set", "typeVersion": 3.3, "position": [ 820, 1040 ] }, { "parameters": { "fields": { "values": [ { "name": "mensagem", "stringValue": "={{ $('Edita Mensagem').item.json.var_msg.split(\"&anexo=\")[0].replace(/\\n/g, \"\\\\n\") }}" }, { "name": "titulo", "stringValue": "={{ $('Campanha').item.json.msg.title }}" }, { "name": "anexo", "stringValue": "={{ $('Campanha').item.json.anexo }}" } ] }, "options": { "includeBinary": true } }, "id": "01833f61-d743-4a4b-8dfc-1fbb83636e43", "name": "Edit Fields2", "type": "n8n-nodes-base.set", "typeVersion": 3.2, "position": [ 3220, 1120 ] }, { "parameters": { "url": "={{ $('Info_Base').item.json.chatwoot_url }}/api/v1/accounts/{{ $('Info_Base').item.json.chatwoot_account_id }}/contacts/{{ $json.payload[0].id }}/conversations", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "api_access_token", "value": "={{ $('Info_Base').item.json.chatwoot_token }}" } ] }, "options": {} }, "id": "b2c7871c-f7a0-44e0-b3f1-a3f266ed025b", "name": "Abre conversa de contato existente", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 4220, 1000 ] }, { "parameters": { "url": "={{ $('Info_Base').item.json.chatwoot_url }}/api/v1/accounts/{{ $('Info_Base').item.json.chatwoot_account_id }}/contacts/search", "sendQuery": true, "queryParameters": { "parameters": [ { "name": "q", "value": "={{ $('contato1').item.json.phone_number }}" } ] }, "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "api_access_token", "value": "={{ $('Info_Base').item.json.chatwoot_token }}" } ] }, "options": {} }, "id": "4d919f25-cd2e-4798-942c-5b914958240d", "name": "Busca Contato Existe", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 4060, 1000 ] }, { "parameters": { "method": "POST", "url": "={{ $('Info_Base').item.json.chatwoot_url }}/api/v1/accounts/{{ $('Info_Base').item.json.chatwoot_account_id }}/conversations/{{ $json.payload[0].id }}/toggle_status", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "api_access_token", "value": "={{ $('Info_Base').item.json.chatwoot_token }}" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={\n\"status\": \"resolved\"\n}", "options": {} }, "id": "10e0f8b6-da76-47fd-8a10-bd4ed79924a6", "name": "Resolve Conversa", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 5120, 1000 ] }, { "parameters": { "content": "## Resolve Conversa\n** Se a conversa estiver aberta mantém / Se for uma conversa nova ele fecha!", "height": 331.5360284004761, "width": 1227.4972493046307 }, "id": "c9a8251b-2798-4995-82f1-423626479581", "name": "Sticky Note12", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ 4020, 900 ] }, { "parameters": { "assignments": { "assignments": [ { "id": "a8de3538-0eac-4149-aaf9-7bc2c5c4b00e", "name": "id_caixa", "value": "={{ $('Busca Contato Existe').item.json.payload[0].contact_inboxes[0].inbox.id }}", "type": "string" }, { "id": "04e8a587-52b0-4ddc-877e-e97fdd1ef171", "name": "id_contato", "value": "={{ $('Busca Contato Existe').item.json.payload[0].id }}", "type": "string" } ] }, "options": {} }, "id": "3d168a28-9b4e-43e2-ba72-db0c3e0fb2d3", "name": "Salva conversa", "type": "n8n-nodes-base.set", "typeVersion": 3.3, "position": [ 4640, 1000 ] }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict" }, "conditions": [ { "id": "493b5963-2314-4179-a065-3a9aca90749e", "leftValue": "={{ $json.payload[0].status }}", "rightValue": "", "operator": { "type": "string", "operation": "exists", "singleValue": true } } ], "combinator": "and" }, "options": {} }, "id": "a8fb12c1-4d6a-4f51-913e-eb65850b77f7", "name": "If3", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ 4380, 1000 ] }, { "parameters": { "amount": 2 }, "id": "3ecefd79-bd5f-4239-b6a5-7ebc4f0dcae3", "name": "Wait", "type": "n8n-nodes-base.wait", "typeVersion": 1.1, "position": [ 4800, 1000 ], "webhookId": "639a6628-d277-44c2-ab5a-5e527e5becd6" }, { "parameters": { "url": "={{ $('Info_Base').item.json.chatwoot_url }}/api/v1/accounts/1/contacts/{{ $json[\"id_contato\"] }}/conversations", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "api_access_token", "value": "={{ $('Info_Base').item.json.chatwoot_token }}" } ] }, "options": {} }, "id": "3b98ac48-c9fe-4058-bdfe-424f422e358a", "name": "Busca conversa", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 4960, 1000 ] }, { "parameters": { "content": "# Resolve Conversa", "height": 246.1701698163285, "width": 547.9785698991002 }, "id": "01ca5461-5181-493e-b0ee-e19e6b1907f8", "name": "Sticky Note13", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ 1560, 400 ] }, { "parameters": { "url": "={{ $('Info_Base').item.json.chatwoot_url }}/api/v1/accounts/{{ $('Info_Base').item.json.chatwoot_account_id }}/contacts/{{ $json.payload[0].id }}/conversations", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "api_access_token", "value": "={{ $('Info_Base').item.json.chatwoot_token }}" } ] }, "options": {} }, "id": "37a88e79-a99d-4b0e-a772-1d44bc32b5d5", "name": "Seleciona conversa", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 1760, 480 ] }, { "parameters": { "url": "={{ $('Info_Base').item.json.chatwoot_url }}/api/v1/accounts/{{ $('Info_Base').item.json.chatwoot_account_id }}/contacts/search", "sendQuery": true, "queryParameters": { "parameters": [ { "name": "q", "value": "=+{{ $('Info_Base').item.json[\"recebe_relatorio\"] }}" } ] }, "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "api_access_token", "value": "={{ $('Info_Base').item.json.chatwoot_token }}" } ] }, "options": {} }, "id": "9dec3a39-369c-4a92-b002-9d24142b393e", "name": "Busca Contato do Relatorio", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 1600, 480 ] }, { "parameters": { "method": "POST", "url": "={{ $('Info_Base').item.json.chatwoot_url }}/api/v1/accounts/{{ $('Info_Base').item.json.chatwoot_account_id }}/conversations/{{ $json.payload[0].id }}/toggle_status", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "api_access_token", "value": "={{ $('Info_Base').item.json[\"chatwoot_token\"] }}" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={\n\"status\": \"resolved\"\n}", "options": {} }, "id": "62dc5e85-53b3-4847-9a98-889cc441eadc", "name": "Fecha Conversa", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 1920, 480 ] }, { "parameters": { "method": "POST", "url": "={{ $('Info_Base').item.json.evolution_url }}/message/sendText/{{ $('Info_Base').item.json.instance_name }}", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "accept", "value": "application/json, text/plain, */*" }, { "name": "apikey", "value": "={{ $('Info_Base').item.json.global_api_key }}" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={\"number\":\"{{ $('Info_Base').item.json[\"recebe_relatorio\"] }}@s.whatsapp.net\",\"options\":{\"delay\":3000,\"presence\":\"composing\"},\"textMessage\":{\"text\":\"📢 Notificação Importante 📢\\n\\n🚀 A campanha *{{ $('Buscar campanhas').item.json.title }}* foi iniciada com sucesso! 🎉\\n\\n📲 As mensagens estão sendo enviadas. Fique atento para atualizações.\\n\\nObrigado por utilizar nossos serviços! 😊\"}}", "options": {} }, "id": "cb3a3f92-8c0f-4c19-8e54-d24706f5ad6b", "name": "Envia Notificação", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, "position": [ 80, 1040 ], "retryOnFail": false, "maxTries": 2, "waitBetweenTries": 2000, "executeOnce": true }, { "parameters": { "operation": "executeQuery", "query": "SELECT falhou, enviou\nFROM campaigns\nWHERE id = {{ $('IF6').item.json.id }};", "options": { "queryReplacement": "=" } }, "id": "dde39e85-fe2c-4522-b372-3186cb44cd4d", "name": "Notifica limite excedido", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, "position": [ 1040, 300 ], "credentials": { "postgres": { "id": "CbrIGpLnj1oilB4h", "name": "Chatwoot" } } } ], "pinData": {}, "connections": { "Schedule Trigger": { "main": [ [ { "node": "Info_Base", "type": "main", "index": 0 } ] ] }, "Horario": { "main": [ [ { "node": "Update Campanha", "type": "main", "index": 0 }, { "node": "IF6", "type": "main", "index": 0 } ] ] }, "Altera fuso horário": { "main": [ [ { "node": "Horario", "type": "main", "index": 0 } ] ] }, "Info_Base": { "main": [ [ { "node": "Buscar campanhas", "type": "main", "index": 0 } ] ] }, "Buscar campanhas": { "main": [ [ { "node": "Altera fuso horário", "type": "main", "index": 0 } ] ] }, "Repetir ação": { "main": [ [ { "node": "Loop Over Items", "type": "main", "index": 0 } ] ] }, "Time Randon1": { "main": [ [ { "node": "Tempo de espera1", "type": "main", "index": 0 } ] ] }, "Tempo de espera1": { "main": [ [ { "node": "If1", "type": "main", "index": 0 } ] ] }, "Limpa numero1": { "main": [ [ { "node": "numero editado1", "type": "main", "index": 0 } ] ] }, "Busca contatos": { "main": [ [ { "node": "Envia Notificação", "type": "main", "index": 0 } ] ] }, "IF6": { "main": [ [ { "node": "Item Lists1", "type": "main", "index": 0 } ] ] }, "Item Lists1": { "main": [ [ { "node": "Campanha", "type": "main", "index": 0 } ] ] }, "numero editado1": { "main": [ [ { "node": "Time Randon1", "type": "main", "index": 0 } ] ] }, "Loop Over Items": { "main": [ [ { "node": "Resumo relatorio", "type": "main", "index": 0 } ], [ { "node": "If2", "type": "main", "index": 0 } ] ] }, "If": { "main": [ [ { "node": "contato1", "type": "main", "index": 0 } ], [ { "node": "Notifica limite excedido", "type": "main", "index": 0 } ] ] }, "Conta Disparo": { "main": [ [ { "node": "If", "type": "main", "index": 0 } ] ] }, "Limitador": { "main": [ [ { "node": "Subtrair", "type": "main", "index": 0 } ] ] }, "Busca falhas": { "main": [ [ { "node": "Adiciona falhas", "type": "main", "index": 0 } ] ] }, "Subtrair": { "main": [ [ { "node": "Conta Disparo", "type": "main", "index": 0 } ] ] }, "Adiciona falhas": { "main": [ [ { "node": "Busca Contato Existe", "type": "main", "index": 0 } ] ] }, "Busca envios": { "main": [ [ { "node": "Adiciona envios", "type": "main", "index": 0 } ] ] }, "Campanha": { "main": [ [ { "node": "Busca contatos", "type": "main", "index": 0 } ] ] }, "Resumo relatorio": { "main": [ [ { "node": "Envia relatorio", "type": "main", "index": 0 } ] ] }, "Envia msg2": { "main": [ [ { "node": "Busca envios", "type": "main", "index": 0 } ], [ { "node": "Busca falhas", "type": "main", "index": 0 } ] ] }, "Envia msg": { "main": [ [ { "node": "Busca envios", "type": "main", "index": 0 } ], [ { "node": "Busca falhas", "type": "main", "index": 0 } ] ] }, "contato1": { "main": [ [ { "node": "Limpa numero1", "type": "main", "index": 0 } ] ] }, "Adiciona envios": { "main": [ [ { "node": "Busca Contato Existe", "type": "main", "index": 0 } ] ] }, "If1": { "main": [ [ { "node": "Envia msg", "type": "main", "index": 0 } ], [ { "node": "Edit Fields2", "type": "main", "index": 0 } ] ] }, "If2": { "main": [ [ { "node": "Edita Mensagem", "type": "main", "index": 0 } ], [ { "node": "Edita Mensagem", "type": "main", "index": 0 } ] ] }, "Edita Mensagem": { "main": [ [ { "node": "Limitador", "type": "main", "index": 0 } ] ] }, "Edit Fields2": { "main": [ [ { "node": "Envia msg2", "type": "main", "index": 0 } ] ] }, "Busca Contato Existe": { "main": [ [ { "node": "Abre conversa de contato existente", "type": "main", "index": 0 } ] ] }, "Resolve Conversa": { "main": [ [ { "node": "Repetir ação", "type": "main", "index": 0 } ] ] }, "Abre conversa de contato existente": { "main": [ [ { "node": "If3", "type": "main", "index": 0 } ] ] }, "Salva conversa": { "main": [ [ { "node": "Wait", "type": "main", "index": 0 } ] ] }, "If3": { "main": [ [ { "node": "Repetir ação", "type": "main", "index": 0 } ], [ { "node": "Salva conversa", "type": "main", "index": 0 } ] ] }, "Wait": { "main": [ [ { "node": "Busca conversa", "type": "main", "index": 0 } ] ] }, "Busca conversa": { "main": [ [ { "node": "Resolve Conversa", "type": "main", "index": 0 } ] ] }, "Envia relatorio1": { "main": [ [ { "node": "Busca Contato do Relatorio", "type": "main", "index": 0 } ] ] }, "Busca Contato do Relatorio": { "main": [ [ { "node": "Seleciona conversa", "type": "main", "index": 0 } ] ] }, "Seleciona conversa": { "main": [ [ { "node": "Fecha Conversa", "type": "main", "index": 0 } ] ] }, "Envia relatorio": { "main": [ [ { "node": "Busca Contato do Relatorio", "type": "main", "index": 0 } ] ] }, "Envia Notificação": { "main": [ [ { "node": "Loop Over Items", "type": "main", "index": 0 } ] ] }, "Notifica limite excedido": { "main": [ [ { "node": "Envia relatorio1", "type": "main", "index": 0 } ] ] } }, "active": false, "settings": { "executionOrder": "v1" }, "versionId": "7d5bb929-70e2-4a0a-8e66-9af478e157cc", "meta": { "templateCredsSetupCompleted": true, "instanceId": "33738330930e3881dd5571eca013f36ddf8aab20e4ea5c1f2ebaf4a2b4668ac6" }, "id": "Cb3RLm6cSulZo90c", "tags": [ { "createdAt": "2024-06-24T17:54:45.734Z", "updatedAt": "2024-06-24T17:54:45.734Z", "id": "W4QFAwjDhUwUJMhH", "name": "Dev" } ] }