From a705291045a4731c76db437f91bda5c165950420 Mon Sep 17 00:00:00 2001 From: Tanci <94814382+rodtanci@users.noreply.github.com> Date: Mon, 9 Sep 2024 12:27:31 -0300 Subject: [PATCH] Update disparador.json --- disparador.json | 407 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 277 insertions(+), 130 deletions(-) diff --git a/disparador.json b/disparador.json index e1fc4b3..f63f0cf 100644 --- a/disparador.json +++ b/disparador.json @@ -1,5 +1,5 @@ { - "name": "Disparador 1.6.1", + "name": "Disparador 1.8", "nodes": [ { "parameters": { @@ -12,7 +12,7 @@ ] } }, - "id": "b111255f-9aac-485d-b494-41c0b055d078", + "id": "fe778228-a383-4d15-9b33-995e8ff25593", "name": "Schedule Trigger", "type": "n8n-nodes-base.scheduleTrigger", "typeVersion": 1, @@ -33,7 +33,7 @@ ] } }, - "id": "257ea5b0-ec73-40eb-a6c7-1c1f77a320f4", + "id": "c7811219-8d15-4722-8b74-535f6cf3af48", "name": "Horario", "type": "n8n-nodes-base.if", "typeVersion": 1, @@ -48,7 +48,7 @@ "height": 456.3958547081602, "width": 1431.3025345443343 }, - "id": "f80b08da-a8a8-412d-bb53-9988bd7cd1fd", + "id": "2667951b-782e-4bd7-b5b6-edd0e7b28d5e", "name": "Sticky Note5", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, @@ -59,12 +59,12 @@ }, { "parameters": { - "content": "# Disparador de Campanha para ChatWoot\n## Evolution API\n\n\nv 1.6.1", + "content": "# Disparador de Campanha para ChatWoot\n## Evolution API\n\n\nv 1.8", "height": 163.30528430133387, "width": 847.4993167412657, "color": 4 }, - "id": "5ec4a7a7-59fb-4dcf-881c-284d199a6285", + "id": "f9922a0a-b405-4ecd-8002-d4f5fbfa293e", "name": "Sticky Note10", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, @@ -83,7 +83,7 @@ "includeInputFields": true } }, - "id": "a31ba72d-3fbb-4107-bcb3-1073427783df", + "id": "d05fca36-c0d4-4ffb-a784-db5541500696", "name": "Altera fuso horário", "type": "n8n-nodes-base.dateTime", "typeVersion": 2, @@ -95,11 +95,11 @@ { "parameters": { "content": "# Busca contatos / Envia campanha\n", - "height": 1190.762291292581, + "height": 1569.3729310736378, "width": 5519.984579857509, "color": 3 }, - "id": "abf4d3d2-8c90-4434-91d5-5d1d8654b84f", + "id": "e5b5da72-75b5-41c0-8856-1d2340e284a6", "name": "Sticky Note", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, @@ -110,7 +110,7 @@ }, { "parameters": {}, - "id": "b84739e1-af5f-4cd5-a43c-c21dbd4e418a", + "id": "150ca21b-482f-465c-93bb-25d001d1fb77", "name": "Repetir ação", "type": "n8n-nodes-base.noOp", "typeVersion": 1, @@ -123,7 +123,7 @@ "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": "27afb1c1-c3f3-49f2-b5a6-3ee0fe88a64c", + "id": "d92c511f-fffb-42dc-af33-119b7befca0c", "name": "Time Randon1", "type": "n8n-nodes-base.code", "typeVersion": 2, @@ -136,7 +136,7 @@ "parameters": { "amount": "={{ $json.waitTime }}" }, - "id": "c0c3c82b-4bd2-4227-a691-a6f61f1b2e9b", + "id": "7d5684f7-3bcd-4879-b706-93b24c3239d9", "name": "Tempo de espera1", "type": "n8n-nodes-base.wait", "typeVersion": 1.1, @@ -144,8 +144,7 @@ 2580, 1060 ], - "webhookId": "c93de3df-0e65-4fe1-badd-25825a47174f", - "disabled": true + "webhookId": "acbaacf5-6f98-4cdc-aa69-c47334b82632" }, { "parameters": { @@ -158,7 +157,7 @@ ] } }, - "id": "0fc8e6fa-c35d-478f-92a8-8e6134b921ac", + "id": "95a3c771-79af-4dc3-9af4-41c95d7ec4b7", "name": "IF6", "type": "n8n-nodes-base.if", "typeVersion": 1, @@ -173,7 +172,7 @@ "include": "allOtherFields", "options": {} }, - "id": "7109a8eb-a5ac-41b9-bbba-27eec9342a91", + "id": "2e98a9ad-5fc3-49c9-89a4-dd53d1951bdc", "name": "Item Lists1", "type": "n8n-nodes-base.itemLists", "typeVersion": 3, @@ -189,7 +188,7 @@ "width": 728.217926985971, "color": 2 }, - "id": "c5107070-9222-4c42-b625-337ece80d7c0", + "id": "8b6974ae-6738-4b1f-a457-6d1307a94302", "name": "Sticky Note2", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, @@ -202,7 +201,7 @@ "parameters": { "options": {} }, - "id": "1fa7b249-0530-46e4-b042-a9c478489025", + "id": "8bc7d69b-8ac0-44e9-93a7-5a490ee19251", "name": "Loop Over Items", "type": "n8n-nodes-base.splitInBatches", "typeVersion": 3, @@ -238,7 +237,7 @@ }, "options": {} }, - "id": "9ee55009-a296-4f52-adae-36217787be8b", + "id": "7df84a3f-af0b-4955-af8a-adf466d6a914", "name": "If", "type": "n8n-nodes-base.if", "typeVersion": 2, @@ -254,7 +253,7 @@ "width": 853.0984671711764, "color": 4 }, - "id": "e06e460f-2a91-49e3-9e21-c076ca488c21", + "id": "460e22ce-bb6f-454e-bcb4-9c76d3320876", "name": "Sticky Note1", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, @@ -270,7 +269,7 @@ "width": 404.53569195365, "color": 4 }, - "id": "57b07206-3f89-44ea-ad6c-00c8a5f704d2", + "id": "b4d086e3-1651-48bd-bbf4-6e2d1c35b897", "name": "Sticky Note3", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, @@ -286,7 +285,7 @@ "width": 546.5336275124715, "color": 2 }, - "id": "f6f06b9b-b6a6-42d0-bf65-81805066de0a", + "id": "19a3eb9a-c552-4eac-83c1-bb8da93e8a53", "name": "Sticky Note6", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, @@ -302,7 +301,7 @@ "width": 376.16757486051324, "color": 2 }, - "id": "2668f9d1-8076-44e2-a353-764bb12dc17a", + "id": "67222cd3-214f-4dc5-b0ed-e6d71743e9d6", "name": "Sticky Note7", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, @@ -319,7 +318,7 @@ "queryReplacement": "=" } }, - "id": "2c0f53b6-d313-48f3-b611-eddee6dd7c0a", + "id": "4a652151-eb76-40ca-8631-be7a4d022e24", "name": "Busca falhas", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, @@ -340,7 +339,7 @@ "query": "SELECT enviou\nFROM campaigns\nWHERE id = {{ $('IF6').item.json.id }};", "options": {} }, - "id": "a2ab63bd-3942-41b0-a934-73db04eae048", + "id": "676a965b-f3c3-4e50-895e-bb26c52ea37c", "name": "Busca envios", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, @@ -362,7 +361,7 @@ { "id": "cbb23691-dfc9-413f-b996-ba0515b0a902", "name": "etiqueta", - "value": "={{ $('Buscar campanhas').item.json.audience[0].id }}", + "value": "={{ $('Buscar campanhas').item.json.audience.map(a => a.id).join(',') }}", "type": "number" }, { @@ -406,12 +405,18 @@ "name": "vid", "value": "={{ $('IF6').item.json.message.split('&vid=')[1].split('&')[0] }}", "type": "string" + }, + { + "id": "12d83710-4f40-4d9b-a6cc-3a12b4f6c358", + "name": "audio", + "value": "={{ $('IF6').item.json.message.split('&audio=')[1].split('&')[0] }}", + "type": "string" } ] }, "options": {} }, - "id": "9f17d297-db4d-4355-acce-d21ca97cf8ac", + "id": "17078c23-af56-452d-aba7-b60a21d393dd", "name": "Campanha", "type": "n8n-nodes-base.set", "typeVersion": 3.3, @@ -426,7 +431,7 @@ "height": 346.43605543050865, "width": 1085.0447604700087 }, - "id": "ac6dbc90-b6ad-4595-8349-4efc29144182", + "id": "835f949e-d335-4ecf-9e41-02bfe9e0ee72", "name": "Sticky Note8", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, @@ -441,7 +446,7 @@ "height": 339.69571412210314, "width": 1088.2492332463764 }, - "id": "e7cdaebc-b14c-49e9-bccd-90abeb6043dc", + "id": "8eb761b6-8dfc-4628-b3cb-3e3ae3a0da7c", "name": "Sticky Note9", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, @@ -456,7 +461,7 @@ "query": "UPDATE campaigns\nSET enviou = {{ $json.enviou +1 }}\nWHERE id = {{ $('IF6').item.json.id }};", "options": {} }, - "id": "c7d16d0f-1613-48b2-9f38-48a161bff428", + "id": "59ce0325-e7bb-4776-9a51-f6618131eaee", "name": "Adiciona envios", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, @@ -477,7 +482,7 @@ "height": 199.63817652105178, "width": 313.99126283929667 }, - "id": "f8f64aa1-d3d8-46e2-905f-4027cba7c69c", + "id": "886bec7d-41e5-44b8-bf40-dbcf4f813f56", "name": "Sticky Note4", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, @@ -492,7 +497,7 @@ "height": 221.17684873191945, "width": 313.99126283929667 }, - "id": "6b53806e-814a-4a8d-a175-49e8e0b67b21", + "id": "9202b3b5-adee-41ea-9ff9-3e43ff14f580", "name": "Sticky Note11", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, @@ -535,7 +540,7 @@ }, "options": {} }, - "id": "f2129a72-ab1e-4486-a1f4-e49f51bd5cab", + "id": "6d93cf92-a22e-4f31-a00a-582c16b0d35e", "name": "If2", "type": "n8n-nodes-base.if", "typeVersion": 2, @@ -550,7 +555,7 @@ "height": 331.5360284004761, "width": 1227.4972493046307 }, - "id": "dffc84f9-8807-4d12-be42-587b59dc303c", + "id": "68e8e520-1782-42bb-afd2-273be2250c26", "name": "Sticky Note12", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, @@ -579,7 +584,7 @@ }, "options": {} }, - "id": "d49ae7c3-47bf-4b14-923b-c989417bf54f", + "id": "f2c1e907-fec3-4198-a26a-0e7278715ac9", "name": "Salva conversa", "type": "n8n-nodes-base.set", "typeVersion": 3.3, @@ -612,7 +617,7 @@ }, "options": {} }, - "id": "9df71d6c-8076-4408-ad6c-1c1370d84f1a", + "id": "be67bfcb-6d85-427b-8f5c-1b6a2c2daa56", "name": "If3", "type": "n8n-nodes-base.if", "typeVersion": 2, @@ -625,7 +630,7 @@ "parameters": { "amount": 1 }, - "id": "4398c043-c266-40d4-bd94-53da3bb9342a", + "id": "fae89c5f-354a-4071-b19e-2c3299384dce", "name": "Wait", "type": "n8n-nodes-base.wait", "typeVersion": 1.1, @@ -633,7 +638,7 @@ 4700, 1040 ], - "webhookId": "d970af57-141e-4d9d-9570-e774bd7f26e8" + "webhookId": "32ea5a17-b2e4-4198-af5f-495e4a4c789c" }, { "parameters": { @@ -641,7 +646,7 @@ "height": 246.1701698163285, "width": 704.4608631799392 }, - "id": "40711eab-647c-4d15-b053-e705cd148c66", + "id": "94bcb70f-3fae-45e3-85ab-d3230aa2efe2", "name": "Sticky Note13", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, @@ -658,7 +663,7 @@ "queryReplacement": "=" } }, - "id": "ff79ed41-0352-4603-bf26-527b33033e35", + "id": "f17538c1-196b-4366-b6b6-37aa87256e50", "name": "Busca limite diario", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, @@ -681,7 +686,7 @@ "text": "=⚠️ Atenção! Algumas mensagens da campanha {{ $node['Buscar campanhas'].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": "e5b3c342-50b1-4f70-b8b1-e078cc846a01", + "id": "bae0c923-9a60-4663-907b-1ecfa3a41fe8", "name": "Send Email", "type": "n8n-nodes-base.emailSend", "typeVersion": 2, @@ -705,7 +710,7 @@ "text": "=📢 Campanha {{ $node['Buscar campanhas'].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": "f23483f6-1cd1-4014-8d6f-40eba1035be5", + "id": "c51b3425-5868-4ee6-b5ee-23cc4e0012a9", "name": "Send Email1", "type": "n8n-nodes-base.emailSend", "typeVersion": 2, @@ -745,7 +750,7 @@ }, "options": {} }, - "id": "162b717d-1cb4-4354-aabc-1be8a0f65c4c", + "id": "1e370e5c-d550-4634-a38e-e72627430dae", "name": "If4", "type": "n8n-nodes-base.if", "typeVersion": 2, @@ -756,7 +761,7 @@ }, { "parameters": {}, - "id": "d3949e7d-e077-4228-babd-1bbdf86bf206", + "id": "9ab30a8c-0d52-4246-8b36-badad7d37b64", "name": "Wait1", "type": "n8n-nodes-base.wait", "typeVersion": 1.1, @@ -764,7 +769,7 @@ 2396, 360 ], - "webhookId": "c4dd821d-55e5-40c7-844d-3f8fcdb4eded" + "webhookId": "6d098b28-941a-40c5-9c9c-327bb4abfd8d" }, { "parameters": { @@ -772,7 +777,7 @@ "query": "UPDATE campaigns\nSET falhou = {{ $json.falhou +1 }}\nWHERE id = {{ $('IF6').item.json.id }};", "options": {} }, - "id": "90fae266-28e2-48cc-b9c3-87404e1f6b06", + "id": "fb6dd13a-50f4-492d-9e42-90a363319c0d", "name": "Adiciona num de falhas", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, @@ -793,7 +798,7 @@ "query": "INSERT INTO campaigns_failled (nomecontato, telefone, id_campanha)\nSELECT '{{ $('Busca contatos').item.json.name }}', '{{ $('Busca contatos').item.json.phone_number }}', {{ $('Buscar campanhas').item.json.id }}\nWHERE NOT EXISTS (\n SELECT 1\n FROM campaigns_failled\n WHERE telefone = '{{ $('Busca contatos').item.json.phone_number }}' AND id_campanha = {{ $('Buscar campanhas').item.json.id }}\n);", "options": {} }, - "id": "dc19a189-d40a-4a46-90a9-42d1f81de7df", + "id": "e2515859-4a4d-47ee-981f-38544dff8edf", "name": "Adiciona num não enviado", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, @@ -831,7 +836,7 @@ }, "options": {} }, - "id": "0c381d9a-dfc9-42eb-8254-ca54e7db1d06", + "id": "98ab312d-848b-4306-ac6f-4951319fa017", "name": "If5", "type": "n8n-nodes-base.if", "typeVersion": 2, @@ -848,7 +853,7 @@ "queryReplacement": "=" } }, - "id": "64beae72-3ec2-430c-be83-6af2bbcf18a0", + "id": "bc269eae-cb86-482c-8408-aa08a431739c", "name": "Notifica limite excedido", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, @@ -886,7 +891,7 @@ }, "options": {} }, - "id": "53db0839-0bda-4972-a79a-2aa9f5d0cf55", + "id": "21cf0f80-e996-4e9c-b93b-ae49cbbdb5b6", "name": "If6", "type": "n8n-nodes-base.if", "typeVersion": 2, @@ -899,7 +904,7 @@ "parameters": { "jsCode": "let contatos = items.map(item => `${item.json.nomecontato} - ${item.json.telefone}`).join('\\n');\n\nreturn [\n {\n json: {\n listaContatos: contatos\n }\n }\n];" }, - "id": "76193df9-973f-4273-accb-7cf2fd5c3903", + "id": "639dde41-6266-4d46-bea2-740abfff8d3d", "name": "Code", "type": "n8n-nodes-base.code", "typeVersion": 2, @@ -912,7 +917,7 @@ "parameters": { "jsCode": "let contatos = items.map(item => `${item.json.nomecontato} - ${item.json.telefone}`).join('\\n');\n\nreturn [\n {\n json: {\n listaContatos: contatos\n }\n }\n];" }, - "id": "33d78929-093f-45dd-9b74-2571e2cc7112", + "id": "b86f10a4-ceec-488f-bc8a-962cceec4653", "name": "Code1", "type": "n8n-nodes-base.code", "typeVersion": 2, @@ -929,7 +934,7 @@ "text": "=📢 Campanha {{ $node['Buscar campanhas'].json.title }} enviada com sucesso! 📢\n\n✔️ Total de envios: {{ $node['Resumo relatorio'].json.enviou }}\n❌ Número de falhas: {{ $node['Resumo relatorio'].json.falhou }} \n#️⃣ Limite restante: {{ $node['Resumo relatorio'].json.limite_disparo }} \n\nContatos não enviados:\n{{ $('Code').item.json[\"listaContatos\"] }}\n\nObrigado por utilizar nossos serviços!", "options": {} }, - "id": "3f950e01-1ac7-4b19-9dd7-f67d6d8b7384", + "id": "2e79c4d9-3914-4df8-ad2f-7cbf9055817f", "name": "Send Email2", "type": "n8n-nodes-base.emailSend", "typeVersion": 2, @@ -951,7 +956,7 @@ "query": "SELECT \n (SELECT COUNT(*) FROM campaigns_failled WHERE id_campanha = {{ $('Buscar campanhas').item.json.id }}) AS total_registros,\n campaigns_failled.*\nFROM campaigns_failled\nWHERE id_campanha = {{ $('Buscar campanhas').item.json.id }};", "options": {} }, - "id": "6c957fad-4b12-408f-b5bd-e3228524ca7c", + "id": "205aa2ae-be61-41d6-ac05-a99a7ba2d539", "name": "Postgres1", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, @@ -975,7 +980,7 @@ "text": "=⚠️ Atenção! Algumas mensagens da campanha {{ $node['Buscar campanhas'].json.title }} podem não ter sido enviadas. ⚠️\n\n✔️ Total de envios: {{ $node['Notifica limite excedido'].json.enviou }}\n❌ Número de falhas: {{ $node['Notifica limite excedido'].json.falhou }}\n#️⃣ Limite restante: {{ $node['Notifica limite excedido'].json.limite_disparo }} \n\nContatos não enviados:\n{{ $node['Code1'].json[\"listaContatos\"] }}\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": "f936c259-0671-4b5a-9d3e-1e1e7ad83103", + "id": "eddf1b71-30cc-40c5-8f62-1d60e21587ac", "name": "Send Email3", "type": "n8n-nodes-base.emailSend", "typeVersion": 2, @@ -1017,7 +1022,7 @@ }, "options": {} }, - "id": "412bc004-852b-43fd-be78-8ac029bde961", + "id": "24a3b46f-19c8-4f50-bf44-b259c46d8414", "name": "Dados da campanha", "type": "n8n-nodes-base.set", "typeVersion": 3.3, @@ -1032,7 +1037,7 @@ "include": "allOtherFields", "options": {} }, - "id": "c4eec246-20fc-47d7-abd3-175eaf5fb4e3", + "id": "2472bf9b-333b-43e3-b082-cf5dbf3aaed7", "name": "Tratamento de lista", "type": "n8n-nodes-base.itemLists", "typeVersion": 3, @@ -1048,7 +1053,7 @@ "query": "SELECT \n (SELECT COUNT(*) FROM campaigns_failled WHERE id_campanha = {{ $node['Dados da campanha'].json.id_campanha }}) AS total_registros,\n cf.*\nFROM campaigns_failled cf\nWHERE cf.id_campanha = {{ $node['Dados da campanha'].json.id_campanha }};", "options": {} }, - "id": "2338de5c-9a3b-464a-9755-4e7314324c61", + "id": "441bb08f-7722-4faa-867f-b507620df22f", "name": "Postgres", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, @@ -1070,7 +1075,7 @@ "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 = {{ $json.id_campanha }};", "options": {} }, - "id": "9c1b60e8-5787-414b-ada4-4a7e9a49543e", + "id": "9ce30354-81ae-4680-83e4-249455576c88", "name": "Resumo relatorio", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, @@ -1091,7 +1096,7 @@ "query": "UPDATE accounts\nSET limite_disparo = {{ $('Busca limite diario').item.json.limite_disparo -1 }}\nWHERE id ={{ $('Info_Base').item.json.chatwoot_account_id }};", "options": {} }, - "id": "fa3358b8-2849-4c2b-b748-c18d7b40016a", + "id": "a0dce6cc-4de0-4061-88c1-d434ee0a6001", "name": "Subtrair", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, @@ -1120,7 +1125,7 @@ }, "options": {} }, - "id": "f296aa1f-7fc9-480f-85ba-a5a74f603920", + "id": "05283c2c-b66c-44e9-b84e-ea91e29b8ff4", "name": "Abre conversa de contato existente", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, @@ -1153,7 +1158,7 @@ }, "options": {} }, - "id": "4a5505fe-b2d2-457b-82d6-081efd7362ed", + "id": "542009a0-2ba4-4ceb-8637-74484fcf1f5a", "name": "Busca Contato Existe", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, @@ -1185,7 +1190,7 @@ "jsonBody": "={\n \"numbers\": [\n \"{{ $node['Edita Mensagem'].json.verificanum }}\"\n ]\n} ", "options": {} }, - "id": "a00c9a82-5c6f-4471-8395-d6de8955545f", + "id": "10fa2039-20de-4606-a145-41a6dd51b3bf", "name": "HTTP Request1", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, @@ -1212,7 +1217,7 @@ "jsonBody": "={\n\"status\": \"resolved\"\n}", "options": {} }, - "id": "b4ab39d2-6a2a-4501-be22-9f96fb46112f", + "id": "3793ac4f-46b3-4a42-92c5-221016e51af6", "name": "Fecha Conversa", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, @@ -1236,7 +1241,7 @@ }, "options": {} }, - "id": "dd328078-9f60-4436-aab2-e3e0e91469fa", + "id": "636b3eba-53a7-407f-a745-4fe51ef2c741", "name": "Seleciona conversa", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, @@ -1269,7 +1274,7 @@ }, "options": {} }, - "id": "1f477a35-8b14-48db-8028-bf0b8f43fe4d", + "id": "08a673f1-3bb0-4dff-b6cc-a0c7d484c3f3", "name": "Busca Contato do Relatorio", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, @@ -1285,7 +1290,7 @@ "query": "UPDATE conversations\nSET status = 1\nWHERE contact_id = {{ $json.id_contato }};", "options": {} }, - "id": "7479237f-3bf1-48a2-9ec9-eb3e4d58fb02", + "id": "60358ca8-7f4b-48f5-a365-bae10faecb29", "name": "Resolve Conversa", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, @@ -1307,7 +1312,7 @@ "height": 221.17684873191945, "width": 313.99126283929667 }, - "id": "8fd9c97c-5619-48c1-82ad-ef9fa69fca65", + "id": "b70106fc-bb53-4ffd-ba0b-685cc0eceb67", "name": "Sticky Note14", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, @@ -1322,7 +1327,7 @@ "query": "SELECT * \nFROM campaigns c \nWHERE account_id = 0\nAND status_envia = 0\nAND inbox_id = 0;", "additionalFields": {} }, - "id": "05409e0d-cf9e-4c90-a169-42f22c90e170", + "id": "79675b5a-61be-4643-b9a8-862654538647", "name": "Buscar campanhas", "type": "n8n-nodes-base.postgres", "typeVersion": 1, @@ -1343,7 +1348,7 @@ "query": "UPDATE campaigns SET status_envia = 1 WHERE id = {{ $json.id }}", "options": {} }, - "id": "2d6ed480-333a-41d5-b324-706391eea51e", + "id": "0207a237-592c-4ca6-a729-c8428b0051f4", "name": "UPDATE CAMPANHA", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, @@ -1362,10 +1367,10 @@ { "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 = {{ $node['Info_Base'].json.chatwoot_account_id }};", + "query": "SELECT DISTINCT c.*\nFROM contacts c\nJOIN taggings tg ON c.id = tg.taggable_id\nWHERE tg.tag_id IN ({{ $('Campanha').item.json.etiqueta }})\nAND tg.taggable_type = 'Contact'\nAND c.account_id = {{ $('Info_Base').item.json.chatwoot_account_id }};", "options": {} }, - "id": "a6293afc-40ae-4428-a5ff-6d3ee3a2b31c", + "id": "bd262158-182b-446f-b4a8-81501aab78e1", "name": "Busca contatos", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, @@ -1402,7 +1407,7 @@ "jsonBody": "={\n \"number\":\"{{ $node['Edita Mensagem'].json.verificanum }}\",\n \"options\":{\"delay\":3000,\"presence\":\"composing\"},\n \"textMessage\":{\"text\":\"{{ $node['Edita Mensagem'].json.var_msg.replace(/\"/g, '\\\\\"').replace(/\\n/g, '\\\\n') }}\"}\n}", "options": {} }, - "id": "2722b8b6-3768-4984-a505-f33b77c1b3d1", + "id": "3d92b924-d262-4f26-b390-738f067bf9f6", "name": "Envia msg", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, @@ -1454,13 +1459,23 @@ "operation": "empty", "singleValue": true } + }, + { + "id": "1454588a-05f2-4306-adb8-2bda761dac54", + "leftValue": "={{ $('Campanha').item.json.audio}}", + "rightValue": "", + "operator": { + "type": "string", + "operation": "empty", + "singleValue": true + } } ], "combinator": "and" }, "options": {} }, - "id": "97249a77-06f3-4023-8f74-30708555364a", + "id": "a611514b-41ce-45a6-8914-8f852b741fea", "name": "If1", "type": "n8n-nodes-base.if", "typeVersion": 2, @@ -1491,7 +1506,7 @@ "jsonBody": "={\n \"number\": \"{{ $node['Info_Base'].json['recebe_relatorio'] }}\",\n \"options\": {\n \"delay\": 3000,\n \"presence\": \"composing\"\n },\n \"textMessage\": {\n \"text\": \"📢 Campanha *{{ $node['Buscar campanhas'].json.title }}* enviada com sucesso! 📢\\n\\n✔️ Total de envios: {{ $node['Resumo relatorio'].json.enviou }}\\n❌ Número de falhas: {{ $node['Resumo relatorio'].json.falhou }}\\n#️⃣ Limite restante: {{ $node['Resumo relatorio'].json.limite_disparo }}\\n\\n*Contatos não enviados:*\\n{{ $node['Code'].json.listaContatos.replace(/\\n/g, '\\\\n') }} \\n\\nObrigado por utilizar nossos serviços!\"\n }\n}\n ", "options": {} }, - "id": "9abf6368-fd48-47d2-a763-2a2502e10114", + "id": "8fab660f-3195-4a63-8f9b-b1de0e68cf67", "name": "Envia relatorio3", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, @@ -1526,7 +1541,7 @@ "jsonBody": "={\"number\":\"{{ $node['Info_Base'].json[\"recebe_relatorio\"] }}\",\"options\":{\"delay\":3000,\"presence\":\"composing\"},\"textMessage\":{\"text\":\"📢 Campanha *{{ $node['Buscar campanhas'].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": "cf0c4210-a3ef-4367-b57b-440d6a7b1f24", + "id": "4da50f83-4957-46fe-8fd9-7edfee2711b5", "name": "Envia relatorio", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, @@ -1561,7 +1576,7 @@ "jsonBody": "={\"number\":\"{{ $node['Info_Base'].json[\"recebe_relatorio\"] }}\",\"options\":{\"delay\":3000,\"presence\":\"composing\"},\"textMessage\":{\"text\":\"⚠️ *Atenção!* Algumas mensagens da campanha *{{ $node['Buscar campanhas'].json.title }}* podem não ter sido enviadas. ⚠️\\n\\n✔️ Total de envios: {{ $node['Notifica limite excedido'].json[\"enviou\"] }}\\n❌ Número de falhas: {{ $node['Notifica limite excedido'].json[\"falhou\"] }}\\n#️⃣ Limite restante: {{ $node['Notifica limite excedido'].json[\"limite_disparo\"] }}\\n\\n*Contatos não enviados:*\\n{{ $node['Code1'].json.listaContatos.replace(/\\n/g, '\\\\n') }} \\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!\"}}\n", "options": {} }, - "id": "fff96809-29fc-425f-b63e-8c28ff56d493", + "id": "4bf33c46-85f5-4000-80d1-e94de03fbaae", "name": "Envia relatorio2", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, @@ -1596,7 +1611,7 @@ "jsonBody": "={\"number\":\"{{ $node['Info_Base'].json[\"recebe_relatorio\"] }}\",\"options\":{\"delay\":3000,\"presence\":\"composing\"},\"textMessage\":{\"text\":\"⚠️ *Atenção!* Algumas mensagens da campanha *{{ $node['Buscar campanhas'].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": "86b057bf-51b2-47d4-8395-79cc562a2e0b", + "id": "8ce545bb-9528-4360-969a-7b61b27aa92a", "name": "Envia relatorio1", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, @@ -1631,7 +1646,7 @@ "jsonBody": "={\"number\":\"{{ $node['Info_Base'].json[\"recebe_relatorio\"] }}\",\"options\":{\"delay\":3000,\"presence\":\"composing\"},\"textMessage\":{\"text\":\"📢 Notificação Importante 📢\\n\\n🚀 A campanha *{{ $node['Buscar campanhas'].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": "81bb1048-e711-4565-a32f-1a5181334069", + "id": "d035a2f5-0491-467f-b8e1-c9221f061b84", "name": "Envia Notificação", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, @@ -1664,7 +1679,7 @@ }, "options": {} }, - "id": "9677206e-b5ce-4039-8fac-ec22b447b4fa", + "id": "24419f4d-6d6a-490d-b386-af809b7e204d", "name": "Edita Mensagem", "type": "n8n-nodes-base.set", "typeVersion": 3.3, @@ -1695,7 +1710,7 @@ "includeBinary": true } }, - "id": "b73aa3d2-df2c-4a45-aa4a-ada0bfd29139", + "id": "3dfc2230-0f09-4d64-a9fd-dccdd19398ce", "name": "Edit Fields", "type": "n8n-nodes-base.set", "typeVersion": 3.2, @@ -1726,7 +1741,7 @@ "includeBinary": true } }, - "id": "8133d877-d4cd-4663-931f-2bf35096e0f7", + "id": "84f1ff60-ec64-4cf3-bf03-48aa14ab6fb1", "name": "Edit Fields2", "type": "n8n-nodes-base.set", "typeVersion": 3.2, @@ -1757,7 +1772,7 @@ "jsonBody": "={\n \"number\":\"{{ $node['Edita Mensagem'].json.verificanum }}\",\n \"options\":{\"delay\":3000,\"presence\":\"composing\"},\n \"mediaMessage\":{\"mediatype\":\"image\",\"caption\":\"{{ $json.mensagem }}\",\n \"media\":\"{{ $json[\"img\"] }}\"}\n}\n", "options": {} }, - "id": "5e3a3a4e-4199-432c-8032-c34fc8ab85d2", + "id": "504ff9b6-5ca6-459a-a6b3-64f8b00df1ea", "name": "Envia msg2", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, @@ -1793,7 +1808,7 @@ "jsonBody": "={\n \"number\": \"{{ $node['Edita Mensagem'].json.verificanum }}\",\n \"options\": {\n \"delay\": 3000,\n \"presence\": \"composing\"\n },\n \"mediaMessage\": {\n \"mediatype\": \"document\",\n \"media\": \"{{ $json[\"doc\"] }}\",\n \"caption\": \"{{ $json.mensagem }}\",\n \"fileName\": \"documento.pdf\"\n }\n}", "options": {} }, - "id": "b4fb48f8-26d7-4c6e-96ca-a277ac71de72", + "id": "d2a47109-e433-40ec-9d7b-8b47d920de79", "name": "Envia msg1", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, @@ -1813,7 +1828,7 @@ "height": 221.17684873191945, "width": 313.99126283929667 }, - "id": "745308c0-9ebb-4740-8bfd-849be200873e", + "id": "60a1db9f-6767-462e-91fc-9c6a965d1ebf", "name": "Sticky Note15", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, @@ -1844,7 +1859,7 @@ "includeBinary": true } }, - "id": "2c26ce80-5313-407c-92af-34db8644a4a8", + "id": "2361404e-7c01-43ed-b70c-16f9c3d27d08", "name": "Edit Fields1", "type": "n8n-nodes-base.set", "typeVersion": 3.2, @@ -1875,7 +1890,7 @@ "jsonBody": "={\n \"number\": \"{{ $node['Edita Mensagem'].json.verificanum }}\",\n \"options\": {\n \"delay\": 3000,\n \"presence\": \"composing\"\n },\n \"mediaMessage\": {\n \"mediatype\": \"video\",\n \"media\": \"{{ $json[\"vid\"] }}\",\n \"caption\": \"{{ $json.mensagem }}\"\n }\n}", "options": {} }, - "id": "cbab628b-a85b-419d-8a27-71bebd7fbc1b", + "id": "42082f2b-78c0-4559-9984-88c0560dfce9", "name": "Envia msg3", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, @@ -1889,6 +1904,104 @@ "executeOnce": true, "onError": "continueErrorOutput" }, + { + "parameters": { + "options": {} + }, + "id": "03218fad-17ee-404a-89b6-cedfe477e991", + "name": "Loop Over Items1", + "type": "n8n-nodes-base.splitInBatches", + "typeVersion": 3, + "position": [ + -1900, + 1040 + ] + }, + { + "parameters": {}, + "id": "3b3e3f08-bb24-4645-b7e8-b4fe17c5aa54", + "name": "Replace Me", + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [ + -1200, + 1120 + ] + }, + { + "parameters": { + "content": "## Com Audio", + "height": 221.17684873191945, + "width": 313.99126283929667 + }, + "id": "b0634135-c05a-49dc-9f90-c9cf89369340", + "name": "Sticky Note16", + "type": "n8n-nodes-base.stickyNote", + "typeVersion": 1, + "position": [ + 3080, + 2000 + ] + }, + { + "parameters": { + "fields": { + "values": [ + { + "name": "audio", + "stringValue": "={{ $('Campanha').item.json.audio }}" + } + ] + }, + "options": { + "includeBinary": true + } + }, + "id": "8549a739-0eb6-40ba-8b49-a45e1794632d", + "name": "Edit Fields3", + "type": "n8n-nodes-base.set", + "typeVersion": 3.2, + "position": [ + 3120, + 2060 + ] + }, + { + "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\t\"number\": \"{{ $node['Edita Mensagem'].json.verificanum }}\",\n\t\"options\": {\n\t\t\"delay\": 1200,\n\t\t\"presence\": \"recording\",\n \"encoding\": true\n\t},\n\t\"audioMessage\": {\n\t\t\"audio\": \"{{ $json[\"audio\"] }}\"\n\t}\n}", + "options": {} + }, + "id": "69184b86-5211-436a-a47e-fbf81e1a2e57", + "name": "Envia msg4", + "type": "n8n-nodes-base.httpRequest", + "typeVersion": 4.1, + "position": [ + 3260, + 2060 + ], + "retryOnFail": false, + "maxTries": 2, + "waitBetweenTries": 2000, + "executeOnce": true, + "onError": "continueErrorOutput" + }, { "parameters": { "rules": { @@ -1946,7 +2059,29 @@ "conditions": [ { "id": "a430d20e-500b-4938-a0c4-78d66d8bdff4", - "leftValue": "{{ $('Campanha').item.json.vid }}", + "leftValue": "={{ $('Campanha').item.json.vid }}", + "rightValue": "", + "operator": { + "type": "string", + "operation": "notEmpty", + "singleValue": true + } + } + ], + "combinator": "and" + } + }, + { + "conditions": { + "options": { + "caseSensitive": true, + "leftValue": "", + "typeValidation": "strict" + }, + "conditions": [ + { + "id": "f4341567-4acc-4f79-a728-9739ba529b47", + "leftValue": "={{ $('Campanha').item.json.audio}}", "rightValue": "", "operator": { "type": "string", @@ -1962,7 +2097,7 @@ }, "options": {} }, - "id": "84aecdf7-7175-4edf-ab06-e60f844c1a93", + "id": "341b5707-379b-4ce9-81a6-718998f360b3", "name": "Switch", "type": "n8n-nodes-base.switch", "typeVersion": 3, @@ -1971,30 +2106,6 @@ 1300 ] }, - { - "parameters": { - "options": {} - }, - "id": "fc07aae2-a655-4335-9dbf-e22d73b8a5da", - "name": "Loop Over Items1", - "type": "n8n-nodes-base.splitInBatches", - "typeVersion": 3, - "position": [ - -1900, - 1040 - ] - }, - { - "parameters": {}, - "id": "7771f905-f94c-4b7e-a417-eb895ea6f44a", - "name": "Replace Me", - "type": "n8n-nodes-base.noOp", - "typeVersion": 1, - "position": [ - -1200, - 1120 - ] - }, { "parameters": { "keepOnlySet": true, @@ -2036,8 +2147,8 @@ }, "options": {} }, - "id": "798f8d5d-1da3-4b46-b45d-69743149d0f1", - "name": "Info_Base1", + "id": "c4a614e6-15b9-40bd-a38f-8d8650359728", + "name": "Info_Base", "type": "n8n-nodes-base.set", "typeVersion": 2, "position": [ @@ -2052,7 +2163,7 @@ "main": [ [ { - "node": "Info_Base1", + "node": "Info_Base", "type": "main", "index": 0 } @@ -2774,55 +2885,91 @@ ] ] }, - "Switch": { + "Loop Over Items1": { "main": [ + [], [ { - "node": "Edit Fields2", + "node": "Altera fuso horário", "type": "main", "index": 0 } - ], + ] + ] + }, + "Replace Me": { + "main": [ [ { - "node": "Edit Fields", + "node": "Loop Over Items1", "type": "main", "index": 0 } - ], + ] + ] + }, + "Edit Fields3": { + "main": [ [ { - "node": "Edit Fields1", + "node": "Envia msg4", "type": "main", "index": 0 } ] ] }, - "Loop Over Items1": { + "Envia msg4": { "main": [ - [], [ { - "node": "Altera fuso horário", + "node": "Busca envios", + "type": "main", + "index": 0 + } + ], + [ + { + "node": "Busca falhas", "type": "main", "index": 0 } ] ] }, - "Replace Me": { + "Switch": { "main": [ [ { - "node": "Loop Over Items1", + "node": "Edit Fields2", + "type": "main", + "index": 0 + } + ], + [ + { + "node": "Edit Fields", + "type": "main", + "index": 0 + } + ], + [ + { + "node": "Edit Fields1", + "type": "main", + "index": 0 + } + ], + [ + { + "node": "Edit Fields3", "type": "main", "index": 0 } ] ] }, - "Info_Base1": { + "Info_Base": { "main": [ [ { @@ -2838,12 +2985,12 @@ "settings": { "executionOrder": "v1" }, - "versionId": "6d14a5e9-d9b9-48b6-902f-de43563bbe24", + "versionId": "e3953423-0592-4fff-bc37-bb183ab5a52c", "meta": { "templateCredsSetupCompleted": true, "instanceId": "33738330930e3881dd5571eca013f36ddf8aab20e4ea5c1f2ebaf4a2b4668ac6" }, - "id": "PyZlm6o2EanDylc3", + "id": "ZBZG5TpT624tdZOc", "tags": [ { "createdAt": "2024-06-24T17:54:45.734Z",