1.0.4 • Published 5 months ago

innovatorswhatsappclass v1.0.4

Weekly downloads
-
License
ISC
Repository
-
Last release
5 months ago

INNOVATORS SOFT WhatsApp Class

A powerful WhatsApp client library that provides seamless integration between Baileys and WhatsApp-web.js style APIs. This library makes it easy to create WhatsApp bots and automation tools with a familiar interface.

Features

  • 🚀 Easy to use, familiar WhatsApp-web.js style API
  • 📱 Multi-device support
  • 💬 Send and receive messages
  • 📸 Media handling (images, videos, documents)
  • 👥 Group management
  • 💾 Message history and chat management
  • 🔄 Auto-reconnect functionality
  • 📝 Read receipts

Installation

npm install innovatorswhatsappclass

Quick Start

const { WhatsAppClient } = require('innovatorswhatsappclass')
const qrcode = require('qrcode-terminal')

// Create client instance
const client = new WhatsAppClient({ sessionName: ".Sessions" });

// Handle QR Code
client.on('qr', qr => {
    qrcode.generate(qr, { small: true })
})

// Handle ready event
client.on('connected', () => {
    console.log('Client is ready!')
})

// Connect to WhatsApp
client.connect()

Usage Examples

1. Basic Messaging

// Send a text message
await client.sendMessage('1234567890@s.whatsapp.net', 'Hello world!')

// Send a reply
await client.sendMessage('1234567890@s.whatsapp.net', 'This is a reply', {
    quoted: originalMessage
})

// Send with mentions
await client.sendMessage('1234567890@s.whatsapp.net', {
    type: 'text',
    text: 'Hey @user!',
    mentions: ['user@s.whatsapp.net']
})

2. Media Handling

// Send an image
await client.sendMedia('1234567890@s.whatsapp.net', './image.jpg', {
    caption: 'Check out this image!'
})

// Send a document
await client.sendDocument('1234567890@s.whatsapp.net', './document.pdf', 
    'Check out this document!'
)

3. Group Management

// Get all groups
const groups = await client.getAllGroups()

// Add participant to group
await client.changeGroupParticipants(groupId, ['1234567890@s.whatsapp.net'], 'add')

// Remove participant
await client.changeGroupParticipants(groupId, ['1234567890@s.whatsapp.net'], 'remove')

// Promote to admin
await client.changeGroupParticipants(groupId, ['1234567890@s.whatsapp.net'], 'promote')

// Demote admin
await client.changeGroupParticipants(groupId, ['1234567890@s.whatsapp.net'], 'demote')

4. Message History

// Get chat history
const messages = await client.loadMessages(chatId, 50)

// Get specific message
const message = await client.loadMessage(chatId, messageId)

More Examples and Information

For a complete working example with message handling, group management, and error handling, check out our example.js file. This example includes:

  • 🔄 Connection handling and QR code generation
  • 📨 Message handling with commands
  • 👥 Group management examples
  • ⚡ Event listeners for various scenarios
  • 🛠️ Error handling and logging

Feel free to use this example as a starting point for your WhatsApp bot implementation.

Bot Commands

The library includes example bot commands that you can use:

  • !ping - Check if bot is alive
  • !echo <text> - Echo back your text
  • !mention - Mention you in a message
  • !reply - Reply to your message
  • !location - Send a location
  • !contact - Send a contact card
  • !react - React to your message with ❤️
  • !media - Send an example image
  • !doc - Send an example document
  • !history [count] - Show message history
  • !groups - List all your groups
  • !add <number> - Add participant to group
  • !remove <number> - Remove participant from group
  • !promote <number> - Promote participant to admin
  • !demote <number> - Demote admin to participant

Error Handling

The library includes comprehensive error handling:

client.on('error', error => {
    console.error('Client Error:', error)
})

try {
    await client.sendMessage(to, message)
} catch (error) {
    console.error('Error sending message:', error)
}

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

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

Credits

Developed by Innovators Soft. Based on the @whiskeysockets/baileys library.

1.0.4

5 months ago

1.0.3

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago