{
  "name": "Polyglot STT - video to Google Docs",
  "active": false,
  "nodes": [
    {
      "id": "79556e97-d433-511f-a83a-e852feb53c72",
      "name": "Manual start",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ],
      "parameters": {}
    },
    {
      "id": "04d17511-a2b3-5d6e-89c5-b324725677af",
      "name": "Configure",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        260,
        0
      ],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "actor",
              "name": "actorId",
              "value": "andronixmd~speech-to-text-transcriber",
              "type": "string"
            },
            {
              "id": "budget",
              "name": "maxTotalChargeUsd",
              "value": 1,
              "type": "number"
            },
            {
              "id": "media",
              "name": "mediaUrl",
              "value": "https://storage.googleapis.com/cloud-samples-data/speech/commercial_mono.wav",
              "type": "string"
            },
            {
              "id": "doc",
              "name": "googleDocumentId",
              "value": "CONFIGURE_GOOGLE_DOCUMENT_ID",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      }
    },
    {
      "id": "efe37ab4-5810-5dfd-92ad-970f1273f532",
      "name": "Start Actor",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        520,
        0
      ],
      "parameters": {
        "url": "={{ 'https://api.apify.com/v2/acts/' + $('Configure').first().json.actorId + '/runs' }}",
        "method": "POST",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {
          "timeout": 30000
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ {urls:[$('Configure').first().json.mediaUrl], timestamps:'segment'} }}",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "maxTotalChargeUsd",
              "value": "={{ $('Configure').first().json.maxTotalChargeUsd }}"
            }
          ]
        }
      },
      "retryOnFail": false
    },
    {
      "id": "69f3fa28-fd86-5fdb-88c4-045298db6820",
      "name": "Wait ten seconds",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        780,
        0
      ],
      "parameters": {
        "amount": 10,
        "unit": "seconds"
      }
    },
    {
      "id": "4bca4af0-976d-5b42-89a1-397c65c3c1f7",
      "name": "Get run",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1040,
        0
      ],
      "parameters": {
        "url": "={{ 'https://api.apify.com/v2/actor-runs/' + $('Start Actor').first().json.data.id }}",
        "method": "GET",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {
          "timeout": 30000
        }
      },
      "retryOnFail": false
    },
    {
      "id": "a94b6c8f-1cc9-59ac-999b-c63e9f223b6d",
      "name": "Check run",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1300,
        0
      ],
      "parameters": {
        "jsCode": "const run = $input.first().json.data;\nconst statuses = ['READY','RUNNING','SUCCEEDED','FAILED','ABORTING','ABORTED','TIMING-OUT','TIMED-OUT'];\nif (!run || !statuses.includes(run.status)) throw new Error('Unexpected Apify run status');\nconst terminal = ['SUCCEEDED','FAILED','ABORTED','TIMED-OUT'].includes(run.status);\nif (!terminal && $runIndex >= 360) throw new Error('Polling limit reached. Inspect the existing run; do not create another run blindly. Telegram temporary storage may require manual cleanup.');\nreturn [{json:{...run,terminal,succeeded:run.status === 'SUCCEEDED'}}];"
      }
    },
    {
      "id": "ccb45db4-b3ed-5000-ae8b-1db24f4d54c7",
      "name": "Run finished",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        0,
        220
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "Run finished",
              "leftValue": "={{ $json.terminal }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      }
    },
    {
      "id": "2e41cef3-776a-5cd6-a77f-5d365cd9cabc",
      "name": "Run succeeded",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        260,
        220
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "Run succeeded",
              "leftValue": "={{ $json.succeeded }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      }
    },
    {
      "id": "ec63cf35-c291-5d7f-91a9-751648818d03",
      "name": "Run failed",
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "position": [
        520,
        220
      ],
      "parameters": {
        "errorMessage": "Actor did not complete successfully. Inspect the existing run and saved JSON before retrying."
      }
    },
    {
      "id": "51f9bafc-cd30-5bf3-b29e-183fd6b08fa5",
      "name": "Get full result",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        780,
        220
      ],
      "parameters": {
        "url": "={{ 'https://api.apify.com/v2/key-value-stores/' + $('Check run').first().json.defaultKeyValueStoreId + '/records/item-000-result' }}",
        "method": "GET",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {
          "timeout": 30000
        }
      },
      "retryOnFail": false
    },
    {
      "id": "7fe5e802-31b6-52d2-9bcb-5317d23f4d81",
      "name": "Format document",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1040,
        220
      ],
      "parameters": {
        "jsCode": "const rows = $input.all().map(item => item.json.value);\nif (rows.some(row => !row || row.error || row.billing?.stop || typeof row.text !== 'string')) throw new Error('Incomplete transcription; inspect the existing run before writing a document');\nconst text = rows.map(row => ['Source: ' + row.url, row.summary || '', ...(row.chapters || []).map(c => '[' + c.start_s + 's] ' + c.title), row.transcript_llm || row.text || ''].join('\\n')).join('\\n\\n');\nreturn [{json:{text:text + '\\n'}}];"
      }
    },
    {
      "id": "f0de4d47-1196-5b92-85cc-f940f263750f",
      "name": "Append to Google Doc",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1300,
        220
      ],
      "parameters": {
        "url": "={{ 'https://docs.googleapis.com/v1/documents/' + $('Configure').first().json.googleDocumentId + ':batchUpdate' }}",
        "method": "POST",
        "authentication": "genericCredentialType",
        "genericAuthType": "oAuth2Api",
        "options": {
          "timeout": 30000
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ {requests:[{insertText:{endOfSegmentLocation:{},text:$json.text} }]} }}"
      },
      "retryOnFail": false
    }
  ],
  "connections": {
    "Manual start": {
      "main": [
        [
          {
            "node": "Configure",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Configure": {
      "main": [
        [
          {
            "node": "Start Actor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Start Actor": {
      "main": [
        [
          {
            "node": "Wait ten seconds",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait ten seconds": {
      "main": [
        [
          {
            "node": "Get run",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get run": {
      "main": [
        [
          {
            "node": "Check run",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check run": {
      "main": [
        [
          {
            "node": "Run finished",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run finished": {
      "main": [
        [
          {
            "node": "Run succeeded",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait ten seconds",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run succeeded": {
      "main": [
        [
          {
            "node": "Get full result",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Run failed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get full result": {
      "main": [
        [
          {
            "node": "Format document",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format document": {
      "main": [
        [
          {
            "node": "Append to Google Doc",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "executionTimeout": 3900,
    "saveDataErrorExecution": "none",
    "saveDataSuccessExecution": "none",
    "saveExecutionProgress": false
  },
  "pinData": {},
  "tags": []
}
