New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

kevinx-baileys

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kevinx-baileys

KevinX Baileys — a WebSockets library for interacting with WhatsApp Web (multi-device, pairing code, interactive messages, newsletter, auto-reconnect, send queue, typings).

latest
npmnpm
Version
1.2.0
Version published
Maintainers
1
Created
Source

KevinX Baileys

A fast, stable WhatsApp Web (multi-device) library over WebSocket — no browser required.

Table of Contents

  • About
  • Installation
  • Import
  • Connect to WhatsApp
  • Usage Examples
  • What's new in 1.2
  • Startup Banner
  • Features
  • Official Channels
  • License

About

KevinX Baileys is a modified Baileys build for developers who want to build WhatsApp bots, automation and integrations directly over WebSocket. It adds a custom pairing code, interactive messages, action buttons, newsletter support and extra message options on top of the Baileys core.

Maintained by KevinX — Telegram: @kevinxddd

Installation

npm install kevinx-baileys

Use it as a drop-in replacement for @whiskeysockets/baileys by aliasing it in your package.json:

{
  "dependencies": {
    "@whiskeysockets/baileys": "npm:kevinx-baileys"
  }
}

Requires Node.js 20 or newer (Node 21 and 22+ are supported).

Import

KevinX Baileys is an ES module:

import makeWASocket, {
  useMultiFileAuthState,
  fetchLatestBaileysVersion,
  Browsers,
  DisconnectReason
} from 'kevinx-baileys'

From CommonJS, use dynamic import (or require() directly on Node 20.19+ / 22.12+):

const { default: makeWASocket, useMultiFileAuthState } = await import('kevinx-baileys')

Connect to WhatsApp

With QR Code

printQRInTerminal is deprecated — listen to connection.update and render the QR yourself (for example with the qrcode-terminal package):

import qrcode from 'qrcode-terminal'

const { state, saveCreds } = await useMultiFileAuthState('session')
const { version } = await fetchLatestBaileysVersion()

const sock = makeWASocket({
  version,
  auth: state,
  browser: Browsers.ubuntu('Chrome')
})

sock.ev.on('creds.update', saveCreds)
sock.ev.on('connection.update', ({ connection, lastDisconnect, qr }) => {
  if (qr) qrcode.generate(qr, { small: true })

  if (connection === 'close') {
    const code = lastDisconnect?.error?.output?.statusCode
    if (code !== DisconnectReason.loggedOut) {
      // reconnect here (re-run your start function)
    }
  }
})

With Pairing Code

const { state, saveCreds } = await useMultiFileAuthState('session')
const { version } = await fetchLatestBaileysVersion()

const sock = makeWASocket({
  version,
  auth: state,
  browser: Browsers.ubuntu('Chrome')
})

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

if (!sock.authState.creds.registered) {
  const number = '628XXXXXXXXXX' // country code, digits only
  const code = await sock.requestPairingCode(number.trim())
  console.log('Your pairing code:', code)
}

Custom Pairing Code

Pass your own code as the second argument — it must be exactly 8 characters. If you omit it, the default KEVINXWA is used.

const code = await sock.requestPairingCode(number.trim(), 'KEVINX01')
console.log('Your pairing code:', code)

Usage Examples

Send a message with ptcp

ptcp: true sends the message without syncing it to your own other linked devices (same behaviour as noSelfSync).

await sock.sendMessage(m.chat, { text: 'KevinX Baileys' }, { ptcp: true })

What's new in 1.2

Everything below is additive. Existing code keeps working, and no existing socket method is replaced.

makeKevinXSocket() - auto-reconnect in one call

import { makeKevinXSocket } from 'kevinx-baileys'

const bot = await makeKevinXSocket({
  sessionPath: 'session',
  pairingNumber: '628XXXXXXXXXX', // omit to use QR (see onQR)
  onSocket: (sock) => {
    // runs on EVERY (re)connect - attach your listeners here
    sock.ev.on('messages.upsert', async ({ messages }) => {
      const m = messages[0]
      if (!m.message || m.key.fromMe) return
      await sock.reply(m, 'pong')
    })
  },
  onPairingCode: (code) => console.log('Pairing code:', code),
  onReconnecting: ({ attempt, waitMs }) => console.log(`reconnect #${attempt} in ${waitMs}ms`)
})

bot.sock      // always the current socket
await bot.stop()

It reconnects with exponential backoff (2s, 4s, 8s ... max 60s, with jitter) and does not reconnect after loggedOut, connectionReplaced (another session took over) or forbidden, because reconnecting there only loops. restartRequired (normal after pairing) reconnects immediately. Tune it with reconnect: { minDelay, maxDelay, factor, jitter, maxRetries }.

Reconnecting reduces "connection closed" problems. No library can promise you will never be disconnected or never be banned.

Other options: auth (custom auth state, see below), socketConfig, cleanup, checkUpdate, autoFollowChannels, onQR, onOpen, onClose, onLoggedOut, onError.

Pairing helper

const code = await sock.pair('628XXXXXXXXXX')            // waits until ready, retries by itself
const code2 = await sock.pair('628XXXXXXXXXX', 'KEVINX01') // custom 8-char code

