My App

WhatsApp Messaging

Endpoints for sending WhatsApp messages, managing templates, and running bulk campaigns.

Send Message

Send a text message or media file to a WhatsApp contact.

Endpoint: POST /api/whatsapp/send

Request Body (multipart/form-data):

  • to: Phone number with country code (e.g., 1234567890) (Required)
  • message: The text message or media caption. (Required for chat type)
  • type: Message type. Options: chat, image, video, audio, document. (Default: chat)
  • file: The media file to send. (Required for media types)
  • sessionId: (Optional) The ID of the WhatsApp session to use.

Constraints:

  • Maximum file size: 50MB.
  • Supported image formats: JPEG, PNG, GIF, WebP.
  • Supported video formats: MP4, 3GPP, QuickTime.
  • Supported audio formats: MPEG, OGG, WAV, WebM, AAC.
  • Supported document formats: PDF, MS Word, MS Excel, Zip, Plain Text.

Response:

  • Status: 200 OK
  • Body:
{
  "success": true,
  "message": "Message sent successfully"
}

Example Requests

# Send text message
curl -X POST $API_URL/whatsapp/send \
  -H "Authorization: Bearer $TOKEN" \
  -F "to=1234567890" \
  -F "message=Hello from the API!" \
  -F "type=chat"

# Send image with caption
curl -X POST $API_URL/whatsapp/send \
  -H "Authorization: Bearer $TOKEN" \
  -F "to=1234567890" \
  -F "message=Check out this image!" \
  -F "type=image" \
  -F "file=@/path/to/image.jpg"

Templates

Manage message templates with variables for personalized messaging.

Create Template

Endpoint: POST /api/templates

Request Body:

{
  "name": "Welcome Message",
  "content": "Hi {{name}}! Welcome to our service.",
  "category": "Marketing"
}

Example Request

curl -X POST $API_URL/templates \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Welcome Message",
    "content": "Hi {{name}}! Welcome to our service.",
    "category": "Marketing"
  }'

List Templates

Endpoint: GET /api/templates

Response:

{
  "success": true,
  "data": [
    {
      "_id": "template_id",
      "name": "Welcome Message",
      "content": "Hi {{name}}! Welcome to our service.",
      "variables": ["name"]
    }
  ]
}

Bulk Messages

Create and manage bulk messaging campaigns.

Create Campaign

Endpoint: POST /api/bulk

Request Body (multipart/form-data):

  • name: Campaign name (Required)
  • templateId: ID of the template to use (Required)
  • sessionId: ID of the active WhatsApp session (Required)
  • recipients: (Optional) JSON array of recipient objects [{ "phone": "1234567890", "variables": { "name": "John" } }]. Required if csv is not provided.
  • csv: (Optional) CSV file containing recipients. Required if recipients is not provided.
  • media: (Optional) Media file to be sent with the campaign.
  • mediaType: (Optional) Type of the media file (image, video, audio, document). (Default: image)

Constraints:

  • Maximum media file size: 50MB.

Response:

{
  "success": true,
  "data": {
    "_id": "campaign_id",
    "name": "Spring Sale",
    "status": "PENDING",
    "totalCount": 100
  }
}

Example Request

curl -X POST $API_URL/bulk \
  -H "Authorization: Bearer $TOKEN" \
  -F "name=Spring Sale" \
  -F "templateId=YOUR_TEMPLATE_ID" \
  -F "sessionId=YOUR_SESSION_ID" \
  -F "csv=@/path/to/recipients.csv" \
  -F "media=@/path/to/promo.jpg" \
  -F "mediaType=image"

Get Campaign Status

Endpoint: GET /api/bulk/:id

Response:

{
  "success": true,
  "data": {
    "_id": "campaign_id",
    "status": "IN_PROGRESS",
    "sentCount": 45,
    "failedCount": 2,
    "totalCount": 100
  }
}

On this page