Skip to content

smoothsoftwareengineer/Whatsapp-Sales-Chatbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WhatsApp Sales Chatbot (Python)

Automates a predefined sales funnel on WhatsApp, integrated with Kommo (CRM), Asaas (payments), Google Drive (digital delivery), and Make (optional orchestration).

Architecture

flowchart LR
  WA[WhatsApp Cloud API] --> API[FastAPI app]
  MK[Make.com scenarios] --> API
  API --> Funnel[Funnel engine]
  Funnel --> Kommo[Kommo CRM]
  Funnel --> Asaas[Asaas payments]
  Funnel --> Drive[Google Drive]
  Asaas -->|webhook| API
Loading
Component Role
app/funnel.py State machine driven by config/funnel.yaml
app/integrations/kommo.py Contacts, leads, pipeline status, notes
app/integrations/asaas.py Customers, payment links, payment status
app/integrations/google_drive.py File metadata and delivery link
app/integrations/whatsapp.py Outbound messages (Meta Cloud API)
app/main.py Webhooks: WhatsApp, Make, Asaas

Inbound messages can arrive via:

  1. Meta WhatsApp Cloud APIPOST /webhooks/whatsapp
  2. Make.com HTTP module → POST /webhooks/make (useful if WhatsApp is connected through Kommo/Make)

Quick start

cd d:\AI_Projects\whatsapp_chatbot
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt
copy .env.example .env
# Edit .env with your API keys
python run.py

API docs: http://localhost:8000/docs

Expose locally with ngrok or similar and set WEBHOOK_BASE_URL to your public URL.

Configuration

1. WhatsApp (Meta)

  • Create a Meta Business app with WhatsApp product.
  • Set WHATSAPP_ACCESS_TOKEN, WHATSAPP_PHONE_NUMBER_ID, WHATSAPP_VERIFY_TOKEN.
  • Configure webhook URL: {WEBHOOK_BASE_URL}/webhooks/whatsapp.

2. Kommo

  • Create a private integration: Kommo developers.
  • Copy long-lived token → KOMMO_ACCESS_TOKEN, subdomain → KOMMO_SUBDOMAIN.
  • In Kommo, note pipeline ID and status IDs for: new lead, payment pending, paid, delivered → map to .env.

3. Asaas

  • API key from Asaas dashboard → ASAAS_API_KEY.
  • Sandbox: ASAAS_ENV=sandbox (default).
  • Webhook URL: {WEBHOOK_BASE_URL}/webhooks/asaas
    Events: PAYMENT_RECEIVED, PAYMENT_CONFIRMED.
  • Set ASAAS_WEBHOOK_TOKEN to match the token Asaas sends in header asaas-access-token.

4. Google Drive

  • Create a Google Cloud project, enable Drive API.
  • Service account JSON → save as credentials/google-service-account.json.
  • Share the product folder/file with the service account email.
  • Set GOOGLE_APPLICATION_CREDENTIALS and GOOGLE_DRIVE_FILE_ID (material to deliver).

5. Sales funnel

Edit config/funnel.yaml — messages, menu options, and step flow. Placeholders:

  • {product_value} — from PRODUCT_VALUE
  • {payment_url} — after Asaas link is created
  • {delivery_link} — Google Drive view link

6. Make.com (optional)

Typical scenario:

  1. Trigger: Kommo new message / WhatsApp / webhook from provider.
  2. HTTPPOST {your-server}/webhooks/make
    Body example:
{
  "phone": "5511999999999",
  "text": "{{message.body}}",
  "name": "{{contact.name}}"
}
  1. Header: X-Make-Secret: <MAKE_WEBHOOK_SECRET> if configured.

Use Make for retries, logging, or when WhatsApp is not connected directly to Meta API.

Endpoints

Method Path Purpose
GET /health Health check
GET/POST /webhooks/whatsapp Meta verification + inbound messages
POST /webhooks/make Generic inbound from Make
POST /webhooks/asaas Payment confirmation → auto-delivery
GET /payments/success Redirect after Asaas checkout

Payment → delivery flow

  1. Customer chooses purchase → bot creates Asaas customer + payment link (externalReference = phone).
  2. Kommo lead moves to payment pending; note stores link.
  3. Asaas webhook fires on payment → on_payment_confirmed sends Drive link on WhatsApp.
  4. Customer can also type 3 (Já paguei) to poll Asaas and trigger delivery.
  5. Kommo lead updates to paid / delivered.

Project layout

whatsapp_chatbot/
├── app/
│   ├── main.py              # FastAPI webhooks
│   ├── funnel.py            # Sales funnel logic
│   ├── config.py            # Settings
│   ├── storage.py           # SQLite sessions
│   └── integrations/
│       ├── whatsapp.py
│       ├── kommo.py
│       ├── asaas.py
│       └── google_drive.py
├── config/funnel.yaml
├── requirements.txt
├── .env.example
└── run.py

Production notes

  • Run behind HTTPS (required by Meta/Asaas webhooks).
  • Use PostgreSQL/Redis instead of SQLite for high volume (swap storage.py).
  • Add idempotency keys for webhooks (Asaas may retry).
  • Restrict webhook IPs where providers document them.
  • Never commit .env or service account JSON.

License

Private client project — all rights reserved unless otherwise agreed.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages