Skip to content
7ucgPublic

About

WhatsApp Web multi-device client library — TypeScript, with libsignal/WABinary/Noise/app-state crypto ported to Rust and compiled to WASM

Topics

Resources

Contributing

Stars

9 stars

Watchers

0 watching

Forks

Repository files navigation

velowa

A WhatsApp Web multi-device client for Node.js, written in TypeScript. Use it to build bots, notification senders, support desks, channel publishers and call bots, or as the engine under your own application.

The crypto- and binary-heavy parts (Signal protocol, WABinary, Noise handshake, app-state crypto, VoIP media) are ported once from whatsapp-rust and run as WebAssembly; everything else is TypeScript. The package ships ESM and CommonJS builds with type definitions.

velowa uses the unofficial WhatsApp Web protocol. It is not affiliated with WhatsApp or Meta. Automating an account can get it restricted or banned; read Reliability and safety before you point it at an account you care about.

License: velowa is free to use and to build on, but copying any part of its code, however small, requires credit to velowa and its author. Using it as a library does not. See License and credit.

How velowa differs from Baileys and its forks

velowa is not a fork: its TypeScript is written fresh, not copied from Baileys, and it was designed from the protocol up and only then compared with Baileys behaviour where that helps. What that changes in practice:

Baileys and libraries derived from it velowa
Where the protocol work runs JavaScript: Signal, Noise, binary encoding and decoding Rust compiled to WebAssembly for Signal, Noise, WABinary, app-state crypto and call media; TypeScript for everything else
Calls usually only seen and rejected: no audio or video real calls: voice and video, one to one and in groups, call links with a waiting room, camera / hand / reactions in a call, audio and video from files or your microphone and speaker
Sending one sendMessage(jid, content) with a loose content object the same one-call style, client.send(jid, {...}), with typed content kinds, plus a typed method for every feature (sendPoll, postToChannel, reportUser, ...)
Connection connection.update with status codes to interpret one connection event (state, qr, pairingCode, reason, loggedOut) and automatic reconnect; no reconnect loop to write
Bots you write your own message parsing serialize() gives a ready Message (text, sender, quoted, reply(), download()), GroupCache / isGroupAdmin for permissions; no framework is imposed, cases and plugin bots are examples
Account safety often an add-on or left to you antiban is built in (rate caps, random gaps, new-chat delay, identical-text limit, warm-up)
Debugging a logger you configure a protocol log of every frame and stanza, grouped by day, rotated, compressed and pruned, with velowa-logs to manage it

Also worth knowing: velowa builds to ESM and CommonJS with types, has three runtime dependencies, and is written in strict TypeScript with a test suite that mirrors src/; the code in this README and in examples/ is type-checked against the built package. It is built once from the repository (Rust and wasm-pack needed for that) and then runs on plain Node. Codec throughput against Baileys' own rust bridge is tracked in docs/benchmarks.md.

What exists and works

"Checked" says how far a row has been tried: live means it was exercised against real WhatsApp accounts and phones; tests means it is covered by unit and loopback tests only.

Area What you get Checked
Connection QR or pairing-code linking, login from the saved folder, automatic reconnect, connection event live
Messages text, replies, mentions, reactions, edit, delete, forward, view-once, link previews, typing / presence, read receipts live
Media image, video, audio, voice note, document, sticker: encrypted upload and download, from bytes, files, URLs or streams live
Interactive buttons, lists, templates, native-flow buttons, Meta-AI style rich answers (text, code, table, LaTeX, map) and HTML live
Polls polls, quizzes, questions, image polls and quizzes live
Groups create, members, admins, name, description, settings, invite links, join approval, disappearing messages, member tags, permissions live
Communities create, link and unlink groups, deactivate live for link and unlink; tests for the rest
Channels create, follow, mute; post text, image, video, polls, quizzes, questions and music; a channel status (text, image, video, voice note); AI-content and paid-partnership labels live for posting (feed and status) and labels; tests for create, follow, mute
Status text status with a chosen audience; group status (text, picture, video, music, voice); channel status live
Contacts and account number lookup, "About", profile picture, username lookup, blocking, privacy settings, profile name and picture live for lookups, blocking and reading settings; tests for changing them
Chats archive, mute, pin, star, mark read, delete, clear, labels, per-chat disappearing timer live for archive, pin, star; tests for the rest
Reports report a user, a group, a channel, a message to the admins live
Payments payment requests and answers live
Calls voice and video one to one in both directions; incoming calls; group calls in both directions; call links, joining, waiting room and its admin commands; camera on and off, raised hands and reactions in a call; files and microphone / speaker as call media live
Anti-ban and analytics rate limits and pacing; WAM usage events live
Business business profile, catalog and collections, editing a business profile; products (add, change, delete), collections, broadcast lists and quota, quick replies live for reading a profile; tests for the rest (the GraphQL calls: see More functions)
Calendar events create, list, change, delete events; answer, invite, invite link, preview, cover pictures unit tests only; live: Bad Request (the token query fails)
Account log out, remove a linked device, trusted devices, linked profiles tests; GraphQL parts see More functions
History the history chunks the phone sends after linking tests
Escape hatches client.request(node) for any stanza, client.mex(queryId, variables) for any GraphQL query live

Not included: registering a new number, managed accounts and interop with other messengers. A call that started as voice-only cannot turn the camera on later.

Contents

  1. How velowa differs from Baileys and its forks
  2. What exists and works
  3. Install and set up
  4. Link an account
  5. A first bot in 20 lines
  6. Receiving: messages and events
  7. Sending: client.send
  8. Writing a bot: your style
  9. Feature guide
  10. Events reference
  11. Configuration
  12. What you can build
  13. Reliability and safety
  14. Development
  15. License and credit
  16. More documentation

