Skip to main content

WhatsApp Notifications

Send WhatsApp messages to your users through the Notifications API. This integration supports both simple text messages and rich template-based messages with formatted content.

Prerequisites

Before implementing WhatsApp notifications, ensure you have:

  1. Authentication token for the WhatsApp API
  2. Phone number ID registered with WhatsApp Business API
  3. Pre-approved message templates (for template messages)
  4. API subscription key

You can access your WhatsApp authentication tokens and phone number IDs through the WhatsApp Developer Hub.

Sending Text Messages

Text messages allow you to send simple content without formatting or media.

Endpoint

POST https://apis.lightstone.co.za/lightstone-capabilities-notifications-api/v1/WhatsApp/Send/TextOnly

Request Headers

HeaderRequiredDescription
Ocp-Apim-Subscription-KeyYesYour API subscription key
correlationidNoUnique identifier for tracking the request
x-ls-party-idNoParty identifier for the sender

Request Body

{
"authToken": "YOUR_WHATSAPP_AUTH_TOKEN",
"phoneNumberId": "YOUR_WHATSAPP_PHONE_ID",
"sendToPhoneNumber": "RECIPIENT_PHONE_NUMBER",
"countryCode": "COUNTRY_CODE",
"messageBody": "Your message text here"
}

Response

A successful request returns:

{
"statusCode": 0,
"message": "Message sent successfully"
}

Sending Template Messages

Template messages use pre-approved formats with placeholders for dynamic content.

Endpoint

POST https://apis.lightstone.co.za/lightstone-capabilities-notifications-api/v1/WhatsApp/Send/Template

Request Headers

Same headers as text-only messages.

Request Body

{
"authToken": "YOUR_WHATSAPP_AUTH_TOKEN",
"phoneNumberId": "YOUR_WHATSAPP_PHONE_ID",
"sendToPhoneNumber": "RECIPIENT_PHONE_NUMBER",
"countryCode": "COUNTRY_CODE",
"templateName": "your_template_name",
"languageCode": "en_US",
"components": [
{
"type": "body",
"parameters": [
{
"type": "text",
"text": "Parameter value 1"
},
{
"type": "text",
"text": "Parameter value 2"
}
]
}
]
}

Component Types

WhatsApp templates support these component types:

  • header: The template header (supports text, image, document, or video)
  • body: The main content section (supports text parameters)
  • button: Interactive buttons (URLs or quick replies)

Header Component Example

{
"type": "header",
"parameters": [
{
"type": "image",
"image": {
"link": "https://example.com/image.jpg"
}
}
]
}

Error Handling

The API returns standard HTTP status codes:

  • 200 OK: Request successful
  • 400 Bad Request: Invalid parameters

Error responses include a descriptive message:

{
"statusCode": 1,
"message": "Error description"
}

Implementation Examples

using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

public class WhatsAppService
{
private readonly HttpClient _httpClient;
private readonly string _baseUrl = "https://apis.lightstone.co.za/lightstone-capabilities-notifications-api/v1";
private readonly string _subscriptionKey;

public WhatsAppService(string subscriptionKey)
{
_httpClient = new HttpClient();
_subscriptionKey = subscriptionKey;
}

public async Task<string> SendTextMessage(string authToken, string phoneNumberId,
string recipientNumber, string countryCode, string messageText)
{
var request = new
{
authToken = authToken,
phoneNumberId = phoneNumberId,
sendToPhoneNumber = recipientNumber,
countryCode = countryCode,
messageBody = messageText
};

var content = new StringContent(JsonSerializer.Serialize(request), Encoding.UTF8, "application/json");

_httpClient.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", _subscriptionKey);

var response = await _httpClient.PostAsync($"{_baseUrl}/WhatsApp/Send/TextOnly", content);
response.EnsureSuccessStatusCode();

return await response.Content.ReadAsStringAsync();
}

public async Task<string> SendTemplateMessage(string authToken, string phoneNumberId,
string recipientNumber, string countryCode, string templateName, string languageCode, object components)
{
var request = new
{
authToken = authToken,
phoneNumberId = phoneNumberId,
sendToPhoneNumber = recipientNumber,
countryCode = countryCode,
templateName = templateName,
languageCode = languageCode,
components = components
};

var content = new StringContent(JsonSerializer.Serialize(request), Encoding.UTF8, "application/json");

_httpClient.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", _subscriptionKey);

var response = await _httpClient.PostAsync($"{_baseUrl}/WhatsApp/Send/Template", content);
response.EnsureSuccessStatusCode();

return await response.Content.ReadAsStringAsync();
}
}

Best Practices

  1. Always validate phone numbers before sending messages
  2. Include country code in international format (example: "ZA" for South Africa)
  3. Keep text messages concise and clear
  4. Test templates thoroughly before sending to customers
  5. Implement error handling for failed message deliveries
  6. Cache authentication tokens when possible to improve performance
  7. Add correlation IDs to trace message flows across systems

Rate Limits and Performance

  • The WhatsApp API imposes rate limits on message sending
  • Batch multiple recipients when possible to reduce API calls
  • Implement exponential backoff for retry logic
  • Monitor delivery success rates to optimize sending patterns