VKirill

n8n - WhatsApp

Aug 24th, 2023 (edited)
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.64 KB | None | 0 0
  1. {
  2. "meta": {
  3. "instanceId": "ddf434a3a7e3a72080e1240fd023c236df5ff4ae11430e2caf356b003ef6eacf"
  4. },
  5. "nodes": [
  6. {
  7. "parameters": {},
  8. "id": "8e5fd67e-c2db-491e-abd3-dba06ead559a",
  9. "name": "When clicking \"Execute Workflow\"",
  10. "type": "n8n-nodes-base.manualTrigger",
  11. "typeVersion": 1,
  12. "position": [
  13. 400,
  14. 800
  15. ]
  16. },
  17. {
  18. "parameters": {
  19. "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",
  20. "authentication": "genericCredentialType",
  21. "genericAuthType": "httpHeaderAuth",
  22. "options": {}
  23. },
  24. "id": "f8c32cb4-6bc3-47ab-bf0c-f1bac04bde1e",
  25. "name": "HTTP Request",
  26. "type": "n8n-nodes-base.httpRequest",
  27. "typeVersion": 4.1,
  28. "position": [
  29. 740,
  30. 540
  31. ],
  32. "credentials": {
  33. "httpHeaderAuth": {
  34. "id": "CoM0ZpqvVlYvSbR5",
  35. "name": "WAPPI"
  36. }
  37. }
  38. },
  39. {
  40. "parameters": {
  41. "documentId": {
  42. "__rl": true,
  43. "value": "***",
  44. "mode": "url",
  45. "__regex": "https:\\/\\/(?:drive|docs)\\.google\\.com(?:\\/.*|)\\/d\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)"
  46. },
  47. "sheetName": {
  48. "__rl": true,
  49. "value": 2020913753,
  50. "mode": "list",
  51. "cachedResultName": "Все заказы",
  52. "cachedResultUrl": "***"
  53. },
  54. "filtersUI": {
  55. "values": [
  56. {
  57. "lookupColumn": "Есть переписка"
  58. }
  59. ]
  60. },
  61. "options": {
  62. "returnAllMatches": "returnAllMatches"
  63. }
  64. },
  65. "id": "5c77c8dc-0cda-4367-8125-92f3e789ffb0",
  66. "name": "Google Sheets",
  67. "type": "n8n-nodes-base.googleSheets",
  68. "typeVersion": 4,
  69. "position": [
  70. 740,
  71. 860
  72. ],
  73. "credentials": {
  74. "googleSheetsOAuth2Api": {
  75. "id": "sWoYZwInHw8Y92qS",
  76. "name": "Google Sheets account"
  77. }
  78. }
  79. },
  80. {
  81. "parameters": {
  82. "fieldToSplitOut": "messages",
  83. "options": {}
  84. },
  85. "id": "988578af-ceb4-44f4-85ad-384b194b922a",
  86. "name": "Item Lists1",
  87. "type": "n8n-nodes-base.itemLists",
  88. "typeVersion": 3,
  89. "position": [
  90. 1200,
  91. 539.168915272531
  92. ]
  93. },
  94. {
  95. "parameters": {
  96. "conditions": {
  97. "string": [
  98. {
  99. "value1": "={{ typeof $json.body }}",
  100. "value2": "string"
  101. }
  102. ]
  103. }
  104. },
  105. "id": "bd94c391-d465-4604-ad2e-89709e8cfafc",
  106. "name": "Filter1",
  107. "type": "n8n-nodes-base.filter",
  108. "typeVersion": 1,
  109. "position": [
  110. 1420,
  111. 540
  112. ]
  113. },
  114. {
  115. "parameters": {
  116. "mode": "chooseBranch"
  117. },
  118. "id": "98155d82-ad2d-4d5d-a94d-9ed120e2cb5f",
  119. "name": "Merge",
  120. "type": "n8n-nodes-base.merge",
  121. "typeVersion": 2.1,
  122. "position": [
  123. 1678,
  124. 695
  125. ]
  126. },
  127. {
  128. "parameters": {
  129. "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();"
  130. },
  131. "id": "4df88f6a-332c-4d9c-a987-7d31f9a262f3",
  132. "name": "Code",
  133. "type": "n8n-nodes-base.code",
  134. "typeVersion": 2,
  135. "position": [
  136. 2058,
  137. 696
  138. ]
  139. },
  140. {
  141. "parameters": {
  142. "operation": "concatenateItems",
  143. "fieldsToAggregate": {
  144. "fieldToAggregate": [
  145. {
  146. "fieldToAggregate": "['Номер заказа']",
  147. "renameField": true,
  148. "outputFieldName": "keywords"
  149. }
  150. ]
  151. },
  152. "options": {}
  153. },
  154. "id": "7ecc867d-2bcd-4c8a-9db3-d050e2453da9",
  155. "name": "Orders",
  156. "type": "n8n-nodes-base.itemLists",
  157. "typeVersion": 3,
  158. "position": [
  159. 1200,
  160. 840
  161. ]
  162. },
  163. {
  164. "parameters": {
  165. "content": "### 1. Разбиваем ответ из wasapi на айтемы\n### 2. Оставляем только текстовые строки (убираем объекты с фотками / аудио)",
  166. "height": 271.51441017428186,
  167. "width": 404.61478648230025
  168. },
  169. "id": "9c289277-dae9-44f2-a0b8-20bd21102eca",
  170. "name": "Sticky Note",
  171. "type": "n8n-nodes-base.stickyNote",
  172. "typeVersion": 1,
  173. "position": [
  174. 1140,
  175. 426.8989735278228
  176. ]
  177. },
  178. {
  179. "parameters": {
  180. "content": "### Собираем все необработанные относительно свежие заказы в массив - он понадобится в ноде Code",
  181. "height": 270.49121505768534,
  182. "width": 354.10180987625597
  183. },
  184. "id": "0b8077e8-5491-4c1b-b16a-76c8340ef805",
  185. "name": "Sticky Note1",
  186. "type": "n8n-nodes-base.stickyNote",
  187. "typeVersion": 1,
  188. "position": [
  189. 1156.0696920583468,
  190. 752.1393841166937
  191. ]
  192. },
  193. {
  194. "parameters": {
  195. "content": "### Здесь Merge просто выдает данные из Input 1, когда на вход поступили данные из двух источников. Это важно, чтобы гарантировать загрузку как сообщений, так и заказов",
  196. "height": 301.33837021046946,
  197. "width": 403.5860766324878
  198. },
  199. "id": "6907518d-c0c3-4f29-9165-76ac14b395eb",
  200. "name": "Sticky Note2",
  201. "type": "n8n-nodes-base.stickyNote",
  202. "typeVersion": 1,
  203. "position": [
  204. 1618,
  205. 554
  206. ]
  207. },
  208. {
  209. "parameters": {
  210. "conditions": {
  211. "boolean": [
  212. {
  213. "value1": "={{ $json.isKeywordPresent }}",
  214. "value2": true
  215. }
  216. ]
  217. }
  218. },
  219. "id": "6bb8cd21-d070-4720-b6f2-ccd57e634957",
  220. "name": "Matched?",
  221. "type": "n8n-nodes-base.if",
  222. "typeVersion": 1,
  223. "position": [
  224. 2300,
  225. 700
  226. ]
  227. },
  228. {
  229. "parameters": {
  230. "conditions": {
  231. "number": [
  232. {
  233. "value1": "={{ Interval.fromDateTimes(DateTime.fromSeconds(Number($json[\"Дата\"])),$now).length('hours') }}",
  234. "operation": "smallerEqual",
  235. "value2": 12
  236. },
  237. {
  238. "value1": "={{ Interval.fromDateTimes(DateTime.fromSeconds(Number($json[\"Дата\"])),$now).length('hours') }}",
  239. "operation": "isNotEmpty"
  240. }
  241. ]
  242. }
  243. },
  244. "id": "6a1e6bd5-9f99-41fc-885e-e7c465839e50",
  245. "name": "New Order?",
  246. "type": "n8n-nodes-base.if",
  247. "typeVersion": 1,
  248. "position": [
  249. 980,
  250. 860
  251. ]
  252. },
  253. {
  254. "parameters": {
  255. "operation": "update",
  256. "documentId": {
  257. "__rl": true,
  258. "value": "***",
  259. "mode": "url",
  260. "__regex": "https:\\/\\/(?:drive|docs)\\.google\\.com(?:\\/.*|)\\/d\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)"
  261. },
  262. "sheetName": {
  263. "__rl": true,
  264. "value": 2020913753,
  265. "mode": "list",
  266. "cachedResultName": "Все заказы",
  267. "cachedResultUrl": "***"
  268. },
  269. "columns": {
  270. "mappingMode": "defineBelow",
  271. "value": {
  272. "Есть переписка": "время истекло",
  273. "ID": "={{ $json.ID }}"
  274. },
  275. "matchingColumns": [
  276. "ID"
  277. ],
  278. "schema": [
  279. {
  280. "id": "ID",
  281. "displayName": "ID",
  282. "required": false,
  283. "defaultMatch": false,
  284. "display": true,
  285. "type": "string",
  286. "canBeUsedToMatch": true,
  287. "removed": false
  288. },
  289. {
  290. "id": "Номер заказа",
  291. "displayName": "Номер заказа",
  292. "required": false,
  293. "defaultMatch": false,
  294. "display": true,
  295. "type": "string",
  296. "canBeUsedToMatch": true,
  297. "removed": true
  298. },
  299. {
  300. "id": "Сайт",
  301. "displayName": "Сайт",
  302. "required": false,
  303. "defaultMatch": false,
  304. "display": true,
  305. "type": "string",
  306. "canBeUsedToMatch": true,
  307. "removed": true
  308. },
  309. {
  310. "id": "UTM CAMPANING",
  311. "displayName": "UTM CAMPANING",
  312. "required": false,
  313. "defaultMatch": false,
  314. "display": true,
  315. "type": "string",
  316. "canBeUsedToMatch": true,
  317. "removed": true
  318. },
  319. {
  320. "id": "Есть переписка",
  321. "displayName": "Есть переписка",
  322. "required": false,
  323. "defaultMatch": false,
  324. "display": true,
  325. "type": "string",
  326. "canBeUsedToMatch": true
  327. },
  328. {
  329. "id": "Что заказал",
  330. "displayName": "Что заказал",
  331. "required": false,
  332. "defaultMatch": false,
  333. "display": true,
  334. "type": "string",
  335. "canBeUsedToMatch": true,
  336. "removed": true
  337. },
  338. {
  339. "id": "Дата",
  340. "displayName": "Дата",
  341. "required": false,
  342. "defaultMatch": false,
  343. "display": true,
  344. "type": "string",
  345. "canBeUsedToMatch": true,
  346. "removed": true
  347. },
  348. {
  349. "id": "Написал",
  350. "displayName": "Написал",
  351. "required": false,
  352. "defaultMatch": false,
  353. "display": true,
  354. "type": "string",
  355. "canBeUsedToMatch": true,
  356. "removed": true
  357. }
  358. ]
  359. },
  360. "options": {}
  361. },
  362. "id": "45db79c8-f0de-4400-a436-8946ce020ee9",
  363. "name": "Google Sheets1",
  364. "type": "n8n-nodes-base.googleSheets",
  365. "typeVersion": 4,
  366. "position": [
  367. 1200,
  368. 1160
  369. ],
  370. "credentials": {
  371. "googleSheetsOAuth2Api": {
  372. "id": "sWoYZwInHw8Y92qS",
  373. "name": "Google Sheets account"
  374. }
  375. }
  376. },
  377. {
  378. "parameters": {
  379. "content": "### Помечаем устаревшие заказы, чтобы не собирать их повторно",
  380. "height": 244.28916211333097,
  381. "width": 344.93109134573206
  382. },
  383. "id": "9b8619b7-e2cc-4966-bc55-07996619e33a",
  384. "name": "Sticky Note3",
  385. "type": "n8n-nodes-base.stickyNote",
  386. "typeVersion": 1,
  387. "position": [
  388. 1160,
  389. 1078
  390. ]
  391. },
  392. {
  393. "parameters": {
  394. "documentId": {
  395. "__rl": true,
  396. "value": "***",
  397. "mode": "url",
  398. "__regex": "https:\\/\\/(?:drive|docs)\\.google\\.com(?:\\/.*|)\\/d\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)"
  399. },
  400. "sheetName": {
  401. "__rl": true,
  402. "value": 2020913753,
  403. "mode": "list",
  404. "cachedResultName": "Все заказы",
  405. "cachedResultUrl": "***"
  406. },
  407. "options": {}
  408. },
  409. "id": "9fb55a8e-2e19-4a1e-9ec3-7323f81f1dc0",
  410. "name": "Google Sheets2",
  411. "type": "n8n-nodes-base.googleSheets",
  412. "typeVersion": 4,
  413. "position": [
  414. 400,
  415. 1140
  416. ],
  417. "credentials": {
  418. "googleSheetsOAuth2Api": {
  419. "id": "sWoYZwInHw8Y92qS",
  420. "name": "Google Sheets account"
  421. }
  422. },
  423. "disabled": true
  424. },
  425. {
  426. "parameters": {
  427. "content": "## Берем необработанные заказы",
  428. "height": 274.306455969746,
  429. "width": 279.9581307401405
  430. },
  431. "id": "0b39346d-8714-47d6-ba77-35609bfd7a0b",
  432. "name": "Sticky Note4",
  433. "type": "n8n-nodes-base.stickyNote",
  434. "typeVersion": 1,
  435. "position": [
  436. 640,
  437. 740
  438. ]
  439. },
  440. {
  441. "parameters": {
  442. "operation": "update",
  443. "documentId": {
  444. "__rl": true,
  445. "value": "***",
  446. "mode": "url",
  447. "__regex": "https:\\/\\/(?:drive|docs)\\.google\\.com(?:\\/.*|)\\/d\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)"
  448. },
  449. "sheetName": {
  450. "__rl": true,
  451. "value": 2020913753,
  452. "mode": "list",
  453. "cachedResultName": "Все заказы",
  454. "cachedResultUrl": "***"
  455. },
  456. "columns": {
  457. "mappingMode": "defineBelow",
  458. "value": {
  459. "Номер заказа": "={{ $json.firstMatchingKeyword }}",
  460. "Есть переписка": "Писал в WhatsApp",
  461. "Номер написавшего": "={{ $json.from }} "
  462. },
  463. "matchingColumns": [
  464. "Номер заказа"
  465. ],
  466. "schema": [
  467. {
  468. "id": "ID",
  469. "displayName": "ID",
  470. "required": false,
  471. "defaultMatch": false,
  472. "display": true,
  473. "type": "string",
  474. "canBeUsedToMatch": true,
  475. "removed": true
  476. },
  477. {
  478. "id": "Номер заказа",
  479. "displayName": "Номер заказа",
  480. "required": false,
  481. "defaultMatch": false,
  482. "display": true,
  483. "type": "string",
  484. "canBeUsedToMatch": true,
  485. "removed": false
  486. },
  487. {
  488. "id": "Сайт",
  489. "displayName": "Сайт",
  490. "required": false,
  491. "defaultMatch": false,
  492. "display": true,
  493. "type": "string",
  494. "canBeUsedToMatch": true,
  495. "removed": true
  496. },
  497. {
  498. "id": "UTM CAMPANING",
  499. "displayName": "UTM CAMPANING",
  500. "required": false,
  501. "defaultMatch": false,
  502. "display": true,
  503. "type": "string",
  504. "canBeUsedToMatch": true,
  505. "removed": true
  506. },
  507. {
  508. "id": "Есть переписка",
  509. "displayName": "Есть переписка",
  510. "required": false,
  511. "defaultMatch": false,
  512. "display": true,
  513. "type": "string",
  514. "canBeUsedToMatch": true
  515. },
  516. {
  517. "id": "Что заказал",
  518. "displayName": "Что заказал",
  519. "required": false,
  520. "defaultMatch": false,
  521. "display": true,
  522. "type": "string",
  523. "canBeUsedToMatch": true,
  524. "removed": true
  525. },
  526. {
  527. "id": "Дата",
  528. "displayName": "Дата",
  529. "required": false,
  530. "defaultMatch": false,
  531. "display": true,
  532. "type": "string",
  533. "canBeUsedToMatch": true,
  534. "removed": true
  535. },
  536. {
  537. "id": "Написал",
  538. "displayName": "Написал",
  539. "required": false,
  540. "defaultMatch": false,
  541. "display": true,
  542. "type": "string",
  543. "canBeUsedToMatch": true,
  544. "removed": true
  545. },
  546. {
  547. "id": "Номер написавшего",
  548. "displayName": "Номер написавшего",
  549. "required": false,
  550. "defaultMatch": false,
  551. "display": true,
  552. "type": "string",
  553. "canBeUsedToMatch": true,
  554. "removed": false
  555. },
  556. {
  557. "id": "yclid_direct",
  558. "displayName": "yclid_direct",
  559. "required": false,
  560. "defaultMatch": false,
  561. "display": true,
  562. "type": "string",
  563. "canBeUsedToMatch": true,
  564. "removed": false
  565. },
  566. {
  567. "id": "yclid_metrika",
  568. "displayName": "yclid_metrika",
  569. "required": false,
  570. "defaultMatch": false,
  571. "display": true,
  572. "type": "string",
  573. "canBeUsedToMatch": true,
  574. "removed": false
  575. }
  576. ]
  577. },
  578. "options": {}
  579. },
  580. "id": "34227995-437d-4981-9745-188d028f05d2",
  581. "name": "Google Sheets3",
  582. "type": "n8n-nodes-base.googleSheets",
  583. "typeVersion": 4,
  584. "position": [
  585. 2578,
  586. 676
  587. ],
  588. "credentials": {
  589. "googleSheetsOAuth2Api": {
  590. "id": "sWoYZwInHw8Y92qS",
  591. "name": "Google Sheets account"
  592. }
  593. }
  594. },
  595. {
  596. "parameters": {
  597. "content": "### Отмечаем наличие переписки по заказам",
  598. "height": 256.9475958941112,
  599. "width": 292.4041058887087
  600. },
  601. "id": "d0a4ae9a-d457-44ac-b1c8-fab7c58be796",
  602. "name": "Sticky Note5",
  603. "type": "n8n-nodes-base.stickyNote",
  604. "typeVersion": 1,
  605. "position": [
  606. 2500,
  607. 605.5888708806051
  608. ]
  609. },
  610. {
  611. "parameters": {
  612. "content": "## Берем макс. 100 сообщений за последние 12 часов",
  613. "height": 307.059022150189,
  614. "width": 278.6480280929229
  615. },
  616. "id": "8244ae7f-da44-4195-a54b-9e0f57b8e160",
  617. "name": "Sticky Note6",
  618. "type": "n8n-nodes-base.stickyNote",
  619. "typeVersion": 1,
  620. "position": [
  621. 640,
  622. 407.24743381955705
  623. ]
  624. },
  625. {
  626. "parameters": {
  627. "rule": {
  628. "interval": [
  629. {
  630. "field": "hours",
  631. "hoursInterval": 4
  632. }
  633. ]
  634. }
  635. },
  636. "id": "d3107ab7-9e07-481a-b6ae-f6e92fdc863c",
  637. "name": "Schedule Trigger",
  638. "type": "n8n-nodes-base.scheduleTrigger",
  639. "typeVersion": 1.1,
  640. "position": [
  641. 400,
  642. 620
  643. ]
  644. },
  645. {
  646. "parameters": {
  647. "content": "## Чтобы таймер срабатывал, надо активироваться переключатель",
  648. "height": 196.84663695299835,
  649. "width": 829.5461912479739
  650. },
  651. "id": "6e8d305d-c1dd-4491-a370-435e5f21d179",
  652. "name": "Sticky Note7",
  653. "type": "n8n-nodes-base.stickyNote",
  654. "typeVersion": 1,
  655. "position": [
  656. 1820,
  657. -100
  658. ]
  659. }
  660. ],
  661. "connections": {
  662. "When clicking \"Execute Workflow\"": {
  663. "main": [
  664. [
  665. {
  666. "node": "HTTP Request",
  667. "type": "main",
  668. "index": 0
  669. },
  670. {
  671. "node": "Google Sheets",
  672. "type": "main",
  673. "index": 0
  674. },
  675. {
  676. "node": "Google Sheets2",
  677. "type": "main",
  678. "index": 0
  679. }
  680. ]
  681. ]
  682. },
  683. "HTTP Request": {
  684. "main": [
  685. [
  686. {
  687. "node": "Item Lists1",
  688. "type": "main",
  689. "index": 0
  690. }
  691. ]
  692. ]
  693. },
  694. "Google Sheets": {
  695. "main": [
  696. [
  697. {
  698. "node": "New Order?",
  699. "type": "main",
  700. "index": 0
  701. }
  702. ]
  703. ]
  704. },
  705. "Item Lists1": {
  706. "main": [
  707. [
  708. {
  709. "node": "Filter1",
  710. "type": "main",
  711. "index": 0
  712. }
  713. ]
  714. ]
  715. },
  716. "Filter1": {
  717. "main": [
  718. [
  719. {
  720. "node": "Merge",
  721. "type": "main",
  722. "index": 0
  723. }
  724. ]
  725. ]
  726. },
  727. "Merge": {
  728. "main": [
  729. [
  730. {
  731. "node": "Code",
  732. "type": "main",
  733. "index": 0
  734. }
  735. ]
  736. ]
  737. },
  738. "Code": {
  739. "main": [
  740. [
  741. {
  742. "node": "Matched?",
  743. "type": "main",
  744. "index": 0
  745. }
  746. ]
  747. ]
  748. },
  749. "Orders": {
  750. "main": [
  751. [
  752. {
  753. "node": "Merge",
  754. "type": "main",
  755. "index": 1
  756. }
  757. ]
  758. ]
  759. },
  760. "Matched?": {
  761. "main": [
  762. [
  763. {
  764. "node": "Google Sheets3",
  765. "type": "main",
  766. "index": 0
  767. }
  768. ]
  769. ]
  770. },
  771. "New Order?": {
  772. "main": [
  773. [
  774. {
  775. "node": "Orders",
  776. "type": "main",
  777. "index": 0
  778. }
  779. ],
  780. [
  781. {
  782. "node": "Google Sheets1",
  783. "type": "main",
  784. "index": 0
  785. }
  786. ]
  787. ]
  788. },
  789. "Schedule Trigger": {
  790. "main": [
  791. [
  792. {
  793. "node": "HTTP Request",
  794. "type": "main",
  795. "index": 0
  796. },
  797. {
  798. "node": "Google Sheets",
  799. "type": "main",
  800. "index": 0
  801. }
  802. ]
  803. ]
  804. }
  805. }
  806. }
Advertisement
Add Comment
Please, Sign In to add comment