Install and set up

velowa is distributed through git only; it is not published on npm. The repository holds the finished build (dist/, with the WebAssembly inside), so installing is one command and needs no Rust:

cd my-bot
npm install github:7ucg/velowa            # the latest
npm install github:7ucg/velowa#v1.2.0     # a release (recommended: it does not move)

Requirements: Node.js 18 or newer. Nothing is compiled or run while installing.

import { Client } from 'velowa' // ESM
const { Client } = require('velowa') // CommonJS

To update, run the same npm install github:7ucg/velowa#<tag> with the new tag.

Working on velowa itself? Then you build it: Rust 1.94 and wasm-pack are needed for that one step.

git clone https://github.com/7ucg/velowa
cd velowa
npm install
npm run build        # wasm-pack + tsup -> dist/ (ESM + CJS)
npm test

and npm install ../velowa in your project uses that folder. The rules for git and for contributing are in CONTRIBUTING.md.

Credentials are stored in a folder on disk (auth/ by default); keep it private and out of git, it is the logged-in account. Two small command line tools come with velowa: npx velowa-pair (link an account and try things in a dev console) and npx velowa-logs (look after the protocol logs), available in a project that installed it as above, or as npm run pair / npm run logs inside the velowa folder.

For a bot, turn the protocol log off (it records every frame and stanza under logs/, which you want only while debugging):

import { Client, ProtocolLogger } from 'velowa'

const client = new Client({
  authDir: 'auth',
  logger: new ProtocolLogger({ enabled: false }),
})

Link an account

The first run has to be linked to a phone: WhatsApp → Linked devices → Link a device. The connection event carries what you need to show; after linking, the next start logs in straight from authDir.

import qrcode from 'qrcode-terminal'
import { Client } from 'velowa'

const client = new Client({ authDir: 'auth' })

client.on('connection', (u) => {
  if (u.qr) qrcode.generate(u.qr, { small: true }) // scan with the phone
  if (u.pairingCode) console.log('code:', u.pairingCode) // or type it in (see below)
  if (u.state === 'open') console.log('online as', client.me?.id)
  if (u.state === 'close') {
    console.log('closed:', u.reason)
    if (u.loggedOut) console.log('logged out on the phone: delete auth/ and link again')
  }
})

await client.connect()

Pairing code instead of a QR: new Client({ authDir: 'auth', pairWithPhoneNumber: '4915...' }) and show pairingCode from the connection event; on the phone choose Link with phone number instead. Add customPairingCode: 'ABCD2345' to use your own 8-character code instead of a random one (exactly 8 characters from 123456789ABCDEFGHJKLMNPQRSTVWXYZ, case-insensitive; an invalid one throws right away, in the constructor).

Connection states: connecting (also while a code or QR is on offer and after a drop that will reconnect), open (ready to send and receive), close (finished: the client does not retry). velowa reconnects by itself after a dropped connection (autoReconnect, on by default), so you do not write a reconnect loop.

Choose the device you link as

By default velowa links as a Windows desktop on the normal release channel. You can pick another identity:

import { Client, deviceProfile, Browsers, DEVICE_PROFILES, PLATFORM_TYPES } from 'velowa'

// a ready-made profile (see Object.keys(DEVICE_PROFILES)): browser name and device type together
const asIphone = new Client({
  authDir: 'auth-ios',
  config: { ...deviceProfile('ios-phone'), releaseChannel: 'BETA' },
})

// or set the parts yourself
const asSafari = new Client({
  authDir: 'auth-safari',
  config: {
    browser: Browsers.macOS('Safari'), // [os, device] shown under "Linked devices"
    platformType: 'SAFARI', // one of PLATFORM_TYPES
    historySync: 'all', // announce every history-sync flag (see HISTORY_SYNC_FLAGS)
  },
})

// Browsers only sets the name shown in the list; the type comes from platformType
const asAndroid = new Client({
  authDir: 'auth-android',
  config: { browser: Browsers.android(), platformType: 'ANDROID_PHONE' },
})
const asIphoneByHand = new Client({
  authDir: 'auth-iphone',
  config: { browser: Browsers.iOS(), platformType: 'IOS_PHONE' },
})
Option Values When it is read
platformType the 31 PLATFORM_TYPES: CHROME, FIREFOX, SAFARI, EDGE, DESKTOP, UWP, IPAD, IOS_PHONE, ANDROID_PHONE, ANDROID_TABLET, WEAR_OS, ... when you link: the phone stores it
browser [os, device], or Browsers.ubuntu('Chrome'), .macOS(..), .windows(..), .appropriate(..), .android() (['Android', 'Phone']), .iOS() (['iOS', 'iPhone']), .baileys(..) when you link
historySync 'all' (every flag on) or { onDemandReady: true, ... } on top of the defaults when you link
releaseChannel RELEASE (default), BETA, ALPHA, DEBUG on every connect
platform, webSubPlatform USER_AGENT_PLATFORMS (default WEB), WEB_SUB_PLATFORMS (default WEB_BROWSER) on every connect

A linked device cannot change its type. To become another device, use a new authDir (a new session) and link again; the old authDir stays as it is and keeps working. Only the default (windows-desktop, RELEASE) is checked against a live account: the other profiles use the values WhatsApp's own clients send, and the phone may list or treat such a device differently. A wrong name throws in the constructor with the list of valid values.

A first bot in 20 lines

import qrcode from 'qrcode-terminal'
import { Client, serialize } from 'velowa'

