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:
- Customer Messages You: A lead sends a WhatsApp message to your Twilio number.
- Twilio Webhook: Twilio forwards this message to your LeadAI webhook URL.
- Lead Creation: LeadAI creates a new profile for the lead or updates their existing
chat history in the CRM.
- AI Processing: LeadAI sends the conversation context and your custom "AI Prompt"
instructions to OpenAI.
- Auto-Reply: The AI generates a tailored response, and LeadAI sends it back to the
customer via Twilio instantly.
- 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
- Go to Twilio.com and sign up or log in.
- In your Twilio Console, copy your Account SID and Auth Token.
Paste these into your LeadAI
.env file or Settings panel.
- 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.
- You will be assigned a Twilio WhatsApp Number (e.g.,
whatsapp:+14155238886). Save this
as your TWILIO_WHATSAPP_NUMBER.
OpenAI Integration
- Go to platform.openai.com and sign up or log in.
- Navigate to API Keys on the left sidebar.
- Click Create new secret key. Name it "LeadAI".
- 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:
- In Twilio, go to Messaging > Senders > WhatsApp Senders.
- Click on your active WhatsApp number.
- Scroll down to the Endpoint Configuration section.
- Under "A message comes in", select Webhook.
- Paste your webhook URL (
https://your-domain.com/webhook/whatsapp) into the URL field.
- Ensure the HTTP method is set to HTTP POST.
- 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.