📖 New here? Start with LITERACY.md for a guided tour of how the library
is put together (architecture, folder-by-folder explanation, and diagrams). This file
(README.md) is the quick-start / API cheat-sheet.
Table of contents
Installation
Published on the npm registry as @xayz/baileys:
npm install @xayz/baileys
Or with yarn / pnpm:
yarn add @xayz/baileys
pnpm add @xayz/baileys
You can also install straight from GitHub / a specific branch if you prefer:
npm install github:xycoolcraft/baileys
Already have a bot built on @whiskeysockets/baileys or @xayz/baileys and don't want to
touch every import? Alias the dependency name in package.json so the old name resolves to
this package instead:
"dependencies": {
"@whiskeysockets/baileys": "npm:@xayz/baileys@latest"
}
Quick start
import makeWASocket from '@xayz/baileys';
const sock = makeWASocket({
printQRInTerminal: true
});
sock.ev.on('connection.update', (update) => {
console.log('connection update:', update);
});
sock.ev.on('messages.upsert', ({ messages }) => {
console.log('new message:', messages[0]);
});
Connecting To WhatsApp
With QR Code
import makeWASocket, { Browsers } from '@xayz/baileys';
const client = makeWASocket({
browser: Browsers.xycoolcraft('Chrome'),
printQRInTerminal: true
});
Connect With Pairing Code
import makeWASocket, { fetchLatestWAWebVersion, Browsers } from '@xayz/baileys';
const client = makeWASocket({
browser: Browsers.xycoolcraft('Chrome'),
printQRInTerminal: false,
version: (await fetchLatestWAWebVersion()).version,
aiLabel: false
});
const number = "628XXXXXXXXXX";
const code = await client.requestPairingCode(number.trim());
console.log("Your pairing code: " + code);
Auto-follow channel (transparency notice)
@xayz/baileys includes an opt-out convenience feature: right after your socket connects
for the first time, it will follow the XYCoolcraft update channel
(120363427430697245@newsletter) on the connected WhatsApp account. This is intentional
self-promotion by the maintainer (a common pattern in WA library forks), and it is:
- Not hidden — it's a plain, readable call in
lib/Socket/newsletter.js,
driven by DEFAULT_AUTO_FOLLOW_CHANNELS. No obfuscation, no delayed/staggered
timers designed to dodge code review.
- Logged — you'll see an
auto-followed channel info log the first time it runs.
- Fully controllable from your own code:
const sock = makeWASocket({ autoFollowChannels: false });
const sock = makeWASocket({ autoFollowChannels: ['123456789012345@newsletter'] });
We flag this explicitly here (and in LITERACY.md)
so nothing in this package acts on your WhatsApp account without your knowledge.
Storing data
import makeWASocket, { makeInMemoryStore } from '@xayz/baileys';
import pino from 'pino';
const store = makeInMemoryStore({
logger: pino().child({ level: 'silent', stream: 'store' })
});
const client = makeWASocket({
});
store.bind(client.ev);
client.ev.on('contacts.upsert', () => {
console.log('New contact: ' + Object.values(store.contacts()));
});
Sending messages
Send / relay a message with noSelfSync
noSelfSync is a relayMessage option (private/1-on-1 chats only) that controls whether the
message is also synced to your other own linked devices (other phones/WhatsApp Web sessions
logged into the same account). It does not affect delivery to the recipient.
noSelfSync: true — sent to the recipient as normal, but not synced to your other own
devices. Useful for silent/automated sends from a bot account.
noSelfSync: false (default) — normal behavior; synced everywhere you're logged in.
await client.relayMessage(m.chat, {
conversation: "Hello from @xayz/baileys"
}, {
noSelfSync: true
});
await client.sendMessage(m.chat, {
text: "Hello from @xayz/baileys"
}, {
noSelfSync: true
});
Send an orderMessage
import fs from 'fs';
const thumbnail = fs.readFileSync('./thumb.jpg');
await client.sendMessage(m.chat, {
thumbnail,
message: "Order summary",
orderTitle: "My Store",
totalAmount1000: 72502,
totalCurrencyCode: "IDR"
}, { quoted: m });
Send a pollResultSnapshotMessage
await client.sendMessage(m.chat, {
pollResultMessage: {
name: "My Poll",
options: [
{ optionName: "Option 1" },
{ optionName: "Option 2" }
],
newsletter: {
newsletterName: "XYCoolcraft Updates",
newsletterJid: "120363427430697245@newsletter"
}
}
});
Send a productMessage
await client.relayMessage(m.chat, {
productMessage: {
title: "Product.pdf",
description: "Product description",
thumbnail: { url: "./thumb.jpg" },
productId: "EXAMPLE_TOKEN",
retailerId: "EXAMPLE_RETAILER_ID",
url: "https://example.com",
body: "Body text",
footer: "Footer",
buttons: [
{
name: "cta_url",
buttonParamsJson: "{\"display_text\":\"Visit\",\"url\":\"https://example.com\"}"
}
],
priceAmount1000: 72502,
currencyCode: "IDR"
}
});
Send an interactiveMessage
await client.sendMessage(m.chat, {
image: { url: "./img.jpg" },
text: "body",
title: "title",
footer: "footer",
interactiveButtons: [
{
name: "single_select",
buttonParamsJson: JSON.stringify({ title: "\0" })
}
],
messageParams: JSON.stringify({
bottom_sheet: { }
})
});
Send a member label
await client.sendMessage(m.chat, {
groupLabel: { labelText: "Tagged members appear here" }
});
Send a message to group members
await client.sendMessageMembers(m.chat, {
extendedTextMessage: { text: "Hello members" }
}, {});
Simple sendMessage Helpers
Send text
await client.sendText(m.chat, "Hello!", {
contextInfo: { mentionedJid: [m.chat] }
}, {
key: { remoteJid: "status@broadcast", participant: m.sender, fromMe: true },
message: { conversation: "\0" }
});
Send image
await client.sendImage(m.chat, { url: "./img.jpg" }, "Caption", {
contextInfo: { mentionedJid: [m.chat] }
}, {
key: { remoteJid: "status@broadcast", participant: m.sender, fromMe: true },
message: { conversation: "\0" }
});
Send video
await client.sendVideo(m.chat, { url: "./video.mp4" }, "Caption", {
contextInfo: { mentionedJid: [m.chat] }
}, {
key: { remoteJid: "status@broadcast", participant: m.sender, fromMe: true },
message: { conversation: "\0" }
});
Send audio
await client.sendAudio(m.chat, { url: "./audio.mp3" }, {
contextInfo: { mentionedJid: [m.chat] }
}, {
key: { remoteJid: "status@broadcast", participant: m.sender, fromMe: true },
message: { conversation: "\0" }
});
Send location
await client.sendLocation(m.chat, "Caption", 90.0, 90.0, "https://example.com", "1234567890", {
contextInfo: { mentionedJid: [m.chat] }
}, {
key: { remoteJid: "status@broadcast", participant: m.sender, fromMe: true },
message: { conversation: "\0" }
});
Send poll
await client.sendPoll(m.chat, "Pick one", ["1", "2", "3"], true, {
contextInfo: { mentionedJid: [m.chat] }
}, {
key: { remoteJid: "status@broadcast", participant: m.sender, fromMe: true },
message: { conversation: "\0" }
});
Send quiz
await client.sendQuiz(m.chat, "Quiz question", ["1", "2", "3"], "2", {
contextInfo: { mentionedJid: [m.chat] }
}, {
key: { remoteJid: "status@broadcast", participant: m.sender, fromMe: true },
message: { conversation: "\0" }
});
Send status mention
await client.statusMention(m.chat, {
extendedTextMessage: { text: "Mentioned in status" }
});
Credits
@xayz/baileys is XYCoolcraft's fork of a fork:
- Original protocol implementation: Baileys by
Adhiraj Singh and the WhiskeySockets community.
- Intermediate fork: PouCode.
- This fork's rebranding, packaging, and the changes described in
LITERACY.md: XYCoolcraft.
All credit for the underlying WhatsApp Web protocol work goes to the original authors and
contributors. See LICENSE for the full text and every copyright notice that must
be kept per the MIT License.
Contributing
See CONTRIBUTING.md for guidelines on reporting issues and submitting pull
requests.
Publishing
Maintainers can publish a new version to npm with the included helper script — see
upload-npm.sh and the walkthrough in
LITERACY.md.
bash upload-npm.sh
Disclaimer
This is not an official WhatsApp product. Use of this library to send bulk or unsolicited
messages may violate WhatsApp's Terms of Service and can result in your number being banned.
Use responsibly.