{
  "name": "Lesson 12 Email and PDF",
  "nodes": [
    {
      "parameters": {
        "content": "### Если писем слишком много\nТогда PDF-файлы могут много весить и имеет смысл разбить на батчи по 10-50 элементов",
        "height": 123.09884432358935,
        "width": 431.1124405166554
      },
      "id": "bdfdd639-b8dc-46bb-8abc-292adb61fc07",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        560,
        1180
      ]
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "getAll",
        "databaseId": {
          "__rl": true,
          "value": "cc045ddb-d05a-44fd-8880-5682d58dad90",
          "mode": "list",
          "cachedResultName": "(рус) База клиентов для шаблона Google Docs (n8n для бизнеса, рус)",
          "cachedResultUrl": "https://www.notion.so/cc045ddbd05a44fd88805682d58dad90"
        },
        "filterType": "manual",
        "matchType": "allFilters",
        "filters": {
          "conditions": [
            {
              "key": "Send|checkbox",
              "condition": "equals",
              "checkboxValue": true
            }
          ]
        },
        "options": {}
      },
      "id": "ee72deef-0c79-418b-a531-ca8a9edcabc1",
      "name": "Notion - получить данные",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2,
      "position": [
        1060,
        680
      ],
      "credentials": {
        "notionApi": {
          "id": "20",
          "name": "Notion account"
        }
      }
    },
    {
      "parameters": {
        "operation": "copy",
        "fileId": {
          "__rl": true,
          "value": "1_v9S1nggShZUFysUlBFrLGD1yxP-F8lcFdhlV_T2wds",
          "mode": ""
        },
        "options": {
          "parents": [
            "1zy4d3jmRcfSdecx76sY8NXE3fwIryudg"
          ]
        }
      },
      "id": "a88fb6f2-f114-4f1c-aff9-fb1295ebaabe",
      "name": "Создать копии шаблонов",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 2,
      "position": [
        1320,
        680
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "14",
          "name": "Google Drive account"
        }
      }
    },
    {
      "parameters": {
        "operation": "update",
        "fileId": {
          "__rl": true,
          "value": "={{ $json.id }}",
          "mode": "id"
        },
        "updateFields": {
          "fileName": "={{ $node[\"Notion - получить данные\"].json[\"name\"] }} - письмо"
        },
        "options": {}
      },
      "id": "0f81ab88-9ff6-40cd-86b3-f8ec3014af78",
      "name": "Переименовать копии шаблонов",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 2,
      "position": [
        1560,
        680
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "14",
          "name": "Google Drive account"
        }
      }
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "operation": "update",
        "documentURL": "={{$json[\"id\"]}}",
        "actionsUi": {
          "actionFields": [
            {
              "action": "replaceAll",
              "text": "{{Полное имя}}",
              "replaceText": "={{ $node[\"Notion - получить данные\"].json[\"name\"] }}"
            },
            {
              "action": "replaceAll",
              "text": "{{Позиция}}",
              "replaceText": "={{ $node[\"Notion - получить данные\"].json[\"property_position\"] }}"
            },
            {
              "action": "replaceAll",
              "text": "{{Адрес 1}}",
              "replaceText": "={{ $node[\"Notion - получить данные\"].json[\"property_address_1\"] }}"
            },
            {
              "action": "replaceAll",
              "text": "{{Дата}}",
              "replaceText": "={{ $('Дата в русском формате').item.json.message.content }}"
            },
            {
              "action": "replaceAll",
              "text": "{{Менеджер}}",
              "replaceText": "={{ $node[\"Notion - получить данные\"].json[\"property_manager_name\"] }}"
            },
            {
              "action": "replaceAll",
              "text": "{{Телефон}}",
              "replaceText": "={{ $node[\"Notion - получить данные\"].json[\"property_manager_phone\"] }}"
            },
            {
              "action": "replaceAll",
              "text": "{{Емейл}}",
              "replaceText": "={{ $node[\"Notion - получить данные\"].json[\"property_manager_email\"] }}"
            },
            {
              "action": "replaceAll",
              "text": "{{Краткое имя}}",
              "replaceText": "={{ $node[\"Notion - получить данные\"].json[\"property_short\"] }}"
            }
          ]
        }
      },
      "name": "Вставить текст в плейсхолдеры",
      "type": "n8n-nodes-base.googleDocs",
      "typeVersion": 1,
      "position": [
        1820,
        680
      ],
      "id": "a52d5c9f-1568-49f4-9eac-cc16e5510be5",
      "credentials": {
        "googleDocsOAuth2Api": {
          "id": "28",
          "name": "Google Docs account"
        }
      }
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "operation": "share",
        "fileId": "={{$json[\"documentId\"]}}",
        "permissionsUi": {
          "permissionsValues": {
            "role": "reader",
            "type": "anyone"
          }
        },
        "options": {}
      },
      "name": "Поделиться документом",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 1,
      "position": [
        360,
        1020
      ],
      "id": "3ae3d0aa-d6b5-42f0-814e-020ec6730f3c",
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "14",
          "name": "Google Drive account"
        }
      }
    },
    {
      "parameters": {
        "content": "### Нужно для превращения в PDF",
        "height": 80,
        "width": 196.60095173351465
      },
      "id": "66223776-1dbb-4a68-8106-9f8b48bedc07",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        300,
        1200
      ]
    },
    {
      "parameters": {
        "url": "=https://docs.google.com/feeds/download/documents/export/Export?id={{$node[\"Создать копии шаблонов\"].json[\"id\"]}}&exportFormat=pdf",
        "responseFormat": "file",
        "dataPropertyName": "=data",
        "options": {}
      },
      "name": "Получить PDF",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        580,
        1020
      ],
      "alwaysOutputData": false,
      "id": "eb34f5b1-52a7-43f0-b128-65ae83914e00"
    },
    {
      "parameters": {
        "binaryData": true,
        "name": "={{ $node[\"Переименовать копии шаблонов\"].json[\"name\"] }}.pdf",
        "parents": [
          "1zy4d3jmRcfSdecx76sY8NXE3fwIryudg"
        ],
        "options": {}
      },
      "id": "4751e59a-c7d6-4e4b-a784-3e44073821c0",
      "name": "Сохранить PDF на диск",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 2,
      "position": [
        820,
        1020
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "14",
          "name": "Google Drive account"
        }
      }
    },
    {
      "parameters": {
        "operation": "download",
        "fileId": {
          "__rl": true,
          "value": "={{ $json[\"id\"] }}",
          "mode": "id"
        },
        "options": {
          "fileName": "={{ $json[\"name\"] }}"
        }
      },
      "id": "acd923e3-abc6-4e3f-a799-eb8dc1bbac2c",
      "name": "Скачать в n8n с именем",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 2,
      "position": [
        1040,
        1020
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "14",
          "name": "Google Drive account"
        }
      }
    },
    {
      "parameters": {
        "sendTo": "=artem.dzyuba@gmail.com",
        "subject": "={{ $('Notion - получить данные').item.json.property_short }}, приглашаем на благотворительный концерт!",
        "message": "=Письмо находится во вложении",
        "options": {
          "attachmentsUi": {
            "attachmentsBinary": [
              {}
            ]
          }
        }
      },
      "id": "8cebf1c4-0fc2-435f-86d2-94fac3d3f271",
      "name": "Отравить через Gmail",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2,
      "position": [
        1280,
        1020
      ],
      "credentials": {
        "gmailOAuth2": {
          "id": "12",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "operation": "delete",
        "fileId": {
          "__rl": true,
          "value": "={{ $('Создать копии шаблонов').item.json.id }}",
          "mode": "id"
        }
      },
      "id": "e93ff4bf-0768-4057-bd5f-84cf9911b8fa",
      "name": "Удалить заполненные шаблоны",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 2,
      "position": [
        1500,
        1020
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "14",
          "name": "Google Drive account"
        }
      }
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "update",
        "pageId": {
          "__rl": true,
          "value": "={{ $node[\"Notion - получить данные\"].json[\"id\"] }}",
          "mode": "id",
          "__regex": "^([0-9a-f]{8}-?[0-9a-f]{4}-?4[0-9a-f]{3}-?[89ab][0-9a-f]{3}-?[0-9a-f]{12})"
        },
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Send|checkbox"
            }
          ]
        },
        "options": {}
      },
      "id": "ddf7a133-8921-460c-9545-003c04c0ba3c",
      "name": "Notion - снять галочки",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2,
      "position": [
        1720,
        1020
      ],
      "credentials": {
        "notionApi": {
          "id": "20",
          "name": "Notion account"
        }
      }
    },
    {
      "parameters": {},
      "id": "9688a150-9a63-4d65-86c9-d944bfe56fef",
      "name": "When clicking \"Execute Workflow\"",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        120,
        680
      ]
    },
    {
      "parameters": {
        "outputFieldName": "дата",
        "options": {}
      },
      "id": "2162abb9-8af0-4907-9ea2-b5146ac5e1fa",
      "name": "Date & Time - текущая дата",
      "type": "n8n-nodes-base.dateTime",
      "typeVersion": 2,
      "position": [
        340,
        680
      ]
    },
    {
      "parameters": {
        "operation": "formatDate",
        "date": "={{ $json.дата }}",
        "format": "yyyy-MM-dd",
        "outputFieldName": "дата",
        "options": {
          "timezone": false
        }
      },
      "id": "95d90ce7-f410-404f-bea5-806dbbf6d217",
      "name": "Date & Time - формат",
      "type": "n8n-nodes-base.dateTime",
      "typeVersion": 2,
      "position": [
        580,
        680
      ]
    },
    {
      "parameters": {
        "resource": "chat",
        "model": "gpt-3.5-turbo-0613",
        "prompt": {
          "messages": [
            {
              "role": "assistant",
              "content": "Edit into Russian date. Example: 2 мая 2023 г."
            },
            {
              "content": "={{ $json.дата }}"
            }
          ]
        },
        "options": {}
      },
      "id": "5e245df0-8cc6-4ea9-92b2-2ca93cd57bdb",
      "name": "Дата в русском формате",
      "type": "n8n-nodes-base.openAi",
      "typeVersion": 1,
      "position": [
        800,
        680
      ],
      "credentials": {
        "openAiApi": {
          "id": "6",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "operation": "formatDate",
        "date": "={{ $json.дата }}",
        "format": "custom",
        "customFormat": "LLLL d, yyyy",
        "outputFieldName": "дата",
        "options": {
          "timezone": false
        }
      },
      "id": "30801831-2407-4b7d-9c68-80434a912905",
      "name": "Date & Time - формат1",
      "type": "n8n-nodes-base.dateTime",
      "typeVersion": 2,
      "position": [
        580,
        520
      ]
    }
  ],
  "pinData": {},
  "connections": {
    "Notion - получить данные": {
      "main": [
        [
          {
            "node": "Создать копии шаблонов",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Создать копии шаблонов": {
      "main": [
        [
          {
            "node": "Переименовать копии шаблонов",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Переименовать копии шаблонов": {
      "main": [
        [
          {
            "node": "Вставить текст в плейсхолдеры",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Вставить текст в плейсхолдеры": {
      "main": [
        [
          {
            "node": "Поделиться документом",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Поделиться документом": {
      "main": [
        [
          {
            "node": "Получить PDF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Получить PDF": {
      "main": [
        [
          {
            "node": "Сохранить PDF на диск",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Сохранить PDF на диск": {
      "main": [
        [
          {
            "node": "Скачать в n8n с именем",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Скачать в n8n с именем": {
      "main": [
        [
          {
            "node": "Отравить через Gmail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Отравить через Gmail": {
      "main": [
        [
          {
            "node": "Удалить заполненные шаблоны",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Удалить заполненные шаблоны": {
      "main": [
        [
          {
            "node": "Notion - снять галочки",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \"Execute Workflow\"": {
      "main": [
        [
          {
            "node": "Date & Time - текущая дата",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Date & Time - текущая дата": {
      "main": [
        [
          {
            "node": "Date & Time - формат",
            "type": "main",
            "index": 0
          },
          {
            "node": "Date & Time - формат1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Date & Time - формат": {
      "main": [
        [
          {
            "node": "Дата в русском формате",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Дата в русском формате": {
      "main": [
        [
          {
            "node": "Notion - получить данные",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {},
  "versionId": "dd848f29-4548-4cc5-a184-ec5dcd4cfb5c",
  "id": "31",
  "meta": {
    "instanceId": "62148517c718afe88189b4557f5264eca24fb302b44a11226f98636805acbeef"
  },
  "tags": [
    {
      "id": "2",
      "createdAt": "2023-06-22T04:56:17.812Z",
      "updatedAt": "2023-06-22T04:56:17.812Z",
      "name": "n8n business course"
    }
  ]
}