How to receive webhook endpoint notifications on the local machine#
To receive notifications, you need to have a static address for requests from our server, this can be implemented using the ngrok application. It allows you to create a temporary static address and redirect requests from it to the local machine. This mechanism is convenient for debugging your code.
Installation#
Go to ngrok register and download ngrok.
Install packages to work with the example
npm i express body-parser
Import#
There are several ways to import a library into a project
Using classic JavaScript
const express = require("express");
Using ES6 JavaScript
import express from "express";
Using TypeScript
import * as express from "express";
How to receive a webhook endpoint notification on the local machine#
The full example can be viewed here: SampleReceiveWebhook.js
Run the example using the command:
node SampleReceiveWebhook.js
ngrok http 80
Forwarding
http://32c4-146-158-66-240.ngrok-free.app -> http://localhost:80
So the notification will be redirected to your local machine.
to end the example, press Ctrl+C
Example#
const express = require('express');
const bodyParser = require('body-parser');
(async () => {
try {
const app = express();
const port = 80;
app.use(bodyParser.json());
app.post('/', (req, res) => {
console.log(req.body);
res.status(200).send('');
});
app.listen(port, () => {
console.log(`Server is listening on port ${port}`);
});
} catch (error) {
console.error(error);
process.exit(1);
}
})();
Full list of examples#
Description | Module |
---|---|
Example of sending text using Async | SendWhatsAppMessageAsync.js |
Example of sending text using Callback | SendWhatsAppMessageCallback.js |
Example of sending a picture by URL | SendWhatsAppFileUrl.js |
Example of sending a picture by uploading from the disk | SendWhatsAppFileUpload.js |
Example of receiving an incoming notification with the receiveNotification method | ReceiveNotifications.js |
Example of receiving a webhook endpoint notification on the local machine | SampleReceiveWebhook.js |
Example of receiving a webhook endpoint notification on the local machine | SampleReceiveWebhook.js |
Example of receiving incoming notifications via webhook service REST API | StartReceivingNotifications.js |
Example of receiving incoming notifications to a server | ReceiveWebhook.js |
Example of getting a QR code via HTTP | getQRCode.js |
Example of getting a QR code via websocket | getQRCodeWebsocket.js |