{
  "name": "My workflow",
  "nodes": [
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "fe7ecc99-e1e8-4a5e-bdd6-6fce9757b234",
              "name": "text",
              "value": "={{ $json.message.text }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "e3b7732c-906d-40f4-be62-7743a65c43c2",
      "name": "Set 'Text'",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        0,
        140
      ]
    },
    {
      "parameters": {
        "resource": "file",
        "fileId": "={{ $json.message.voice.file_id }}"
      },
      "id": "0e5b3f83-0b76-4b3e-a86b-26745b22c143",
      "name": "Download Voice File",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        -80,
        -20
      ],
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "resource": "audio",
        "operation": "transcribe",
        "options": {}
      },
      "id": "b8ba3f88-211b-4833-9b6d-53b95dc19f42",
      "name": "Transcribe Audio",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.6,
      "position": [
        80,
        -20
      ],
      "credentials": {
        "openAiApi": {
          "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
                    }
                  }
                ],
                "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": "exists",
                      "singleValue": true
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Text"
            }
          ]
        },
        "options": {}
      },
      "id": "914f2bdc-101a-4fa6-b65e-22efc50ecaf2",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        -340,
        60
      ]
    },
    {
      "parameters": {
        "content": "# Trigger\n",
        "height": 400,
        "width": 360,
        "color": 6
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -540,
        -100
      ],
      "id": "7c27fbba-86e6-487e-829a-fefef5adcc56",
      "name": "Sticky Note1"
    },
    {
      "parameters": {
        "content": "# Voice or Text",
        "height": 400,
        "width": 420,
        "color": 7
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -160,
        -100
      ],
      "id": "dac91f97-fb9f-426e-94ab-c36cce5b24c4",
      "name": "Sticky Note7"
    },
    {
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.2,
      "position": [
        -520,
        60
      ],
      "id": "2530814f-b9ea-4aca-a015-3fd110ed7896",
      "name": "Telegram_Trigger",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://52.0.132.35:8000/extract-audio",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "url",
              "value": "={{ $json.text }}"
            },
            {
              "name": "format",
              "value": "mp3"
            },
            {
              "name": "quality",
              "value": "192"
            },
            {
              "name": "return_url",
              "value": "false"
            }
          ]
        },
        "options": {
          "response": {
            "response": {
              "responseFormat": "file",
              "outputPropertyName": "audio"
            }
          },
          "timeout": 120000
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        460,
        0
      ],
      "id": "255bf626-f354-4716-a82b-5e1c7120e52e",
      "name": "AudioExtractor"
    },
    {
      "parameters": {
        "operation": "sendAudio",
        "chatId": "={{ $('Telegram_Trigger').item.json.message.chat.id }}",
        "binaryData": true,
        "binaryPropertyName": "audio",
        "additionalFields": {
          "caption": "\ud83c\udfb5 Audio extracted from: {{ $('Set \\'Text\\'').item.json.text }}",
          "title": "Extracted Audio"
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        660,
        0
      ],
      "id": "9121aee0-7389-47d0-9173-0bd8cfb5cacb",
      "name": "Send Audio to Telegram",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "content": "# Audio Processing",
        "height": 300,
        "width": 420,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        400,
        -100
      ],
      "id": "13805739-5cde-495a-970c-83d0b9264882",
      "name": "Sticky Note - Audio"
    }
  ],
  "connections": {
    "Set 'Text'": {
      "main": [
        [
          {
            "node": "AudioExtractor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Voice File": {
      "main": [
        [
          {
            "node": "Transcribe Audio",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Download Voice File",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set 'Text'",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram_Trigger": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AudioExtractor": {
      "main": [
        [
          {
            "node": "Send Audio to Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "75adbb28-ada1-4459-86b3-252efc7df63e",
  "id": "WcKHYZLZu5oN0wSH",
  "tags": []
}