npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@dutakey/whatsmulti

v1.6.1

Published

Whatsapp Client With Multi Session

Readme

@Dutakey/WhatsMulti

NPM Downloads GitHub code size in bytes

📌 Overview

@Dutakey/WhatsMulti is a powerful wrapper for @whiskeysockets/baileys, designed to efficiently manage multiple WhatsApp Web sessions. It offers advanced session handling, flexible event listeners, and various storage options, making it ideal for developers integrating WhatsApp into their applications.

🚀 Installation

Install via npm:

npm install @dutakey/whatsmulti

Or using yarn:

yarn add @dutakey/whatsmulti

✨ Key Features

  • Seamless Multi-Session Management: Effortlessly create, manage, and maintain multiple WhatsApp sessions.
  • Flexible Storage Options: Store sessions locally, in memory, or integrate with databases like MongoDB.
  • Robust Event Handling: Easily handle events across multiple sessions for real-time monitoring.
  • QR Code Generation: Automatically generate QR codes for session authentication.
  • Message Sending: Send various types of messages (text, images, etc.) across sessions.
  • Session Lifecycle Management: Start, stop, restart, and delete sessions programmatically.

📋 Table of Contents

🚀 Quick Start

import WhatsMulti from '@dutakey/whatsmulti';

const client = new WhatsMulti({
    mongoUri: 'mongodb://localhost:27017/whatsmulti-db', // Optional
    defaultConnectionType: 'local', // 'local' | 'mongodb' | 'memory'
});

// Create and start a session
await client.createSession('my-session', 'local', {
    printQR: true, // Print QR code to console
});

await client.startSession('my-session');

// Listen for events
client.on('open', (_, { sessionId }) => {
    console.log(`Session ${sessionId} is connected!`);
});

client.on('messages.upsert', async (data, { sessionId }) => {
    const message = data.messages[0];
    console.log('New message:', message);
});

⚙️ Configuration

Constructor Options

interface ConfigType {
    defaultConnectionType?: 'local' | 'mongodb' | 'memory';
    localConnectionPath?: string;
    LoggerLevel?: 'silent' | 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace';
    BaileysLoggerLevel?: 'silent' | 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace';
    mongoUri?: string;
    startWhenSessionCreated?: boolean;
}

Socket Configuration

interface SockConfig {
    disableQRRetry?: boolean;
    qrMaxWaitMs?: number;
    printQR?: boolean;
    // ... other Baileys SocketConfig options
}

🔧 Session Management

Creating Sessions

Sessions can be created with different storage types:

// Local storage (files)
await client.createSession('session-1', 'local');

// MongoDB storage
await client.createSession('session-2', 'mongodb');

// Memory storage (temporary)
await client.createSession('session-3', 'memory');

Session Lifecycle

// Create and start
await client.createSession('my-session', 'local', {
    printQR: true,
    qrMaxWaitMs: 60000,
});
await client.startSession('my-session');

// Stop temporarily
await client.stopSession('my-session');

// Restart
await client.restartSession('my-session');

// Logout and clean up
await client.logoutSession('my-session');

// Completely remove
await client.deleteSession('my-session');

Loading Existing Sessions

// Load all previously created sessions
await client.loadSessions();

📡 Event Handling

WhatsMulti extends EventEmitter and provides all Baileys events plus custom events:

Built-in Events

// Connection events
client.on('open', (data, { sessionId, socket }) => {
    console.log(`Session ${sessionId} connected`);
});

client.on('close', (data, { sessionId }) => {
    console.log(`Session ${sessionId} disconnected`);
});

client.on('connecting', (data, { sessionId }) => {
    console.log(`Session ${sessionId} is connecting...`);
});

// QR Code event
client.on('qr', (data, { sessionId }) => {
    console.log(`QR Code for ${sessionId}:`, data.qr);
    // data.image contains base64 image data
});

// Message events
client.on('messages.upsert', (data, { sessionId, socket }) => {
    data.messages.forEach((message) => {
        console.log(`New message in ${sessionId}:`, message);
    });
});

// Contact events
client.on('contacts.update', (contacts, { sessionId }) => {
    console.log(`Contacts updated in ${sessionId}:`, contacts);
});

// Group events
client.on('groups.update', (groups, { sessionId }) => {
    console.log(`Groups updated in ${sessionId}:`, groups);
});

Event Processing

You can also use the process method to handle all events in one place:

client.process((events, { sessionId, socket }) => {
    if (events['messages.upsert']) {
        // Handle messages
    }
    if (events.qr) {
        // Handle QR code
    }
    // Handle other events...
});

💬 Message Operations

Selain sendMessage, WhatsMulti menyediakan helper method yang lebih sederhana untuk mengirim berbagai tipe pesan melalui client.message.

Generic Send

await client.sendMessage('session-1', '[email protected]', { text: 'Hello World!' });

MessageService Helper Methods

WhatsMulti expose client.message untuk mempermudah pengiriman pesan.

Send Text

await client.message.sendText('session-1', '[email protected]', 'Hello World!');

Send Text with Quote

await client.message.sendQuote('session-1', msg, 'This is a reply', msg);

Send Text with Mention

await client.message.sendMention('session-1', '[email protected]', 'Hello @user', [
    '[email protected]',
]);

Forward Message

await client.message.forwardMessage('session-1', '[email protected]', msg);

Send Location

await client.message.sendLocation('session-1', '[email protected]', -6.2, 106.816666);

Send Contact

const vcard = `BEGIN:VCARD
VERSION:3.0
FN:John Doe
TEL:+1234567890
END:VCARD`;

await client.message.sendContact('session-1', '[email protected]', 'John Doe', vcard);

Send Reaction

await client.message.sendReaction('session-1', msg.key.remoteJid!, '👍', msg);

Send Poll

await client.message.sendPoll('session-1', '[email protected]', 'Favorite Fruit?', ['Apple', 'Banana'], 1);

Send Link Preview

await client.message.sendLinkPreview('session-1', '[email protected]', 'Check this out: https://example.com');

Send Image

await client.message.sendImage(
    'session-1',
    '[email protected]',
    'https://example.com/image.jpg',
    'Nice image!'
);

Send Video

await client.message.sendVideo(
    'session-1',
    '[email protected]',
    'https://example.com/video.mp4',
    'Watch this!',
    true
);

Send Audio

await client.message.sendAudio('session-1', '[email protected]', 'https://example.com/audio.mp3', 'audio/mp3');

💾 Storage Options

Local Storage

Sessions are stored as files in the local filesystem:

const client = new WhatsMulti({
    localConnectionPath: './sessions', // Default: './whatsmulti_sessions'
});

await client.createSession('my-session', 'local');

MongoDB Storage

Sessions are stored in a MongoDB database:

const client = new WhatsMulti({
    mongoUri: 'mongodb://localhost:27017/whatsmulti-db',
});

await client.createSession('my-session', 'mongodb');

Memory Storage

Sessions are stored in memory (lost on restart):

await client.createSession('my-session', 'memory');

🎯 Contributing

Contributions are welcome! If you find a bug, have feature suggestions, or want to improve the project, feel free to open an issue or submit a pull request.

Development Setup

  1. Clone the repository
  2. Install dependencies: npm install
  3. Build the project: npm run build
  4. Run linting: npm run lint
  5. Run the example: npm run example

📄 License

This project is licensed under MIT, allowing free use, modification, and distribution.