Skip to content

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.

License

Notifications You must be signed in to change notification settings

fitri-hy/whastapp-webhook

Repository files navigation

Whastapp Webhook

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.

Webhook

You can configure and manage your application's webhooks in the /routes/web.js file. This is where you can define routes and logic to effectively handle incoming webhook requests.

➤ Text

POST http://localhost:3000/webhook/text

Authorization

Key Value Add to
x-api-key your-api-key-here Headers

Body Request

Supports multiple recipients

{
  "recipient": [628xxxxxxxx, 628xxxxxxxx],
  "data": "your string data"
}

➤ Image

POST http://localhost:3000/webhook/image

Authorization

Key Value Add to
x-api-key your-api-key-here Headers

Body Request

Supports multiple recipients

{
  "recipient": [628xxxxxxxx, 628xxxxxxxx],
  "image": "url_images",
  "data": "your string data"
}

➤ Audio

POST http://localhost:3000/webhook/audio

Authorization

Key Value Add to
x-api-key your-api-key-here Headers

Body Request

Supports multiple recipients

{
  "recipient": [628xxxxxxxx, 628xxxxxxxx],
  "audio": "url_audio"
}

➤ Video

POST http://localhost:3000/webhook/video

Authorization

Key Value Add to
x-api-key your-api-key-here Headers

Body Request

Supports multiple recipients

{
  "recipient": [628xxxxxxxx, 628xxxxxxxx],
  "video": "url_video",
  "data": "your string data"
}

➤ Location

POST http://localhost:3000/webhook/location

Authorization

Key Value Add to
x-api-key your-api-key-here Headers

Body Request

Supports multiple recipients

{
  "recipient": [628xxxxxxxx, 628xxxxxxxx],
  "location": "latitude,longitude"
}

Bot Auto Reply

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

Plugin Templates

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

Create Plugin In Messages

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.

Watch Video

Config (/config/config.js)

  • 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).

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published