{
  "name": "Voice Auto Converter Bot",
  "nodes": [
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.openai.com/v1/audio/transcriptions",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "name": "model",
              "value": "whisper-1"
            },
            {
              "parameterType": "formBinaryData",
              "name": "=file",
              "inputDataFieldName": "data"
            },
            {
              "name": "prompt",
              "value": "\u0418\u0441\u043f\u0440\u0430\u0432\u044c \u0432\u0441\u0435 \u043e\u0440\u0444\u043e\u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0435, \u0433\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0438 \u0440\u0435\u0447\u0435\u0432\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438. \u0420\u0430\u0441\u0441\u0442\u0430\u0432\u044c \u0437\u043d\u0430\u043a\u0438 \u043f\u0440\u0435\u043f\u0438\u043d\u0430\u043d\u0438\u044f \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u0441 \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c\u0438 \u0440\u0443\u0441\u0441\u043a\u043e\u0433\u043e \u044f\u0445\u044b\u043a\u0430."
            }
          ]
        },
        "options": {}
      },
      "id": "64bf33dc-7daa-418a-a652-e08cabd06610",
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        1300,
        420
      ],
      "alwaysOutputData": true,
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "resource": "file",
        "fileId": "={{ $('Telegram Trigger').item.json.message.voice.file_id }}"
      },
      "id": "ba123783-1938-4913-a1bc-02980fa3adb2",
      "name": "Get an audio message",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.1,
      "position": [
        1000,
        340
      ],
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "url": "=https://api.telegram.org/bot{{ $('Globals').item.json.telegram_bot_token }}/sendMessage ",
        "sendBody": true,
        "contentType": "form-urlencoded",
        "bodyParameters": {
          "parameters": [
            {
              "name": "chat_id",
              "value": "={{ $('Telegram Trigger').item.json.message.chat.id }}"
            },
            {
              "name": "text",
              "value": "=\ud83d\udd0a {{ $json.text }}"
            },
            {
              "name": "reply_to_message_id",
              "value": "={{ $('Telegram Trigger').item.json.message.message_id }}"
            }
          ]
        },
        "options": {}
      },
      "id": "26eab372-34eb-4279-958a-6c3c6320c6b0",
      "name": "Response to the chat",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        1820,
        540
      ]
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{ $json.message.voice.duration }}",
              "operation": "larger"
            }
          ]
        }
      },
      "id": "e32bb377-1353-4418-9200-30d547ccf986",
      "name": "IF VOICE",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        700,
        360
      ]
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{ $json.message.video_note.duration }}",
              "operation": "larger"
            }
          ]
        }
      },
      "id": "e959e5ce-1e5b-481e-823c-52fe1791588b",
      "name": "IF CIRCLE",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        700,
        520
      ]
    },
    {
      "parameters": {
        "resource": "file",
        "fileId": "={{ $json.message.video_note.file_id }}"
      },
      "id": "a042a315-885e-4c25-9ead-28bd06f992ce",
      "name": "Get a video message",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.1,
      "position": [
        1000,
        500
      ],
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {},
      "id": "f96dedef-c6c4-4489-bd8a-7568e15c89dc",
      "name": "No Operation, do nothing",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1000,
        740
      ]
    },
    {
      "parameters": {
        "operation": "editMessageText",
        "chatId": "={{ $('Telegram Trigger').item.json.callback_query.message.chat.id }}",
        "messageId": "={{ $('Telegram Trigger').item.json.callback_query.message.message_id }}",
        "replyMarkup": "inlineKeyboard",
        "text": "={{ $json.message.content }}",
        "inlineKeyboard": {
          "rows": [
            {
              "row": {
                "buttons": [
                  {
                    "text": "Summarise",
                    "additionalFields": {
                      "callback_data": "summarise"
                    }
                  }
                ]
              }
            }
          ]
        },
        "additionalFields": {}
      },
      "id": "3396ef23-2a7d-454c-940c-9a05cc143ffe",
      "name": "Telegram",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.1,
      "position": [
        1300,
        960
      ],
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.callback_query.data }}",
              "value2": "summarise"
            }
          ]
        }
      },
      "id": "2bb79fc1-e587-4ce1-a77c-722864677189",
      "name": "IF summarise",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        700,
        980
      ]
    },
    {
      "parameters": {
        "resource": "chat",
        "model": "gpt-4-1106-preview",
        "prompt": {
          "messages": [
            {
              "role": "system",
              "content": "Summarize content you are provided for 4 times less."
            },
            {
              "content": "={{ $json.callback_query.message.text }}"
            }
          ]
        },
        "options": {}
      },
      "id": "83ea2d4a-1da7-4b6c-82c1-791c03a530cb",
      "name": "OpenAI",
      "type": "n8n-nodes-base.openAi",
      "typeVersion": 1,
      "position": [
        1000,
        960
      ],
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.hasOwnProperty('message') }}",
              "value2": true
            }
          ]
        }
      },
      "id": "a5a8f236-f964-4234-baeb-776d60a87fb5",
      "name": "If message",
      "type": "n8n-nodes-base.filter",
      "typeVersion": 1,
      "position": [
        200,
        480
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.hasOwnProperty('callback_query') }}",
              "value2": true
            }
          ]
        }
      },
      "id": "208e018c-c9b9-4aca-aedb-d1dca303bed0",
      "name": "If callback_query",
      "type": "n8n-nodes-base.filter",
      "typeVersion": 1,
      "position": [
        200,
        620
      ]
    },
    {
      "parameters": {
        "updates": [
          "*"
        ],
        "additionalFields": {}
      },
      "id": "7013ddd3-ef85-4718-9bba-4fb50b61b92d",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1,
      "position": [
        -220,
        480
      ],
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "url": "=https://api.telegram.org/bot{{ $('Globals').item.json.telegram_bot_token }}/sendMessage",
        "sendBody": true,
        "contentType": "form-urlencoded",
        "bodyParameters": {
          "parameters": [
            {
              "name": "chat_id",
              "value": "={{ $('Telegram Trigger').item.json.message.chat.id }}"
            },
            {
              "name": "text",
              "value": "=\ud83d\udd0a {{ $json.text }}"
            },
            {
              "name": "reply_to_message_id",
              "value": "={{ $('Telegram Trigger').item.json.message.message_id }}"
            },
            {
              "name": "reply_markup",
              "value": "={\n   \"inline_keyboard\":[\n      [\n         {\n            \"text\":\"Summarise\",\n            \"callback_data\":\"summarise\"\n         }\n      ]\n   ]\n}"
            }
          ]
        },
        "options": {}
      },
      "id": "f1f4d88f-dc0e-4399-a11b-7a2618f57774",
      "name": "Response to the chat with inlines",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        1820,
        320
      ]
    },
    {
      "parameters": {
        "fields": {
          "values": [
            {
              "name": "telegram_bot_token",
              "stringValue": "secret-token"
            },
            {
              "name": "reply_markup",
              "stringValue": "="
            }
          ]
        },
        "options": {}
      },
      "id": "93a5a1b4-4179-43f5-8075-21709a4e1929",
      "name": "Globals",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.1,
      "position": [
        0,
        480
      ]
    },
    {
      "parameters": {
        "content": "## Manual\n1. \u0417\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043a\u043b\u044e\u0447\u0438 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0434\u0441\u0432\u0435\u0447\u0435\u043d\u044b \u043a\u0440\u0430\u0441\u043d\u044b\u043c\n1.1 Credentials \u0434\u043b\u044f Telegram API\n1.2 Credentials \u0434\u043b\u044f OpenAI\n1.3 Credentials \u0434\u043b\u044f OpenAI auth header\n2. \u0417\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0432 Globals telegram_bot_token, \u0432\u0437\u044f\u0432 \u0435\u0433\u043e \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0441\u0432\u043e\u0435\u0433\u043e \u0431\u043e\u0442\u0430 \u0432 @BotFather\n3. \u0417\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0432 Globals \u043f\u043e\u043b\u0435 \"...\" \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0439 \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u043e\u0439 \u0434\u043b\u044f \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u043e\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0431\u043e\u0442\u0430 (\u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438). \u041f\u0440\u0438\u043c\u0435\u0440:\n\n```\n{\n   \"inline_keyboard\":[\n      [\n         {\n            \"text\":\"Summarise\",\n            \"callback_data\":\"summarise\"\n         }\n      ]\n   ]\n}\n```",
        "height": 453.42465753424625,
        "width": 428.63013698630135
      },
      "id": "3667062b-b8c9-455c-a2c7-8d30b41d9a51",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -740,
        320
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $('Globals').item.json.reply_markup.length > 0 }}",
              "value2": true
            }
          ]
        }
      },
      "id": "98343652-b2aa-42db-a80e-1777e1ddb985",
      "name": "IF has reply_markup",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1520,
        420
      ]
    }
  ],
  "connections": {
    "Get an audio message": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "IF has reply_markup",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF VOICE": {
      "main": [
        [
          {
            "node": "Get an audio message",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF CIRCLE": {
      "main": [
        [
          {
            "node": "Get a video message",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get a video message": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF summarise": {
      "main": [
        [
          {
            "node": "OpenAI",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI": {
      "main": [
        [
          {
            "node": "Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If message": {
      "main": [
        [
          {
            "node": "IF VOICE",
            "type": "main",
            "index": 0
          },
          {
            "node": "IF CIRCLE",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If callback_query": {
      "main": [
        [
          {
            "node": "IF summarise",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Globals",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Globals": {
      "main": [
        [
          {
            "node": "If message",
            "type": "main",
            "index": 0
          },
          {
            "node": "If callback_query",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF has reply_markup": {
      "main": [
        [
          {
            "node": "Response to the chat with inlines",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Response to the chat",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "576fa033-0d74-4817-8358-9bc56b531eda",
  "id": "3xqw6fm9RN4Xq3u7",
  "tags": []
}