CRMconnect Azuvio · Docs

Workflow: WhatsApp → Lead / Support

Modules involved: WhatsApp (Inbox · Bots · Campaigns · Templates) · WhatsApp API (Event Notifications) · Leads · Tickets · Marketing Automation
Who uses it: Sales · Customer Support · Marketing
Typical duration: Real-time (incoming messages) + campaign cycle (onetime/recurring)

Overview

CRMConnect has three distinct WhatsApp modules with completely different purposes:

Module Purpose Requires Meta API?
whatsapp Bidirectional inbox, bots, bulk campaigns, auto-lead Yes — full setup
whatsapp_api Outbound notifications on CRM events (lead created, invoice, ticket, etc.) Yes — shared credentials
whatsapp_chat Embedded click-to-chat widget (third-party HTML snippet) No — no own API

This workflow covers the main whatsapp module (inbox + auto-lead + bots + campaigns) and whatsapp_api (event notifications).

Note: Automatic ticket creation from WhatsApp conversations is partially implemented (AI collects data but the insert into tbltickets is missing from code). Tickets are created manually by staff from the chat interface.


Flow diagram

[SETUP — admin, once only]
  │
  ├── Meta App + WhatsApp Business Account configured
  ├── Webhook registered with Meta: {site_url}/whatsapp/webhook/getdata
  ├── Phone number connected in WhatsApp → Numbers
  ├── Templates loaded from Meta (manual sync or hourly cron)
  └── Auto-lead enabled (optional): whatsapp_auto_lead_settings = 'enable'
  │
  ↓
[INCOMING MESSAGE]
  │
  ├── Meta sends webhook POST to /whatsapp/webhook/getdata
  ├── System searches number in: leads → contacts → staff
  │
  ├── NUMBER IDENTIFIED → maps conversation to existing record
  │     rel_type = 'leads' / 'contacts' / 'staff'
  │
  └── UNKNOWN NUMBER:
        ├── auto_lead ENABLED → creates Lead automatically
        │     status = whatsapp_lead_status
        │     source = whatsapp_lead_source
        │     assigned = whatsapp_lead_assigned
        │     rel_type = 'leads'
        │
        └── auto_lead DISABLED (default) → rel_type = 'general'
              staff sees conversation as unknown in inbox
  │
  ↓
[BOT (if active)]
  │
  ├── BotHandler::processBots() evaluates ALL active bots
  ├── Trigger match → sends automatic response (text / template / menu / AI)
  └── No match → message remains in inbox for manual response
  │
  ↓
[STAFF RESPONSE / ESCALATION]
  │
  ├── Staff opens /admin/whatsapp → inbox
  ├── Sees conversations grouped: identified (lead/contact) + general
  ├── Replies directly or uses Quick Replies
  └── Creates ticket manually from conversation (if support requires it)
  │
  ↓
[BULK CAMPAIGN (separate flow)]
  │
  ├── Approved Meta template created
  ├── New campaign: type (onetime/recurring/custom), recipients, sender number
  ├── send_now=1 or scheduled_send_time planned
  └── Cron executes sending → status per recipient: failed(0) / success(2) / invalid(3)
  │
  ↓
[EVENT NOTIFICATIONS — whatsapp_api module]
  │
  ├── Lead created → template mapped to 'leads' category sent automatically
  ├── Ticket created → template mapped to 'ticket' sent automatically
  ├── Invoice added → template mapped to 'invoice'
  └── Payment recorded → template mapped to after_payment_added

[CONVERSATION CLOSED / LEAD QUALIFIED ✓]

Step by step

1. Meta setup + connection (admin)

Where: /admin/whatsapp → Settings → Connection tab

Condition: All fields below are is_admin() only — regular staff cannot access.

Field / Option Description
whatsapp_business_id Meta Business ID (from Meta Business Suite)
whatsapp_business_account_id WABA ID (WhatsApp Business Account)
whatsapp_access_token Permanent System User Token (not a temporary user token)
whatsapp_webhook_token Any string of your choosing — used for Meta webhook verification
whatsapp_meta_app_id App ID from Meta for Developers
whatsapp_meta_app_secret App Secret from Meta for Developers

Webhook URL to register with Meta:

{site_url}/whatsapp/webhook/getdata

Required Meta subscriptions: messages + message_status_updates.

Phone numbers: after connecting credentials, numbers are added in WhatsApp → Numbers (via OAuth or manually). Set one number as default for outgoing messages.

Templates: WhatsApp → Templates → Load Templates (syncs from Meta). Cron automatically refreshes every hour.


2. Auto-lead configuration (optional)

Where: /admin/whatsapp → Settings → Auto Lead tab

Option Description
whatsapp_auto_lead_settings 'enable' activates automatic creation · 'disable' (default) deactivates
whatsapp_lead_status Lead status ID (from /admin/leads_status) set at creation
whatsapp_lead_source Lead source ID (from /admin/leads_sources) set at creation
whatsapp_lead_assigned staffid to whom the lead is automatically assigned

Number identification flow (in order):

  1. Search in tblleads.phonenumber (normalized without non-numeric characters)
  2. Search in tblcontacts.phonenumber
  3. Search in tblstaff.phonenumber
  4. If no match → create lead (if auto_lead enabled) or leave as general

3. Bot configuration (optional)

Where: /admin/whatsapp → Bots → New Bot

Trigger types (reply_type):

Value Trigger
1 Message exact match with trigger keyword
2 Message contains trigger keyword
3 First message in conversation history
4 Keyword match (synonyms included)
5 Message within business hours (trigger = "09:00-17:00")
6 Message outside business hours
7 First message in current session (24h window)
8 User idle for X minutes
9 User requests human agent
10 Synonym match
11 Conversation timeout reminder
12 No staff response in X minutes
13 Conversation closed + rating request

Response types (bot_type):

Value Response
1 Plain text
2 Approved Meta template
3 List menu (multi-level, state kept in interaction_menu_state)
4 Flow bot (JSON node graph in flow_data)
5 Media file
6 GPS location
7 Interactive buttons
11 Contact card
12 AI response (OpenAI / Gemini — requires configured API key)
13 Star rating

AI configuration (for bot_type=12): Where: Settings → AI tab: choose provider (openai/gemini), enter API key, set whatsapp_openai_status:

  • auto = AI automatically responds to all messages with no match on other bots
  • manual = AI generates a response suggestion visible to staff, but does not send automatically

4. Inbox and manual response

Where: /admin/whatsapp (requires whatsapp_chat → view permission)

Conversations are grouped by rel_type:

  • leads — conversations linked to leads
  • contacts — conversations linked to contacts
  • staff — conversations with employees
  • general — unidentified numbers (auto_lead disabled)

Staff can:

  • Reply with text, files, Quick Replies (tblquick_replies)
  • Assign conversation to another staff member
  • Manually create a Ticket from the interface (ticket is NOT created automatically)
  • View complete message history (tblwhatsapp_interaction_messages)

5. Bulk campaigns

Where: /admin/whatsapp → Campaigns → New Campaign

Prerequisites:

  • Approved Meta template (status = 'APPROVED' in tblwhatsapp_interaction_templates)
  • At least one phone number configured

Campaign fields:

Field Description
name Campaign name
rel_type Recipients: leads · contacts · whatsapp_groups · whatsapp_contacts
template_id Approved Meta template
number_id Sender number (from tblwhatsapp_numbers)
campaign_type onetime · recurring · custom
auto_reminder_days Days between sends (for recurring)
scheduled_send_time Scheduled date/time
send_now 1 = send immediately at cron execution

Statuses per recipient (tblwhatsapp_campaign_data):

status Meaning
0 Failed (API error)
2 Success — message sent
3 Invalid number

Delivery statuses (message_status): sentdeliveredread

Note: Campaigns are executed by cron, not instantly. If the CRM cron is not running, scheduled campaigns are not sent.


6. Automatic notifications on CRM events (whatsapp_api module)

Where: /admin/whatsapp_api → Template Mapping

The whatsapp_api module fires independently of the inbox, based on hooks:

CRM Hook Template category
lead_created leads
web_to_lead_form_submitted leads
contact_created contacts
after_invoice_added invoice
after_add_task task
after_add_project project
proposal_created proposal
after_payment_added payment
ticket_created ticket
after_cron_run Scheduled reminders

Configuration per notification:

  1. Sync templates: WhatsApp API → Templates → Load
  2. Create mapping: WhatsApp API → Template Mapping → Add
  3. Choose template + category + send_to (contact / lead / staff) + header/body/footer parameters

The whatsapp_api module shares Meta credentials with the whatsapp module (same access_token and phone_number_id), but stores them separately in its own options.


Required permissions

Permission Access
whatsapp_chat → view Access to inbox (read + send messages)
whatsapp_bot → view/create/edit/delete Manage bots
whatsapp_template → view / load_template View and sync templates
whatsapp_campaign → view/create/edit/delete Manage campaigns
whatsapp_numbers → view/edit View/edit numbers
whatsapp_contacts → view/create/edit/delete Manage WhatsApp contacts
whatsapp_groups → view/create/edit/delete Manage groups
whatsapp_log_activity → view/clear_log View API activity log
quickreplies → view/create/edit/delete Quick replies
Connection Settings (Meta credentials) is_admin() exclusively
WhatsApp Chat widget settings is_admin() exclusively

Gotchas

Problem Cause Solution
Meta webhook does not receive messages Incorrect URL or mismatched token Verify that {site_url}/whatsapp/webhook/getdata is publicly accessible and the token matches
Leads are not created automatically whatsapp_auto_lead_settings is 'disable' (default) Explicitly enable from Settings → Auto Lead
Bot does not respond is_bot_active = 0 or trigger does not match Enable bot and check trigger condition (exact match vs. contains)
Campaign was not sent at scheduled time CRM cron is not running Check /admin/misc/cron_jobs — cron must be active
Template does not appear in campaign Status in Meta is not APPROVED Check status in Meta Business Manager; reload templates
whatsapp_api notifications are not sent phone_number_id not set in whatsapp_api module Configure credentials separately in WhatsApp API → Settings
Ticket was not created from conversation Automatic creation is not implemented Staff must manually create the ticket from the chat interface

Module references

Tip

Get WhatsApp message templates approved by Meta before any campaign or support workflow launches — approval takes 24-48 hours and without an approved template you cannot initiate conversations outside the 24-hour session window.

Warning

WhatsApp Business API credentials must be kept strictly confidential. A leaked Access Token allows anyone to send messages from your business number — rotate credentials immediately if exposure is suspected and revoke from the Connection page.