WhatsApp Webhook acts as a communication bridge between the WhatsApp messaging platform and your application. It listens for incoming messages or events sent by users and allows your backend to process and respond accordingly with an auto-reply bot.
You can configure and manage your application's webhooks in the
/routes/web.jsfile. This is where you can define routes and logic to effectively handle incoming webhook requests.
POST http://localhost:3000/webhook/text
| Key | Value | Add to |
|---|---|---|
x-api-key |
your-api-key-here |
Headers |
Supports multiple recipients
{
"recipient": [628xxxxxxxx, 628xxxxxxxx],
"data": "your string data"
}
POST http://localhost:3000/webhook/image
| Key | Value | Add to |
|---|---|---|
x-api-key |
your-api-key-here |
Headers |
Supports multiple recipients
{
"recipient": [628xxxxxxxx, 628xxxxxxxx],
"image": "url_images",
"data": "your string data"
}
POST http://localhost:3000/webhook/audio
| Key | Value | Add to |
|---|---|---|
x-api-key |
your-api-key-here |
Headers |
Supports multiple recipients
{
"recipient": [628xxxxxxxx, 628xxxxxxxx],
"audio": "url_audio"
}
POST http://localhost:3000/webhook/video
| Key | Value | Add to |
|---|---|---|
x-api-key |
your-api-key-here |
Headers |
Supports multiple recipients
{
"recipient": [628xxxxxxxx, 628xxxxxxxx],
"video": "url_video",
"data": "your string data"
}
POST http://localhost:3000/webhook/location
| Key | Value | Add to |
|---|---|---|
x-api-key |
your-api-key-here |
Headers |
Supports multiple recipients
{
"recipient": [628xxxxxxxx, 628xxxxxxxx],
"location": "latitude,longitude"
}
How to add auto reply You can follow the steps in the plugin section.
| Message Condition (exact) | Utility |
|---|---|
.text |
Sends a text |
.img |
Sends a image |
.audio |
Sends a audio file |
.video |
Sends a video file |
.location |
Sends a location (coordinates/map) |
.add-plugin <filename.js> <code> |
Create or Edit plugins |
.list-plugin |
list of plugin names |
.delete-plugin <filename.js> |
delete plugins |
.copy-plugin <filename.js> |
copy plugins |
Rules you must follow for the plugin to work.
module.exports = async (sock, message, msg, sender) => {
// your plugin function
};
This is a complete plugin example with emoji reactions and quote message replies. You can see more examples in plugin/basicMessage.js
You can create a plugin directly in the message format
.add-plugin <filename>.js <code>. See this example:
.add-plugin test.js
module.exports = async (sock, message, msg, sender) => {
if (msg && msg.toLowerCase() === '.test') {
await sock.sendMessage(sender, { text: 'This is the answer to the test' });
}
};
The system will automatically sync data and install your plugin's required dependencies if they are not already available.
- BOT_NUMBER: WhatsApp number registered for the bot (pairing code).
- PORT: Server port number.
- WEBHOOK_TIMEOUT: Maximum time (in ms) for webhook response.
- WEBHOOK_SANITATION : Use sanitation on every request (
true/false). - SOCKET_TIMEOUT: Timeout duration (in ms) for socket connection.
- SOCKET_ATTEMPTS: Number of retries for socket connection.
- SOCKET_PAIRING: Use connection using pairing code (
true/false). - API_KEY: Authentication key for webhook service.
- CORS_ORIGIN: List of domains allowed to access the API.
- CORS_CREDENTIALS: Are credentials allowed in cross-domain requests (
true/false). - SELF_MODE_GLOBAL:: Only bots that respond to own global message commands? (
true/false). - SELF_MODE_PLUGIN:: Only bots that respond to own plugin commands? (
true/false). - GROUP_GREETING:: Greeting when members join/leave (
true/false).