CRM Workflow
π§βπΌ Integrate a CRM Workflow with WhatsApp
This tutorial guides you through integrating a CRM system with Lipachat to allow operators to respond to WhatsApp messages in real time. It includes logic for handling both 24-hour session replies and template-based messages.
πͺ Step 1: Set Up Webhook
Set your webhook endpoint in the Lipachat Dashboard β Settings. This allows Lipachat to notify your CRM when a customer sends a WhatsApp message.
Example:
https://yourcrm.com/api/whatsapp-webhook
When a message is received, a POST request will be made to this URL with the message details.
π₯ Step 2: Receive and Display Incoming Messages
Sample webhook payload:
{
"messageId": "c94ced08-5f40-46b7-a88d-7d4fbe113fe9",
"from": "CUSTOMER_PHONE_NUMBER",
"to": "WHATSAPP_NUMBER",
"profileName": "CUSTOMER_NAME",
"type": "TEXT",
"text": "Text Content"
}
Display the message in your CRMβs chat interface and associate it with the appropriate customer profile.
π§ Step 3: Determine Session Status
Check whether the 24-hour session window is still valid. If the current timestamp is before session_expires_at
, respond with a free-form message. Otherwise, use a pre-approved template.
const isSessionActive = Date.now() < session_expires_at;
π Step 4A: Respond Within 24-Hour Session (Free Form)
curl --location 'https://gateway.lipachat.com/api/v1/whatsapp/message/text' \
--header 'apiKey: YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"message": "Hello, how can I help you today?",
"messageId": "e66fc7b8-680f-4887-8dc8-ee062d65b54f",
"to": "254XXXXXXX",
"from": "254110090747"
}'
π§Ύ Step 4B: Respond Outside Session (Template Message)
curl --location 'https://gateway.lipachat.com/api/v1/whatsapp/template' \
--header 'apiKey: YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"messageId": "5c7be224-be61-4aa5-97aa-98906f1f6d15",
"to": "254XXXXXXX",
"from": "254110090747",
"template": {
"name": "declined_transfert",
"languageCode": "en",
"components": {
"header": {
"type": "IMAGE",
"mediaUrl": "https://picsum.photos/id/237/200/300"
},
"body": {
"placeholders": [
"John",
"Airtime",
"KES 100",
"Insufficient funds",
"funding your account"
]
}
}
}
}'
End-to-End Flow Summary
Customer sends message β webhook sends to CRM
CRM operator sees message and session info
If the session is active β send a reply
If the session expired β send the approved template
With this setup, your CRM team can interact with customers compliantly and in real time via WhatsApp.
Need help creating message templates? Visit the Message Templates Guide.
Last updated