Skip to content

rayenking/whatsapperha

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

23 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

WhatsApp Erha (Ryns Hook)

TypeScript Node.js Baileys

⚠️ Important Note from Baileys

Baileys library was originally a project for CS-2362 at Ashoka University and is in no way affiliated with or endorsed by WhatsApp. Use at your own discretion. Do not spam people with this. We discourage any stalkerware, bulk or automated messaging usage.

πŸ“– Description

WhatsApp Erha is a WhatsApp bot framework built with TypeScript using the Baileys library. This framework provides an easy-to-use command system with decorator pattern, supports various message types, and includes admin management features.

✨ Key Features

  • πŸ”§ Decorator-based Command System - Easy command creation with decorators
  • πŸ“± Multi-message Support - Supports text, image, video, audio, sticker, location, etc.
  • πŸ‘₯ Admin System - Admin system with permission management
  • πŸ—„οΈ MongoDB Integration - Database support for data storage
  • πŸ” QR Code Authentication - Login using QR code
  • ⚑ PM2 Process Management - Production-ready with PM2
  • 🎯 TypeScript Support - Full TypeScript support with type safety

πŸš€ Installation

Prerequisites

  • Node.js v16.14.2 or higher
  • Yarn package manager
  • MongoDB (optional, for database features)

Setup

  1. Install Yarn (if not already installed):
npm install -g yarn
  1. Clone repository:
git clone https://github.com/rayenking/whatsapperha.git
cd whatsapperha
  1. Install dependencies:
yarn install
  1. Install Baileys library:
yarn install-baileys
  1. Setup environment variables:
cp .env.example .env

Edit the .env file with appropriate configurations:

# Database
MONGODB_URL=mongodb://localhost:27017/whatsapperha

# Logging
LOG_LEVEL=info

# Data paths
DATA_DIR=./data/baileys
STORE_PATH=./data/baileys/store.json
AUTH_PATH=./data/baileys/auth

# Admin numbers (comma separated)
ADMINS=6281234567890,6289876543210

πŸƒβ€β™‚οΈ How to Run

Development Mode

# Normal mode (QR code authentication)
yarn dev

# Pairing code mode
yarn dev -- --pairing-code

Production Mode

# Build project
yarn build

# Start with Node.js
yarn start

# Start with PM2 (recommended for production)
yarn start:erha

PM2 Commands

# Restart application
yarn restart

# Stop application
yarn stop

πŸ“ Project Structure

whatsapperha/
β”œβ”€β”€ commands/           # Command modules
β”‚   β”œβ”€β”€ auto/          # Auto-response commands
β”‚   β”œβ”€β”€ dialog/        # Dialog/interactive commands
β”‚   β”œβ”€β”€ help/          # Help and utility commands
β”‚   └── owners/        # Owner/admin commands
β”œβ”€β”€ lib/               # Core library files
β”‚   β”œβ”€β”€ client.ts      # WhatsApp client implementation
β”‚   β”œβ”€β”€ hook.ts        # Decorator system
β”‚   β”œβ”€β”€ message.ts     # Message parsing
β”‚   └── types.ts       # TypeScript type definitions
β”œβ”€β”€ models/            # Database models
β”œβ”€β”€ helpers/           # Helper utilities
└── main.ts           # Application entry point

πŸ› οΈ Creating Commands

Basic Command Structure

Create a new folder inside commands/ and create a .ts file for your command:

import { RhClient } from "@rhook/rh";
import { commands, entity, hook } from "@rhook/hook";
import { ParseMessage } from "@rhook/types";

class MyCommand {
    @commands('hello')
    @entity({ignoreSelf: false})
    @hook('text')
    async hello(client: RhClient, message: ParseMessage): Promise<void> {
        await client.sendMessage(message.parse.to, `Hello ${message.pushName}!`);
    }
}

Decorator Options

@commands(command, type, prefix)

  • command: String command or array of commands
  • type: 'startswith' | 'contains' | 'exact' | 'endswith' | 'regex' (default: 'startswith')
  • prefix: Custom prefix (default: '!')

@entity(options)

@entity({
    case_sensitive: false,    // Case sensitive matching
    chat_type: 'all',        // 'all' | 'group' | 'private'
    ignoreSelf: true,        // Ignore own messages
    ignorePublic: false,     // Only respond to self messages
    isAdmin: false          // Admin only command
})

@hook(type)

Available types:

  • 'text' - Text messages
  • 'image' - Image messages
  • 'video' - Video messages
  • 'audio' - Audio messages
  • 'location' - Location messages
  • 'sticker' - Sticker messages
  • 'caption' - Image/video captions
  • 'listResponse' - List response messages
  • 'buttonResponse' - Button response messages
  • 'join' - Group join events
  • 'leave' - Group leave events
  • 'contact' - Contact messages

Example Commands

Simple Ping Command

@commands('ping')
@entity({ignoreSelf: false})
@hook('text')
async ping(client: RhClient, message: ParseMessage): Promise<void> {
    await client.sendMessage(message.parse.to, `PONG! ${message.pushName}`);
}

Admin Only Command

@commands('restart')
@entity({isAdmin: true})
@hook('text')
async restart(client: RhClient, message: ParseMessage): Promise<void> {
    await client.sendMessage(message.parse.to, `Restarting...`);
    await client.restart(message.parse.to);
}

Image Handler

@commands('caption')
@entity({ignoreSelf: false})
@hook('caption')
async handleCaption(client: RhClient, message: ParseMessage): Promise<void> {
    await client.sendMessage(message.parse.to, `Caption: ${message.parse.text}`);
}

πŸ”§ Configuration

Environment Variables

Variable Description Default
MONGODB_URL MongoDB connection string -
LOG_LEVEL Logging level info
DATA_DIR Data directory path ./data/baileys
STORE_PATH Store file path ./data/baileys/store.json
AUTH_PATH Auth directory path ./data/baileys/auth
ADMINS Admin phone numbers (comma separated) -

Default Prefix

The default prefix is !. To change the prefix globally:

import { setDefaultPrefix } from "@rhook/rh";

setDefaultPrefix('.'); // Change prefix to '.'

πŸ“ Available Scripts

Script Description
yarn dev Run in development mode with hot reload
yarn dev -- --pairing-code Run in development mode with pairing code authentication
yarn build Build TypeScript to JavaScript
yarn start Start compiled application
yarn start:erha Start with PM2 process manager
yarn restart Restart PM2 process
yarn stop Stop PM2 process
yarn install-baileys Install latest Baileys library

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the ISC License.

πŸ‘¨β€πŸ’» Author

πŸ™ Special Thanks

⚠️ Disclaimer

This project is for educational purposes only. Please use responsibly and in accordance with WhatsApp's Terms of Service. The authors are not responsible for any misuse of this software.

About

Whatsapp Bot with Hook Function in Typescript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors