{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["admonition","tabs","tab"]},"type":"markdown"},"seo":{"title":"Set Up Webhooks","description":"Complete developer documentation for the eCommunicate Omnichannel platform. WhatsApp Cloud, WhatsApp Lite, SMS, Live Chat, and Conversations APIs. Send messages, manage templates, configure webhooks, and build customer engagement at scale.","siteUrl":"https://docs.ecommunicate.co.za","lang":"en-ZA","image":"/assets/og-cover.93cb0a29e46afb76d2e2ad760ae643881a756bfe5784b4b0c3553ecb20635632.db81178d.png","keywords":["eCommunicate API","WhatsApp Business API","SMS API","omnichannel messaging","WhatsApp templates","messaging platform","South Africa messaging API","bulk SMS API","two-way SMS","SMS gateway","delivery receipts"],"meta":[{"name":"author","content":"eCommunicate (Pty) Ltd"},{"name":"robots","content":"index, follow"}],"jsonLd":{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://www.ecommunicate.co.za/#organization","name":"eCommunicate","url":"https://www.ecommunicate.co.za/","logo":"https://docs.ecommunicate.co.za/images/logo.png","sameAs":["https://www.ecommunicate.co.za/"],"contactPoint":{"@type":"ContactPoint","email":"support@ecommunicate.co.za","contactType":"customer support"}},{"@type":"WebSite","@id":"https://docs.ecommunicate.co.za/#website","name":"eCommunicate API Documentation","url":"https://docs.ecommunicate.co.za","publisher":{"@id":"https://www.ecommunicate.co.za/#organization"}}]},"llmstxt":{"hide":false,"title":"eCommunicate Omnichannel API","description":"Developer documentation for the eCommunicate Omnichannel platform — WhatsApp Cloud, WhatsApp Lite, SMS, Live Chat, and Conversations APIs.","sections":[{"title":"Guides","includeFiles":["guides/**/*.md"]},{"title":"Tutorials","includeFiles":["tutorials/**/*.md"]},{"title":"API Reference","includeFiles":["apis/**/*.yaml"]},{"title":"Changelog","includeFiles":["changelog.md"]}]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"set-up-webhooks","__idx":0},"children":["Set Up Webhooks"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This tutorial walks you through building a webhook receiver and registering it with the eCommunicate API. You'll have a working server that processes incoming messages and delivery status updates."]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"what-youll-build","__idx":1},"children":["What you'll build"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["A Node.js Express server that:"]},{"$$mdtype":"Tag","name":"ol","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Receives incoming WhatsApp messages from customers"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Receives delivery status updates (sent, delivered, read, failed)"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Handles different content types (text, media, location)"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Responds quickly to avoid webhook retries"]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"prerequisites","__idx":2},"children":["Prerequisites"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Node.js 18+"]}," installed"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["An eCommunicate account with an API key"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["A publicly accessible URL (or ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://ngrok.com/"},"children":["ngrok"]}," for local development)"]}]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"step-1-create-the-project","__idx":3},"children":["Step 1: Create the project"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"mkdir ecomm-webhooks && cd ecomm-webhooks\nnpm init -y\nnpm install express\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"step-2-build-the-webhook-server","__idx":4},"children":["Step 2: Build the webhook server"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Create ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["server.js"]},":"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"javascript","header":{"controls":{"copy":{}}},"source":"const express = require('express');\nconst app = express();\nconst PORT = process.env.PORT || 3000;\n\napp.use(express.json());\n\n// ── Health check ──────────────────────────────────────────────────────\napp.get('/health', (req, res) => {\n  res.json({ status: 'ok', timestamp: new Date().toISOString() });\n});\n\n// ── Incoming message webhook ──────────────────────────────────────────\napp.post('/webhooks/incoming', (req, res) => {\n  const message = req.body;\n\n  console.log('--- Incoming Message ---');\n  console.log(`From:    ${message.sender} (${message.profileName})`);\n  console.log(`User ID: ${message.senderUserId ?? 'n/a'} | Username: ${message.username ?? 'n/a'}`);\n  console.log(`To:      ${message.receiver}`);\n  console.log(`Type:    ${message.messageContentType}`);\n  console.log(`Text:    ${message.text || '(no text)'}`);\n  console.log(`Time:    ${message.sentTime}`);\n\n  // Route by content type\n  switch (message.messageContentType) {\n    case 'TEXT':\n      handleTextMessage(message);\n      break;\n    case 'MEDIA':\n      handleMediaMessage(message);\n      break;\n    case 'LOCATION':\n      handleLocationMessage(message);\n      break;\n    case 'BUTTON':\n    case 'INTERACTIVE':\n      handleButtonMessage(message);\n      break;\n    case 'REACTION':\n      handleReactionMessage(message);\n      break;\n    case 'CONTACT':\n      console.log(`Contact shared: ${message.text}`);\n      break;\n    default:\n      console.log(`Unhandled content type: ${message.messageContentType}`);\n  }\n\n  // Always respond 200 immediately to avoid retries\n  res.status(200).send('OK');\n});\n\n// ── Status update webhook ─────────────────────────────────────────────\napp.post('/webhooks/status', (req, res) => {\n  const update = req.body;\n\n  console.log('--- Status Update ---');\n  console.log(`Message ID (gstId): ${update.gstId}`);\n  console.log(`Tracking ID (ctId): ${update.ctId}`);\n  console.log(`Status:             ${update.status}`);\n\n  switch (update.status) {\n    case 'SENT':\n      console.log(`-> Sent at: ${update.sendTime}`);\n      break;\n    case 'DELIVERED':\n      console.log(`-> Delivered at: ${update.deliveryTime}`);\n      break;\n    case 'READ':\n      console.log(`-> Read at: ${update.readTime}`);\n      break;\n    case 'PLAYED':\n      console.log(`-> Voice note played at: ${update.playedTime}`);\n      break;\n    case 'FAILED':\n      console.error(`-> Failed: ${update.errorCodeString} (code: ${update.errorCode}) ${update.errorDetail ?? ''}`);\n      // TODO: Trigger retry logic or alert your team\n      break;\n  }\n\n  res.status(200).send('OK');\n});\n\n// ── Session status webhook (WhatsApp Lite only) ──────────────────────\napp.post('/webhooks/session', (req, res) => {\n  const session = req.body;\n  console.log('--- Session Status ---');\n  console.log(`Number: ${session.whatsAppNumber}`);\n  console.log(`Status: ${session.status} (${session.statusType})`);\n  res.status(200).send('OK');\n});\n\n// ── Message handlers ─────────────────────────────────────────────────\nfunction handleTextMessage(message) {\n  console.log(`Processing text: \"${message.text}\"`);\n  // Persist senderUserId (BSUID) as the durable customer key — it survives phone-number changes and is present even when sender is withheld.\n  // Example: Route to auto-reply, chatbot, or agent queue\n}\n\nfunction handleMediaMessage(message) {\n  console.log(`Media URL:   ${message.mediaUrl}`);\n  console.log(`Extension:   ${message.fileExtension}`);\n  console.log(`Caption:     ${message.caption || 'N/A'}`);\n  // Example: Download and store the media file\n}\n\nfunction handleLocationMessage(message) {\n  console.log(`Location: ${message.latitude}, ${message.longitude}`);\n  console.log(`Label:    ${message.label || 'N/A'}`);\n  console.log(`Address:  ${message.address || 'N/A'}`);\n}\n\nfunction handleButtonMessage(message) {\n  console.log(`Button text:    ${message.buttonText}`);\n  console.log(`Button payload: ${message.buttonPayload}`);\n  // Example: Process the user's button selection\n}\n\nfunction handleReactionMessage(message) {\n  const emoji = message.text;\n  const reactedMessageId = message.gstId;\n  if (emoji) {\n    console.log(`Reaction \"${emoji}\" on message ${reactedMessageId}`);\n  } else {\n    console.log(`Reaction removed from message ${reactedMessageId}`);\n  }\n}\n\n// ── Start server ─────────────────────────────────────────────────────\napp.listen(PORT, () => {\n  console.log(`Webhook server running on http://localhost:${PORT}`);\n  console.log(`Health check: http://localhost:${PORT}/health`);\n});\n","lang":"javascript"},"children":[]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"step-3-expose-your-local-server","__idx":5},"children":["Step 3: Expose your local server"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["For local development, use ngrok to create a public HTTPS URL:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"# Terminal 1: Start your server\nnode server.js\n\n# Terminal 2: Expose it via ngrok\nngrok http 3000\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Copy the HTTPS URL from ngrok output (e.g., ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["https://abc123.ngrok.io"]},")."]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"warning","name":"HTTPS required"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Webhook URLs must use HTTPS with a valid SSL certificate. ngrok provides this automatically for local development."]}]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"step-4-register-your-webhooks","__idx":6},"children":["Step 4: Register your webhooks"]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"cURL","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"curl -X POST \\\n  \"https://api.payless4messaging.com/payless4messaging-service/WhatsApp/WhatsAppClientWebHook\" \\\n  -H \"Authorization: $ECOMM_API_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"incomingMessageURL\": \"https://abc123.ngrok.io/webhooks/incoming\",\n    \"statusUpdateURL\": \"https://abc123.ngrok.io/webhooks/status\",\n    \"sessionStatusURL\": \"https://abc123.ngrok.io/webhooks/session\",\n    \"eventWebhookURL\": \"https://abc123.ngrok.io/webhooks/events\"\n  }'\n","lang":"bash"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"Node.js","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"javascript","header":{"controls":{"copy":{}}},"source":"const API_KEY = process.env.ECOMM_API_KEY;\nconst BASE_URL = 'https://api.payless4messaging.com';\nconst NGROK_URL = 'https://abc123.ngrok.io'; // Replace with your ngrok URL\n\nconst response = await fetch(\n  `${BASE_URL}/payless4messaging-service/WhatsApp/WhatsAppClientWebHook`,\n  {\n    method: 'POST',\n    headers: {\n      'Authorization': API_KEY,\n      'Content-Type': 'application/json',\n    },\n    body: JSON.stringify({\n      incomingMessageURL: `${NGROK_URL}/webhooks/incoming`,\n      statusUpdateURL: `${NGROK_URL}/webhooks/status`,\n      sessionStatusURL: `${NGROK_URL}/webhooks/session`,\n      eventWebhookURL: `${NGROK_URL}/webhooks/events`,\n    }),\n  }\n);\n\nconsole.log(await response.json());\n","lang":"javascript"},"children":[]}]}]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"step-5-verify-configuration","__idx":7},"children":["Step 5: Verify configuration"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Confirm your webhooks are registered:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"curl -s -X GET \\\n  \"https://api.payless4messaging.com/payless4messaging-service/WhatsApp/WhatsAppClientWebHook/getForCurrentLoginUser\" \\\n  -H \"Authorization: $ECOMM_API_KEY\" | python3 -m json.tool\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Response:"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"json","header":{"controls":{"copy":{}}},"source":"{\n  \"id\": \"webhook-uuid\",\n  \"incomingMessageURL\": \"https://abc123.ngrok.io/webhooks/incoming\",\n  \"statusUpdateURL\": \"https://abc123.ngrok.io/webhooks/status\",\n  \"sessionStatusURL\": \"https://abc123.ngrok.io/webhooks/session\",\n  \"eventWebhookURL\": \"https://abc123.ngrok.io/webhooks/events\"\n}\n","lang":"json"},"children":[]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"step-6-test-it","__idx":8},"children":["Step 6: Test it"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Send a test message (see ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/tutorials/send-first-message"},"children":["Send Your First Message"]},") and watch your terminal for live status updates:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"--- Status Update ---\nMessage ID (gstId): a1b2c3d4-5678-90ab-cdef-1234567890ab\nTracking ID (ctId): customer-tracking-001\nStatus:             SENT\n-> Sent at: 2026-01-15T10:30:02.000+00:00\n\n--- Status Update ---\nMessage ID (gstId): a1b2c3d4-5678-90ab-cdef-1234567890ab\nTracking ID (ctId): customer-tracking-001\nStatus:             DELIVERED\n-> Delivered at: 2026-01-15T10:30:05.000+00:00\n"},"children":[]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"production-checklist","__idx":9},"children":["Production checklist"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Before going live, address these items:"]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"warning","name":"Production requirements"},"children":[{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Use a permanent URL"]}," — Replace ngrok with your production server URL and update the webhook configuration"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Add error handling"]}," — Wrap webhook handlers in try/catch blocks and log errors"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Process asynchronously"]}," — Use a message queue (Redis, RabbitMQ, SQS) for heavy processing instead of handling inline"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Respond within 5 seconds"]}," — Return ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["200 OK"]}," immediately; do all processing in the background"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Deduplicate events"]}," — Use ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["gstId"]}," to detect and skip duplicate webhook deliveries"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Key your customer records on ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["senderUserId"]}," (BSUID)"]},", not the phone number — the phone may change or be withheld, while the BSUID is stable per business."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Monitor uptime"]}," — If your webhook endpoint is down, you'll miss events with no way to recover them"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Log everything"]}," — Log all payloads with timestamps; redact sensitive customer data before storing"]}]}]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"next-steps","__idx":10},"children":["Next steps"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Guide"},"children":["Guide"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"What you'll learn"},"children":["What you'll learn"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/guides/webhooks"},"children":["Webhooks Guide"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Full webhook configuration reference and payload schemas"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/guides/whatsapp-messaging"},"children":["WhatsApp Messaging"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Template types, media, and components"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/guides/error-handling"},"children":["Error Handling"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Delivery failure codes and troubleshooting"]}]}]}]}]}]},"headings":[{"value":"Set Up Webhooks","id":"set-up-webhooks","depth":1},{"value":"What you'll build","id":"what-youll-build","depth":2},{"value":"Prerequisites","id":"prerequisites","depth":2},{"value":"Step 1: Create the project","id":"step-1-create-the-project","depth":2},{"value":"Step 2: Build the webhook server","id":"step-2-build-the-webhook-server","depth":2},{"value":"Step 3: Expose your local server","id":"step-3-expose-your-local-server","depth":2},{"value":"Step 4: Register your webhooks","id":"step-4-register-your-webhooks","depth":2},{"value":"Step 5: Verify configuration","id":"step-5-verify-configuration","depth":2},{"value":"Step 6: Test it","id":"step-6-test-it","depth":2},{"value":"Production checklist","id":"production-checklist","depth":2},{"value":"Next steps","id":"next-steps","depth":2}],"frontmatter":{"title":"Tutorial: Set Up Webhooks","description":"Build a webhook receiver to handle delivery receipts and incoming messages from eCommunicate.","seo":{"title":"Set Up Webhooks"}},"lastModified":"2026-10-27T15:26:11.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/tutorials/setup-webhooks","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}