DEV Community

Cover image for Building a WhatsApp Order Notification System with Node.js and Webhooks
Ivan Amato
Ivan Amato

Posted on

Building a WhatsApp Order Notification System with Node.js and Webhooks

Online shoppers expect instant communication. As soon as they click "Place Order," they want to know their purchase was successful and when it's on the way.

Email confirmations are the norm, but they often get buried or delayed. SMS is better—but WhatsApp? Now you're speaking the customer's language.

In this post, we'll walk you through building a simple but powerful WhatsApp order notification system using Node.js, Express, and webhooks. You’ll learn how to receive order events from your e-commerce backend and instantly notify the customer via WhatsApp.

This tutorial is developer-focused, practical, and API-driven. Let’s get started.


Prerequisites

Here’s what you need before we dive in:

  • Node.js installed (v14 or later)
  • Basic knowledge of Express and working with APIs
  • A way to expose a local server to the internet (e.g., ngrok)
  • Access to a WhatsApp Business API (via any provider that supports message sending via REST)
  • Familiarity with JSON and webhooks

Optional:

  • Postman or curl to test your endpoint

Step 1: Setting Up a Simple Express Server

Let’s begin by creating a simple webhook listener that will receive order data and trigger a WhatsApp message.

First, initialize your Node.js project:

mkdir whatsapp-order-notifier
cd whatsapp-order-notifier
npm init -y
Enter fullscreen mode Exit fullscreen mode

Install the required packages:

npm install express axios body-parser dotenv
Enter fullscreen mode Exit fullscreen mode

Create a file named index.js and add the following boilerplate:

const express = require('express');
const bodyParser = require('body-parser');
const axios = require('axios');
require('dotenv').config();

const app = express();
const PORT = process.env.PORT || 3000;

app.use(bodyParser.json());

app.listen(PORT, () => {
  console.log(`Server listening on port ${PORT}`);
});
Enter fullscreen mode Exit fullscreen mode

Now let’s define a POST endpoint that will handle incoming order data.

app.post('/order-confirmation', async (req, res) => {
  const { customerName, phoneNumber, orderId, total } = req.body;

  if (!customerName || !phoneNumber || !orderId || !total) {
    return res.status(400).json({ message: 'Missing required fields' });
  }

  try {
    await sendWhatsAppMessage({ customerName, phoneNumber, orderId, total });
    res.status(200).json({ message: 'WhatsApp message sent!' });
  } catch (error) {
    console.error('Error sending WhatsApp message:', error.message);
    res.status(500).json({ message: 'Internal server error' });
  }
});
Enter fullscreen mode Exit fullscreen mode

Step 2: Sending the WhatsApp Message

Now, let’s implement the sendWhatsAppMessage function using axios to send a POST request to your WhatsApp provider’s API.

For this example, we’ll use supersimplewhats api.

Create a new file called whatsapp.js (or place it inside your main file):

const axios = require('axios');

async function sendWhatsAppMessage({ customerName, phoneNumber, orderId, total }) {
    const message = `Hi ${customerName}, thanks for your order #${orderId}! Total: ${total}. We'll notify you when it ships.`;
    const config = {
        headers: {
            Authorization: `Bearer ${process.env.WHATSAPP_API_TOKEN}`,
            'Content-Type': 'text/plain',
        },
    };

    const url = `${process.env.WHATSAPP_API_URL}/${process.env.WHATSAPP_API_DEVICE_NAME}/${phoneNumber}`;

    const response = await axios.post(url, message, config);
    console.log('WhatsApp message sent:', response.data);

    return response.data;
}

module.exports = { sendWhatsAppMessage };
Enter fullscreen mode Exit fullscreen mode

Don’t forget to import it in index.js:

const { sendWhatsAppMessage } = require('./whatsapp');
Enter fullscreen mode Exit fullscreen mode

Then, in your .env file, set the API token and endpoint:

WHATSAPP_API_TOKEN=your-supersimplewhats-api-key
WHATSAPP_API_URL=https://app.supersimplewhats.com/v1/messages/send/
WHATSAPP_API_DEVICE_NAME=your-supersimplewhats-device-name
Enter fullscreen mode Exit fullscreen mode

Step 3: Testing with a Mock Request

Now that your webhook is up and running, let’s test it.

First, start the server:

node index.js
Enter fullscreen mode Exit fullscreen mode

Expose it using ngrok (or another tunneling tool):

ngrok http 3000
Enter fullscreen mode Exit fullscreen mode

You’ll get a public URL like https://abc123.ngrok.io. This is the URL you’ll use to simulate a webhook request.

Use Postman or curl to send a test request:

curl -X POST https://abc123.ngrok.io/order-confirmation \
  -H "Content-Type: application/json" \
  -d '{
    "customerName": "Ana Silva",
    "phoneNumber": "+5511999999999",
    "orderId": "12345",
    "total": "$ 249.90"
  }'
Enter fullscreen mode Exit fullscreen mode

If everything is working, your WhatsApp API provider should deliver the message to the specified number.


Wrapping Up

And there you have it — a functional WhatsApp order notification system built in under 100 lines of code.

With just Node.js, Express, and your provider's API, you've created a highly effective notification tool that gives your customers peace of mind and keeps them engaged.

Want to go further?

You can extend this project to:

  • Send messages for different order statuses (e.g., "Shipped", "Out for delivery")
  • Include tracking links or support contact info
  • Localize messages based on customer language
  • Integrate with Shopify, WooCommerce, or a headless CMS

For developers building e-commerce platforms, integrating WhatsApp notifications is a lightweight but powerful UX upgrade.

Have questions or want a GitHub starter repo? Reach out!


Happy coding!

Top comments (1)

Some comments have been hidden by the post's author - find out more