Lipachat Docs
  • Lipachat Docs
  • Getting Started
    • Getting Started with Lipachat
  • API
    • Sending Messages
    • Sending Media
    • Sending Buttons
    • Sending Interactive Lists
    • Templates
      • Creating a Template
      • Updating a Template
      • Listing Message Templates
      • Sending Message Templates
    • Whatsapp Flows
      • Creating a flow
      • Updating a flow
      • Get flow preview
      • Publish a flow
      • Send a flow
      • List all flows
    • Webhooks
  • Reference
    • Sandbox
  • Go Live
  • Guides
    • Build A Chat Bot
  • CRM Workflow
Powered by GitBook
On this page
  • ๐Ÿช Step 1: Set Up Webhook
  • ๐Ÿ“ฅ Step 2: Receive and Display Incoming Messages
  • ๐Ÿง  Step 3: Determine Session Status
  • ๐Ÿ“ Step 4A: Respond Within 24-Hour Session (Free Form)
  • ๐Ÿงพ Step 4B: Respond Outside Session (Template Message)
  • End-to-End Flow Summary

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.

PreviousBuild A Chat Bot

Last updated 18 hours ago

Need help creating message templates? Visit the Guide.

Message Templates