How to Create an n8n AI Agent for WhatsApp Customer Replies

Automate your customer interactions using n8n, WhatsApp, and an AI brain like ChatGPT or Gemini. In this guide, you’ll learn exactly how to build a fully automated WhatsApp AI agent — no coding needed.


🧠 Overview

You’ll create a workflow in n8n where:

  1. WhatsApp acts as the trigger to capture incoming messages.

  2. The AI Agent Node (ChatGPT or Gemini) processes and generates a response.

  3. WhatsApp sends the AI-generated reply back to the customer.


⚙️ Tools You’ll Need

  • n8n account (self-hosted or cloud) → https://n8n.io

  • WhatsApp API connection (can use providers like 360Dialog, Twilio, or WhatsApp Cloud API)

  • OpenAI (ChatGPT) or Google Gemini API key

  • Basic understanding of n8n workflows


🧩 Step 1: Create WhatsApp Trigger

  1. Log into n8n and click Create Workflow.

  2. Add a Webhook Node (or your WhatsApp API trigger node).

  3. Set it to receive incoming messages.

  4. Copy the webhook URL and connect it to your WhatsApp API so that every new message hits your workflow.

Tip: Use test messages from your WhatsApp number to verify the trigger works.


🧠 Step 2: Add AI Agent Node (ChatGPT or Gemini)

  1. Add a new node → choose OpenAI (for ChatGPT) or Gemini (for Google AI).

  2. In the Prompt field, type something like:

     
    The user said: {{$json["message"]}} Reply in a friendly and helpful tone as a customer support agent.
  3. Choose your model (e.g., gpt-4-turbo or gemini-pro).

  4. Test it — make sure the output returns a relevant reply.

Pro Tip: You can add logic or conditions to filter certain keywords before sending to the AI node.


💬 Step 3: Send Reply Back via WhatsApp

  1. Add another node — HTTP Request or WhatsApp Send Message Node (depending on your provider).

  2. Set it to POST the AI’s reply to the WhatsApp API endpoint.

  3. Map the AI’s output text like:

     
    {{$json["data"]["choices"][0]["message"]["content"]}}

    or the equivalent for Gemini.

  4. Include recipient number and message body in JSON format.

Example JSON Body:

 
{ "to": "{{$json["from"]}}", "type": "text", "text": { "body": "{{$json["ai_reply"]}}" } }

🔄 Step 4: Test the Flow

  1. Save and activate your workflow.

  2. Send a message from WhatsApp — your n8n AI agent should now respond automatically!


Optional Enhancements

  • Add Google Sheets or Airtable to log all messages.

  • Use If/Else nodes for intent-based replies (e.g., FAQ, greeting, complaint).

  • Add Telegram or Slack notifications for monitoring activity.


🧩 Example Workflow Summary

  • Trigger: WhatsApp → incoming message

  • Node 1: AI Agent (ChatGPT/Gemini) → generates response

  • Node 2: WhatsApp → sends AI response back to user


💡 Final Thoughts

With this setup, your WhatsApp becomes an AI-powered customer assistant — answering questions, greeting new leads, or providing instant replies 24/7.

Once you’ve mastered this basic flow, you can expand it with CRM integration, lead scoring, and analytics inside n8n.


Created by: LeadGenSpot
💻 www.leadgenspot.com
✨ Smart Automations for Coaches, Creators, and Consultants

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top