const client = new Client({ authDir: 'auth' })

client.on('connection', (u) => {
  if (u.qr) qrcode.generate(u.qr, { small: true })
  if (u.state === 'open') console.log('online')
})

client.on('message', async (raw) => {
  const m = serialize(client, raw) // who, where, text, quoted message, reply()
  if (m.fromMe) return
  if (m.text === '!ping') await m.reply('pong')
})

await client.connect()

serialize turns the raw event into a Message with chat, sender, text, isGroup, quoted, reply(), react(), download() and more; see Receiving.

Receiving: messages and events

Everything arrives through client.on(event, listener) (it returns an unsubscribe function) or as an async iterator with for await (const m of client.events('message')).

The raw message event holds { id, from, participant, timestamp, pushName, message } where message is the decrypted WhatsApp protobuf as plain JSON. Most bots want serialize(client, raw) instead:

Message field / method What it is
m.chat the chat JID: a user, a group (…@g.us) or a channel
m.sender who wrote it (inside a group: the member), without device part
m.pushName, m.fromMe, m.isGroup, m.timestamp, m.id the obvious
m.type, m.content the kind (conversation, imageMessage, …) and the content with wrappers (disappearing, view-once, edited) removed
m.text text or caption, or the id of a tapped button / chosen list row; '' when there is none
m.isMedia, m.mimetype image, video, audio, document or sticker
m.mentionedJids who is @mentioned
m.quoted the message this one answers: { id, sender, fromMe, type, text, mimetype, key, download() }
m.reply(content) answer in the chat, quoting the message; a string is sent as text, an object is anything client.send takes
m.react(emoji), m.delete(), m.markRead(), m.forward(jid) the usual actions on this message
m.download() decrypt and download the media
m.key, m.asQuoted what the client.* methods and the quoted option want

Group helpers for permission checks:

import { GroupCache, isGroupAdmin, serialize } from 'velowa'

const groups = new GroupCache(client) // one lookup per group and minute, however busy it is

client.on('message', async (raw) => {
  const m = serialize(client, raw)
  if (!m.isGroup) return
  const group = await groups.get(m.chat) // { subject, size, admins, participants, announce }
  if (m.text === '!kick' && isGroupAdmin(group, m.sender) && m.quoted)
    await client.groups.updateParticipants(m.chat, [m.quoted.sender], 'remove')
})

JID helpers: jidNormalizedUser, areJidsSameUser, isJidGroup, isJidUser, isLidUser, isJidNewsletter, isJidStatusBroadcast, jidEncode, jidDecode. Content helpers: getContentType, normalizeMessageContent, messageText, isAudioSticker, isLottieSticker, audioStickerSound, stickerReactionParentKey.

LIDs. WhatsApp is moving accounts to anonymous ids (…@lid). A sender or group member can show up as a LID or a phone-number JID. isGroupAdmin and areJidsSameUser compare the user part, and group participants carry both forms (id, phoneNumber, lid). client.lidsFor(pnJid) maps a phone-number JID to its LID.

Sending: client.send

One call, the content object says what to send. It returns the message id.

await client.send(jid, { text: 'hello' })
await client.send(jid, { image: fs.readFileSync('cat.jpg'), caption: 'look' })
await client.send(jid, { video: { url: 'https://example.com/clip.mp4' } }) // URLs are fetched safely
await client.send(jid, { audio: { path: './voice.ogg' }, voiceNote: true }) // a local file needs { path }
await client.send(jid, { poll: { name: 'Pizza?', values: ['yes', 'no'] } })
await client.send(jid, { text: 'thanks', mentions: ['4915...@s.whatsapp.net'] }, { quoted: m.asQuoted })
Content Fields
text text, mentions?, linkPreview?
image / video image or video, caption?, mimetype?, viewOnce?, gif? (video)
audio audio, voiceNote? (push-to-talk), seconds?, mimetype?
document document, mimetype, fileName?, caption?
sticker sticker (WebP)
poll poll: { name, values, selectableCount? }
location location: { latitude, longitude, name?, address? }
contacts contacts: { displayName?, contacts: [{ name, vcard }] }
reaction / edit / delete react: { key, emoji }, edit: key with text, revoke: key
forward forward: message (the WhatsApp content of a received message)
buttons text, buttons: [{ id, text }] (up to 3), footer?, title?
list text, title, buttonText, sections: [{ title, rows: [{ id, title, description? }] }]

A media source is bytes (Buffer/Uint8Array), { url } (an http(s) URL only), { path } (a local file) or { stream }. URL downloads refuse private network addresses and cap the size. { url } never reads local files, so a link taken from a chat message is safe to pass; only give { path } paths you chose yourself.

Options (third argument): quoted (reply to a message), expiration (disappearing-message seconds).

The older specific methods stay and take the same arguments in a more explicit form (sendText, sendImage, sendVideo, sendAudio, sendDocument, sendSticker, sendMedia, sendPoll, sendLocation, sendContact, react, edit, revoke, forwardMessage, sendMessage for a raw WhatsApp message object).

Send different group messages to admins and members

With sendSplitGroupMessage(), the same group JID can receive one message for admins and a different one for non-admins. The roles are read automatically from the group metadata:

const result = await client.sendSplitGroupMessage('1234567890-123456789@g.us', {
    selfMessage: { conversation: 'Message for non-admins' },
    message: { conversation: 'Message for admins' },
    wait: 200,
    adminWait: 200,
})

console.log(result)
// { msgId: '3EB0...', admins: 2, nonAdmins: 15 }

