{
  "name": "Telegram B-1 (Variant A): create sheet + send Submit button",
  "nodes": [
    {
      "parameters": {
        "updates": [
          "*"
        ],
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.2,
      "position": [
        -368,
        0
      ],
      "id": "b086273d-b099-4736-a21e-62fb1d1f0e36",
      "name": "Telegram Trigger",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "disabled": true
    },
    {
      "parameters": {
        "chatId": "544911412",
        "text": "B-1",
        "replyMarkup": "replyKeyboard",
        "replyKeyboard": {
          "rows": [
            {
              "row": {
                "buttons": [
                  {
                    "text": "B-1",
                    "additionalFields": {}
                  }
                ]
              }
            }
          ]
        },
        "replyKeyboardOptions": {
          "resize_keyboard": true
        },
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        112,
        -256
      ],
      "id": "d97fff7f-f9d6-46eb-8798-005168e2c072",
      "name": "Send a text message",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "3a97f6e1-edd0-4dd8-8675-6a78c5ef583a",
                    "leftValue": "={{ $json.message.text }}",
                    "rightValue": "B-1",
                    "operator": {
                      "type": "string",
                      "operation": "notEquals"
                    }
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.message.text }}",
                    "rightValue": "B-1",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "id": "0162a7c5-4410-490b-89be-80f75ab1d42e"
                  }
                ],
                "combinator": "and"
              }
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        -128,
        0
      ],
      "id": "742911b5-6be3-48ea-a7d0-cbcda8d12c01",
      "name": "Switch"
    },
    {
      "parameters": {
        "chatId": "={{ $('Switch').item.json.message.chat.id }}",
        "text": "=\u0412\u043e\u0442 \u0448\u0430\u0431\u043b\u043e\u043d B-1: <a href=\"https://docs.google.com/spreadsheets/d/{{ $json.id }}/edit?gid=454683091\">\u043e\u0442\u043a\u0440\u044b\u0442\u044c</a>",
        "replyMarkup": "replyKeyboardRemove",
        "replyKeyboardRemove": {
          "remove_keyboard": true
        },
        "additionalFields": {
          "appendAttribution": false,
          "parse_mode": "HTML"
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        800,
        16
      ],
      "id": "92d6576b-2586-4194-b79d-85e9060a8639",
      "name": "Send a text message1",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "copy",
        "fileId": {
          "__rl": true,
          "value": "14_EGBTpwBqkX5WzhvOCTHmSW7lRHaONDFjB35GhJpUg",
          "mode": "id"
        },
        "name": "={{ $json.one_c_name + '_' +$now.toMillis()+ '_B-1'  }}",
        "sameFolder": false,
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "folderId": {
          "__rl": true,
          "value": "=1uOO0xuvg-cgEdlF1s6jqH9MymKvs0Iiv",
          "mode": "id"
        },
        "options": {
          "description": "parentId/parents/1uOO0xuvg-cgEdlF1s6jqH9MymKvs0Iiv"
        }
      },
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        416,
        16
      ],
      "id": "e664b612-c4c1-40a9-9d7d-01bd9c80f50d",
      "name": "Copy file",
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "value": "orvzFdhR7uCZR23l",
          "mode": "list",
          "cachedResultName": "HEE_Team",
          "cachedResultUrl": "/projects/aYwTG2YSCDJ4D7Wf/datatables/orvzFdhR7uCZR23l"
        },
        "matchType": "allConditions",
        "filters": {
          "conditions": [
            {
              "keyName": "tg_account",
              "keyValue": "={{ $json.message.chat.id }}"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1,
      "position": [
        96,
        16
      ],
      "id": "6f519e6e-4331-4c81-add3-49b55edc2571",
      "name": "Get row(s)"
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "text",
              "value": "={{ $json.message?.text || '' }}"
            },
            {
              "name": "employeeName",
              "value": "={{ $json.message?.from?.username || [$json.message?.from?.first_name, $json.message?.from?.last_name].filter(Boolean).join(' ') || 'employee' }}"
            },
            {
              "name": "dateStr",
              "value": "={{ $now.setZone('Europe/Kyiv').toFormat('yyyy-LL-dd') }}"
            },
            {
              "name": "newFileName",
              "value": "={{ 'B-1 ' + $json.employeeName + ' ' + $json.dateStr }}"
            },
            {
              "name": "draftFileId",
              "value": "PUT_DRAFT_FILE_ID_HERE"
            },
            {
              "name": "tempFolderId",
              "value": "14_EGBTpwBqkX5WzhvOCTHmSW7lRHaONDFjB35GhJpUg"
            }
          ],
          "number": [
            {
              "name": "chatId",
              "value": "={{ $json.message?.chat?.id }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 2,
      "position": [
        -608,
        384
      ],
      "id": "e0316ab6-452c-4f33-800e-2344fab1d0c0",
      "name": "Prepare vars"
    },
    {
      "parameters": {
        "value1": "={{ $json.text }}",
        "rules": {
          "rules": [
            {
              "operation": "equal",
              "value2": null
            }
          ]
        }
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 2,
      "position": [
        -1088,
        -16
      ],
      "id": "2ba97ae0-6662-4eef-bddd-50f80847ff98",
      "name": "Is B-1 button?"
    },
    {
      "parameters": {
        "chatId": "={{ $json.chatId }}",
        "text": "\u041d\u0430\u0436\u043c\u0438\u0442\u0435 \u043a\u043d\u043e\u043f\u043a\u0443: \u0444\u043e\u0440\u043c\u0430 B-1",
        "replyMarkup": "replyKeyboard",
        "replyKeyboard": {
          "rows": [
            {
              "row": {
                "buttons": [
                  {
                    "text": "forma B-1",
                    "additionalFields": {}
                  }
                ]
              }
            }
          ]
        },
        "replyKeyboardOptions": {
          "resize_keyboard": true
        },
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        -400,
        416
      ],
      "id": "060f0ed7-a838-48c3-a192-e8a4b6819f42",
      "name": "Send menu keyboard",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "copy",
        "fileId": {
          "__rl": true,
          "value": "={{ $json.draftFileId }}",
          "mode": "id"
        },
        "name": "={{ $json.newFileName }}",
        "sameFolder": false,
        "driveId": {
          "__rl": true,
          "value": "My Drive",
          "mode": "list"
        },
        "folderId": {
          "__rl": true,
          "value": "={{ $json.tempFolderId }}",
          "mode": "id"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        -144,
        320
      ],
      "id": "60508ebb-d89c-4520-90f5-1a8dc2f4a975",
      "name": "Google Drive: Copy draft",
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "spreadsheetId",
              "value": "={{ $json.id || $json.fileId }}"
            },
            {
              "name": "sheetUrl",
              "value": "={{ 'https://docs.google.com/spreadsheets/d/' + ($json.id || $json.fileId) + '/edit' }}"
            }
          ],
          "number": [
            {
              "name": "chatId",
              "value": "={{ $node['Prepare vars'].json.chatId }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 2,
      "position": [
        80,
        320
      ],
      "id": "1f747bf0-6fd7-407e-9245-ecab82c4dc73",
      "name": "Build sheet URL"
    },
    {
      "parameters": {
        "chatId": "={{ $json.chatId }}",
        "text": "={{ '\u0412\u043e\u0442 \u0432\u0430\u0448\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0430: ' + $json.sheetUrl }}",
        "replyMarkup": "inlineKeyboard",
        "inlineKeyboard": {
          "rows": [
            {
              "row": {
                "buttons": [
                  {
                    "text": "Submit B-1",
                    "additionalFields": {
                      "callback_data": "={{ 'B1_SUBMIT:' + $json.spreadsheetId }}"
                    }
                  }
                ]
              }
            }
          ]
        },
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        368,
        320
      ],
      "id": "ead5600e-bb80-4b8c-8fce-4b68be700a66",
      "name": "Send sheet link + Submit button",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.2,
      "position": [
        -832,
        384
      ],
      "id": "1c887ceb-3f41-4115-8a0b-6d7ed13f38a4",
      "name": "Telegram Trigger1",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "3a97f6e1-edd0-4dd8-8675-6a78c5ef583a",
                    "leftValue": "={{ $json.text }}",
                    "rightValue": "forma B-1",
                    "operator": {
                      "type": "string",
                      "operation": "notEquals"
                    }
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.text }}",
                    "rightValue": "forma B-1",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "id": "0162a7c5-4410-490b-89be-80f75ab1d42e"
                  }
                ],
                "combinator": "and"
              }
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        -432,
        624
      ],
      "id": "0732b1ec-9cf1-4201-a48b-c44d90d621ce",
      "name": "Switch1"
    }
  ],
  "connections": {
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Send a text message",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get row(s)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Copy file": {
      "main": [
        [
          {
            "node": "Send a text message1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get row(s)": {
      "main": [
        [
          {
            "node": "Copy file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare vars": {
      "main": [
        [
          {
            "node": "Switch1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is B-1 button?": {
      "main": [
        [
          {
            "node": "Google Drive: Copy draft",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Drive: Copy draft": {
      "main": [
        [
          {
            "node": "Build sheet URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build sheet URL": {
      "main": [
        [
          {
            "node": "Send sheet link + Submit button",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger1": {
      "main": [
        [
          {
            "node": "Prepare vars",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch1": {
      "main": [
        [
          {
            "node": "Send menu keyboard",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Google Drive: Copy draft",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "e0430458-5474-48a8-a7db-d3b7129a84da",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "E42M4trw91JP6TMI"
}