> For the complete documentation index, see [llms.txt](https://docs.lipachat.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.lipachat.com/guides/build-a-chat-bot.md).

# Build A Chat Bot

This guide walks you through setting up a basic WhatsApp chatbot using Lipachat APIs. It assumes you’ve already joined the sandbox or connected your own WhatsApp Business number.

### 🪝 Step 1: Set Up Your Webhook

Navigate to the Lipachat Dashboard → **Settings** → **Webhook**

Set the **Webhook URL** to point to your server endpoint that will handle incoming messages.

**Example:**

```
https://yourdomain.com/webhook
```

When a customer sends a message on WhatsApp, Lipachat will send a POST request to your webhook with the message payload.

### 📩 Step 2: Handle Incoming Message

Example payload:

```json
{
     "messageId": "c94ced08-5f40-46b7-a88d-7d4fbe113fe9",
     "from": "CUSTOMER_PHONE_NUMBER",
     "to": "WHATSAPP_NUMBER",
     "profileName": "CUSTOMER_NAME",
     "type": "TEXT",
     "text": "Text Content"
}
```

Your backend logic should parse this payload and determine the appropriate response (e.g., predefined replies or bot logic).

### 📤 Step 3: Respond with a Message

Once your bot determines a reply, call the [**Free-Form Message API**](/api/sending-messages.md) to respond.

**Text reply example:**

```shellscript
curl --location 'https://gateway.lipachat.com/api/v1/whatsapp/message/text' \
--header 'apiKey: YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
    "message": "Hello world",
    "messageId": "e66fc7b8-680f-4887-8dc8-ee062d65b54f",
    "to": "254XXXXXXX",
    "from": "254110090747"
}'
```

### 🖼 Optional: Respond with Media

Use the **Send Media API** to reply with images, PDFs, audio, or video.

**Media reply example:**

```shellscript
curl --location 'https://gateway.lipachat.com/api/v1/whatsapp/media' \
--header 'apiKey: YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
    "messageId": "5d3f62c3-eb8f-4150-8941-bdceb0f429bb",
    "to": "254XXXXX",
    "from": "254110090747",
    "mediaType": "IMAGE",
    "mediaUrl": "https://picsum.photos/id/237/200/300",
    "caption": ""
}'
```

Other supported message types are: Buttons, Interactive Lists, Contacts, Location, and Flows.

### Summary: End-to-End Flow

1. The customer sends a message via WhatsApp
2. Lipachat delivers the message to your **Webhook**
3. Your chatbot processes the message
4. Your system calls `Send Message` or `Send Media` API
5. The customer receives the bot reply on WhatsApp
