{ "name": "Disparador 1.3.1", "nodes": [ { "parameters": { "rule": { "interval": [ { "field": "minutes", "minutesInterval": 1 } ] } }, "id": "8fce1296-5035-4782-9ab6-1e1e1f1e1642", "name": "Schedule Trigger", "type": "n8n-nodes-base.scheduleTrigger", "typeVersion": 1, "position": [ -2180, 1040 ] }, { "parameters": { "conditions": { "dateTime": [ { "value1": "={{ $json.newDate }}", "operation": "before", "value2": "={{ $now }}" } ] } }, "id": "ef18df6b-05f0-437e-aa20-5296c4feb0f8", "name": "Horario", "type": "n8n-nodes-base.if", "typeVersion": 1, "position": [ -1460, 1040 ] }, { "parameters": { "content": "# Buscando Campanhas", "height": 456.3958547081602, "width": 1221.218469617133 }, "id": "19fd0560-dff1-4cc8-a3e3-7ec6389a929f", "name": "Sticky Note5", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ -2240, 840 ] }, { "parameters": { "content": "# Disparador de Campanha para ChatWoot\n## Evolution API\n\n\nv 1.3.1", "height": 163.30528430133387, "width": 847.4993167412657, "color": 4 }, "id": "a696c0ff-0e8a-4121-a8f0-6bc24992d3e3", "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": "7e7948ea-0584-4292-86df-746137366cf8", "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://urlchatwoot.com" }, { "name": "evolution_url", "value": "https://urlevo.com" }, { "name": "global_api_key", "value": "global api evo" }, { "name": "instance_name", "value": "=nome da tenancia evo" }, { "name": "chatwoot_token", "value": "=token perfil chatwoot" }, { "name": "email_relatorio", "value": "email@email.com" } ], "number": [ { "name": "chatwoot_account_id", "value": "=id conta chatwoot" }, { "name": "recebe_relatorio", "value": 551199996666 } ] }, "options": {} }, "id": "be515822-2179-46ac-a625-85f61675b5fb", "name": "Info_Base", "type": "n8n-nodes-base.set", "typeVersion": 2, "position": [ -2000, 1040 ] }, { "parameters": { "content": "# Busca contatos / Envia campanha\n", "height": 918.3121272287237, "width": 5345.205229325977, "color": 3 }, "id": "b2092ba7-5b7e-40d1-ba9b-7fc2a0c04eee", "name": "Sticky Note", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ -120.58977543169021, 800 ] }, { "parameters": { "operation": "executeQuery", "query": "SELECT * \nFROM campaigns c \nWHERE account_id = ID_CHATWOOT\nAND status_envia = 0\nAND inbox_id = ID_DO_DISPARADOR\nLIMIT 1;", "additionalFields": { "queryParams": "=" } }, "id": "9d73d2f8-0762-4aef-97b0-fd3b889f3b40", "name": "Buscar campanhas", "type": "n8n-nodes-base.postgres", "typeVersion": 1, "position": [ -1820, 1040 ], "credentials": { "postgres": { "id": "CbrIGpLnj1oilB4h", "name": "Chatwoot" } } }, { "parameters": {}, "id": "e920f471-2c25-4a44-97c1-92af8b909286", "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": "bdbffb4f-7ee4-4fa2-94bc-54ecc3fe9923", "name": "Time Randon1", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 2240, 1060 ] }, { "parameters": { "amount": "={{ $json.waitTime }}" }, "id": "2d6d2fe2-a618-46d4-8408-9faf49682ee0", "name": "Tempo de espera1", "type": "n8n-nodes-base.wait", "typeVersion": 1.1, "position": [ 2420, 1060 ], "webhookId": "12c42019-31f5-4506-8efd-b992dc5d5e31" }, { "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": "38fd4c79-b997-4562-98b6-31c240b80ba2", "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": "58a3dbdb-0eb2-414b-ac55-5feeab2c0003", "name": "IF6", "type": "n8n-nodes-base.if", "typeVersion": 1, "position": [ -840, 1000 ] }, { "parameters": { "fieldToSplitOut": "audience", "include": "allOtherFields", "options": {} }, "id": "6eebf64f-d9e1-456e-bc45-e58df35b51fc", "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": "ef3b0989-9abc-4f3b-a768-b055076b4178", "name": "Sticky Note2", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ -940, 840 ] }, { "parameters": { "options": {} }, "id": "92631519-1207-4439-9c4d-90f2e40fc472", "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": "63cf2edf-e36b-493a-be99-332467cb4738", "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": "3b97588c-77a7-4592-9fe8-4ebeee573e6b", "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": "097487f3-76f6-4501-9857-503a2f5f6886", "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": "981a407d-9e7c-48ce-b37a-000739c7fc7d", "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": "1ba895be-ffbe-4e2c-9ead-54b1d12d07a7", "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": "8be6f23f-2f16-4050-95b7-190e751d5563", "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": "7bc90e10-3ffb-495c-bc1b-b894bd106350", "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": "894694b9-4b54-4b64-9ff6-cecc6ab1dd8a", "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": "e7d2bbe8-b14b-4d0c-b3a9-4588e1f242aa", "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": "af6cd466-d970-4cf5-a6c8-a3139a513a3e", "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": "fb938aec-8992-4085-acee-d058a057cc28", "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": "9b774442-7171-4483-88cf-0239f11a6388", "name": "Resumo relatorio", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, "position": [ 1120, 580 ], "credentials": { "postgres": { "id": "CbrIGpLnj1oilB4h", "name": "Chatwoot" } } }, { "parameters": { "content": "# Limite exedido", "height": 253.00924578984532, "width": 566.1013825500216 }, "id": "3e1ab826-2d6e-49ce-8b8a-9371efd77a4b", "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": "3ebf8469-c629-4619-82d2-7bbbff26b462", "name": "Envia relatorio", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, "position": [ 1280, 580 ], "retryOnFail": false, "maxTries": 2, "waitBetweenTries": 2000, "executeOnce": true }, { "parameters": { "operation": "executeQuery", "query": "=UPDATE campaigns SET status_envia = 1 WHERE id = {{ $json.id }}", "additionalFields": {} }, "id": "fef339d3-2ca7-410b-acc4-1148514e14aa", "name": "Update Campanha", "type": "n8n-nodes-base.postgres", "typeVersion": 1, "position": [ -1160, 900 ], "alwaysOutputData": true, "credentials": { "postgres": { "id": "CbrIGpLnj1oilB4h", "name": "Chatwoot" } } }, { "parameters": { "operation": "executeQuery", "query": "UPDATE campaigns\nSET enviou = {{ $json.enviou +1 }}\nWHERE id = {{ $('IF6').item.json.id }};", "options": {} }, "id": "b870df1b-8270-49a5-8c5d-0b3e73a88e7b", "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": "2a839077-92c1-4e11-8108-b7a6266e0b63", "name": "Sticky Note4", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ 2920, 840 ] }, { "parameters": { "content": "## Com Anexo", "height": 221.17684873191945, "width": 313.99126283929667 }, "id": "40738a1e-c572-490b-ab05-5757d1f7bb8b", "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": "9ebeed5b-0ef7-4ac1-9efc-212eac9c4f6d", "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": "f9897be3-97b2-41d1-863c-9d8bf16e8ad2", "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": "88549ccf-02b5-41db-bf7c-ca69e5d18152", "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": "9f151dce-25fd-4333-89d1-2f443004d7c5", "name": "Edit Fields2", "type": "n8n-nodes-base.set", "typeVersion": 3.2, "position": [ 2960, 1160 ] }, { "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": "f4ce64b8-8c25-4903-871e-02cc6191b4c0", "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": "9e5f8336-9dcf-4c93-b690-9654438df7e2", "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": "338288df-3cf8-4197-9fa0-a2f36ef373ad", "name": "If3", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ 4120, 1040 ] }, { "parameters": { "amount": 2 }, "id": "533fd799-add0-4c9f-85e3-d747a8d5dd49", "name": "Wait", "type": "n8n-nodes-base.wait", "typeVersion": 1.1, "position": [ 4540, 1040 ], "webhookId": "91b155c8-7a16-4845-addb-3fc02670ae20" }, { "parameters": { "content": "# Resolve Conversa", "height": 246.1701698163285, "width": 704.4608631799392 }, "id": "42e61ff9-fa35-4238-a489-055d9b456f5c", "name": "Sticky Note13", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ 1743.517706719161, 380 ] }, { "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": "2cc37d31-0165-429f-a32a-638cf61566f7", "name": "Envia Notificação", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, "position": [ 160, 920 ], "retryOnFail": false, "maxTries": 2, "waitBetweenTries": 2000, "executeOnce": 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": "d81c9c40-c696-4e8f-8944-b96471177948", "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": "ed14d0aa-29f0-4ba4-b0ba-22d75133284c", "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": "e96bdf4a-a19b-4a8f-b9b4-fb6a8fcf2be1", "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": "2f7f12bd-98cb-4dbc-a9a9-3f3eea53a0eb", "name": "Send Email1", "type": "n8n-nodes-base.emailSend", "typeVersion": 2, "position": [ 1480, 600 ], "credentials": { "smtp": { "id": "VmMDyV2dTfPZUzPS", "name": "SMTP account" } }, "continueOnFail": true }, { "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": "bc83dead-76f4-478e-af22-a6beff4227c5", "name": "If4", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ 1320, 1060 ] }, { "parameters": {}, "id": "5e296314-c057-4659-91af-fd9fec4943b1", "name": "Wait1", "type": "n8n-nodes-base.wait", "typeVersion": 1.1, "position": [ 1780, 460 ], "webhookId": "cecee368-df5c-4a08-b959-22039c50284a" }, { "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": "03e43bb1-657c-423a-8530-b9157c6dd418", "name": "Envia msg", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, "position": [ 3020, 880 ], "retryOnFail": false, "maxTries": 2, "waitBetweenTries": 2000, "executeOnce": true, "onError": "continueRegularOutput" }, { "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": "fe6ec433-ac28-4f2c-a4ac-99ad86085a9f", "name": "Envia msg2", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, "position": [ 3100, 1160 ], "retryOnFail": false, "maxTries": 2, "waitBetweenTries": 2000, "executeOnce": true, "onError": "continueRegularOutput" }, { "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": "e3c5af48-c661-4376-95c3-34b82958c812", "name": "HTTP Request1", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 1140, 1060 ] }, { "parameters": { "method": "POST", "url": "={{ $node['Info_Base'].json.chatwoot_url }}/api/v1/accounts/{{ $node['Info_Base'].json.chatwoot_account_id }}/conversations/{{ $json.payload[0].id }}/toggle_status", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "api_access_token", "value": "={{ $node['Info_Base'].json.chatwoot_token }}" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={\n\"status\": \"resolved\"\n}", "options": {} }, "id": "1a792741-39e2-4330-bf21-bba6329c182d", "name": "Resolve Conversa", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 4860, 1040 ], "onError": "continueRegularOutput" }, { "parameters": { "url": "={{ $node['Info_Base'].json.chatwoot_url }}/api/v1/accounts/1/contacts/{{ $json[\"id_contato\"] }}/conversations", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "api_access_token", "value": "={{ $node['Info_Base'].json.chatwoot_token }}" } ] }, "options": {} }, "id": "f73fe5a2-8899-48de-b58f-3a7439e28f99", "name": "Busca conversa", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 4700, 1040 ], "onError": "continueRegularOutput" }, { "parameters": { "url": "={{ $node['Info_Base'].json.chatwoot_url }}/api/v1/accounts/{{ $node['Info_Base'].json.chatwoot_account_id }}/contacts/{{ $json.payload[0].id }}/conversations", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "api_access_token", "value": "={{ $node['Info_Base'].json.chatwoot_token }}" } ] }, "options": {} }, "id": "29a3f3d0-cab3-49ad-adfd-0fbdfb6a7fdf", "name": "Abre conversa de contato existente", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 3960, 1040 ], "onError": "continueRegularOutput" }, { "parameters": { "url": "={{ $node['Info_Base'].json.chatwoot_url }}/api/v1/accounts/{{ $node['Info_Base'].json.chatwoot_account_id }}/contacts/search", "sendQuery": true, "queryParameters": { "parameters": [ { "name": "q", "value": "={{ $node['Busca contatos'].json.phone_number }}" } ] }, "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "api_access_token", "value": "={{ $node['Info_Base'].json.chatwoot_token }}" } ] }, "options": {} }, "id": "547b1cdd-3ac2-43f7-9e67-b2623e7a4dd3", "name": "Busca Contato Existe", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 3800, 1040 ] }, { "parameters": { "method": "POST", "url": "={{ $node['Info_Base'].json.chatwoot_url }}/api/v1/accounts/{{ $node['Info_Base'].json.chatwoot_account_id }}/conversations/{{ $json.payload[0].id }}/toggle_status", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "api_access_token", "value": "={{ $node['Info_Base'].json[\"chatwoot_token\"] }}" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={\n\"status\": \"resolved\"\n}", "options": {} }, "id": "bc9deb8b-56c7-491a-a11e-abb0d7b75ff9", "name": "Fecha Conversa", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 2260, 460 ], "onError": "continueRegularOutput" }, { "parameters": { "url": "={{ $node['Info_Base'].json.chatwoot_url }}/api/v1/accounts/{{ $node['Info_Base'].json.chatwoot_account_id }}/contacts/{{ $json.payload[0].id }}/conversations", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "api_access_token", "value": "={{ $node['Info_Base'].json.chatwoot_token }}" } ] }, "options": {} }, "id": "9c5369d0-bcf8-457d-9443-6b0da8b2ed4e", "name": "Seleciona conversa", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 2100, 460 ], "onError": "continueRegularOutput" }, { "parameters": { "url": "={{ $node['Info_Base'].json.chatwoot_url }}/api/v1/accounts/{{ $node['Info_Base'].json.chatwoot_account_id }}/contacts/search", "sendQuery": true, "queryParameters": { "parameters": [ { "name": "q", "value": "=+{{ $node['Info_Base'].json[\"recebe_relatorio\"] }}" } ] }, "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "api_access_token", "value": "={{ $node['Info_Base'].json.chatwoot_token }}" } ] }, "options": {} }, "id": "de0ac4ad-d6ef-4d33-9ec8-94a1404cb3f1", "name": "Busca Contato do Relatorio", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 1940, 460 ], "onError": "continueRegularOutput" }, { "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": "df52e073-b806-41ba-bccc-accf793658fb", "name": "Envia relatorio1", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, "position": [ 1280, 280 ], "retryOnFail": false, "maxTries": 2, "waitBetweenTries": 2000, "executeOnce": true } ], "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 } ] ] }, "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 } ] ] }, "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 } ] ] }, "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 } ] ] }, "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 } ] ] }, "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 } ] ] }, "Envia msg": { "main": [ [ { "node": "Busca envios", "type": "main", "index": 0 } ] ] }, "Envia msg2": { "main": [ [ { "node": "Busca envios", "type": "main", "index": 0 } ] ] }, "HTTP Request1": { "main": [ [ { "node": "If4", "type": "main", "index": 0 } ] ] }, "Resolve Conversa": { "main": [ [ { "node": "Repetir ação", "type": "main", "index": 0 } ] ] }, "Busca conversa": { "main": [ [ { "node": "Resolve Conversa", "type": "main", "index": 0 } ] ] }, "Abre conversa de contato existente": { "main": [ [ { "node": "If3", "type": "main", "index": 0 } ] ] }, "Busca Contato Existe": { "main": [ [ { "node": "Abre conversa de contato existente", "type": "main", "index": 0 } ] ] }, "Seleciona conversa": { "main": [ [ { "node": "Fecha Conversa", "type": "main", "index": 0 } ] ] }, "Busca Contato do Relatorio": { "main": [ [ { "node": "Seleciona conversa", "type": "main", "index": 0 } ] ] }, "Envia relatorio1": { "main": [ [ { "node": "Send Email", "type": "main", "index": 0 }, { "node": "Wait1", "type": "main", "index": 0 } ] ] } }, "active": false, "settings": { "executionOrder": "v1" }, "versionId": "70f6dcc5-c4db-4b0a-bb81-9ae9076bd8dd", "meta": { "templateCredsSetupCompleted": true, "instanceId": "33738330930e3881dd5571eca013f36ddf8aab20e4ea5c1f2ebaf4a2b4668ac6" }, "id": "4VsLUjqTMlyS0AW3", "tags": [ { "createdAt": "2024-06-24T17:54:45.734Z", "updatedAt": "2024-06-24T17:54:45.734Z", "id": "W4QFAwjDhUwUJMhH", "name": "Dev" } ] }