{
  "id": "0VCIafTEoeozjqPE",
  "meta": {
    "builderVariant": "mcp",
    "aiBuilderAssisted": true
  },
  "name": "Answer WhatsApp text, voice, image and video messages with GPT-5 and Gemini",
  "tags": [],
  "nodes": [
    {
      "id": "04177b1c-7f29-44f5-9e74-5020f281708f",
      "name": "WhatsApp Trigger",
      "type": "n8n-nodes-base.whatsAppTrigger",
      "position": [
        0,
        288
      ],
      "parameters": {
        "options": {},
        "updates": [
          "messages"
        ]
      },
      "credentials": {
        "whatsAppTriggerApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "923f35a2-c447-4797-9898-11f5d01c1837",
      "name": "Configuration",
      "type": "n8n-nodes-base.set",
      "position": [
        224,
        288
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "cfg-system-prompt",
              "name": "system_prompt",
              "type": "string",
              "value": "You are a friendly and helpful AI assistant chatting with users on WhatsApp. Answer clearly and factually. Use the Wikipedia tool when you need reliable facts about people, places, events or concepts. Always reply in the same language as the user. Keep replies short and conversational, use plain text only (no markdown symbols), and never exceed 4000 characters."
            },
            {
              "id": "cfg-openai-model",
              "name": "openai_model",
              "type": "string",
              "value": "gpt-5-mini"
            },
            {
              "id": "cfg-gemini-model",
              "name": "gemini_model",
              "type": "string",
              "value": "gemini-2.5-flash"
            },
            {
              "id": "cfg-image-prompt",
              "name": "image_prompt",
              "type": "string",
              "value": "Describe this image in detail and transcribe any text visible in it."
            },
            {
              "id": "cfg-video-prompt",
              "name": "video_prompt",
              "type": "string",
              "value": "Describe this video in detail: the scenes, the actions, any spoken words and any on-screen text."
            },
            {
              "id": "cfg-memory-window",
              "name": "memory_context_window",
              "type": "number",
              "value": 10
            },
            {
              "id": "cfg-max-reply",
              "name": "max_reply_length",
              "type": "number",
              "value": 4096
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "5319beb5-937e-4477-9969-fbdc199f2faa",
      "name": "Split Out Message Parts",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        448,
        288
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "messages"
      },
      "typeVersion": 1
    },
    {
      "id": "9ce19a81-15e5-4f27-a689-8ae6e26b0aab",
      "name": "Route by Message Type",
      "type": "n8n-nodes-base.switch",
      "position": [
        672,
        256
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "Audio",
              "conditions": {
                "options": {
                  "version": 1,
                  "leftValue": "",
                  "caseSensitive": false,
                  "typeValidation": "loose"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.type }}",
                    "rightValue": "audio"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Video",
              "conditions": {
                "options": {
                  "version": 1,
                  "leftValue": "",
                  "caseSensitive": false,
                  "typeValidation": "loose"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.type }}",
                    "rightValue": "video"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Image",
              "conditions": {
                "options": {
                  "version": 1,
                  "leftValue": "",
                  "caseSensitive": false,
                  "typeValidation": "loose"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.type }}",
                    "rightValue": "image"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra",
          "renameFallbackOutput": "Text"
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "6082b414-2eb0-4cb2-a5db-da6539609b18",
      "name": "Get Audio Download URL",
      "type": "n8n-nodes-base.whatsApp",
      "position": [
        896,
        0
      ],
      "parameters": {
        "resource": "media",
        "operation": "mediaUrlGet",
        "mediaGetId": "={{ $json.audio.id }}"
      },
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "5e29f917-d087-41f5-a65d-1e8c094f1637",
      "name": "Download Audio File",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1120,
        0
      ],
      "parameters": {
        "url": "={{ $json.url }}",
        "options": {},
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "whatsAppApi"
      },
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.4
    },
    {
      "id": "ccf39e2b-c6c0-4666-9caa-7980911d743c",
      "name": "Transcribe Voice Note with OpenAI",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        1344,
        0
      ],
      "parameters": {
        "options": {},
        "resource": "audio",
        "operation": "transcribe"
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "128f7839-0ab9-424d-9ae8-8058703200ff",
      "name": "Prepare Agent Input",
      "type": "n8n-nodes-base.set",
      "position": [
        1568,
        288
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "agi-type",
              "name": "message_type",
              "type": "string",
              "value": "={{ $('Split Out Message Parts').item.json.type }}"
            },
            {
              "id": "agi-text",
              "name": "message_text",
              "type": "string",
              "value": "={{ $json.text?.body ?? $json.text ?? $json.content ?? '' }}"
            },
            {
              "id": "agi-caption",
              "name": "message_caption",
              "type": "string",
              "value": "={{ $('Split Out Message Parts').item.json.image?.caption ?? $('Split Out Message Parts').item.json.video?.caption ?? $('Split Out Message Parts').item.json.audio?.caption ?? '' }}"
            },
            {
              "id": "agi-from",
              "name": "from",
              "type": "string",
              "value": "={{ $('WhatsApp Trigger').item.json.messages[0].from }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "956da7e2-0cbc-4a88-9543-26c192e15835",
      "name": "Get Video Download URL",
      "type": "n8n-nodes-base.whatsApp",
      "position": [
        896,
        192
      ],
      "parameters": {
        "resource": "media",
        "operation": "mediaUrlGet",
        "mediaGetId": "={{ $json.video.id }}"
      },
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "a050059a-1e62-4000-b1f8-8add1b37c319",
      "name": "Download Video File",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1120,
        192
      ],
      "parameters": {
        "url": "={{ $json.url }}",
        "options": {},
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "whatsAppApi"
      },
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.4
    },
    {
      "id": "1090d24a-e040-4d2d-93c1-9d1750b0d33a",
      "name": "Describe Video with Gemini",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "position": [
        1344,
        192
      ],
      "parameters": {
        "text": "={{ $('Configuration').item.json.video_prompt }}",
        "modelId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Configuration').item.json.gemini_model }}"
        },
        "options": {},
        "resource": "video",
        "inputType": "binary",
        "operation": "analyze"
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "ec3c55ce-f064-44fc-af29-23d70e7364e7",
      "name": "Get Image Download URL",
      "type": "n8n-nodes-base.whatsApp",
      "position": [
        896,
        384
      ],
      "parameters": {
        "resource": "media",
        "operation": "mediaUrlGet",
        "mediaGetId": "={{ $json.image.id }}"
      },
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "de67a14e-5b19-453e-9c88-02f72f3ab2d7",
      "name": "Download Image File",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1120,
        384
      ],
      "parameters": {
        "url": "={{ $json.url }}",
        "options": {},
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "whatsAppApi"
      },
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.4
    },
    {
      "id": "89f33063-5d97-426b-bf10-44d99e854398",
      "name": "Analyze Image with GPT Vision",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        1344,
        384
      ],
      "parameters": {
        "text": "={{ $('Configuration').item.json.image_prompt }}",
        "images": {
          "values": [
            {}
          ]
        },
        "modelId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Configuration').item.json.openai_model }}"
        },
        "options": {},
        "resource": "image",
        "inputType": "base64",
        "operation": "analyze"
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "6e5a9d74-3216-47f9-bd97-9bb17f310e61",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1728,
        288
      ],
      "parameters": {
        "text": "=The user sent a message on WhatsApp.\nMessage type: {{ $json.message_type }}\nMessage text, transcription or media description:\n\"\"\"{{ $json.message_text }}\"\"\"\n{{ $json.message_caption ? \"Media caption: \" + $json.message_caption : \"\" }}",
        "options": {
          "systemMessage": "={{ $('Configuration').item.json.system_prompt }}"
        },
        "promptType": "define"
      },
      "typeVersion": 3.1
    },
    {
      "id": "4e3403d0-6d66-4785-8b99-f1fe2969f09f",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1792,
        512
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Configuration').item.json.openai_model }}"
        },
        "options": {},
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "c177d2d9-b6a2-4bc2-941f-66997847ffed",
      "name": "Per-User Chat Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        1920,
        512
      ],
      "parameters": {
        "sessionKey": "=whatsapp-assistant-{{ $('Prepare Agent Input').item.json.from }}",
        "sessionIdType": "customKey",
        "contextWindowLength": "={{ $('Configuration').item.json.memory_context_window }}"
      },
      "typeVersion": 1.4
    },
    {
      "id": "cc0110b2-b0b8-4a18-aff5-efd0e5c361c4",
      "name": "Wikipedia",
      "type": "@n8n/n8n-nodes-langchain.toolWikipedia",
      "position": [
        2048,
        512
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "b193eb0a-e15d-4c3a-a7d9-df47cb20d2aa",
      "name": "Send Reply on WhatsApp",
      "type": "n8n-nodes-base.whatsApp",
      "position": [
        2016,
        288
      ],
      "parameters": {
        "textBody": "={{ ($json.output ?? '').slice(0, $('Configuration').item.json.max_reply_length) }}",
        "operation": "send",
        "phoneNumberId": "<__PLACEHOLDER_VALUE__Select your WhatsApp business phone number ID__>",
        "additionalFields": {},
        "recipientPhoneNumber": "={{ $('WhatsApp Trigger').item.json.messages[0].from }}"
      },
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "7a7fee8a-4743-4e8c-bb17-a21af9d86bbf",
      "name": "Sticky Note ea024313",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2224,
        -528
      ],
      "parameters": {
        "color": 4,
        "width": 560,
        "height": 1760,
        "content": "# Answer WhatsApp text, voice, image and video messages with GPT-5 and Gemini\n# \ud83d\udce5  [Open full documentation on Notion](https://automatisation.notion.site/Course-Answer-WhatsApp-text-voice-image-and-video-messages-with-GPT-5-and-Gemini-39e3d6550fd981d2b319d9773c808e21)\n\n## How it works\n* The WhatsApp Trigger receives every incoming message from your WhatsApp Business number.\n* A Switch node routes each message to 1 of 4 branches based on its type: text, voice note, image or video.\n* Voice notes are transcribed with OpenAI, images are described by GPT vision, and videos are analyzed natively by Google Gemini (the only major model that accepts video input).\n* Everything is normalized into a single message and handed to an AI Agent with per-user conversation memory and a Wikipedia tool for factual questions.\n* The agent reply is sent back to the same user through the WhatsApp node, trimmed to the WhatsApp character limit.\n\n## Setup\n1. Connect your WhatsApp Trigger (Client ID + Client Secret) and WhatsApp Business Cloud credentials \u2014 follow the n8n WhatsApp docs.\n2. Connect your OpenAI and Google Gemini credentials.\n3. In \"Send Reply on WhatsApp\", select your business Phone Number ID.\n4. Open the Configuration node and adjust the variables (system prompt, models, prompts, memory size).\n5. Activate the workflow and message your WhatsApp Business number.\n\n## Requirements\n* A WhatsApp Business Cloud account (Meta app with the WhatsApp product enabled)\n* An OpenAI API key (chat replies, voice transcription, image analysis)\n* A Google Gemini API key (video analysis only \u2014 remove the video branch if you do not need it)\n\n## Customization\n* Every user-adjustable value lives in the Configuration node: AI models, system prompt, image/video prompts, memory window and reply length.\n* Swap Wikipedia for your own tools (CRM, calendar, vector store) to turn this into a support or booking assistant.\n* Reply with images, audio or documents instead of text by changing the message type in the WhatsApp node.\n\nNeed help customizing?\nContact me for consulting and support : [Linkedin](https://www.linkedin.com/in/doctor-firass/)\n\n# MY NEW YOUTUBE CHANNEL\n\ud83d\udc49 [Subscribe to my new YouTube channel](https://www.youtube.com/@DrFiras_AI). Here I'll share videos and Shorts with practical tutorials and FREE templates for n8n.\n\n[![The AI Doctor](https://www.dr-firas.com/the-ai-doctor.png)](https://www.youtube.com/@DrFiras_AI)"
      },
      "typeVersion": 1
    },
    {
      "id": "6d6d22c0-bb36-4f67-b829-24e837228185",
      "name": "Sticky Note 15f59dc5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -640,
        -48
      ],
      "parameters": {
        "color": 7,
        "width": 300,
        "height": 200,
        "content": "## 1. Receive WhatsApp messages\nThe trigger listens to incoming messages on your WhatsApp Business number, then the payload is split into individual messages."
      },
      "typeVersion": 1
    },
    {
      "id": "2b4e00e2-061f-425d-b463-2ae3c039fe88",
      "name": "Sticky Note 0ccafaa0",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -640,
        -368
      ],
      "parameters": {
        "color": 7,
        "width": 300,
        "height": 264,
        "content": "## \u2699\ufe0f Configuration \u2014 edit me first\nAll user-adjustable variables live here: system prompt, OpenAI & Gemini models, image/video prompts, memory window and max reply length. No need to open any other node."
      },
      "typeVersion": 1
    },
    {
      "id": "6c451878-d829-42cb-a533-aa0b9d4dd819",
      "name": "Sticky Note 369fac2f",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -320,
        -368
      ],
      "parameters": {
        "color": 7,
        "width": 300,
        "height": 264,
        "content": "## 2. Route by message type\nEach message is sent to 1 of 4 branches: voice note, video, image or plain text."
      },
      "typeVersion": 1
    },
    {
      "id": "79946a68-35e3-43ef-868d-8715fde1acc1",
      "name": "Sticky Note 3e564b69",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        16,
        -368
      ],
      "parameters": {
        "color": 7,
        "width": 300,
        "height": 264,
        "content": "## 3. Voice notes \u2192 OpenAI transcription \ud83d\udcac\nThe voice note is downloaded from WhatsApp and transcribed to text with OpenAI."
      },
      "typeVersion": 1
    },
    {
      "id": "7d67f3e8-cfca-47fa-adb9-1505cb3222c4",
      "name": "Sticky Note d041f4df",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        336,
        -368
      ],
      "parameters": {
        "color": 7,
        "width": 300,
        "height": 264,
        "content": "## 4. Videos \u2192 Gemini description \ud83c\udfac\nGemini natively understands video. The file is downloaded and described (scenes, speech, on-screen text). Requires a Google Gemini API key."
      },
      "typeVersion": 1
    },
    {
      "id": "b6a60cd9-17ab-43aa-a1e9-75f219a56e50",
      "name": "Sticky Note fdb48800",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        656,
        -368
      ],
      "parameters": {
        "color": 7,
        "width": 300,
        "height": 264,
        "content": "## 5. Images \u2192 GPT vision \ud83c\udfde\ufe0f\nThe image is downloaded and described by GPT vision, including any visible text."
      },
      "typeVersion": 1
    },
    {
      "id": "8549a716-4a0c-414a-a6b5-3bb3fa1ea5cb",
      "name": "Sticky Note 7f1b746a",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        976,
        -368
      ],
      "parameters": {
        "color": 7,
        "width": 300,
        "height": 264,
        "content": "## 6. AI agent with memory & tools \ud83e\udd16\nThe agent replies using the system prompt from Configuration, remembers each user separately (per-phone-number memory) and can search Wikipedia for facts."
      },
      "typeVersion": 1
    },
    {
      "id": "e958de7b-713a-4e6e-9820-c12fe36805a1",
      "name": "Sticky Note 35c92876",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1312,
        -368
      ],
      "parameters": {
        "color": 7,
        "width": 300,
        "height": 264,
        "content": "## 7. Reply on WhatsApp \u2705\nThe answer is sent back to the same user, trimmed to the character limit. Select your business Phone Number ID here."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "availableInMCP": true,
    "executionOrder": "v1"
  },
  "versionId": "4dd3d28d-ca2c-41cd-9878-20dd90c1bfe4",
  "nodeGroups": [],
  "connections": {
    "AI Agent": {
      "main": [
        [
          {
            "node": "Send Reply on WhatsApp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wikipedia": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Configuration": {
      "main": [
        [
          {
            "node": "Split Out Message Parts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "WhatsApp Trigger": {
      "main": [
        [
          {
            "node": "Configuration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Download Audio File": {
      "main": [
        [
          {
            "node": "Transcribe Voice Note with OpenAI",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Image File": {
      "main": [
        [
          {
            "node": "Analyze Image with GPT Vision",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Video File": {
      "main": [
        [
          {
            "node": "Describe Video with Gemini",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Agent Input": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Per-User Chat Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Route by Message Type": {
      "main": [
        [
          {
            "node": "Get Audio Download URL",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get Video Download URL",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get Image Download URL",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Prepare Agent Input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Audio Download URL": {
      "main": [
        [
          {
            "node": "Download Audio File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Image Download URL": {
      "main": [
        [
          {
            "node": "Download Image File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Video Download URL": {
      "main": [
        [
          {
            "node": "Download Video File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out Message Parts": {
      "main": [
        [
          {
            "node": "Route by Message Type",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Describe Video with Gemini": {
      "main": [
        [
          {
            "node": "Prepare Agent Input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Analyze Image with GPT Vision": {
      "main": [
        [
          {
            "node": "Prepare Agent Input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Transcribe Voice Note with OpenAI": {
      "main": [
        [
          {
            "node": "Prepare Agent Input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}