{
  "name": "WhatsApp Chat Bot",
  "nodes": [
    {
      "parameters": {
        "updates": [
          "messages"
        ],
        "options": {}
      },
      "type": "n8n-nodes-base.whatsAppTrigger",
      "typeVersion": 1,
      "position": [
        64,
        192
      ],
      "id": "d7206316-3f20-49cd-9fed-c6989bcd63e0",
      "name": "BotWhatsApp",
      "credentials": {
        "whatsAppTriggerApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "5f2c9a39-2297-4e9f-943f-6138d5b29e54",
              "leftValue": "={{ $('BotWhatsApp').item.json.messages[0].audio }}",
              "rightValue": "",
              "operator": {
                "type": "object",
                "operation": "exists",
                "singleValue": true
              }
            },
            {
              "id": "a53a1cb2-6aa8-4809-8e64-52e0e1eacff4",
              "leftValue": "={{ $('BotWhatsApp').item.json.messages[0].text.body }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notExists",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        288,
        192
      ],
      "id": "f05cca02-7b97-44af-99d1-2963b6af9967",
      "name": "isVoiceMsg"
    },
    {
      "parameters": {
        "url": "={{ $('BotWhatsApp').item.json.messages[0].audio.url }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        736,
        128
      ],
      "id": "424346ba-522f-4352-a4cc-83ca2cf3a5c8",
      "name": "getAudio",
      "credentials": {
        "httpBearerAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "resource": "audio",
        "operation": "transcribe",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 2.1,
      "position": [
        960,
        128
      ],
      "id": "22a2db1e-ec08-40c6-af53-c5c3ea788cc9",
      "name": "transcribeAudio",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "resource": "media",
        "operation": "mediaUrlGet",
        "mediaGetId": "={{ $json.messages[0].audio.id }}"
      },
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1.1,
      "position": [
        512,
        128
      ],
      "id": "24d5b316-eaf2-49e2-b707-5aa52c9a3060",
      "name": "Download media",
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "content": "## Get text or voice msg",
        "height": 352,
        "width": 432,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        0
      ],
      "typeVersion": 1,
      "id": "fca4c911-33b0-40d1-8529-1ee137966d80",
      "name": "Sticky Note"
    },
    {
      "parameters": {
        "content": "## Download voice msg",
        "height": 336,
        "width": 624,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        464,
        16
      ],
      "typeVersion": 1,
      "id": "3144584b-9edc-4e33-8151-aeac55c7ab61",
      "name": "Sticky Note1"
    },
    {
      "parameters": {
        "content": "## Execute OpenAI LLM & send message",
        "height": 528,
        "width": 768
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1120,
        16
      ],
      "typeVersion": 1,
      "id": "5f1f0caa-3999-4d4e-9a2e-d3b62141994c",
      "name": "Sticky Note2"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-5-mini"
        },
        "builtInTools": {},
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        1472,
        416
      ],
      "id": "cf2b5ebd-e31b-4b0e-92d4-a837e52f7561",
      "name": "OpenAI LLM",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "={{ $('BotWhatsApp').item.json.metadata.phone_number_id }}",
        "recipientPhoneNumber": "={{ $('BotWhatsApp').item.json.messages[0].from }}",
        "textBody": "={{ $('AI Agent').item.json.output }}",
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1.1,
      "position": [
        1760,
        192
      ],
      "id": "41cb30f4-83eb-4841-9c8e-306554e88f80",
      "name": "sendMsg",
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "f3aeea63-076c-46a6-be23-99819f0b66ee",
              "name": "text",
              "value": "={{ $('BotWhatsApp').item.json.messages[0].text?.values() ?? $('transcribeAudio').item.json.text }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1184,
        192
      ],
      "id": "94f388ce-0d1c-4800-a6be-771d2ea9ac10",
      "name": "setMsgText"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $('setMsgText').item.json.text }}",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        1408,
        192
      ],
      "id": "52862e6c-9136-4bfd-a79e-93c98fcca1fd",
      "name": "AI Agent",
      "executeOnce": true
    }
  ],
  "connections": {
    "BotWhatsApp": {
      "main": [
        [
          {
            "node": "isVoiceMsg",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "isVoiceMsg": {
      "main": [
        [
          {
            "node": "Download media",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "setMsgText",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "getAudio": {
      "main": [
        [
          {
            "node": "transcribeAudio",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "transcribeAudio": {
      "main": [
        [
          {
            "node": "setMsgText",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download media": {
      "main": [
        [
          {
            "node": "getAudio",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI LLM": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "setMsgText": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "sendMsg",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate"
  },
  "versionId": "26504a0a-8ad6-430c-b825-3c1212cb75fd",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "TjbDhZGvZwB4qO8J",
  "tags": []
}