{
  "name": "WhatsApp voice note to text (BroadNet Inference)",
  "nodes": [
    {
      "parameters": {
        "updates": [
          "messages"
        ],
        "options": {}
      },
      "id": "40387717-c640-4668-a304-b214e9927470",
      "name": "WhatsApp Trigger",
      "type": "n8n-nodes-base.whatsAppTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ],
      "webhookId": "744daecb-3c71-4493-86d5-e2c98e7dd078",
      "credentials": {
        "whatsAppTriggerApi": {
          "name": "REPLACE: WhatsApp OAuth account (Client ID and Client Secret of your Meta app)"
        }
      },
      "notes": "Event: Messages. WhatsApp allows one webhook URL per app, so test and production URLs overwrite each other. Subscribe your Meta app to the WhatsApp Business Account yourself; n8n does not.",
      "notesInFlow": false
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "5ea8ab53-3adc-4ddb-a55c-02698bf8db42",
              "leftValue": "={{ $json.messages?.[0]?.type ?? '' }}",
              "rightValue": "audio",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "30d8de4f-6396-4ddd-9a24-c2a08afbdc27",
      "name": "Is it a voice note?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        220,
        0
      ]
    },
    {
      "parameters": {
        "resource": "media",
        "operation": "mediaUrlGet",
        "mediaGetId": "={{ $json.messages[0].audio.id }}"
      },
      "id": "48458a45-088d-40e8-b7f9-11a1479ffa5a",
      "name": "Get media URL",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1.1,
      "position": [
        440,
        0
      ],
      "credentials": {
        "whatsAppApi": {
          "name": "REPLACE: WhatsApp account (access token and business account ID)"
        }
      },
      "notes": "Download returns JSON with a temporary url (valid 5 minutes), not the audio."
    },
    {
      "parameters": {
        "url": "={{ $json.url }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file",
              "outputPropertyName": "data"
            }
          }
        }
      },
      "id": "d2f0babf-9578-4db8-a752-8eb98dab8ae9",
      "name": "Download voice note",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        660,
        0
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "REPLACE: WhatsApp token header (name Authorization, value Bearer + your WhatsApp access token)"
        }
      }
    },
    {
      "parameters": {
        "operation": "write",
        "fileName": "=/home/node/.n8n-files/{{ $('WhatsApp Trigger').item.json.messages[0].audio.id }}.ogg",
        "dataPropertyName": "data",
        "options": {}
      },
      "id": "50ee6a08-82a2-4e08-a1dc-5a310bf7b85c",
      "name": "Write .ogg to disk",
      "type": "n8n-nodes-base.readWriteFile",
      "typeVersion": 1,
      "position": [
        880,
        0
      ]
    },
    {
      "parameters": {
        "executeOnce": false,
        "command": "=ffmpeg -y -loglevel error -i /home/node/.n8n-files/{{ $('WhatsApp Trigger').item.json.messages[0].audio.id }}.ogg -ar 16000 -ac 1 /home/node/.n8n-files/{{ $('WhatsApp Trigger').item.json.messages[0].audio.id }}.wav"
      },
      "id": "56c3370e-9ace-4bb2-90a8-ce37e99216c2",
      "name": "Convert to WAV (ffmpeg)",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        1100,
        0
      ],
      "notes": "Self-hosted n8n only. Needs ffmpeg in the n8n image and NODES_EXCLUDE set so Execute Command is not blocked (n8n 2.0+)."
    },
    {
      "parameters": {
        "fileSelector": "=/home/node/.n8n-files/{{ $('WhatsApp Trigger').item.json.messages[0].audio.id }}.wav",
        "options": {
          "dataPropertyName": "data"
        }
      },
      "id": "3c3d9554-fc95-4502-979d-28e7dfed1a03",
      "name": "Read .wav from disk",
      "type": "n8n-nodes-base.readWriteFile",
      "typeVersion": 1,
      "position": [
        1320,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://inference.broadnet.ai/v1/audio/transcriptions",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "name": "model",
              "value": "broadnet/cohere-transcribe-arabic"
            },
            {
              "name": "language",
              "value": "ar"
            },
            {
              "parameterType": "formBinaryData",
              "name": "file",
              "inputDataFieldName": "data"
            }
          ]
        },
        "options": {}
      },
      "id": "ee084e91-1c2d-417c-a8f3-3ae4c1f60492",
      "name": "Transcribe (BroadNet)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1540,
        0
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "REPLACE: BroadNet API key header (name Authorization, value Bearer + your BroadNet key)"
        }
      },
      "notes": "Arabic model. For the other 13 languages use broadnet/cohere-transcribe and set language (en, es, ...). The transcript is in $json.text."
    }
  ],
  "connections": {
    "WhatsApp Trigger": {
      "main": [
        [
          {
            "node": "Is it a voice note?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is it a voice note?": {
      "main": [
        [
          {
            "node": "Get media URL",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "Get media URL": {
      "main": [
        [
          {
            "node": "Download voice note",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download voice note": {
      "main": [
        [
          {
            "node": "Write .ogg to disk",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write .ogg to disk": {
      "main": [
        [
          {
            "node": "Convert to WAV (ffmpeg)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert to WAV (ffmpeg)": {
      "main": [
        [
          {
            "node": "Read .wav from disk",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read .wav from disk": {
      "main": [
        [
          {
            "node": "Transcribe (BroadNet)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}
