diff --git a/disparador.json b/disparador.json index 1a6d204..1eb2fbc 100644 --- a/disparador.json +++ b/disparador.json @@ -1,5 +1,5 @@ { - "name": "Disparador 1.0.1", + "name": "Disparador 1.0.2 Sem Credenciais", "nodes": [ { "parameters": { @@ -12,7 +12,7 @@ ] } }, - "id": "6200dded-efbe-4735-a9a8-bf9846e7b17e", + "id": "1cfaf902-48a5-4bdb-8c64-bdb7277a9973", "name": "Schedule Trigger", "type": "n8n-nodes-base.scheduleTrigger", "typeVersion": 1, @@ -33,7 +33,7 @@ ] } }, - "id": "1ae6809d-0caa-457b-8bb6-42d462adcbe9", + "id": "e176bc6b-970f-49e6-97c7-c2c96c32fe5c", "name": "Horario", "type": "n8n-nodes-base.if", "typeVersion": 1, @@ -48,7 +48,7 @@ "height": 456.3958547081602, "width": 1221.218469617133 }, - "id": "4be04fbc-a001-4c70-b392-f5464e6b857a", + "id": "94fd2c2d-5389-4891-8898-2e7acd7d6f12", "name": "Sticky Note5", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, @@ -59,18 +59,18 @@ }, { "parameters": { - "content": "# Disparador de Campanha para ChatWoot\n## Evolution API\n\n\nv 1.0.0", + "content": "# Disparador de Campanha para ChatWoot\n## Evolution API\n\n\nv 1.0.2", "height": 163.30528430133387, "width": 847.4993167412657, "color": 4 }, - "id": "f08c4494-0cb6-40f9-ac6e-085a6c6b28f6", + "id": "f74f9346-3516-482d-bf9b-73337b405a02", "name": "Sticky Note10", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ - -2220, - 540 + -1940, + 520 ] }, { @@ -83,7 +83,7 @@ "includeInputFields": true } }, - "id": "ae7f2e2b-b1e4-45d3-8fb0-43579fe294b7", + "id": "eed9040e-545b-4db7-a72b-b21e32bf02c3", "name": "Altera fuso horário", "type": "n8n-nodes-base.dateTime", "typeVersion": 2, @@ -122,12 +122,16 @@ { "name": "chatwoot_account_id", "value": "=id da tenancia" + }, + { + "name": "recebe_relatorio", + "value": 5511944446666 } ] }, "options": {} }, - "id": "6ece6b5a-556d-4927-9bf6-1ecfc0aaa128", + "id": "cad27d51-bb25-4eba-8276-cc0a12be9378", "name": "Info_Base", "type": "n8n-nodes-base.set", "typeVersion": 2, @@ -140,15 +144,15 @@ "parameters": { "content": "# Busca contatos / Envia campanha\n", "height": 580.894584655091, - "width": 4534.358334878044, + "width": 5367.989846984048, "color": 3 }, - "id": "49aada24-1740-4101-b632-3722ea658927", + "id": "2c84fd88-ae25-46dd-aec5-9d80ce3601e3", "name": "Sticky Note", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ - -166.29942964894326, + -160, 800 ] }, @@ -158,18 +162,24 @@ "query": "select * from campaigns c where campaign_type = 1 and status_envia = 0 LIMIT 1", "additionalFields": {} }, - "id": "b8606e09-dd8a-43b6-9ba3-d71aa29f7f52", + "id": "b547d8cc-b196-4ae8-adc2-1609fb0657a2", "name": "Buscar campanhas", "type": "n8n-nodes-base.postgres", "typeVersion": 1, "position": [ -1820, 1040 - ] + ], + "credentials": { + "postgres": { + "id": "CbrIGpLnj1oilB4h", + "name": "Chatwoot" + } + } }, { "parameters": {}, - "id": "916b3991-01c2-4db9-9cf0-6403fe978c8e", + "id": "ae972dbf-451e-49b3-803e-747619631f1b", "name": "Merge6", "type": "n8n-nodes-base.merge", "typeVersion": 2.1, @@ -180,12 +190,12 @@ }, { "parameters": {}, - "id": "532cf0ce-cc58-4758-86df-f475e331d23c", + "id": "a89c3746-a144-4c94-abb9-a3f737ce590a", "name": "Repetir ação", "type": "n8n-nodes-base.noOp", "typeVersion": 1, "position": [ - 4180, + 5020, 1180 ] }, @@ -193,12 +203,12 @@ "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": "1b9c8ef5-f86c-448f-9044-d440982092c2", + "id": "50c6e128-7677-4171-a0d3-11e87b23a2f0", "name": "Time Randon1", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ - 2040, + 2160, 1080 ] }, @@ -206,26 +216,26 @@ "parameters": { "amount": "={{ $json.waitTime }}" }, - "id": "22f536aa-6927-4623-ae03-5d372e7b4825", + "id": "5c15afd8-1e3c-4e4b-abe8-507afeed47a9", "name": "Tempo de espera1", "type": "n8n-nodes-base.wait", "typeVersion": 1.1, "position": [ - 2220, + 2340, 1080 ], - "webhookId": "6bc26e38-68a7-4962-8f74-5fdff94bfe5b" + "webhookId": "f9a302ed-3741-45c0-a261-64fd40b25f98" }, { "parameters": { "jsCode": "return items.map(item => {\n if (item.json.phone_number) {\n item.json.phone_number = item.json.phone_number.substring(1);\n }\n return item;\n});" }, - "id": "cb126c5a-22dc-487b-b547-7c9ac4c7d066", + "id": "869f1011-62a1-419c-be0d-7f5d95a956a5", "name": "Limpa numero1", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ - 1680, + 1800, 1080 ] }, @@ -235,14 +245,20 @@ "query": "SELECT c.*\nFROM contacts c\nJOIN taggings tg ON c.id = tg.taggable_id\nWHERE tg.tag_id = {{ $json.etiqueta }};", "options": {} }, - "id": "f038636a-84a9-478f-8e22-409cbe7d5807", + "id": "655b49c8-e120-4730-bc26-a4394513eddd", "name": "Busca contatos", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, "position": [ -120, 1040 - ] + ], + "credentials": { + "postgres": { + "id": "CbrIGpLnj1oilB4h", + "name": "Chatwoot" + } + } }, { "parameters": { @@ -255,7 +271,7 @@ ] } }, - "id": "5f8c9e2c-2e37-4cfb-92e1-20a0a55efbf4", + "id": "0942fd3c-8751-44ba-81a8-b81b1e5f5588", "name": "IF6", "type": "n8n-nodes-base.if", "typeVersion": 1, @@ -270,7 +286,7 @@ "include": "allOtherFields", "options": {} }, - "id": "d49e9ca5-2780-42b7-8f99-d8c72daadbff", + "id": "91186821-d8fb-4cdb-b3d3-e6efcd29fbe8", "name": "Item Lists1", "type": "n8n-nodes-base.itemLists", "typeVersion": 3, @@ -286,7 +302,7 @@ "width": 728.217926985971, "color": 2 }, - "id": "90ab96a1-8593-4606-9784-a290d5892f3e", + "id": "bfcf2d30-5441-48dd-88b3-4de2804d2d0f", "name": "Sticky Note2", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, @@ -309,12 +325,12 @@ }, "options": {} }, - "id": "8b453827-03ff-472e-aaf3-868640d0f936", + "id": "572534d8-5eb5-4bc3-bc0b-edc7d813a389", "name": "numero editado1", "type": "n8n-nodes-base.set", "typeVersion": 3.3, "position": [ - 1860, + 1980, 1080 ] }, @@ -322,7 +338,7 @@ "parameters": { "options": {} }, - "id": "206a9d0d-bd00-4a83-a64d-78a1e52fd80c", + "id": "c26b46a4-5b64-4f53-a1ad-6820bafcba90", "name": "Loop Over Items", "type": "n8n-nodes-base.splitInBatches", "typeVersion": 3, @@ -358,12 +374,12 @@ }, "options": {} }, - "id": "935720e3-47b6-4d90-8b11-a3a4c41dc27a", + "id": "c6f7a23c-c99b-40fa-b692-5327c364d2fe", "name": "If", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ - 1240, + 1360, 1080 ] }, @@ -375,14 +391,20 @@ "queryReplacement": "={{ $('Info_Base').item.json.chatwoot_account_id }}" } }, - "id": "63aad44f-a567-4d10-863b-64329a76c5b4", + "id": "38d9025e-2cf1-4be5-9fab-3917a9bdf7d9", "name": "Conta Disparo", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, "position": [ - 1080, + 1200, 1080 - ] + ], + "credentials": { + "postgres": { + "id": "CbrIGpLnj1oilB4h", + "name": "Chatwoot" + } + } }, { "parameters": { @@ -391,12 +413,12 @@ "width": 653.3075078799386, "color": 4 }, - "id": "8974cf02-bc83-4e65-b92c-44039bc982dd", + "id": "8bc79b4d-0ae2-4cb0-ad7c-3234ca798f29", "name": "Sticky Note1", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ - 740, + 860, 1020 ] }, @@ -407,12 +429,12 @@ "width": 911.0441675732073, "color": 4 }, - "id": "4511b20c-b9a9-43a3-8e4f-dae5a32b7fe9", + "id": "0a00a30f-fc3f-4252-886d-a4f7cd0d51b6", "name": "Sticky Note3", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ - 1460, + 1580, 1020 ] }, @@ -424,14 +446,20 @@ "queryReplacement": "=" } }, - "id": "61597641-77cc-46dd-b63a-c5425b701daf", + "id": "4a8eadd6-dda1-41df-8766-5b8eef14c03f", "name": "Limitador", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, "position": [ - 760, + 880, 1080 - ] + ], + "credentials": { + "postgres": { + "id": "CbrIGpLnj1oilB4h", + "name": "Chatwoot" + } + } }, { "parameters": { @@ -440,13 +468,13 @@ "width": 374.41687218580967, "color": 2 }, - "id": "a598f9d9-7c75-461c-86e0-b94fd5083e8e", + "id": "ba679c99-6c1e-4998-ae5a-1dd40351ea17", "name": "Sticky Note6", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ - 3020, - 860 + 3260, + 840 ] }, { @@ -456,13 +484,13 @@ "width": 382.34450749002, "color": 2 }, - "id": "69e3aa34-cb8e-4005-890c-9c30dcb5d02c", + "id": "da0aada0-5e1f-41f4-8857-ad03d8442984", "name": "Sticky Note7", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ - 3020, - 1100 + 3260, + 1080 ] }, { @@ -473,14 +501,20 @@ "queryReplacement": "=" } }, - "id": "7ddb1fe0-1cca-40f5-8c0f-25358d6c7934", + "id": "8858e0a6-48de-4eb3-999c-47f7d8eea08c", "name": "Busca falhas", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, "position": [ - 3060, - 920 - ] + 3300, + 900 + ], + "credentials": { + "postgres": { + "id": "CbrIGpLnj1oilB4h", + "name": "Chatwoot" + } + } }, { "parameters": { @@ -488,14 +522,20 @@ "query": "UPDATE accounts\nSET limite_disparo ={{ $json.limite_disparo -1 }}\nWHERE id ={{ $('Info_Base').item.json.chatwoot_account_id }};", "options": {} }, - "id": "396e1190-ef6b-4295-ae34-695d77358173", + "id": "9a1d532c-bce2-4943-9abb-917e42d26ff3", "name": "Subtrair", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, "position": [ - 920, + 1040, 1080 - ] + ], + "credentials": { + "postgres": { + "id": "CbrIGpLnj1oilB4h", + "name": "Chatwoot" + } + } }, { "parameters": { @@ -503,14 +543,20 @@ "query": "UPDATE campaigns\nSET falhou = {{ $json.falhou +1 }}\nWHERE id = {{ $('IF6').item.json.id }};", "options": {} }, - "id": "a8be1590-768a-415c-bb39-296a22076aaf", + "id": "f34f45c6-6133-42de-b207-a535fa38bd93", "name": "Adiciona falhas", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, "position": [ - 3220, - 920 - ] + 3460, + 900 + ], + "credentials": { + "postgres": { + "id": "CbrIGpLnj1oilB4h", + "name": "Chatwoot" + } + } }, { "parameters": { @@ -518,14 +564,20 @@ "query": "SELECT enviou\nFROM campaigns\nWHERE id = {{ $('IF6').item.json.id }};", "options": {} }, - "id": "25e075c0-b46e-4762-9dcb-af0fea44e389", + "id": "c3218f23-1809-42a6-bca7-3f5fa1e102e2", "name": "Busca envios", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, "position": [ - 3060, - 1160 - ] + 3300, + 1140 + ], + "credentials": { + "postgres": { + "id": "CbrIGpLnj1oilB4h", + "name": "Chatwoot" + } + } }, { "parameters": { @@ -565,7 +617,7 @@ }, "options": {} }, - "id": "3164c4b6-18de-425e-acc9-827495522430", + "id": "a92126df-dc73-41da-9e83-dc91c83e1e85", "name": "Campanha", "type": "n8n-nodes-base.set", "typeVersion": 3.3, @@ -577,16 +629,16 @@ { "parameters": { "content": "# Relatorio da campanha", - "height": 272.1581724156961, - "width": 500.60281237764696 + "height": 260.9879652172832, + "width": 449.5390080420451 }, - "id": "0015f320-dc25-42f8-aca6-1db2386598a7", + "id": "7d85b02a-be13-4eea-8fbd-ee14eac437b1", "name": "Sticky Note8", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ - 460, - 460 + 1000, + 520 ] }, { @@ -597,14 +649,20 @@ "queryReplacement": "=" } }, - "id": "2ce2d02d-4b1c-448d-966c-664989b2770b", + "id": "2df586b4-262a-4cd8-be77-723e5e62ef65", "name": "Resumo relatorio", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, "position": [ - 600, - 560 - ] + 1040, + 620 + ], + "credentials": { + "postgres": { + "id": "CbrIGpLnj1oilB4h", + "name": "Chatwoot" + } + } }, { "parameters": { @@ -628,13 +686,13 @@ "jsonBody": "={\"number\":\"{{ $('numero editado1').item.json.numberdispara }}@s.whatsapp.net\",\"options\":{\"delay\":3000,\"presence\":\"composing\"},\"mediaMessage\":{\"mediatype\":\"image\",\"caption\":\"{{ $json.mensagem }}\",\"media\":\"{{ $json[\"anexo\"] }}\"}}", "options": {} }, - "id": "2d622329-4c3d-4256-bfec-1ca0ffd93d88", + "id": "03a42d74-63d6-438e-8db4-50679c2b6ba9", "name": "Envia msg2", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, "position": [ - 2820, - 1160 + 3060, + 1140 ], "retryOnFail": false, "maxTries": 2, @@ -664,13 +722,13 @@ "jsonBody": "={\"number\":\"{{ $('numero editado1').item.json.numberdispara }}@s.whatsapp.net\",\"options\":{\"delay\":3000,\"presence\":\"composing\"},\"textMessage\":{\"text\":\"{{ $('Edita Mensagem').item.json.var_msg }}\"}} ", "options": {} }, - "id": "0d90b729-8882-44d1-9ed5-c6764fe47f47", + "id": "0a339681-e0b3-48aa-88c1-861e1ce220c3", "name": "Envia msg", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, "position": [ - 2740, - 880 + 2980, + 860 ], "retryOnFail": false, "maxTries": 2, @@ -681,16 +739,16 @@ { "parameters": { "content": "# Limite exedido", - "height": 272.1581724156961, + "height": 253.00924578984532, "width": 421.4323377312729 }, - "id": "80d33d2f-fd6e-4ef1-a7af-3a07924735d6", + "id": "8b41f4fa-9738-4dea-9cab-325b1b427aeb", "name": "Sticky Note9", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ - 1080, - 460 + 1000, + 220 ] }, { @@ -712,16 +770,16 @@ }, "sendBody": true, "specifyBody": "json", - "jsonBody": "={\"number\":\"5511988884444@s.whatsapp.net\",\"options\":{\"delay\":3000,\"presence\":\"composing\"},\"textMessage\":{\"text\":\"📢 Campanha *{{ $('Buscar campanhas').item.json.title }}* enviada com sucesso! 📢\\n\\n✔️ Total de envios: {{ $json[\"enviou\"] }}\\n❌ Número de falhas: {{ $json[\"falhou\"] }}\\n\\nObrigado por utilizar nossos serviços!\"}}", + "jsonBody": "={\"number\":\"{{ $('Info_Base').item.json[\"recebe_relatorio\"] }}@s.whatsapp.net\",\"options\":{\"delay\":3000,\"presence\":\"composing\"},\"textMessage\":{\"text\":\"📢 Campanha *{{ $('Buscar campanhas').item.json.title }}* enviada com sucesso! 📢\\n\\n✔️ Total de envios: {{ $json[\"enviou\"] }}\\n❌ Número de falhas: {{ $json[\"falhou\"] }}\\n\\nObrigado por utilizar nossos serviços!\"}}", "options": {} }, - "id": "5af8d13b-ec07-4678-a211-c56d4f0e3101", + "id": "abcf3afa-fa25-4137-9835-2e455b0e8070", "name": "Envia relatorio", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, "position": [ - 760, - 560 + 1200, + 620 ], "retryOnFail": false, "maxTries": 2, @@ -736,14 +794,20 @@ "queryReplacement": "=" } }, - "id": "8f36408b-d688-49e0-a8e1-ce72ad8f3625", + "id": "a8536018-b700-40a3-9fc5-71f3dbe4a109", "name": "Resumo relatorio1", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, "position": [ - 1120, - 560 - ] + 1040, + 300 + ], + "credentials": { + "postgres": { + "id": "CbrIGpLnj1oilB4h", + "name": "Chatwoot" + } + } }, { "parameters": { @@ -764,16 +828,16 @@ }, "sendBody": true, "specifyBody": "json", - "jsonBody": "={\"number\":\"5511988884444@s.whatsapp.net\",\"options\":{\"delay\":3000,\"presence\":\"composing\"},\"textMessage\":{\"text\":\"⚠️ *Atenção!* Algumas mensagens da campanha podem não ter sido enviadas. ⚠️\\n\\n✔️ Total de envios: {{ $json[\"enviou\"] }}\\n❌ Número de falhas: {{ $json[\"falhou\"] }}\\n\\nO limite de disparos diários foi excedido. Por favor, verifique os envios ou entre em contato com o suporte para mais informações.\\n\\nObrigado pela compreensão!\"}}", + "jsonBody": "={\"number\":\"{{ $('Info_Base').item.json[\"recebe_relatorio\"] }}@s.whatsapp.net\",\"options\":{\"delay\":3000,\"presence\":\"composing\"},\"textMessage\":{\"text\":\"⚠️ *Atenção!* Algumas mensagens da campanha podem não ter sido enviadas. ⚠️\\n\\n✔️ Total de envios: {{ $json[\"enviou\"] }}\\n❌ Número de falhas: {{ $json[\"falhou\"] }}\\n\\nO limite de disparos diários foi excedido. Por favor, verifique os envios ou entre em contato com o suporte para mais informações.\\n\\nObrigado pela compreensão!\"}}", "options": {} }, - "id": "e6ebb80c-df69-4711-9b39-990c5bb547d2", + "id": "dd241b51-b0ab-4923-bf0d-4922970d0d98", "name": "Envia relatorio1", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.1, "position": [ - 1280, - 560 + 1200, + 300 ], "retryOnFail": false, "maxTries": 2, @@ -786,7 +850,7 @@ "query": "=UPDATE campaigns SET status_envia = 1 WHERE id = {{ $json.id }}", "additionalFields": {} }, - "id": "586aa133-ff10-4a08-8658-4caf40e6de71", + "id": "42c6f5d3-821d-447a-b391-0d32e80cccfe", "name": "Update Campanha", "type": "n8n-nodes-base.postgres", "typeVersion": 1, @@ -794,7 +858,13 @@ -1160, 900 ], - "alwaysOutputData": true + "alwaysOutputData": true, + "credentials": { + "postgres": { + "id": "CbrIGpLnj1oilB4h", + "name": "Chatwoot" + } + } }, { "parameters": { @@ -810,12 +880,12 @@ }, "options": {} }, - "id": "c8072727-522c-475a-8950-7bb13d7373e5", + "id": "47d44b28-244c-4500-ad28-e46e4d198bd7", "name": "contato1", "type": "n8n-nodes-base.set", "typeVersion": 3.3, "position": [ - 1520, + 1640, 1080 ] }, @@ -825,14 +895,20 @@ "query": "UPDATE campaigns\nSET enviou = {{ $json.enviou +1 }}\nWHERE id = {{ $('IF6').item.json.id }};", "options": {} }, - "id": "c74887ec-9e10-40a7-9787-6f29aed9e7b8", + "id": "7b8a379b-6ee9-40f8-bc57-9ee2a5640d55", "name": "Adiciona envios", "type": "n8n-nodes-base.postgres", "typeVersion": 2.4, "position": [ - 3220, - 1160 - ] + 3460, + 1140 + ], + "credentials": { + "postgres": { + "id": "CbrIGpLnj1oilB4h", + "name": "Chatwoot" + } + } }, { "parameters": { @@ -840,12 +916,12 @@ "height": 199.63817652105178, "width": 313.99126283929667 }, - "id": "ea0f760a-425a-41ae-a852-46ecdd63e332", + "id": "bf436bd4-0342-458e-9e40-51463188daca", "name": "Sticky Note4", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ - 2640, + 2880, 820 ] }, @@ -855,13 +931,13 @@ "height": 216.81471968017428, "width": 313.99126283929667 }, - "id": "bb1da829-8a2e-477d-a1e4-cb5f7a641528", + "id": "55eb5070-a91b-4002-95c0-39a2e0357e39", "name": "Sticky Note11", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ - 2640, - 1100 + 2880, + 1080 ] }, { @@ -888,12 +964,12 @@ }, "options": {} }, - "id": "396ed791-bce3-44a5-bb27-df0b2085161a", + "id": "f7db5804-7058-4d8f-80da-91d16fb26eec", "name": "If1", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ - 2440, + 2560, 1080 ] }, @@ -921,7 +997,7 @@ }, "options": {} }, - "id": "7620299b-abd7-4ec0-8d04-ae34719bbe2d", + "id": "936d63a6-072a-4ca6-810a-d574b94eaa8a", "name": "If2", "type": "n8n-nodes-base.if", "typeVersion": 2, @@ -944,7 +1020,7 @@ }, "options": {} }, - "id": "e8441037-7278-448b-ad5e-031afab0a80c", + "id": "9eac3249-1284-4fcf-b386-94d9f48fbcdb", "name": "Edita Mensagem", "type": "n8n-nodes-base.set", "typeVersion": 3.3, @@ -975,13 +1051,13 @@ "includeBinary": true } }, - "id": "912a1ef5-8816-47f7-ade3-ba6fa3c477f7", + "id": "6a9e7e86-402d-472f-be69-058df1bd7f0f", "name": "Edit Fields2", "type": "n8n-nodes-base.set", "typeVersion": 3.2, "position": [ - 2680, - 1160 + 2920, + 1140 ] }, { @@ -998,13 +1074,13 @@ }, "options": {} }, - "id": "2a55749c-7ff1-4743-95e4-bdea0edaabe3", + "id": "0c270b9b-d118-43b9-bf07-26e2f4370a7b", "name": "Abre conversa de contato existente", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ - 3680, - 1040 + 3920, + 1020 ] }, { @@ -1030,19 +1106,19 @@ }, "options": {} }, - "id": "bd0f4c9f-f04f-4fdf-806d-128f7cb95e6b", + "id": "bdd3c7b9-927a-4911-972f-6ef1e6a5e62e", "name": "Busca Contato Existe", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ - 3520, - 1040 + 3760, + 1020 ] }, { "parameters": { "method": "POST", - "url": "={{ $('Info_Base').item.json.chatwoot_url }}/api/v1/accounts/{{ $('Info_Base').item.json.chatwoot_account_id }}/conversations/{{ $('Abre conversa de contato existente').item.json.payload[0].id }}/toggle_status", + "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": [ @@ -1057,13 +1133,57 @@ "jsonBody": "={\n\"status\": \"resolved\"\n}", "options": {} }, - "id": "53f7edfd-9a71-4938-8da8-e78c347dd61d", + "id": "78af808f-b2de-4fc2-a8b9-ca9289a01627", "name": "Resolve Conversa", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ - 4000, - 1040 + 4820, + 1020 + ] + }, + { + "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": "bde0d6f2-77c3-446f-ae16-2352d3fe529f", + "name": "Sticky Note12", + "type": "n8n-nodes-base.stickyNote", + "typeVersion": 1, + "position": [ + 3720, + 920 + ] + }, + { + "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": "8191c8ee-6717-4701-b62a-859fe228f47d", + "name": "Salva conversa", + "type": "n8n-nodes-base.set", + "typeVersion": 3.3, + "position": [ + 4340, + 1020 ] }, { @@ -1076,52 +1196,161 @@ }, "conditions": [ { - "id": "f36a7740-f515-41a5-8a06-0d8438005e11", + "id": "493b5963-2314-4179-a065-3a9aca90749e", "leftValue": "={{ $json.payload[0].status }}", - "rightValue": "open", + "rightValue": "", "operator": { "type": "string", - "operation": "equals", - "name": "filter.operator.equals" - } - }, - { - "id": "a9ee241b-e05e-4ffe-ba4f-98076524b5a4", - "leftValue": "={{ $json.payload[0].status }}", - "rightValue": "pending", - "operator": { - "type": "string", - "operation": "equals", - "name": "filter.operator.equals" + "operation": "exists", + "singleValue": true } } ], - "combinator": "or" + "combinator": "and" }, "options": {} }, - "id": "273480c3-7cc1-4c2b-a60d-4a1e9146778d", + "id": "bad2c170-66d4-4be7-86fa-d1a9df44c14c", "name": "If3", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ - 3840, - 1040 + 4080, + 1020 ] }, { "parameters": { - "content": "## Resolve Conversa\n** Se a conversa estiver aberta mantém / Se não houver conversa aberta ele fecha", - "height": 331.5360284004761, - "width": 639.1511430088007 + "amount": 2 }, - "id": "8410d7fa-4d01-4b6d-85d6-4816ba16a48d", - "name": "Sticky Note12", + "id": "e05be943-091c-44f4-ba9a-a2ba4fdfe4f4", + "name": "Wait", + "type": "n8n-nodes-base.wait", + "typeVersion": 1.1, + "position": [ + 4500, + 1020 + ], + "webhookId": "fce65e4c-ac22-4bea-8e0f-c4ac42fdc82c" + }, + { + "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": "cc7674c0-04e4-4da0-8ad2-4320645a5d56", + "name": "Busca conversa", + "type": "n8n-nodes-base.httpRequest", + "typeVersion": 3, + "position": [ + 4660, + 1020 + ] + }, + { + "parameters": { + "content": "# Resolve Conversa", + "height": 246.1701698163285, + "width": 547.9785698991002 + }, + "id": "cb239743-14e4-46ac-ae82-2d46771fcc2a", + "name": "Sticky Note13", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ - 3480, - 940 + 1560, + 400 + ] + }, + { + "parameters": { + "url": "={{ $('Info_Base').item.json.chatwoot_url }}/api/v1/accounts/{{ $('Info_Base').item.json.chatwoot_account_id }}/contacts/{{ $json.payload[0].id }}/conversations", + "sendHeaders": true, + "headerParameters": { + "parameters": [ + { + "name": "api_access_token", + "value": "={{ $('Info_Base').item.json.chatwoot_token }}" + } + ] + }, + "options": {} + }, + "id": "334ec436-ffd4-46b0-b748-dbe84219ff59", + "name": "Seleciona conversa", + "type": "n8n-nodes-base.httpRequest", + "typeVersion": 3, + "position": [ + 1760, + 480 + ] + }, + { + "parameters": { + "url": "={{ $('Info_Base').item.json.chatwoot_url }}/api/v1/accounts/{{ $('Info_Base').item.json.chatwoot_account_id }}/contacts/search", + "sendQuery": true, + "queryParameters": { + "parameters": [ + { + "name": "q", + "value": "=+{{ $('Info_Base').item.json[\"recebe_relatorio\"] }}" + } + ] + }, + "sendHeaders": true, + "headerParameters": { + "parameters": [ + { + "name": "api_access_token", + "value": "={{ $('Info_Base').item.json.chatwoot_token }}" + } + ] + }, + "options": {} + }, + "id": "b514eab9-5e16-4d26-a39a-2fe628998bbc", + "name": "Busca Contato do Relatorio", + "type": "n8n-nodes-base.httpRequest", + "typeVersion": 3, + "position": [ + 1600, + 480 + ] + }, + { + "parameters": { + "method": "POST", + "url": "={{ $('Info_Base').item.json.chatwoot_url }}/api/v1/accounts/{{ $('Info_Base').item.json.chatwoot_account_id }}/conversations/{{ $json.payload[0].id }}/toggle_status", + "sendHeaders": true, + "headerParameters": { + "parameters": [ + { + "name": "api_access_token", + "value": "={{ $('Info_Base').item.json[\"chatwoot_token\"] }}" + } + ] + }, + "sendBody": true, + "specifyBody": "json", + "jsonBody": "={\n\"status\": \"resolved\"\n}", + "options": {} + }, + "id": "8705077d-644a-49b2-8b54-d2c5b8ad3bdd", + "name": "Fecha Conversa", + "type": "n8n-nodes-base.httpRequest", + "typeVersion": 3, + "position": [ + 1920, + 480 ] } ], @@ -1526,6 +1755,28 @@ ] ] }, + "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": [ [ @@ -1537,11 +1788,11 @@ ] ] }, - "Busca Contato Existe": { + "Salva conversa": { "main": [ [ { - "node": "Abre conversa de contato existente", + "node": "Wait", "type": "main", "index": 0 } @@ -1557,6 +1808,28 @@ "index": 0 } ], + [ + { + "node": "Salva conversa", + "type": "main", + "index": 0 + } + ] + ] + }, + "Wait": { + "main": [ + [ + { + "node": "Busca conversa", + "type": "main", + "index": 0 + } + ] + ] + }, + "Busca conversa": { + "main": [ [ { "node": "Resolve Conversa", @@ -1565,18 +1838,62 @@ } ] ] + }, + "Envia relatorio1": { + "main": [ + [ + { + "node": "Busca Contato do Relatorio", + "type": "main", + "index": 0 + } + ] + ] + }, + "Busca Contato do Relatorio": { + "main": [ + [ + { + "node": "Seleciona conversa", + "type": "main", + "index": 0 + } + ] + ] + }, + "Seleciona conversa": { + "main": [ + [ + { + "node": "Fecha Conversa", + "type": "main", + "index": 0 + } + ] + ] + }, + "Envia relatorio": { + "main": [ + [ + { + "node": "Busca Contato do Relatorio", + "type": "main", + "index": 0 + } + ] + ] } }, "active": false, "settings": { "executionOrder": "v1" }, - "versionId": "4098f114-0f4b-4a55-8290-b716149185bd", + "versionId": "0400ac95-a2bf-436f-b0d6-44f231242a45", "meta": { "templateCredsSetupCompleted": true, "instanceId": "33738330930e3881dd5571eca013f36ddf8aab20e4ea5c1f2ebaf4a2b4668ac6" }, - "id": "LLTG80erAd39vd1f", + "id": "1A7lYGzOEvgRfL3A", "tags": [ { "createdAt": "2024-06-24T17:54:45.734Z",