Documentation & Integration Guide

Learn how LeadAI connects WhatsApp, Twilio, and OpenAI to automate your lead generation.

1. Platform Workflow

LeadAI acts as the intelligent middle layer between your customers on WhatsApp, Twilio's messaging infrastructure, and OpenAI's language models. Here is how it works:

  1. Customer Messages You: A lead sends a WhatsApp message to your Twilio number.
  2. Twilio Webhook: Twilio forwards this message to your LeadAI webhook URL.
  3. Lead Creation: LeadAI creates a new profile for the lead or updates their existing chat history in the CRM.
  4. AI Processing: LeadAI sends the conversation context and your custom "AI Prompt" instructions to OpenAI.
  5. Auto-Reply: The AI generates a tailored response, and LeadAI sends it back to the customer via Twilio instantly.
  6. Human Handoff: You can monitor chats in the dashboard and toggle off the AI Auto-Reply at any time to take over the conversation manually.

2. Getting Your API Keys

To power this workflow, you need active accounts with Twilio (for WhatsApp sending/receiving) and OpenAI (for the brain).

Twilio Integration

  1. Go to Twilio.com and sign up or log in.
  2. In your Twilio Console, copy your Account SID and Auth Token. Paste these into your LeadAI .env file or Settings panel.
  3. Navigate to Messaging > Try it out > Send a WhatsApp message to activate your Twilio Sandbox for WhatsApp, or apply for a dedicated WhatsApp Business Number.
  4. You will be assigned a Twilio WhatsApp Number (e.g., whatsapp:+14155238886). Save this as your TWILIO_WHATSAPP_NUMBER.

OpenAI Integration

  1. Go to platform.openai.com and sign up or log in.
  2. Navigate to API Keys on the left sidebar.
  3. Click Create new secret key. Name it "LeadAI".
  4. Copy the generated key (it starts with sk-...) and save it as your OPENAI_API_KEY.
    Note: Ensure you have added billing details to your OpenAI account, or the API will reject requests.

3. Setting up the Webhook (The Fallback URL)

For Twilio to know where to send incoming WhatsApp messages, you must configure a webhook URL. This URL is the entry point to your LeadAI application.

Your Webhook URL

https://your-domain.com/webhook/whatsapp

*Replace your-domain.com with your actual deployed website domain.

How to configure it in Twilio:

  1. In Twilio, go to Messaging > Senders > WhatsApp Senders.
  2. Click on your active WhatsApp number.
  3. Scroll down to the Endpoint Configuration section.
  4. Under "A message comes in", select Webhook.
  5. Paste your webhook URL (https://your-domain.com/webhook/whatsapp) into the URL field.
  6. Ensure the HTTP method is set to HTTP POST.
  7. Click Save.

You're All Set!

Your integration is now live. Send a message to your Twilio WhatsApp number to see the AI reply automatically.