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

@rucas-code/baileys

v1.0.1

Published

A lightweight and clean wrapper around @itsliaaa/baileys for building WhatsApp bots with minimal code.

Downloads

3,385

Readme

✨ @rucas-code/baileys

A lightweight, clean, and developer-friendly wrapper around @itsliaaa/baileys for building WhatsApp bots with minimal boilerplate code.

Node.js Version License: ISC Baileys Compatible


✨ Features

  • 🔑 Easy Pairing Code Authentication: Quick phone number login with automated session management.
  • 📩 Simplified Message Listener: Easily extract sender details, chat IDs, message text, and media flags without digging into raw Baileys objects.
  • 🔔 Group Participant Alerts: Track group joins, leaves, promotions, and demotions effortlessly.
  • ⚙️ Dynamic Configuration: Customize CLI prompts and status messages at runtime.

📦 Installation

Install the package via npm:

npm install @rucas-code/baileys

🚀 Quick Start

Here is a simple example to get your WhatsApp bot running in minutes:

const rucas = require('@rucas-code/baileys');

async function startBot() {
    // 1. Establish WhatsApp connection
    const { status, sock } = await rucas.wa.toConnect();

    if (!status || !sock) {
        console.error("Failed to connect to WhatsApp!");
        return;
    }

    console.log("Bot connected successfully!");

    // 2. Listen for incoming messages
    rucas.wa.message(sock, async (data) => {
        console.log(`[Message] From ${data.name} (${data.sender}): ${data.message}`);

        if (data.message.toLowerCase() === 'ping') {
            await sock.sendMessage(data.chatId, { text: 'pong 🏓' }, { quoted: data.msg });
        }
    });

    // 3. Listen for group updates (join/leave/promote/demote)
    rucas.wa.alert(sock, (update) => {
        console.log(`[Group Update] JID: ${update.jid} | Action: ${update.action} | Members: ${update.participants.join(', ')}`);
    });
}

startBot();

📖 API Reference

1. rucas.wa.toConnect()

Establishes a connection to WhatsApp servers. If unauthenticated, prompts the user via terminal for a phone number to request a Pairing Code.

Parameters

None

Returns

  • Promise<Object>: Resolves to an object with connection status:
    • status (Boolean): true if connected successfully, false otherwise.
    • sock (WASocket | null): Active Baileys socket instance or null if connection failed.

2. rucas.wa.message(sock, onMessageReceived)

Subscribes to incoming WhatsApp messages (messages.upsert) and parses common message attributes into a clean JavaScript object.

Parameters

| Parameter | Type | Required | Description | | :--- | :--- | :--- | :--- | | sock | WASocket | Yes | Active Baileys socket instance returned by toConnect(). | | onMessageReceived | Function | Yes | Callback function invoked whenever a new message is received. |

Callback Response Object Structure

The onMessageReceived callback receives a single object containing:

| Property | Type | Description | | :--- | :--- | :--- | | m | Object | Raw Baileys messages.upsert event payload. | | msgType | String | Type of the message (e.g. conversation, extendedTextMessage, imageMessage). | | msg | Object | Raw individual message object (useful for quoting replies). | | id | String | Unique message ID. | | sender | String | Sender JID (e.g., [email protected]). | | name | String | Sender's WhatsApp push name (defaults to "WhatsApp User"). | | message | String | Extracted text content or caption of the message. | | chatId | String | Remote JID of the chat session. | | hasMedia | Boolean | true if the message contains image, video, or document media. | | timestamp | Date | Date object representing when the message event occurred. |


3. rucas.wa.alert(sock, onGroupUpdateReceived)

Subscribes to group participant updates (group-participants.update).

Parameters

| Parameter | Type | Required | Description | | :--- | :--- | :--- | :--- | | sock | WASocket | Yes | Active Baileys socket instance returned by toConnect(). | | onGroupUpdateReceived | Function | Yes | Callback function invoked on group member changes. |

Callback Response Object Structure

The onGroupUpdateReceived callback receives an object containing:

| Property | Type | Description | | :--- | :--- | :--- | | jid | String | Group Chat JID (e.g. [email protected]). | | participants | Array<String> | List of participant JIDs affected by the update. | | action | String | Update type: "add", "remove", "promote", or "demote". | | sock | WASocket | Active socket instance. | | rawUpdate | Object | Raw Baileys group update payload. |


4. rucas.configures(key, value)

Modifies default CLI log messages and prompt strings stored in config.json.

Parameters

| Parameter | Type | Required | Description | | :--- | :--- | :--- | :--- | | key | String | Yes | Configuration key to update. | | value | String | Yes | New string value to set. |

Available Configuration Keys

  • "start_connect" - Initial connection start prompt.
  • "enter_number" - Phone number entry instruction.
  • "question" - Input prompt for phone number.
  • "pairing_code" - Pairing code display label.
  • "try_connect" - Connection attempt log message.
  • "broker_connection" - Connection broken warning message.
  • "success_connect" - Connection success indicator.

Returns

  • Object: The updated configuration object.

🧪 Testing

Run the built-in test suite to verify all modules and functions:

npm test

📝 License

This project is licensed under the ISC License.