Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "meta": {
- "instanceId": "ddf434a3a7e3a72080e1240fd023c236df5ff4ae11430e2caf356b003ef6eacf"
- },
- "nodes": [
- {
- "parameters": {},
- "id": "8e5fd67e-c2db-491e-abd3-dba06ead559a",
- "name": "When clicking \"Execute Workflow\"",
- "type": "n8n-nodes-base.manualTrigger",
- "typeVersion": 1,
- "position": [
- 400,
- 800
- ]
- },
- {
- "parameters": {
- "url": "=https://wappi.pro/api/sync/messages/all/get?profile_id=ca7e2215-3a24&limit=100&offset=0&date={{$now.minus({hours: 12}).toFormat('yyyy-MM-dd')}}T{{$now.minus({hours: 12}).toFormat('HH:mm:ss')}}&order=desc",
- "authentication": "genericCredentialType",
- "genericAuthType": "httpHeaderAuth",
- "options": {}
- },
- "id": "f8c32cb4-6bc3-47ab-bf0c-f1bac04bde1e",
- "name": "HTTP Request",
- "type": "n8n-nodes-base.httpRequest",
- "typeVersion": 4.1,
- "position": [
- 740,
- 540
- ],
- "credentials": {
- "httpHeaderAuth": {
- "id": "CoM0ZpqvVlYvSbR5",
- "name": "WAPPI"
- }
- }
- },
- {
- "parameters": {
- "documentId": {
- "__rl": true,
- "value": "***",
- "mode": "url",
- "__regex": "https:\\/\\/(?:drive|docs)\\.google\\.com(?:\\/.*|)\\/d\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)"
- },
- "sheetName": {
- "__rl": true,
- "value": 2020913753,
- "mode": "list",
- "cachedResultName": "Все заказы",
- "cachedResultUrl": "***"
- },
- "filtersUI": {
- "values": [
- {
- "lookupColumn": "Есть переписка"
- }
- ]
- },
- "options": {
- "returnAllMatches": "returnAllMatches"
- }
- },
- "id": "5c77c8dc-0cda-4367-8125-92f3e789ffb0",
- "name": "Google Sheets",
- "type": "n8n-nodes-base.googleSheets",
- "typeVersion": 4,
- "position": [
- 740,
- 860
- ],
- "credentials": {
- "googleSheetsOAuth2Api": {
- "id": "sWoYZwInHw8Y92qS",
- "name": "Google Sheets account"
- }
- }
- },
- {
- "parameters": {
- "fieldToSplitOut": "messages",
- "options": {}
- },
- "id": "988578af-ceb4-44f4-85ad-384b194b922a",
- "name": "Item Lists1",
- "type": "n8n-nodes-base.itemLists",
- "typeVersion": 3,
- "position": [
- 1200,
- 539.168915272531
- ]
- },
- {
- "parameters": {
- "conditions": {
- "string": [
- {
- "value1": "={{ typeof $json.body }}",
- "value2": "string"
- }
- ]
- }
- },
- "id": "bd94c391-d465-4604-ad2e-89709e8cfafc",
- "name": "Filter1",
- "type": "n8n-nodes-base.filter",
- "typeVersion": 1,
- "position": [
- 1420,
- 540
- ]
- },
- {
- "parameters": {
- "mode": "chooseBranch"
- },
- "id": "98155d82-ad2d-4d5d-a94d-9ed120e2cb5f",
- "name": "Merge",
- "type": "n8n-nodes-base.merge",
- "typeVersion": 2.1,
- "position": [
- 1678,
- 695
- ]
- },
- {
- "parameters": {
- "jsCode": "\nconst orders = $('Orders').first().json ;\n\n// Проходим по всем входящим айтемам и смотрим, есть ли упоминание хотя бы одного заказа в тексте\n// Cм документацию:\n// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find\n// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some\n// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes\n// в нашем случае item.json.body - это текстовая строка, поэтому includes работает даже когда текстовое сообщение содержит много слов.\nfor (const item of $input.all()) {\n item.json.isKeywordPresent = orders.keywords.some(keyword => item.json.body.includes(keyword));\n item.json.firstMatchingKeyword = orders.keywords.find(keyword => item.json.body.includes(keyword));\n}\n\nreturn $input.all();"
- },
- "id": "4df88f6a-332c-4d9c-a987-7d31f9a262f3",
- "name": "Code",
- "type": "n8n-nodes-base.code",
- "typeVersion": 2,
- "position": [
- 2058,
- 696
- ]
- },
- {
- "parameters": {
- "operation": "concatenateItems",
- "fieldsToAggregate": {
- "fieldToAggregate": [
- {
- "fieldToAggregate": "['Номер заказа']",
- "renameField": true,
- "outputFieldName": "keywords"
- }
- ]
- },
- "options": {}
- },
- "id": "7ecc867d-2bcd-4c8a-9db3-d050e2453da9",
- "name": "Orders",
- "type": "n8n-nodes-base.itemLists",
- "typeVersion": 3,
- "position": [
- 1200,
- 840
- ]
- },
- {
- "parameters": {
- "content": "### 1. Разбиваем ответ из wasapi на айтемы\n### 2. Оставляем только текстовые строки (убираем объекты с фотками / аудио)",
- "height": 271.51441017428186,
- "width": 404.61478648230025
- },
- "id": "9c289277-dae9-44f2-a0b8-20bd21102eca",
- "name": "Sticky Note",
- "type": "n8n-nodes-base.stickyNote",
- "typeVersion": 1,
- "position": [
- 1140,
- 426.8989735278228
- ]
- },
- {
- "parameters": {
- "content": "### Собираем все необработанные относительно свежие заказы в массив - он понадобится в ноде Code",
- "height": 270.49121505768534,
- "width": 354.10180987625597
- },
- "id": "0b8077e8-5491-4c1b-b16a-76c8340ef805",
- "name": "Sticky Note1",
- "type": "n8n-nodes-base.stickyNote",
- "typeVersion": 1,
- "position": [
- 1156.0696920583468,
- 752.1393841166937
- ]
- },
- {
- "parameters": {
- "content": "### Здесь Merge просто выдает данные из Input 1, когда на вход поступили данные из двух источников. Это важно, чтобы гарантировать загрузку как сообщений, так и заказов",
- "height": 301.33837021046946,
- "width": 403.5860766324878
- },
- "id": "6907518d-c0c3-4f29-9165-76ac14b395eb",
- "name": "Sticky Note2",
- "type": "n8n-nodes-base.stickyNote",
- "typeVersion": 1,
- "position": [
- 1618,
- 554
- ]
- },
- {
- "parameters": {
- "conditions": {
- "boolean": [
- {
- "value1": "={{ $json.isKeywordPresent }}",
- "value2": true
- }
- ]
- }
- },
- "id": "6bb8cd21-d070-4720-b6f2-ccd57e634957",
- "name": "Matched?",
- "type": "n8n-nodes-base.if",
- "typeVersion": 1,
- "position": [
- 2300,
- 700
- ]
- },
- {
- "parameters": {
- "conditions": {
- "number": [
- {
- "value1": "={{ Interval.fromDateTimes(DateTime.fromSeconds(Number($json[\"Дата\"])),$now).length('hours') }}",
- "operation": "smallerEqual",
- "value2": 12
- },
- {
- "value1": "={{ Interval.fromDateTimes(DateTime.fromSeconds(Number($json[\"Дата\"])),$now).length('hours') }}",
- "operation": "isNotEmpty"
- }
- ]
- }
- },
- "id": "6a1e6bd5-9f99-41fc-885e-e7c465839e50",
- "name": "New Order?",
- "type": "n8n-nodes-base.if",
- "typeVersion": 1,
- "position": [
- 980,
- 860
- ]
- },
- {
- "parameters": {
- "operation": "update",
- "documentId": {
- "__rl": true,
- "value": "***",
- "mode": "url",
- "__regex": "https:\\/\\/(?:drive|docs)\\.google\\.com(?:\\/.*|)\\/d\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)"
- },
- "sheetName": {
- "__rl": true,
- "value": 2020913753,
- "mode": "list",
- "cachedResultName": "Все заказы",
- "cachedResultUrl": "***"
- },
- "columns": {
- "mappingMode": "defineBelow",
- "value": {
- "Есть переписка": "время истекло",
- "ID": "={{ $json.ID }}"
- },
- "matchingColumns": [
- "ID"
- ],
- "schema": [
- {
- "id": "ID",
- "displayName": "ID",
- "required": false,
- "defaultMatch": false,
- "display": true,
- "type": "string",
- "canBeUsedToMatch": true,
- "removed": false
- },
- {
- "id": "Номер заказа",
- "displayName": "Номер заказа",
- "required": false,
- "defaultMatch": false,
- "display": true,
- "type": "string",
- "canBeUsedToMatch": true,
- "removed": true
- },
- {
- "id": "Сайт",
- "displayName": "Сайт",
- "required": false,
- "defaultMatch": false,
- "display": true,
- "type": "string",
- "canBeUsedToMatch": true,
- "removed": true
- },
- {
- "id": "UTM CAMPANING",
- "displayName": "UTM CAMPANING",
- "required": false,
- "defaultMatch": false,
- "display": true,
- "type": "string",
- "canBeUsedToMatch": true,
- "removed": true
- },
- {
- "id": "Есть переписка",
- "displayName": "Есть переписка",
- "required": false,
- "defaultMatch": false,
- "display": true,
- "type": "string",
- "canBeUsedToMatch": true
- },
- {
- "id": "Что заказал",
- "displayName": "Что заказал",
- "required": false,
- "defaultMatch": false,
- "display": true,
- "type": "string",
- "canBeUsedToMatch": true,
- "removed": true
- },
- {
- "id": "Дата",
- "displayName": "Дата",
- "required": false,
- "defaultMatch": false,
- "display": true,
- "type": "string",
- "canBeUsedToMatch": true,
- "removed": true
- },
- {
- "id": "Написал",
- "displayName": "Написал",
- "required": false,
- "defaultMatch": false,
- "display": true,
- "type": "string",
- "canBeUsedToMatch": true,
- "removed": true
- }
- ]
- },
- "options": {}
- },
- "id": "45db79c8-f0de-4400-a436-8946ce020ee9",
- "name": "Google Sheets1",
- "type": "n8n-nodes-base.googleSheets",
- "typeVersion": 4,
- "position": [
- 1200,
- 1160
- ],
- "credentials": {
- "googleSheetsOAuth2Api": {
- "id": "sWoYZwInHw8Y92qS",
- "name": "Google Sheets account"
- }
- }
- },
- {
- "parameters": {
- "content": "### Помечаем устаревшие заказы, чтобы не собирать их повторно",
- "height": 244.28916211333097,
- "width": 344.93109134573206
- },
- "id": "9b8619b7-e2cc-4966-bc55-07996619e33a",
- "name": "Sticky Note3",
- "type": "n8n-nodes-base.stickyNote",
- "typeVersion": 1,
- "position": [
- 1160,
- 1078
- ]
- },
- {
- "parameters": {
- "documentId": {
- "__rl": true,
- "value": "***",
- "mode": "url",
- "__regex": "https:\\/\\/(?:drive|docs)\\.google\\.com(?:\\/.*|)\\/d\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)"
- },
- "sheetName": {
- "__rl": true,
- "value": 2020913753,
- "mode": "list",
- "cachedResultName": "Все заказы",
- "cachedResultUrl": "***"
- },
- "options": {}
- },
- "id": "9fb55a8e-2e19-4a1e-9ec3-7323f81f1dc0",
- "name": "Google Sheets2",
- "type": "n8n-nodes-base.googleSheets",
- "typeVersion": 4,
- "position": [
- 400,
- 1140
- ],
- "credentials": {
- "googleSheetsOAuth2Api": {
- "id": "sWoYZwInHw8Y92qS",
- "name": "Google Sheets account"
- }
- },
- "disabled": true
- },
- {
- "parameters": {
- "content": "## Берем необработанные заказы",
- "height": 274.306455969746,
- "width": 279.9581307401405
- },
- "id": "0b39346d-8714-47d6-ba77-35609bfd7a0b",
- "name": "Sticky Note4",
- "type": "n8n-nodes-base.stickyNote",
- "typeVersion": 1,
- "position": [
- 640,
- 740
- ]
- },
- {
- "parameters": {
- "operation": "update",
- "documentId": {
- "__rl": true,
- "value": "***",
- "mode": "url",
- "__regex": "https:\\/\\/(?:drive|docs)\\.google\\.com(?:\\/.*|)\\/d\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)"
- },
- "sheetName": {
- "__rl": true,
- "value": 2020913753,
- "mode": "list",
- "cachedResultName": "Все заказы",
- "cachedResultUrl": "***"
- },
- "columns": {
- "mappingMode": "defineBelow",
- "value": {
- "Номер заказа": "={{ $json.firstMatchingKeyword }}",
- "Есть переписка": "Писал в WhatsApp",
- "Номер написавшего": "={{ $json.from }} "
- },
- "matchingColumns": [
- "Номер заказа"
- ],
- "schema": [
- {
- "id": "ID",
- "displayName": "ID",
- "required": false,
- "defaultMatch": false,
- "display": true,
- "type": "string",
- "canBeUsedToMatch": true,
- "removed": true
- },
- {
- "id": "Номер заказа",
- "displayName": "Номер заказа",
- "required": false,
- "defaultMatch": false,
- "display": true,
- "type": "string",
- "canBeUsedToMatch": true,
- "removed": false
- },
- {
- "id": "Сайт",
- "displayName": "Сайт",
- "required": false,
- "defaultMatch": false,
- "display": true,
- "type": "string",
- "canBeUsedToMatch": true,
- "removed": true
- },
- {
- "id": "UTM CAMPANING",
- "displayName": "UTM CAMPANING",
- "required": false,
- "defaultMatch": false,
- "display": true,
- "type": "string",
- "canBeUsedToMatch": true,
- "removed": true
- },
- {
- "id": "Есть переписка",
- "displayName": "Есть переписка",
- "required": false,
- "defaultMatch": false,
- "display": true,
- "type": "string",
- "canBeUsedToMatch": true
- },
- {
- "id": "Что заказал",
- "displayName": "Что заказал",
- "required": false,
- "defaultMatch": false,
- "display": true,
- "type": "string",
- "canBeUsedToMatch": true,
- "removed": true
- },
- {
- "id": "Дата",
- "displayName": "Дата",
- "required": false,
- "defaultMatch": false,
- "display": true,
- "type": "string",
- "canBeUsedToMatch": true,
- "removed": true
- },
- {
- "id": "Написал",
- "displayName": "Написал",
- "required": false,
- "defaultMatch": false,
- "display": true,
- "type": "string",
- "canBeUsedToMatch": true,
- "removed": true
- },
- {
- "id": "Номер написавшего",
- "displayName": "Номер написавшего",
- "required": false,
- "defaultMatch": false,
- "display": true,
- "type": "string",
- "canBeUsedToMatch": true,
- "removed": false
- },
- {
- "id": "yclid_direct",
- "displayName": "yclid_direct",
- "required": false,
- "defaultMatch": false,
- "display": true,
- "type": "string",
- "canBeUsedToMatch": true,
- "removed": false
- },
- {
- "id": "yclid_metrika",
- "displayName": "yclid_metrika",
- "required": false,
- "defaultMatch": false,
- "display": true,
- "type": "string",
- "canBeUsedToMatch": true,
- "removed": false
- }
- ]
- },
- "options": {}
- },
- "id": "34227995-437d-4981-9745-188d028f05d2",
- "name": "Google Sheets3",
- "type": "n8n-nodes-base.googleSheets",
- "typeVersion": 4,
- "position": [
- 2578,
- 676
- ],
- "credentials": {
- "googleSheetsOAuth2Api": {
- "id": "sWoYZwInHw8Y92qS",
- "name": "Google Sheets account"
- }
- }
- },
- {
- "parameters": {
- "content": "### Отмечаем наличие переписки по заказам",
- "height": 256.9475958941112,
- "width": 292.4041058887087
- },
- "id": "d0a4ae9a-d457-44ac-b1c8-fab7c58be796",
- "name": "Sticky Note5",
- "type": "n8n-nodes-base.stickyNote",
- "typeVersion": 1,
- "position": [
- 2500,
- 605.5888708806051
- ]
- },
- {
- "parameters": {
- "content": "## Берем макс. 100 сообщений за последние 12 часов",
- "height": 307.059022150189,
- "width": 278.6480280929229
- },
- "id": "8244ae7f-da44-4195-a54b-9e0f57b8e160",
- "name": "Sticky Note6",
- "type": "n8n-nodes-base.stickyNote",
- "typeVersion": 1,
- "position": [
- 640,
- 407.24743381955705
- ]
- },
- {
- "parameters": {
- "rule": {
- "interval": [
- {
- "field": "hours",
- "hoursInterval": 4
- }
- ]
- }
- },
- "id": "d3107ab7-9e07-481a-b6ae-f6e92fdc863c",
- "name": "Schedule Trigger",
- "type": "n8n-nodes-base.scheduleTrigger",
- "typeVersion": 1.1,
- "position": [
- 400,
- 620
- ]
- },
- {
- "parameters": {
- "content": "## Чтобы таймер срабатывал, надо активироваться переключатель",
- "height": 196.84663695299835,
- "width": 829.5461912479739
- },
- "id": "6e8d305d-c1dd-4491-a370-435e5f21d179",
- "name": "Sticky Note7",
- "type": "n8n-nodes-base.stickyNote",
- "typeVersion": 1,
- "position": [
- 1820,
- -100
- ]
- }
- ],
- "connections": {
- "When clicking \"Execute Workflow\"": {
- "main": [
- [
- {
- "node": "HTTP Request",
- "type": "main",
- "index": 0
- },
- {
- "node": "Google Sheets",
- "type": "main",
- "index": 0
- },
- {
- "node": "Google Sheets2",
- "type": "main",
- "index": 0
- }
- ]
- ]
- },
- "HTTP Request": {
- "main": [
- [
- {
- "node": "Item Lists1",
- "type": "main",
- "index": 0
- }
- ]
- ]
- },
- "Google Sheets": {
- "main": [
- [
- {
- "node": "New Order?",
- "type": "main",
- "index": 0
- }
- ]
- ]
- },
- "Item Lists1": {
- "main": [
- [
- {
- "node": "Filter1",
- "type": "main",
- "index": 0
- }
- ]
- ]
- },
- "Filter1": {
- "main": [
- [
- {
- "node": "Merge",
- "type": "main",
- "index": 0
- }
- ]
- ]
- },
- "Merge": {
- "main": [
- [
- {
- "node": "Code",
- "type": "main",
- "index": 0
- }
- ]
- ]
- },
- "Code": {
- "main": [
- [
- {
- "node": "Matched?",
- "type": "main",
- "index": 0
- }
- ]
- ]
- },
- "Orders": {
- "main": [
- [
- {
- "node": "Merge",
- "type": "main",
- "index": 1
- }
- ]
- ]
- },
- "Matched?": {
- "main": [
- [
- {
- "node": "Google Sheets3",
- "type": "main",
- "index": 0
- }
- ]
- ]
- },
- "New Order?": {
- "main": [
- [
- {
- "node": "Orders",
- "type": "main",
- "index": 0
- }
- ],
- [
- {
- "node": "Google Sheets1",
- "type": "main",
- "index": 0
- }
- ]
- ]
- },
- "Schedule Trigger": {
- "main": [
- [
- {
- "node": "HTTP Request",
- "type": "main",
- "index": 0
- },
- {
- "node": "Google Sheets",
- "type": "main",
- "index": 0
- }
- ]
- ]
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment