{
  "name": "SpeechKit Yandex Dzen",
  "nodes": [
    {
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.2,
      "position": [
        -340,
        -340
      ],
      "id": "2f73f8b9-7adf-4969-aea3-acd90e8824db",
      "name": "Telegram Trigger",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.message.voice.file_id }}",
                    "rightValue": "",
                    "operator": {
                      "type": "string",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "id": "ceb72356-cefd-49ec-ae88-dc7ed4f3365d"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Voice"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "8c844924-b2ed-48b0-935c-c66a8fd0c778",
                    "leftValue": "={{ $json.message.text }}",
                    "rightValue": "/",
                    "operator": {
                      "type": "string",
                      "operation": "notStartsWith"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Text"
            }
          ]
        },
        "options": {}
      },
      "id": "0031d70a-e668-4af5-939c-8cc1200c1fc3",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        -160,
        -340
      ]
    },
    {
      "parameters": {
        "resource": "file",
        "fileId": "={{ $json.message.voice.file_id }}"
      },
      "id": "d7280bb2-81fb-41eb-a7ba-ded40edab755",
      "name": "Download Voice File",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        40,
        -560
      ],
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://stt.api.cloud.yandex.net/speech/v1/stt:recognize",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Api-Key YOUR_API_KEY"
            }
          ]
        },
        "sendBody": true,
        "contentType": "binaryData",
        "inputDataFieldName": "data",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        200,
        -560
      ],
      "id": "ee12bab7-b89c-4e3b-8a05-9a1454cbbcc6",
      "name": "STT",
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://tts.api.cloud.yandex.net/speech/v1/tts:synthesize",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Api-Key YOUR_API_KEY"
            }
          ]
        },
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "name": "text",
              "value": "={{ $('Telegram Trigger').item.json.message.text }}"
            },
            {
              "name": "lang",
              "value": "ru-RU"
            },
            {
              "name": "voice",
              "value": "jane"
            },
            {
              "name": "format",
              "value": "oggopus"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        200,
        -200
      ],
      "id": "28b464d6-f084-40d7-96a0-a44785b631ad",
      "name": "TTS",
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "operation": "sendAudio",
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "binaryData": true,
        "additionalFields": {
          "fileName": "voice.ogg"
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        460,
        -120
      ],
      "id": "f3ef1658-0360-4e20-8506-42a16faa2492",
      "name": "Telegram_Voice_OK",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "sendChatAction",
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "action": "record_audio"
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        460,
        -300
      ],
      "id": "dd981329-71bb-49fe-9345-3f1f5237e672",
      "name": "actionRecordAudio",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "text": "={{ $json.result }}",
        "additionalFields": {
          "appendAttribution": false,
          "parse_mode": "HTML"
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        460,
        -660
      ],
      "id": "ae0451b4-dfc6-460a-9ac2-5d5733d2c3c1",
      "name": "Telegram_Text_OK",
      "alwaysOutputData": false,
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "text": "={{ $json.error }}",
        "replyMarkup": "forceReply",
        "forceReply": {},
        "additionalFields": {
          "appendAttribution": false,
          "parse_mode": "HTML"
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        460,
        -480
      ],
      "id": "0618e4f6-7c70-4447-a4bb-1a9dac8109d1",
      "name": "Debug_Text_ERROR",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "text": "={{ $json.error }}",
        "replyMarkup": "forceReply",
        "forceReply": {},
        "additionalFields": {
          "appendAttribution": false,
          "parse_mode": "HTML"
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        460,
        60
      ],
      "id": "c165d5ca-0bfe-4911-9849-2613a58ee081",
      "name": "Debug_Voice_ERROR",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "content": "## \u042f\u043d\u0434\u0435\u043a\u0441 SpeechKit",
        "height": 920,
        "width": 1100
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -400,
        -680
      ],
      "id": "7d16ba73-684c-4c44-afb4-1865c0796009",
      "name": "Sticky Note"
    }
  ],
  "connections": {
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Voice File": {
      "main": [
        [
          {
            "node": "STT",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Download Voice File",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "TTS",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "STT": {
      "main": [
        [
          {
            "node": "Telegram_Text_OK",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Debug_Text_ERROR",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "TTS": {
      "main": [
        [
          {
            "node": "actionRecordAudio",
            "type": "main",
            "index": 0
          },
          {
            "node": "Telegram_Voice_OK",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Debug_Voice_ERROR",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "2e270807-594b-4449-8bda-a3b28387939e",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "0i0ifdRpuCRbquVe",
  "tags": [
    {
      "createdAt": "2025-04-28T18:11:47.783Z",
      "updatedAt": "2025-04-28T18:11:47.783Z",
      "id": "tiKWOyaOMVCJB8GU",
      "name": "kgn-dev"
    },
    {
      "name": "dzen",
      "id": "8px38elFJCmVPcP0",
      "createdAt": "2025-05-08T09:33:44.143Z",
      "updatedAt": "2025-05-08T09:33:44.143Z"
    }
  ]
}