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

@onepunya/baileys

v1.0.0

Published

A WebSockets library for interacting with WhatsApp Web

Downloads

52

Readme

Fork dari Baileys — WhatsApp Web API library dengan tambahan bot utilities oleh Onepunya.

Version Based On License


✨ Apa yang Berbeda?

Fork ini menambahkan bot utilities yang memudahkan pembuatan bot WhatsApp tanpa perlu install library tambahan.

Fitur Tambahan

| Fitur | Deskripsi | |-------|-----------| | createBotSocket() | Wrapper sock dengan helper methods bawaan | | downloadMedia() | Download semua jenis media dengan mudah | | ReconnectManager | Smart reconnect dengan exponential backoff | | MessageQueue | Rate limiter untuk pengiriman pesan | | toJid() / fromJid() | Helper format nomor WA | | getMessageText() | Ambil teks dari semua jenis pesan | | getQuoted() | Ambil quoted message |


📦 Instalasi

npm install github:onepunya/baileys

Atau clone langsung:

git clone https://github.com/onepunya/baileys.git
cd baileys
npm install
npm run build

🚀 Quick Start

Tanpa Bot Utils (cara lama)

import makeWASocket, { useMultiFileAuthState } from '@whiskeysockets/baileys'

const { state, saveCreds } = await useMultiFileAuthState('session')
const sock = makeWASocket({ auth: state })

sock.ev.on('messages.upsert', async ({ messages }) => {
  const msg = messages[0]
  const text = msg.message?.conversation || ''
  if (text === 'ping') {
    await sock.sendMessage(msg.key.remoteJid, { text: 'pong' }, { quoted: msg })
  }
})

Dengan Bot Utils (cara baru)

import makeWASocket, { useMultiFileAuthState, createBotSocket, ReconnectManager } from '@onepunya/baileys'

const reconnect = new ReconnectManager({
  maxRetries: 10,
  onReconnecting: (attempt, delay) => console.log(`Reconnecting... attempt ${attempt}`)
})

async function connect() {
  const { state, saveCreds } = await useMultiFileAuthState('session')
  const raw = makeWASocket({ auth: state })
  
  // Wrap dengan bot utils
  const sock = createBotSocket(raw, {
    messageDelay: 500,
    ownerNumbers: ['628xxxxxxxxx']
  })

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

  sock.ev.on('connection.update', ({ connection, lastDisconnect }) => {
    if (connection === 'open') {
      reconnect.reset()
      console.log('Connected!')
    }
    if (connection === 'close') {
      reconnect.handle(lastDisconnect?.error, connect)
    }
  })

  sock.ev.on('messages.upsert', async ({ messages }) => {
    const msg = messages[0]
    if (!msg.message) return

    const text = sock.getText(msg)
    const from = msg.key.remoteJid!

    if (text === 'ping') await sock.reply(msg, 'pong! 🏓')
    if (text === 'hi') await sock.reply(msg, 'Halo! 👋')
  })
}

connect()

📚 API Reference

createBotSocket(sock, config?)

Wrap makeWASocket dengan helper methods.

const bot = createBotSocket(sock, {
  messageDelay: 500,      // Delay antar pesan (ms)
  ownerNumbers: ['628x'], // Nomor owner
})

Text Methods

await bot.reply(msg, 'Halo!')
await bot.sendText(jid, 'Teks biasa')
await bot.replyMention(msg, 'Halo @user!', [jid1, jid2])

Media Methods

// Kirim gambar dari URL atau buffer
await bot.sendImage(jid, 'https://example.com/img.jpg', 'Caption')
await bot.sendImage(jid, buffer, 'Caption')

// Kirim video
await bot.sendVideo(jid, 'https://example.com/video.mp4', 'Caption')

// Kirim audio
await bot.sendAudio(jid, buffer)

// Kirim voice note
await bot.sendVoice(jid, buffer)

// Kirim dokumen
await bot.sendDocument(jid, buffer, 'application/pdf', 'file.pdf', 'Caption')

// Kirim sticker
await bot.sendSticker(jid, buffer)

Presence Methods

await bot.sendTyping(jid)    // Tampilkan typing...
await bot.sendRecording(jid) // Tampilkan recording...
await bot.stopTyping(jid)    // Stop typing
await bot.markRead(msg)      // Tandai pesan dibaca

React Methods

await bot.react(msg, '👍')  // React dengan emoji
await bot.unreact(msg)       // Hapus react

Group Methods

const members = await bot.getGroupMembers(jid)
const isAdm = await bot.isAdmin(jid, userId)
const isBotAdm = await bot.isBotAdmin(jid)
await bot.tagAll(jid, 'Perhatian semua!')

Utility Methods

const text = bot.getText(msg)        // Ambil teks pesan
const type = bot.getMedia(msg)       // Ambil media type
const quoted = bot.getQuotedMsg(msg) // Ambil quoted message
const media = await bot.download(msg) // Download media
const owner = bot.isOwner(userId)    // Cek apakah owner
const jid = bot.toJid('628xxx')      // Format ke JID
const number = bot.fromJid(jid)      // Ambil nomor dari JID

downloadMedia(msg)

Download media dari pesan, kembalikan { buffer, mimetype, ext, size, filename }.

import { downloadMedia } from '@onepunya/baileys'

const media = await downloadMedia(msg)
if (media) {
  console.log(media.mimetype) // image/jpeg
  console.log(media.size)     // 12345
  // media.buffer siap digunakan
}

ReconnectManager

Smart reconnect dengan exponential backoff.

import { ReconnectManager } from '@onepunya/baileys'

const reconnect = new ReconnectManager({
  maxRetries: 10,
  initialDelay: 2000,
  maxDelay: 60000,
  factor: 1.5,
  onReconnecting: (attempt, delay) => {
    console.log(`Retry ${attempt} in ${delay}ms`)
  },
  onConnected: () => console.log('Connected!'),
  onFailed: () => console.log('Max retries reached'),
})

// Di connection.update:
if (connection === 'close') {
  reconnect.handle(lastDisconnect?.error, connect)
}
if (connection === 'open') {
  reconnect.reset()
}

MessageQueue

Rate limiter untuk kirim pesan.

import { MessageQueue } from '@onepunya/baileys'

const queue = new MessageQueue(500) // 500ms delay

await queue.add(() => sock.sendMessage(jid1, { text: 'msg 1' }))
await queue.add(() => sock.sendMessage(jid2, { text: 'msg 2' }))
// Pesan dikirim dengan jeda 500ms

⚠️ Disclaimer

Fork ini tidak berafiliasi dengan WhatsApp. Gunakan dengan bijak sesuai Terms of Service WhatsApp.

Berdasarkan Baileys oleh WhiskeySockets.