Important options (AdminSplitSendOptions)

  • message: The (WAProto) plain-object message sent to admins (admin / superadmin) (default: { conversation: 'admin' }).
  • selfMessage: The message sent to non-admins (default: { conversation: 'non-admin' }).
  • sendToAdmins: Set to false to skip admins and send only selfMessage to non-admins (default: true).
  • wait / adminWait: Delay in milliseconds before the corresponding send (default: 200 ms).
  • pmode2 & ptarget: When pmode2: true, only the participant specified by ptarget receives message; all other participants receive selfMessage.
  • participantRoles: Optional mapping (Record<string, string>) for known or overridden participant roles.
  • messageId, additionalNodes, additionalAttributes, encAttrs, stanzaAttrs: Optional overrides equivalent to SendOptions.

Example with pmode2 and ptarget

await client.sendSplitGroupMessage('1234567890-123456789@g.us', {
    pmode2: true,
    ptarget: '4915112345678@s.whatsapp.net',
    selfMessage: { conversation: 'For everyone else' },
    message: { conversation: 'Only for ptarget' },
})

Writing a bot: your style

velowa does not prescribe how a bot is organised. Two complete, runnable examples show the two common ways; copy the one you like and change it:

Example Style
examples/cases-bot.js Cases: one switch (command) over the message text, helper values (isOwner, isAdmin, group) computed on the way
examples/plugin-bot/ Plugins: one file per command (export default { commands: ['ping'], run }), loaded from a folder and reloaded when a file changes

All examples, with how to run them, are listed in examples/.

The cases style in short:

import { serialize } from 'velowa'

const PREFIXES = ['!', '.']

client.on('message', async (raw) => {
  const m = serialize(client, raw)
  if (m.fromMe) return
  const prefix = PREFIXES.find((p) => m.text.startsWith(p))
  if (!prefix) return
  const [word, ...args] = m.text.slice(prefix.length).trim().split(/\s+/)
  const text = args.join(' ')

  switch (word.toLowerCase()) {
    case 'ping':
      await m.reply('pong')
      break
    case 'say':
      await m.reply(text || 'say what?')
      break
    case 'poll': {
      const [name, ...values] = text.split('|').map((s) => s.trim())
      await client.send(m.chat, { poll: { name, values } })
      break
    }
  }
})

The plugin style in short:

// plugins/ping.js
export default {
  commands: ['ping', 'p'],
  help: 'answers pong',
  run: async ({ reply }) => reply('pong'),
}

Things nearly every bot needs, and where to get them:

Need How
ignore old messages after a reconnect compare m.timestamp with the clock (the examples skip anything older than 2 minutes)
ignore the bot's own messages if (m.fromMe) return
owner-only commands compare m.sender's number with a list; owners can also appear as LIDs, client.lidsFor maps them
admin-only commands isGroupAdmin(await groups.get(m.chat), m.sender)
"typing…" before answering await client.sendChatState(m.chat, 'composing') then 'paused'
button and list taps they arrive as messages; m.text holds the id you gave the button
keep an account safe new Client({ antiban: true }), see Reliability and safety

Feature guide

Every example assumes const client = new Client(...) is connected and jid is a chat JID (4915…@s.whatsapp.net, …@g.us, …@newsletter).

Messages: reply, mention, react, edit, delete, forward

const id = await client.sendText(jid, 'hi @4915…', { mentions: ['4915…@s.whatsapp.net'] })
await client.sendText(jid, 'a reply', { quoted: { key: m.key, message: m.raw.message } })
await client.react({ remoteJid: jid, id, fromMe: true }, '👍') // '' removes the reaction
await client.edit({ remoteJid: jid, id, fromMe: true }, 'hi (edited)')
await client.revoke({ remoteJid: jid, id, fromMe: true }) // delete for everyone
await client.forwardMessage(otherJid, m.raw.message)
await client.markRead([m.key])
await client.sendChatState(jid, 'composing') // 'recording' | 'paused'
await client.sendPresence('available') // needs client.setName('…') once
await client.subscribePresence(jid) // then listen to the 'presence' event

Link previews: sendText(jid, 'https://…', { linkPreview: true }) fetches title, description and picture of the first link (private addresses are refused; use fetchLinkPreview and pass your own preview if you want control).

Media

await client.sendImage(jid, bytes, { caption: 'hi' })
await client.sendImage(jid, { path: './cat.jpg' }, { caption: 'from disk' })
await client.sendVideo(jid, { url: 'https://example.com/clip.mp4' }, { gifPlayback: true }) // fetched safely
await client.sendAudio(jid, bytes, { ptt: true }) // voice note
await client.sendDocument(jid, bytes, { mimetype: 'application/pdf', fileName: 'a.pdf' })
await client.sendSticker(jid, { path: './cat.png' }) // any image/animation -> sticker WebP (needs ffmpeg)
await client.sendSticker(jid, webpBytes) // a WebP is sent as is, no conversion
await client.sendSticker(jid, webpBytes, { stickerMetadata: { packName: 'My Pack', publisher: 'Me' } }) // "Added by Me"

const data = await client.downloadMedia(m.raw.message) // Buffer, decrypted