Shortcuts

await sock.reply(m, 'text')                      // quotes m
await sock.reply(m, { image: { url }, caption }) // any content
await sock.sendWithTyping(jid, 'hello', { typingMs: 1500 }) // "typing..." first, length-based if typingMs is omitted

sendText, sendImage, sendVideo, sendAudio and sendDocument already existed and keep their signatures.

Send queue and broadcast

const results = await sock.broadcast(['628111@s.whatsapp.net', '628222@s.whatsapp.net'], { text: 'Hello' }, undefined, {
  onProgress: ({ done, total }) => console.log(done, '/', total)
})
// [{ jid, ok: true, message } | { jid, ok: false, error }]

// per-recipient content
await sock.broadcast(jids, (jid) => ({ text: `Hi ${jid.split('@')[0]}` }))

sock.queue.pause(); sock.queue.resume(); sock.queue.clear()

Messages go out one by one with a random 1.5 - 4 s gap (makeWASocket({ sendQueue: { minDelay, maxDelay, retries } })). This reduces burst sending. It does not guarantee you will not be flagged or banned.

Status / story

await sock.sendStatusText('Good morning', ['628111', '628222'])
await sock.sendStatusImage('https://example.com/a.jpg', ['628111'], 'caption')
await sock.sendStatusVideo('./clip.mp4', ['628111'])

Only the listed contacts see it. Your own number is added automatically.

Session tools

import { backupSession, restoreSession, cleanSession } from 'kevinx-baileys'

await backupSession('session', 'backups/session-backup-1.kxsession', { keep: 5 })
await restoreSession('backups/session-backup-1.kxsession', 'session')
await cleanSession('session', { maxAgeDays: 3, dryRun: true }) // prunes old re-creatable cache files only

cleanSession never touches creds.json. By default it only removes old sender-key-memory-* and device-list-* files. Add session-* or pre-key-* to patterns only if you accept that some chats may need to renegotiate keys. Or let makeKevinXSocket({ cleanup: { maxAgeDays: 3, intervalHours: 24 } }) do it.

MongoDB / Redis auth state

import { useMongoAuthState, useRedisAuthState, makeKevinXSocket } from 'kevinx-baileys'
import { MongoClient } from 'mongodb'

const client = await new MongoClient(process.env.MONGO_URL).connect()
const auth = await useMongoAuthState(client.db('wa').collection('auth'), { sessionId: 'bot1' })
const bot = await makeKevinXSocket({ auth, pairingNumber: '628XXXXXXXXXX' })

// Redis (ioredis or node-redis v4+)
const auth2 = await useRedisAuthState(redisClient, { prefix: 'wa:bot1' })

You bring your own driver (mongodb, ioredis or redis), so this library adds no extra dependency. auth.clear() deletes the stored session.

Channels

await sock.channel.info('https://whatsapp.com/channel/XXXX')
await sock.channel.follow('https://whatsapp.com/channel/XXXX')
await sock.channel.react('120363...@newsletter', serverId, '🔥')
await sock.channel.followMany([...links])

Nothing is followed unless you call it. autoFollowChannels in makeKevinXSocket is an empty list by default.

Group cache and tag all

The group metadata cache is on by default (5 minutes, refreshed on group events). Turn it off with makeWASocket({ groupCache: false }), or pass your own cachedGroupMetadata.

await sock.tagAll(groupJid, 'Meeting at 8')   // mentions everyone
await sock.hidetag(groupJid, 'Read this')
const meta = await sock.getGroupMetadata(groupJid)

Update check

Opt-in. Run with KEVINX_CHECK_UPDATE=true (or makeKevinXSocket({ checkUpdate: true })) to print a notice when a newer version exists on npm. It never installs anything.

import { checkForUpdate } from 'kevinx-baileys'
const { updateAvailable, latestVersion } = await checkForUpdate()

TypeScript

Typings ship with the package (lib/index.d.ts). New features and the most used core API are fully typed. Other exports are typed as any for now so autocomplete still knows their names.

Startup Banner

An ASCII banner is printed once when the library is loaded. To disable it:

KEVINX_BANNER=false node index.js

Features

  • QR code and pairing code login
  • Custom pairing code (8 characters)
  • WhatsApp multi-device
  • Interactive messages and action buttons
  • Group and message management
  • Newsletter (channel) support
  • Message builder (MessageBuilder / MB)
  • Efficient session handling (multi-file, SQLite, MongoDB and Redis auth state)
  • Auto-reconnect with backoff (makeKevinXSocket), pairing helper, send queue / broadcast
  • Reply / typing / status helpers, channel helpers, group cache, tag all
  • Session backup / restore / clean, opt-in update check, TypeScript typings
  • Node.js 20+ (21 and 22+ supported)

Official Channels

For questions, support, bug reports and updates, contact the developer on Telegram.

License

Released under the MIT License. Based on Baileys by Rajeh Taher / WhiskeySockets.

KevinX Baileys
Maintained by @kevinxddd • t.me/kevinstore1122

Keywords

baileys

FAQs

Package last updated on 24 Oct 2026

Related posts