@znan/wabot

0.0.103 • Public • Published

@ZNAN/WABOT - Baileys WhatsApp Bot Module

NPM Version NPM Downloads License: MIT

ℹ️ Introduction

Welcome to @ZNAN/WABOT! This module, built upon the robust Baileys library, offers a streamlined, elegant, and easy-to-understand approach to developing your own WhatsApp bots. It's designed for developers seeking an efficient way to build and deploy WhatsApp bot scripts.

✨ Key Features

  • Simplified Baileys Integration: Leverage the power of Baileys with a more user-friendly interface.
  • Flexible Configuration: Extensive options to tailor your bot's behavior.
  • Efficient Session Management: Robust handling of connection sessions.
  • Comprehensive Event Handling: Supports various Baileys events for bot responsiveness.
  • Developer-Centric Design: Built with ease of use and learning in mind.

🔰 Installation

Install the module using npm or yarn:

Using npm:

npm install @znan/wabot

Using yarn:

yarn add @znan/wabot

🔌 Connection

Here's an example of how to initialize your bot connection:

// Import the module
const { Connection } = require('@znan/wabot'); // or import { Connection } from '@znan/wabot';

// Initialize connection with options
const Conn = new Connection({
   plugins_dir: 'plugins',      // Directory for your bot plugins
   session_dir: 'session',      // Directory for session data
   online: true,                // Set bot presence to online
   presence: true,              // Send presence updates
   bypass_ephemeral: true,      // Bypass ephemeral messages (if supported)
   pairing: {
      state: true,              // Enable pairing mode (QR code scan)
      number: 6283175395970,    // Your phone number (optional, for automatic pairing)
      code: 'MOONXBOT'          // Unique code for your session (optional)
   }
}, {
   browser: ['Ubuntu', 'Firefox', '20.0.00'], // Simulated browser info
   version: [2, 3000, 1029030078],         // Simulated Baileys version
   shouldIgnoreJid: jid => {               // Function to ignore specific JIDs (e.g., newsletters, other bots)
      return /(newsletter|bot)/.test(jid);
   }
});

💡 Usage (Event Handling)

Once connected, you can listen for various events. Here's a sample of common event handlers:

// Handle connection event
Conn.on('connect', () => {
   console.log('Bot connected successfully!');
   // Implement actions after connection, e.g., broadcast messages
});

// Handle connection errors
Conn.on('error', (error) => {
   console.error('Connection error:', error);
});

// Handle bot preparation state
Conn.on('prepare', () => {
   console.log('Bot is preparing...');
});

// Handle message updates (incoming/outgoing)
Conn.on('messages.update', (messageUpdate) => {
   // console.log('Message update:', messageUpdate);
   // Process incoming messages here or in a dedicated handler
});

// Handle message reactions
Conn.on('messages.reaction', (reaction) => {
   console.log('Message reaction:', reaction);
});

// Handle message receipts (read status)
Conn.on('messages.receipt', (receipt) => {
   console.log('Message received:', receipt);
});

// Handle deleted messages
Conn.on('messages.delete', (deletedMessage) => {
   console.log('Message deleted:', deletedMessage);
});

// Handle presence updates
Conn.on('presence.update', (presenceUpdate) => {
   // console.log('Presence update:', presenceUpdate);
});

// Handle story updates (if supported)
Conn.on('stories', (stories) => {
   console.log('Stories update:', stories);
});

// Handle group participant updates
Conn.on('group-participants.update', (groupUpdate) => {
   console.log('Group participants updated:', groupUpdate);
});

// Handle group information updates
Conn.on('groups.update', (groupInfoUpdate) => {
   console.log('Group info updated:', groupInfoUpdate);
});

// Handle call information
Conn.on('call', (callInfo) => {
   console.log('Call info:', callInfo);
});

📜 License

This project is licensed under the MIT License - see the LICENSE file for details.


Developed with dedication by Znan.

Readme

Keywords