Every media-sending method (sendImage, sendVideo, sendAudio, sendDocument, sendSticker, sendAudioSticker, sendLottieSticker, stickerReact, sendMedia, sendImagePoll, sendMusic, sendQuestionImage, sendStickerPack, postChannelStatusMedia) takes a MediaSource: bytes (Buffer/Uint8Array), { path } (a local file), { url } (an http(s) URL, fetched safely the same way as client.send's media) or { stream } - not just client.send's content-object form. See Sending for the safety rules around { url } vs. { path }.

Media is encrypted and uploaded for you; channels get unencrypted uploads automatically. Options (viewOnce, seconds, width, height, groupStatus, …) are on MediaOptions.

Audio stickers, lottie stickers and sticker reactions

Every sticker method takes any image or short animation (PNG, JPEG, GIF, MP4, …) as its sticker, not only a ready-made WebP: velowa converts it to a 512×512 sticker WebP with ffmpeg (install it on the host). A source that is already WebP is sent untouched; pass stickerConvert: false to skip conversion, or stickerConvert: { size, quality } to tune it. The conversion helpers (ensureStickerWebp, toStickerWebp, isWebp) are exported too.

An audio sticker is an animated sticker with a sound. Pass the sticker and the sound (e.g. Opus/OGG) separately; velowa uploads both, nests the sound inside the sticker and wraps it exactly the way WhatsApp does:

await client.sendAudioSticker(jid, { sticker: { path: './cat.gif' }, audio: { path: './boing.ogg' } }, {
    emojis: '🔊', // emoji shown on the sticker
    seconds: 2, // length of the sound
})

A lottie (animated) sticker is sent like a normal sticker, only tagged as one:

await client.sendLottieSticker(jid, { path: './wave.gif' })

React to a message with a sticker ("sticker annotation") — like an emoji reaction (client.react), but the reaction is a sticker tied to the message you react to:

// m is a received message (e.g. from the 'message' event, via serialize)
await client.stickerReact(m.chat, m.key, { path: './thumbsup.png' }) // m.key is the { remoteJid, fromMe, id } reacted to

On the receiving side, tell them apart and reach their parts:

import { isAudioSticker, audioStickerSound, stickerReactionParentKey } from 'velowa'

if (isAudioSticker(m.raw.message)) {
    const image = await client.downloadMedia(m.raw.message) // the WebP sticker
    const sound = audioStickerSound(m.raw.message)
    if (sound) await client.downloadMedia(sound) // the sound track
}
const reactedTo = stickerReactionParentKey(m.raw.message) // key of the reacted message, or undefined

Hosted devices (WhatsApp Business Coexistence). 1:1 DMs now also fan out to a recipient's hosted (Cloud-API, …:99@hosted) device when they have one, so a coexistence business receives your message on its API side too. This is automatic and best-effort — a hosted device that cannot be keyed is skipped, never breaking the send. Groups and calls leave hosted devices out, as before.

Chat theme and wallpaper

Set a chat's theme or wallpaper (works for a group or a 1:1 chat) with a CHAT_THEME_SETTING message:

import { CHAT_THEME_IDS } from 'velowa'

await client.setChatWallpaper(jid, { path: './bg.jpg' }, { dimLevel: 0.3 }) // a custom image (any format)
await client.setChatThemeColor(jid, { lightArgb: 0xffff0000 }) // a solid colour (ARGB; darkArgb defaults to it)
await client.setChatTheme(jid, 'Emerald@Minimal') // a preset theme - the ids are in CHAT_THEME_IDS
await client.clearChatTheme(jid) // back to the default theme

setChatWallpaper encrypts and uploads the image like any other media (needs no extra setup). Colours are ARGB integers, e.g. 0xFFFF0000 for opaque red; setChatThemeColor also takes doodle, doodleLightArgb, doodleDarkArgb. The preset ids in CHAT_THEME_IDS are Default-Blue@Minimal, Emerald@Minimal, Pink@Minimal, Red@Minimal, Royal-Blue@Minimal, Tyrian-Purple@Minimal, WhatsApp-Green@Minimal and their @Tonal variants.

Buttons, lists and rich answers

import { quickReply, urlButton, parseButtonReply } from 'velowa'

await client.sendButtons(jid, { text: 'Pick one', buttons: [{ id: 'a', text: 'A' }, { id: 'b', text: 'B' }] })
await client.sendList(jid, {
  title: 'Menu', text: 'Choose', buttonText: 'Open',
  sections: [{ title: 'Drinks', rows: [{ id: 'tea', title: 'Tea' }, { id: 'coffee', title: 'Coffee' }] }],
})
await client.sendTemplate(jid, {
  text: 'Need help?',
  buttons: [
    { type: 'reply', text: 'Yes', id: 'yes' },
    { type: 'url', text: 'Website', url: 'https://example.com' },
    { type: 'call', text: 'Call us', phone: '+4915…' },
  ],
})
await client.sendInteractive(jid, {
  body: 'Choose',
  footer: 'velowa',
  buttons: [quickReply('Yes', 'yes'), urlButton('Docs', 'https://example.com')],
})

// the tap comes back as a normal message
client.on('message', (raw) => {
  const reply = parseButtonReply(raw.message)
  if (reply) console.log(reply.kind, reply.id, reply.text)
})

Meta AI style answers: sendRichResponse(jid, { text, code, table, latex, map, images }) and sendHtml (HTML is rendered as markup; pass only HTML you wrote yourself, never received text).

Polls, quizzes, questions

await client.sendPoll(jid, 'Pizza?', ['yes', 'no'], 1) // 2-12 options, last argument = how many may be chosen
await client.sendQuiz(jid, '2 + 2?', ['3', '4', '5'], '4') // a poll with a right answer
await client.sendQuestion(jid, 'What should we build?') // the audience answers in a box
await client.sendImagePoll(jid, 'Which logo?', ['A', 'B'], [imageA, imageB]) // channels

Votes arrive encrypted as poll updates (pollUpdateMessage); pollOptionHash(name) gives the hash a vote refers to an option by.

Groups and communities

const g = await client.groups.create('Team', ['4915…@s.whatsapp.net'])
await client.groups.metadata(g.id) // subject, owner, participants (id / phoneNumber / lid / admin), settings
await client.groups.fetchAll() // every group the account is in
await client.groups.updateParticipants(g.id, [jid], 'add') // | 'remove' | 'promote' | 'demote'
await client.groups.setSubject(g.id, 'Team 2')
await client.groups.setDescription(g.id, 'Rules: be nice')
await client.groups.setting(g.id, 'announcement') // only admins write; 'locked' = only admins edit info
await client.groups.setEphemeral(g.id, 604800) // disappearing messages, seconds (0 = off)
await client.groups.inviteCode(g.id) // + revokeInvite, acceptInvite(code), inviteInfo(code)
await client.groups.setJoinApproval(g.id, 'on') // + joinRequests(), updateJoinRequests()
await client.groups.leave(g.id)

await client.setGroupMemberAddMode(g.id, 'admin_add') // permissions, member tag, share history
await client.setMemberLabel(g.id, 'Moderator')

await client.communities.create('Club') // + createGroup, linkGroup, unlinkGroup, linkedGroups, deactivate

group.update events report joins, leaves, promotions, subject and setting changes.

Channels

const ch = await client.newsletters.create('News', 'Daily news')
await client.newsletters.metadata('invite', 'CODE') // or ('jid', jid)
await client.newsletters.follow(jid) // unfollow, mute, unmute, subscribers, update, react

await client.postToChannel(ch.id, 'Hello channel') // text
await client.postToChannel(ch.id, { /* any message */ }, { aiContent: true }) // label: AI content / paid partnership
await client.sendImage(jid, bytes, { caption: 'photo' }) // images, videos, polls, quizzes, questions and music
await client.sendMusic(channelJid, videoWithSongTrack, { title: 'Song', author: 'Artist', songId: '…' }) // the sound must be in the video's own track; catalog data (`MusicInfo`) is best copied from a music post you received

await client.postChannelStatus(ch.id, 'Good morning!') // shows in followers' Status tray, not the permanent feed
await client.postChannelStatusMedia(ch.id, 'image', bytes, { caption: 'photo' })
await client.postChannelStatusMedia(ch.id, 'video', bytes, { seconds: 10, jpegThumbnail })
await client.postChannelStatusMedia(ch.id, 'audio', bytes, { ptt: true, seconds: 3, waveform })

Channel posts are not end-to-end encrypted (the server fans them out); velowa handles the different wire format. A channel status is a distinct send (its own <status> stanza, not a message) that disappears from the Status tray the way a personal status does; postToChannel is the permanent feed post. The channel.status event fires for both your own posts (on another linked device) and reactions/edits to one.

Status (stories)

await client.sendStatusText('good morning', ['4915…@s.whatsapp.net'], 'allowlist') // audience must be given
await client.setStatusPrivacy('only', ['4915…@s.whatsapp.net']) // 'contacts' (all) | 'except' (all but …) | 'only' (just …)
await client.sendGroupStatusText(groupJid, 'hello group') // group status; pictures/videos: sendImage(group, data, { groupStatus: true })

Contacts, profile and privacy

await client.onWhatsApp('4915…', '4916…') // [{ jid, exists }]
await client.fetchStatus(jid) // "About" text
await client.profilePictureUrl(jid, 'image')
await client.findUserByUsername('someone')
await client.usernames.check('wanted-name') // + set, mine
await client.lidsFor(jid)
await client.securityCode(jid) // 60-digit safety-number-style code, compare it to the other side's out of band

await client.updateProfileName('My Bot')
await client.updateProfileStatus('Ask me with !help')
await client.updateProfilePicture(jpegBytes) // square JPEG; pass a group JID as second argument for a group
await client.fetchPrivacySettings()
await client.updatePrivacy('last', 'contacts') // last, online, profile, status, groupadd, readreceipts, calladd, messages
await client.blockUser(jid)
await client.unblockUser(jid)
await client.fetchBlocklist()

Business and payments

await client.getBusinessProfile(jid) // null for a private account
await client.getCatalog(jid)
await client.updateBusinessProfile({ description: 'We repair bikes' }) // Business accounts only
await client.getOrder(jid, id, 'the orderMessage’s token') // from the orderMessage a "Review and pay" tap sends
await client.requestPayment(jid, { amount1000: 12_500, currency: 'EUR', note: 'Lunch' }) // 12.50 EUR; + sendPaymentNote, declinePaymentRequest, cancelPaymentRequest

More account, chat, group, channel, event and business functions

velowa also covers calendar events, business products and collections, trusted devices, community ownership transfer, group pastParticipants/reportedMessages, the AI bot directory, server experiment flags and more - about 50 further methods, each backed by a request builder with its own unit tests. A few:

await client.pinMessage(m.key, 7 * 86_400) // + unpinMessage(m.key); live-verified
await client.sendAlbum(jid, [{ image: bytes }, { image: bytes, caption: 'two' }])
const fresh = await client.updateMediaMessage(m.key, m.content!) // the phone uploads expired media again
await client.getOrder(jid, id, 'the orderMessage’s token') // from a "Review and pay" tap

The full list, with examples and which ones were checked against a real account (worked, Bad Request, no answer, arrived on the phone, …), is in docs/more-functions.md. client.mex(queryId, variables) lets you run any w:mex GraphQL query yourself, including ones not wrapped here.

Reports

await client.reportUser(jid, { block: true, deleteChat: true }) // sends the latest messages as evidence
await client.reportGroup(groupJid, { leave: true })
await client.reportChannel(channelJid, { unfollow: true }) // …@newsletter
await client.reportToAdmins(groupJid, m.id) // tells the admins about that message id ("reported messages")

Calls

Voice and video, one to one, in groups and through call links ("rooms"), in both directions. Media can come from files or from this machine's microphone and speaker.

A silent group call (someone opens a voice chat in a group and waves at everyone) arrives as a call event with lightweight: true and silence: 'vc_wave_all'. It rings nobody, and a linked device cannot join it: the server answers preaccept and accept with 403 and ends the call. WhatsApp Web only offers voice chats when the account's experiment flag voice_chat_companion_experience_version (client.server.abProps(), key 17052) is 2 or more; for the tested account it is 1. acceptCall throws a clear error instead of sending a doomed answer; ignore it or react with a message.

// one to one
const call = await client.startCall(jid, { audioFile: 'announcement.mp3' }) // voice, plays the file
await client.startCall(jid, { video: true, videoFile: 'clip.mp4' }) // video with the sound of the file
await client.startCall(jid, { localAudio: { mic: true, speaker: true } }) // talk through this machine
await client.endCall(call.callId)

// incoming
client.on('call', async (c) => {
  if (c.status === 'offer') await client.acceptCall(c.callId, { audioFile: 'busy.mp3' }) // or rejectCall(c.callId, c.creator ?? c.from)
})

// groups and rooms
const gc = await client.startGroupCall([], { group: groupJid, audioFile: 'hello.mp3' }) // rings every member
const link = await client.createCallLink('audio') // https://call.whatsapp.com/voice/…
await client.joinCallLink(link.url, 'audio') // waits in the waiting room if the creator wants approval
await client.setApprovalRequired(gc.callId, true) // creator: require approval
await client.answerWaitingRoom(gc.callId, userLid, true) // creator: admit (false = turn away)

// during a call
await client.enableCamera(call.callId, { videoFile: 'clip.mp4' }) // ask to turn video on
await client.disableCamera(call.callId)
await client.raiseHand(gc.callId, true) // group calls
await client.setMuteState(gc.callId, false) // tell a group call our microphone is unmuted (others' state: `muteState` on the `call` event)
await client.sendReaction(gc.callId, '👍') // group calls
await client.inviteParticipant(gc.callId, jid) // add someone not yet in this running group call
await client.ringParticipant(gc.callId, jid) // re-ring a disconnected member of the roster

Three more specialized parts, in docs/calls-rooms-and-guests.md: running your own room (createRoom, a call link you own that admits people by a rule you choose), joining as a guest (no WhatsApp account, one call link, one throwaway identity), and raw call media (audioIn/videoFrames instead of files).

Chats and app state

Changes that sync to every device the account has (the phone shows them too):

await client.archiveChat(jid)
await client.muteChat(jid, Date.now() + 8 * 3600_000) // until; -1 = forever, null = unmute
await client.pinChat(jid)
await client.markChatRead(jid)
await client.starMessage(m.key)
await client.deleteChat(jid) // clearChat, deleteMessageForMe
await client.addLabel({ id: '1', name: 'Customers', color: 3 }) // then labelChat(jid, '1'), labelMessage(jid, '1', messageId)
await client.setChatEphemeral(jid, 86400)

They need the phone to have shared the app-state keys once: await client.waitForAppState().

Events reference

Event Payload
connection { state: 'connecting' | 'open' | 'close', qr?, pairingCode?, newLogin?, reason?, code?, willReconnect?, loggedOut? }
message a decrypted incoming message (serialize it)
receipt delivery / read / played receipts for what we sent
presence online / typing / recording of a chat or member
group.update a group changed: members, subject, settings
call calls and everything inside a call (offer, accept, terminate, group_update, video, user_action, …)
chat.update, contact.update a chat was muted / archived / pinned / read on another device; a saved name changed
channel.status a channel status or a reaction / edit / revoke of one
message.unavailable { key, reason, kind?, timestamp?, pushName? }: a message with no content for this device, e.g. a view-once photo (reason: 'view_once'); only the phone can open it, nothing can be asked for again
history a chunk of chat history the phone sent after linking
app-state, notification raw app-state changes and any other server notification
qr, pairing-code, paired, open, close the individual connection events (the connection event carries the same)

Configuration

import { Client, ProtocolLogger } from 'velowa'

new Client({
  authDir: 'auth', // credentials and Signal state
  logger: new ProtocolLogger({ enabled: false }), // or { dir, label, rotateMB, retention, compressAfterHours, keep }
  autoReconnect: true, // reconnect after a drop (default)
  pairWithPhoneNumber: '4915…', // link with a code instead of a QR
  customPairingCode: 'ABCD2345', // your own code instead of a random one (needs pairWithPhoneNumber)
  antiban: true, // or your own limits, see below
  additionalMediaHosts: ['relay.example.org'], // extra hosts downloadMedia may also fetch from
  config: { /* override the WhatsApp Web version / browser identity */ },
  // Device identity, e.g. config: { ...deviceProfile('ios-phone'), releaseChannel: 'BETA' }
  //   platformType (PLATFORM_TYPES: CHROME, SAFARI, IOS_PHONE, ANDROID_PHONE, ...): read when pairing, re-link to change
  //   releaseChannel (RELEASE | BETA | ALPHA | DEBUG), platform (USER_AGENT_PLATFORMS), webSubPlatform: sent on every connect
  //   Browsers.ubuntu('Chrome') / macOS / windows / baileys give the [os, device] pair; DEVICE_PROFILES lists the presets.
  //   historySync: 'all' (every HistorySyncConfig flag on, see HISTORY_SYNC_FLAGS) or { onDemandReady: true, ... }; read when pairing
  //   Only the default (windows-desktop, RELEASE) is checked live; wrong names throw in the constructor.
})

antiban throttles sending like a person would: caps per minute, hour and day (a send over the minute cap waits, over the hour or day cap it throws AntiBanError), random gaps, a pause before the first message to a new chat, a limit on identical texts, a warm-up for new accounts, and "typing…" before text. Pass true for the defaults (ANTIBAN_DEFAULTS) or a partial AntiBanConfig.

Protocol logs (for debugging) are kept as logs/<day>/<time>-<label>/ with a session.json per run; logs/latest points at the newest one. Big files rotate, runs older than a day are compressed, and runs older than 30 days (or beyond 1 GB) are deleted when the next logger starts. Manage them with npm run logs -- list | migrate | compress | prune --dry | keep <run>.

What you can build

  • Command bots for a group or a team: !help, !poll, !remind, admin tools (kick, promote, lock the group).
  • Support desks: answer with buttons and lists, hand over to a person, keep the conversation in one place.
  • Notifications: send alerts, receipts or reports from a script, a CI job or a server to a person, a group or a channel.
  • Channel publishers: post text, images, videos, polls, quizzes and music to a channel on a schedule, with AI or paid-partnership labels.
  • Moderation: watch group.update and messages, report or remove, answer with rules.
  • Call bots: pick up incoming calls and play an announcement, call people with a recorded message, join a room.
  • Archiving and sync: read the history event, mirror chats to your own storage, download media.
  • Anything else on top of the protocol: client.request(node) sends a raw stanza and client.mex(queryId, variables) runs any WhatsApp GraphQL query.

Reliability and safety

  • Use a number you can lose. Unofficial clients can be restricted or banned. Start slowly, warm accounts up, do not message people who have not written to you, and turn on antiban.
  • auth/ is the account. Anyone with the folder can act as the account; keep it out of git and off shared disks.
  • Logs contain account data (ids, message content). The default logs/ folder is git-ignored; give a bot new ProtocolLogger({ enabled: false }) unless you are debugging.
  • Untrusted input. Do not pass received text to sendHtml; { url } media downloads and link previews refuse private network addresses, but only fetch URLs you trust.
  • One process per account. Two processes using the same authDir fight over the session.
  • Handle errors. Wrap handlers in try/catch (a thrown error in a listener is yours to handle) and expect AntiBanError when limits are on.

Development

npm run build         # wasm-pack (bridge + voip) and tsup -> dist/index.js, dist/index.cjs, types
npm run build:js      # only the TypeScript part (when the WebAssembly did not change)
npm test              # vitest
npm run lint          # tsc --noEmit + eslint (src and tests)
npm run check:package # publint + are-the-types-wrong + the package rules (tests/package)
npm run check:docs    # type-checks the code in this README and in examples/ against the built package
npm run pair          # a dev console that exercises everything and logs every frame
npm run example       # a tour of the features against your own account (examples/tour.js)
npm run logs -- list  # look after the protocol logs
src/
  client/            Client, connection, sender, receiver
    features/<area>/ request builders and parsers, one folder per area:
                     account call channel chat community contact group message payment report
  bot/               serialize() and GroupCache: helpers for people who write bots
  crypto/ codec/     WebAssembly-backed Signal, Noise, app-state and WABinary
  auth/ logging/ events/ wam/ cli/
tests/               mirrors src/ one to one; tests/helpers has the fake remote world
rust/                the WebAssembly crates (wacore-* are one-time copies from whatsapp-rust)
examples/            runnable programs: echo-bot, cases-bot, plugin-bot, notifier, channel-post, group-admin, calls, tour
docs/                longer notes

The Rust crates copied from whatsapp-rust are a one-time copy, not a live dependency; they are owned and maintained here.

License and credit

velowa is released under the velowa License: MIT with mandatory credit (LICENSE). It is the MIT license with one condition added.

What you may do: use velowa, change it, put it in your product, sell that product, run bots with it. Installing it from npm and calling its API from your program is use, not copying: your own code owes nothing.

What you must do when you copy code from velowa: give credit, for any part you copy, however small. A whole file, a function, a class, a type, a table, a test, an example from examples/ or this README, or a few lines; and a translation of such a part into another language that follows the original. Credit has two parts:

  1. next to the copied code, a comment that names velowa, the author and the project:

    // Based on velowa (https://github.com/7ucg/velowa) by Baron - velowa License

    (for a whole copied file: leave its velowa header line in place)

  2. in the documentation of what you ship (README, credits or "about" page, or a NOTICE file): one line with the name, the author, the address and the license. The credit stays when the code is moved, edited or bundled; for a bundle or binary that cannot hold a comment, the line in the documentation is enough.

Without the credit the permission to use the copied part does not apply (clause 4 of the license); it applies again once the credit is given. Every source file of velowa carries a one-line notice, and so does every built file.

Parts from other projects keep their own licenses and are not covered by the clause above. They come from whatsapp-rust (MIT), from Signal's libsignal (the Signal protocol code in rust/wacore-libsignal, under the AGPL-3.0) and from the Baileys project (the WhatsApp protobuf schema, MIT). The complete list with the original notices is in THIRD_PARTY_NOTICES.md; read it before you use velowa in a product, because the AGPL has conditions of its own.

More documentation

About

WhatsApp Web multi-device client library — TypeScript, with libsignal/WABinary/Noise/app-state crypto ported to Rust and compiled to WASM

Topics

Resources

Contributing

Stars

9 stars

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages