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;

Session expires at should hold the timestamp of the last message time + 24 hours. E.g., if a customer's last message is 27th May 2025 9.00 am, the 'session_expires_at' will be 28th May 2025 9.00 am

πŸ“ 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

  1. Customer sends message β†’ webhook sends to CRM

  2. CRM operator sees message and session info

  3. If the session is active β†’ send a reply

  4. 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