{ "name": "Disparador 1.3", "nodes": [ { "parameters": { "rule": { "interval": [ { "field": "minutes", "minutesInterval": 1 } ] } }, "id": "4452959e-df86-49c1-9198-9637d5db5899", "name": "Schedule Trigger", "type": "n8n-nodes-base.scheduleTrigger", "typeVersion": 1, "position": [ -2180, 1040 ] }, { "parameters": { "conditions": { "dateTime": [ { "value1": "={{ $json.newDate }}", "operation": "before", "value2": "={{ $now }}" } ] } }, "id": "d1b0e00d-8655-416e-be1b-185602fc3c5b", "name": "Horario", "type": "n8n-nodes-base.if", "typeVersion": 1, "position": [ -1460, 1040 ] }, { "parameters": { "content": "# Buscando Campanhas", "height": 456.3958547081602, "width": 1221.218469617133 }, "id": "02db442a-cd4e-4a5a-89dc-296c93eadc84", "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.3", "height": 163.30528430133387, "width": 847.4993167412657, "color": 4 }, "id": "bde3b3f2-9623-401b-830f-c5da7e263d94", "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": "04923613-b480-41ae-9f91-a6cdcebe62c5", "name": "Altera fuso horário", "type": "n8n-nodes-base.dateTime", "typeVersion": 2, "position": [ -1640, 1040 ] }, { "parameters": { "content": "# Busca contatos / Envia campanha\n", "height": 918.3121272287237, "width": 5345.205229325977, "color": 3 }, "id": "63df87d4-ebdb-42a5-99d9-4c38eef9f38d", "name": "Sticky Note", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ -120.58977543169021, 800 ] }, { "parameters": { "operation": "executeQuery", "query": "select * from campaigns c where campaign_type = 1 and status_envia = 0 LIMIT 1", "additionalFields": {} }, "id": "bf04807b-ffa9-4050-b8c5-fefe644b5638", "name": "Buscar campanhas", "type": "n8n-nodes-base.postgres", "typeVersion": 1, "position": [ -1820, 1040 ], "credentials": { "postgres": { "id": "CbrIGpLnj1oilB4h", "name": "Chatwoot" } } }, { "parameters": {}, "id": "7d61bf85-d647-4d21-a5ef-ddafa1a61cd2", "name": "Repetir ação", "type": "n8n-nodes-base.noOp", "typeVersion": 1, "position": [ 5060, 1220 ] }, { "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": "f427a3df-2316-43ae-953a-fc42daf93153", "name": "Time Randon1", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 2240, 1060 ] }, { "parameters": { "amount": "={{ $json.waitTime }}" }, "id": "3b39659b-09b4-4afa-b02b-6b0cb37e31f7", "name": "Tempo de espera1", "type": "n8n-nodes-base.wait", "typeVersion": 1.1, "position": [ 2420, 1060 ], "webhookId": "dc200d84-f36d-46c9-812f-da7ed75f0f75", "disabled": true }, { "parameters": { "operation": "executeQuery", "query": "SELECT c.*\nFROM contacts c\nJOIN taggings tg ON c.id = tg.taggable_id\nWHERE tg.tag_id = {{ $json.etiqueta }}\nAND tg.taggable_type = 'Contact'\nAND c.account_id = {{ $('Info_Base').item.json.chatwoot_account_id }};", "options": {} }, "id": "f7717d60-3cce-4140-b1b8-460c815253b6", "name": "Busca contatos", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, "position": [ -80, 1040 ], "credentials": { "postgres": { "id": "CbrIGpLnj1oilB4h", "name": "Chatwoot" } } }, { "parameters": { "conditions": { "string": [ { "value1": "={{ $('Buscar campanhas').item.json.campaign_type }}", "value2": "={{ 1 }}" } ] } }, "id": "8ef0df3f-a6c3-4dd7-a61f-251de01b01f6", "name": "IF6", "type": "n8n-nodes-base.if", "typeVersion": 1, "position": [ -840, 1000 ] }, { "parameters": { "fieldToSplitOut": "audience", "include": "allOtherFields", "options": {} }, "id": "62022390-4093-4298-876d-cb5ab65e91bf", "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": "17041050-2a07-4398-8103-072ffb01aa4a", "name": "Sticky Note2", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ -940, 840 ] }, { "parameters": { "options": {} }, "id": "d7690c38-6a64-4493-9a4c-545c84ffa870", "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": "a843cb96-5697-4f69-9247-8c054b989816", "name": "If", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ 1740, 1060 ] }, { "parameters": { "content": "## Limita disparo Diario", "height": 225.35612209945384, "width": 541.3647232510804, "color": 4 }, "id": "f240fd62-5b0a-4d9d-ab12-306246b481a8", "name": "Sticky Note1", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ 1556, 1000 ] }, { "parameters": { "content": "## Tempo entre as mensagens", "height": 230.3746650610074, "width": 404.53569195365, "color": 4 }, "id": "9731ca27-f42b-43c1-96ea-5d3f10d9b818", "name": "Sticky Note3", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ 2180, 1000 ] }, { "parameters": { "content": "## Contabiliza falhas", "height": 211.13093154244973, "width": 374.41687218580967, "color": 2 }, "id": "c3f1bf2b-ad3f-4bcc-a81b-b9d90143a7ad", "name": "Sticky Note6", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ 3300, 1440 ] }, { "parameters": { "content": "## Contabiliza envios", "height": 215.09474919455494, "width": 376.16757486051324, "color": 2 }, "id": "f283ed02-2487-4738-ace6-1df7db7de2ce", "name": "Sticky Note7", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ 3300, 980 ] }, { "parameters": { "operation": "executeQuery", "query": "SELECT falhou\nFROM campaigns\nWHERE id = {{ $('IF6').item.json.id }};", "options": { "queryReplacement": "=" } }, "id": "7890db73-fc8e-4400-8d7d-483eb9f652be", "name": "Busca falhas", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, "position": [ 3340, 1500 ], "credentials": { "postgres": { "id": "CbrIGpLnj1oilB4h", "name": "Chatwoot" } } }, { "parameters": { "operation": "executeQuery", "query": "UPDATE accounts\nSET limite_disparo ={{ $json.limite_disparo -1 }}\nWHERE id ={{ $('Info_Base').item.json.chatwoot_account_id }};", "options": {} }, "id": "9b34f824-acca-434a-8813-f20f45d16750", "name": "Subtrair", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, "position": [ 1940, 1040 ], "credentials": { "postgres": { "id": "CbrIGpLnj1oilB4h", "name": "Chatwoot" } } }, { "parameters": { "operation": "executeQuery", "query": "UPDATE campaigns\nSET falhou = {{ $json.falhou +1 }}\nWHERE id = {{ $('IF6').item.json.id }};", "options": {} }, "id": "94f201ed-3c97-443f-805a-d02a3a3ce822", "name": "Adiciona falhas", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, "position": [ 3500, 1500 ], "credentials": { "postgres": { "id": "CbrIGpLnj1oilB4h", "name": "Chatwoot" } } }, { "parameters": { "operation": "executeQuery", "query": "SELECT enviou\nFROM campaigns\nWHERE id = {{ $('IF6').item.json.id }};", "options": {} }, "id": "d9d31efc-ce26-48d7-8b3e-fdc7e6d819a0", "name": "Busca envios", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, "position": [ 3360, 1040 ], "credentials": { "postgres": { "id": "CbrIGpLnj1oilB4h", "name": "Chatwoot" } } }, { "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" }, { "id": "afa0b53c-9933-44e1-ab91-49a9540f9c7d", "name": "emailcontato", "value": "={{ $json.message.match(/&email/)[0] }}", "type": "string" } ] }, "options": {} }, "id": "acfd9367-1a7f-4160-9a3c-e353c114ed5c", "name": "Campanha", "type": "n8n-nodes-base.set", "typeVersion": 3.3, "position": [ -420, 1000 ] }, { "parameters": { "content": "# Relatorio da campanha", "height": 260.9879652172832, "width": 572.0821989473383 }, "id": "78b47cf8-c13c-401a-a7bd-cc7d775c7b09", "name": "Sticky Note8", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ 1060, 500 ] }, { "parameters": { "operation": "executeQuery", "query": "SELECT \n c.falhou, \n c.enviou, \n a.limite_disparo \nFROM \n campaigns c\nJOIN \n accounts a ON c.account_id = a.id\nWHERE \n c.id = {{ $('IF6').item.json.id }};", "options": { "queryReplacement": "=" } }, "id": "a7774a5b-6460-4f5f-9264-02987a3959a9", "name": "Resumo relatorio", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, "position": [ 1120, 580 ], "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": "={\n \"number\":\"{{ $('Busca contatos').item.json.phone_number }}\",\n \"options\":{\"delay\":3000,\"presence\":\"composing\"},\n \"mediaMessage\":{\"mediatype\":\"image\",\"caption\":\"{{ $json.mensagem }}\",\n \"media\":\"{{ $json[\"anexo\"] }}\"}\n}\n", "options": {} }, "id": "39654931-d40a-4ccb-af5f-a401c434e453", "name": "Envia msg2", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, "position": [ 3100, 1160 ], "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": "={\n \"number\":\"{{ $('Busca contatos').item.json.phone_number }}\",\n \"options\":{\"delay\":3000,\"presence\":\"composing\"},\n \"textMessage\":{\"text\":\"{{ $('Edita Mensagem').item.json.var_msg.replace(/\\n/g, '\\\\n') }}\"}\n} ", "options": {} }, "id": "f5c1102f-c895-4848-bdcd-47a963484975", "name": "Envia msg", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, "position": [ 3020, 880 ], "retryOnFail": false, "maxTries": 2, "waitBetweenTries": 2000, "executeOnce": true, "onError": "continueErrorOutput" }, { "parameters": { "content": "# Limite exedido", "height": 253.00924578984532, "width": 566.1013825500216 }, "id": "4a469859-4a64-47dc-b52a-734fd2328a32", "name": "Sticky Note9", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ 1060, 200 ] }, { "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#️⃣ Limite restante: {{ $json[\"limite_disparo\"] }}\\n\\nObrigado por utilizar nossos serviços!\"}}", "options": {} }, "id": "7ce334eb-8692-4a5f-b8c9-1237157f4bd9", "name": "Envia relatorio", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, "position": [ 1280, 580 ], "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 *{{ $('Buscar campanhas').item.json.title }}* podem não ter sido enviadas. ⚠️\\n\\n✔️ Total de envios: {{ $json[\"enviou\"] }}\\n❌ Número de falhas: {{ $json[\"falhou\"] }}\\n#️⃣ Limite restante: {{ $json[\"limite_disparo\"] }}\\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": "cc4e81c1-2678-4ed0-8658-223cb69798b5", "name": "Envia relatorio1", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, "position": [ 1280, 280 ], "retryOnFail": false, "maxTries": 2, "waitBetweenTries": 2000, "executeOnce": true }, { "parameters": { "operation": "executeQuery", "query": "=UPDATE campaigns SET status_envia = 1 WHERE id = {{ $json.id }}", "additionalFields": {} }, "id": "a5d2f541-47fa-4b37-875c-d1cd9957b3f9", "name": "Update Campanha", "type": "n8n-nodes-base.postgres", "typeVersion": 1, "position": [ -1160, 900 ], "alwaysOutputData": true, "credentials": { "postgres": { "id": "CbrIGpLnj1oilB4h", "name": "Chatwoot" } }, "disabled": true }, { "parameters": { "operation": "executeQuery", "query": "UPDATE campaigns\nSET enviou = {{ $json.enviou +1 }}\nWHERE id = {{ $('IF6').item.json.id }};", "options": {} }, "id": "e5d89e25-495a-43ed-92da-1fa75dae4ac7", "name": "Adiciona envios", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, "position": [ 3520, 1040 ], "credentials": { "postgres": { "id": "CbrIGpLnj1oilB4h", "name": "Chatwoot" } } }, { "parameters": { "content": "## Sem Anexo", "height": 199.63817652105178, "width": 313.99126283929667 }, "id": "804fc136-12b5-4f40-b48b-28e5fc635c7a", "name": "Sticky Note4", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ 2920, 840 ] }, { "parameters": { "content": "## Com Anexo", "height": 221.17684873191945, "width": 313.99126283929667 }, "id": "c3b19e5e-b472-4c8a-aa6f-d39cb7855a2f", "name": "Sticky Note11", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ 2920, 1096 ] }, { "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": "31e4e1fc-d9ac-475c-a8dc-43210c65c9c1", "name": "If1", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ 2680, 1080 ] }, { "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 } }, { "id": "77ff2a0a-ae27-427a-b489-2daac4e90429", "leftValue": "{{ $('Campanha').item.json.emailcontato}}", "rightValue": "", "operator": { "type": "string", "operation": "empty", "singleValue": true } } ], "combinator": "or" }, "options": {} }, "id": "22b9cf8c-175f-445e-8637-f2f6833e0541", "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).split('&email').join($json.email) }}", "type": "string" } ] }, "options": {} }, "id": "a3fd6f99-34fe-43b3-a85a-1711aef68bc7", "name": "Edita Mensagem", "type": "n8n-nodes-base.set", "typeVersion": 3.3, "position": [ 880, 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": "250bb120-7022-406b-9d54-545a7afe2696", "name": "Edit Fields2", "type": "n8n-nodes-base.set", "typeVersion": 3.2, "position": [ 2960, 1160 ] }, { "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": "7e6a3f17-0b0b-472c-9041-eed7747e5df3", "name": "Abre conversa de contato existente", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 3960, 1040 ] }, { "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": "={{ $('Busca contatos').item.json.phone_number }}" } ] }, "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "api_access_token", "value": "={{ $('Info_Base').item.json.chatwoot_token }}" } ] }, "options": {} }, "id": "187271b6-05f9-4d6a-813b-4609734e2370", "name": "Busca Contato Existe", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 3800, 1040 ] }, { "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": "f84fca45-e817-4f02-ae2a-0c5170de67af", "name": "Resolve Conversa", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 4860, 1040 ] }, { "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": "6aaa8d71-6d7c-4e66-bd00-dd95decfb97a", "name": "Sticky Note12", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ 3760, 940 ] }, { "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": "b5b5f680-da2e-4883-8d83-24b46023a94f", "name": "Salva conversa", "type": "n8n-nodes-base.set", "typeVersion": 3.3, "position": [ 4380, 1040 ] }, { "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": "a32d9ad2-b090-48fe-8429-7a1491be38a1", "name": "If3", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ 4120, 1040 ] }, { "parameters": { "amount": 2 }, "id": "5649307b-7a02-45c4-91fa-0e1d28fee271", "name": "Wait", "type": "n8n-nodes-base.wait", "typeVersion": 1.1, "position": [ 4540, 1040 ], "webhookId": "d3ab4c19-a79f-4561-b2a2-dd4678da799c" }, { "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": "bb717465-9540-4911-bc52-9e2d85dc5f7e", "name": "Busca conversa", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 4700, 1040 ] }, { "parameters": { "content": "# Resolve Conversa", "height": 246.1701698163285, "width": 704.4608631799392 }, "id": "38d5fc83-3555-4d5d-84e7-872ddd7c4c71", "name": "Sticky Note13", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ 1743.517706719161, 380 ] }, { "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": "f5ebfada-7816-4fac-825d-cd5f39bd64fb", "name": "Seleciona conversa", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 2100, 460 ] }, { "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": "f10e0111-9a63-47be-9a4e-f619137592e2", "name": "Busca Contato do Relatorio", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 1940, 460 ] }, { "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": "77090159-6fe6-4106-adca-548ca3b3cb37", "name": "Fecha Conversa", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 2260, 460 ] }, { "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": "2fccdd81-f998-41d9-b270-f2c7651e67ad", "name": "Envia Notificação", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, "position": [ 160, 920 ], "retryOnFail": false, "maxTries": 2, "waitBetweenTries": 2000, "executeOnce": true, "disabled": true }, { "parameters": { "operation": "executeQuery", "query": "SELECT \n c.falhou, \n c.enviou, \n a.limite_disparo \nFROM \n campaigns c\nJOIN \n accounts a ON c.account_id = a.id\nWHERE \n c.id = {{ $('IF6').item.json.id }};", "options": { "queryReplacement": "=" } }, "id": "ffda661c-e4b7-4dff-a730-cfadf3345723", "name": "Notifica limite excedido", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, "position": [ 1120, 280 ], "credentials": { "postgres": { "id": "CbrIGpLnj1oilB4h", "name": "Chatwoot" } } }, { "parameters": { "operation": "executeQuery", "query": "SELECT limite_disparo\nFROM accounts\nWHERE id ={{ $('Info_Base').item.json.chatwoot_account_id }};", "options": { "queryReplacement": "=" } }, "id": "d4ce6ee0-86fc-4bef-88f8-2bc2944e3e88", "name": "Busca limite diario", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, "position": [ 1600, 1060 ], "credentials": { "postgres": { "id": "CbrIGpLnj1oilB4h", "name": "Chatwoot" } } }, { "parameters": { "fromEmail": "suportesetabot@gmail.com", "toEmail": "={{ $('Info_Base').item.json.email_relatorio }}", "subject": "SetaBot - Limite de disparo excedido", "text": "=⚠️ Atenção! Algumas mensagens da campanha {{ $('Buscar campanhas').item.json.title }} podem não ter sido enviadas. ⚠️\n\n✔️ Total de envios: {{ $('Notifica limite excedido').item.json.enviou }}\n❌ Número de falhas: {{ $('Notifica limite excedido').item.json.falhou }}\n#️⃣ Limite restante: {{ $('Notifica limite excedido').item.json.limite_disparo }} \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": "00c67c94-3ea8-44c5-bd31-ea32bba06b3a", "name": "Send Email", "type": "n8n-nodes-base.emailSend", "typeVersion": 2, "position": [ 1480, 220 ], "credentials": { "smtp": { "id": "VmMDyV2dTfPZUzPS", "name": "SMTP account" } }, "continueOnFail": true }, { "parameters": { "fromEmail": "suportesetabot@gmail.com", "toEmail": "={{ $('Info_Base').item.json.email_relatorio }}", "subject": "SetaBot - Relatório a Campanha", "text": "=📢 Campanha {{ $('Buscar campanhas').item.json.title }} enviada com sucesso! 📢\n\n✔️ Total de envios: {{ $('Resumo relatorio').item.json.enviou }}\n❌ Número de falhas: {{ $('Resumo relatorio').item.json.falhou }} \n#️⃣ Limite restante: {{ $('Resumo relatorio').item.json.limite_disparo }} \n\nObrigado por utilizar nossos serviços!", "options": {} }, "id": "f792c86c-d19a-415c-9988-96dc89a81c33", "name": "Send Email1", "type": "n8n-nodes-base.emailSend", "typeVersion": 2, "position": [ 1480, 600 ], "credentials": { "smtp": { "id": "VmMDyV2dTfPZUzPS", "name": "SMTP account" } }, "continueOnFail": true }, { "parameters": { "method": "POST", "url": "={{ $('Info_Base').item.json.evolution_url }}/chat/whatsappNumbers/{{ $('Info_Base').item.json.instance_name }}", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "Content-Type", "value": "application/json" }, { "name": "apikey", "value": "={{ $('Info_Base').item.json.global_api_key }}" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={\n \"numbers\": [\n \"{{ $('Busca contatos').item.json.phone_number }}\"\n ]\n} ", "options": {} }, "id": "25dd968c-418e-4b5f-ab54-61d0f87081e2", "name": "HTTP Request1", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 1140, 1060 ] }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict" }, "conditions": [ { "id": "c2573aed-9acc-4fc6-a799-b11e2191d408", "leftValue": "={{ $json.exists }}", "rightValue": "true", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "options": {} }, "id": "f72c7a2f-885e-4d81-8661-05691018be19", "name": "If4", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ 1320, 1060 ] }, { "parameters": {}, "id": "58cf13cc-7b5d-4e37-a3c3-b26ea6caefb0", "name": "Wait1", "type": "n8n-nodes-base.wait", "typeVersion": 1.1, "position": [ 1780, 460 ], "webhookId": "7a91c17d-7a90-40c6-905f-2e6479420bf6" }, { "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" }, { "name": "email_relatorio", "value": "email pra receber relatorio" } ], "number": [ { "name": "chatwoot_account_id", "value": "=id da tenancia" }, { "name": "recebe_relatorio", "value": 5511944446666 } ] }, "options": {} }, "id": "b79915aa-62a5-43e7-a256-d3c2a3d8d025", "name": "Info_Base1", "type": "n8n-nodes-base.set", "typeVersion": 2, "position": [ -2000, 1040 ] } ], "pinData": {}, "connections": { "Schedule Trigger": { "main": [ [ { "node": "Info_Base1", "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 } ] ] }, "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 } ] ] }, "Busca contatos": { "main": [ [ { "node": "Envia Notificação", "type": "main", "index": 0 }, { "node": "Loop Over Items", "type": "main", "index": 0 } ] ] }, "IF6": { "main": [ [ { "node": "Item Lists1", "type": "main", "index": 0 } ] ] }, "Item Lists1": { "main": [ [ { "node": "Campanha", "type": "main", "index": 0 } ] ] }, "Loop Over Items": { "main": [ [ { "node": "Resumo relatorio", "type": "main", "index": 0 } ], [ { "node": "If2", "type": "main", "index": 0 } ] ] }, "If": { "main": [ [ { "node": "Subtrair", "type": "main", "index": 0 } ], [ { "node": "Notifica limite excedido", "type": "main", "index": 0 } ] ] }, "Busca falhas": { "main": [ [ { "node": "Adiciona falhas", "type": "main", "index": 0 } ] ] }, "Subtrair": { "main": [ [ { "node": "Time Randon1", "type": "main", "index": 0 } ] ] }, "Adiciona falhas": { "main": [ [ { "node": "Repetir ação", "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 } ] ] }, "Envia msg": { "main": [ [ { "node": "Busca envios", "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 } ] ] }, "Edita Mensagem": { "main": [ [ { "node": "HTTP Request1", "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": "Send Email", "type": "main", "index": 0 }, { "node": "Wait1", "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": "Send Email1", "type": "main", "index": 0 }, { "node": "Wait1", "type": "main", "index": 0 } ] ] }, "Notifica limite excedido": { "main": [ [ { "node": "Envia relatorio1", "type": "main", "index": 0 } ] ] }, "Busca limite diario": { "main": [ [ { "node": "If", "type": "main", "index": 0 } ] ] }, "If2": { "main": [ [ { "node": "Edita Mensagem", "type": "main", "index": 0 } ], [ { "node": "Edita Mensagem", "type": "main", "index": 0 } ] ] }, "HTTP Request1": { "main": [ [ { "node": "If4", "type": "main", "index": 0 } ] ] }, "If4": { "main": [ [ { "node": "Busca limite diario", "type": "main", "index": 0 } ], [ { "node": "Busca falhas", "type": "main", "index": 0 } ] ] }, "Wait1": { "main": [ [ { "node": "Busca Contato do Relatorio", "type": "main", "index": 0 } ] ] }, "Info_Base1": { "main": [ [ { "node": "Buscar campanhas", "type": "main", "index": 0 } ] ] } }, "active": false, "settings": { "executionOrder": "v1" }, "versionId": "6011a582-ecaa-4d05-8bad-fbbb0b97b523", "meta": { "templateCredsSetupCompleted": true, "instanceId": "33738330930e3881dd5571eca013f36ddf8aab20e4ea5c1f2ebaf4a2b4668ac6" }, "id": "bmwifouK4HVcc03B", "tags": [ { "createdAt": "2024-06-24T17:54:45.734Z", "updatedAt": "2024-06-24T17:54:45.734Z", "id": "W4QFAwjDhUwUJMhH", "name": "Dev" } ] }