Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

redis-baileys

hacxk22MIT1.0.1TypeScript support: included

Save your baileys session in redisdb using this package

Baileys, Baileys WhatsApp Bot, Baileys Multi-Device, Baileys MD, Baileys Node.js, Node.js WhatsApp Bot, WhatsApp Web API, WhatsApp Bot API, WhatsApp Bot Tutorial, WhatsApp Multi-Device Bot, Redis WhatsApp State, Redis Session Store, WhatsApp Bot Authentication, WhatsApp Bot Development, Baileys Documentation, Baileys Examples, Baileys GitHub, WhatsApp Bot Framework, Multi-Device WhatsApp Bot, WhatsApp Business API (unofficial), Real-time WhatsApp Bot, Secure WhatsApp Bot, Scalable WhatsApp Bot, WhatsApp Chatbot, WhatsApp Automation

readme

Redis-Baileys

License npm version GitHub stars GitHub issues

Save your Baileys session in Redis DB using this powerful and efficient package!

🌟 Features

  • 🚀 Fast and efficient storage of Baileys sessions
  • 🔒 Secure data management with Redis
  • 🔄 Easy integration with existing Baileys projects
  • 📦 TypeScript support
  • 🛠 Simple API for session management

📦 Installation

npm install redis-baileys

or

yarn add redis-baileys

🚀 Usage

TypeScript

import { useRedisAuthState } from 'redis-baileys';
import { Boom } from '@hapi/boom';
import makeWASocket, { DisconnectReason } from '@whiskeysockets/baileys';

async function connectToWhatsApp() {
    const redisConfig = {
        password: 'your_redis_password',
        host: 'your_redis_host',
        port: 6379,
    };

    const { state, saveCreds } = await useRedisAuthState(redisConfig, 'your_session_id');

    const sock = makeWASocket({
        auth: state,
        printQRInTerminal: true,
    });

    sock.ev.on('connection.update', (update) => {
        const { connection, lastDisconnect } = update;
        if (connection === 'close') {
            const shouldReconnect = (lastDisconnect?.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut;
            console.log('connection closed due to ', lastDisconnect?.error, ', reconnecting ', shouldReconnect);
            if (shouldReconnect) {
                connectToWhatsApp();
            }
        } else if (connection === 'open') {
            console.log('opened connection');
        }
    });

    sock.ev.on('creds.update', saveCreds);
}

connectToWhatsApp();

JavaScript

const { useRedisAuthState } = require('redis-baileys');
const { Boom } = require('@hapi/boom');
const makeWASocket = require('@whiskeysockets/baileys').default;

async function connectToWhatsApp() {
    const redisConfig = {
        password: 'your_redis_password',
        host: 'your_redis_host',
        port: 6379,
    };

    const { state, saveCreds } = await useRedisAuthState(redisConfig, 'your_session_id');

    const sock = makeWASocket({
        auth: state,
        printQRInTerminal: true,
    });

    sock.ev.on('connection.update', (update) => {
        const { connection, lastDisconnect } = update;
        if (connection === 'close') {
            const shouldReconnect = (lastDisconnect?.error instanceof Boom) && lastDisconnect.error.output.statusCode !== DisconnectReason.loggedOut;
            console.log('connection closed due to ', lastDisconnect?.error, ', reconnecting ', shouldReconnect);
            if (shouldReconnect) {
                connectToWhatsApp();
            }
        } else if (connection === 'open') {
            console.log('opened connection');
        }
    });

    sock.ev.on('creds.update', saveCreds);
}

connectToWhatsApp();

🛠 API

useRedisAuthState(redisConfig, sessionId)

Creates and manages the authentication state using Redis.

  • redisConfig: An object containing Redis connection details (password, host, port).
  • sessionId: A unique identifier for the session.

Returns an object with:

  • state: The current authentication state.
  • saveCreds: A function to save credentials.
  • deleteSession: A function to delete the current session.

📚 Documentation

For more detailed documentation, please visit our Wiki.

🤝 Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.

🙏 Acknowledgements

  • Baileys - The awesome WhatsApp Web API library
  • Redis - The open-source, in-memory data store used by millions of developers

Made with ❤️ by HacxK