Skip to main content

Agent-TS API Reference

The Agent-TS service exposes REST endpoints for WhatsApp integration, health monitoring, and internal notifications.

Base URL

http://localhost:8000    # Development
https://agent.olive.example.com  # Production

Endpoints Overview

MethodEndpointDescriptionAuth
GET/healthHealth checkNone
DELETE/api/v1/conversation/:phoneClear conversationNone
GET/api/v1/webhooks/whatsappMeta webhook verificationVerify Token
POST/api/v1/webhooks/whatsappMeta WhatsApp messagesNone
POST/api/v1/external/whatsappExternal client messagesNone
POST/api/v1/notifications/whatsappInternal notificationsHMAC

Health Check

/health
Check if the agent service is running and healthy.

Response

{
  "status": "healthy",
  "service": "olive-agent-ts",
  "activeConversations": 5
}

Example

curl http://localhost:8000/health

Clear Conversation

/api/v1/conversation/:phone
Clear the conversation history for a specific user.

Path Parameters

ParameterTypeDescription
phonestringPhone number (E.164 or local format)

Response

{
  "success": true,
  "message": "Conversation history cleared for +23279123456"
}

Example

curl -X DELETE "http://localhost:8000/api/v1/conversation/+23279123456"

External WhatsApp Webhook

/api/v1/external/whatsapp
Receive messages from external WhatsApp clients (whatsapp-web.js, Baileys).

Request Body

event
string
required
Event type: message, connected, disconnected
message
string
Text message content
from
string
Sender JID (e.g., 23279123456@c.us)
phoneE164
string
required
Phone in E.164 format (e.g., +23279123456)
messageType
string
Message type: text, image, document
hasMedia
boolean
Whether message contains media
media
object
Media object with data, mimetype, filename, size

Text Message Request

{
  "event": "message",
  "message": "What is my balance?",
  "from": "23279123456@c.us",
  "phoneE164": "+23279123456"
}

Image Message Request (KYC)

{
  "event": "message",
  "messageType": "image",
  "hasMedia": true,
  "phoneE164": "+23279123456",
  "message": "Here is my ID",
  "media": {
    "data": "data:image/jpeg;base64,/9j/4AAQSkZJRg...",
    "mimetype": "image/jpeg",
    "filename": "id_card_front.jpg",
    "size": 52643
  }
}
The media.data field must include the data URI prefix (data:image/jpeg;base64,).

Response

{
  "answer": "Your balance is 5,000 SLE",
  "status": "success"
}

Example

curl -X POST "http://localhost:8000/api/v1/external/whatsapp" \
  -H "Content-Type: application/json" \
  -d '{
    "event": "message",
    "message": "check my balance",
    "phoneE164": "+23279123456"
  }'

Meta WhatsApp Webhook (Verification)

/api/v1/webhooks/whatsapp
Verify webhook with Meta WhatsApp Business API.

Query Parameters

ParameterTypeDescription
hub.modestringMust be subscribe
hub.verify_tokenstringYour verify token
hub.challengestringChallenge to echo back

Response

Returns the hub.challenge value on success, or 403 on failure.

Example

curl "http://localhost:8000/api/v1/webhooks/whatsapp?hub.mode=subscribe&hub.verify_token=YOUR_TOKEN&hub.challenge=CHALLENGE"

Meta WhatsApp Webhook (Messages)

/api/v1/webhooks/whatsapp
Receive messages from Meta WhatsApp Business API.

Request Body

Standard Meta webhook format:
{
  "object": "whatsapp_business_account",
  "entry": [{
    "id": "WHATSAPP_BUSINESS_ACCOUNT_ID",
    "changes": [{
      "value": {
        "messaging_product": "whatsapp",
        "metadata": {
          "display_phone_number": "15551234567",
          "phone_number_id": "PHONE_NUMBER_ID"
        },
        "contacts": [{
          "profile": { "name": "John Doe" },
          "wa_id": "23279123456"
        }],
        "messages": [{
          "from": "23279123456",
          "id": "wamid.xxx",
          "timestamp": "1234567890",
          "type": "text",
          "text": { "body": "What is my balance?" }
        }]
      }
    }]
  }]
}

Response

Returns 200 OK on success.

Internal Notifications

/api/v1/notifications/whatsapp
Send transaction notifications via WhatsApp (internal service use only).

Authentication

HMAC service authentication required:
X-Service-Auth: HMAC {timestamp}:{signature}

Request Body

phoneE164
string
required
Recipient phone in E.164 format
message
string
required
Notification message text
transactionType
string
Transaction type for receipt generation
metadata
object
Transaction metadata for receipt

Transaction Types

TypeDescription
pos_paymentPOS terminal payment
pos_refundPOS refund
agent_cash_inAgent cash-in
p2p_transferPeer-to-peer transfer
cash_outCash withdrawal

Request Example

{
  "phoneE164": "+23279123456",
  "message": "You received 5,000 SLE from John Doe",
  "transactionType": "p2p_transfer",
  "metadata": {
    "amount": 5000,
    "currency": "SLE",
    "sender_name": "John Doe",
    "transaction_id": "txn_abc123"
  }
}

Response

{
  "success": true,
  "message": "Receipt image sent",
  "details": { "messageId": "msg_123" }
}

Example

curl -X POST "http://localhost:8000/api/v1/notifications/whatsapp" \
  -H "X-Service-Auth: HMAC 1704067200:5d41402abc4b2a..." \
  -H "Content-Type: application/json" \
  -d '{
    "phoneE164": "+23279123456",
    "message": "Payment received: 5,000 SLE"
  }'

Error Responses

Standard Error Format

{
  "error": "Error description",
  "status": "error"
}

Common Errors

StatusErrorDescription
400Phone number requiredMissing phoneE164
401Service authentication failedInvalid HMAC
500Error processing webhookInternal error
503Agent not initializedService starting

Next Steps