Skip to content
MessageBuilder
Documentation menu
Installation

Installation

Dependencies, file placement, imports, and Baileys socket setup for MessageBuilder.js v4.8.

Getting started
v4.8/Baileys runtime
On this page

MessageBuilder is not published as a separate npm package in this documentation. You copy the two library files into your project, then install the runtime dependencies it needs.

Dependencies

Package Required Used for
@whiskeysockets/baileys Yes Socket, generateWAMessageFromContent, prepareWAMessageMedia, relayMessage.
sharp Yes Image resizing in Toolkit.resize, thumbnails, and media headers.
fluent-ffmpeg For video Frame extraction in Toolkit.getMp4Preview.
crypto Node built-in Random IDs and metadata.
stream Node built-in PassThrough and Readable for media.

Install dependencies

npm install @whiskeysockets/baileys sharp fluent-ffmpeg

Make sure you are running Node.js 20 or newer. pnpm and yarn work the same way.

Copy the library files

Place both files in the same folder, for example lib/:

project/
├── lib/
│   ├── MessageBuilder.js
│   └── MessageBuilderEnums.js
├── index.js
└── package.json

MessageBuilderEnums.js only exports the Enums object. It is optional if you do not need enums, but keeping the import consistent is recommended.

Import

import makeWASocket, { useMultiFileAuthState } from '@whiskeysockets/baileys';
import { Button, ButtonV2, Carousel, AIRich, Toolkit, VERSION } from './lib/MessageBuilder.js';
import { Enums } from './lib/MessageBuilderEnums.js';

Use "type": "module" in package.json, or the .mjs extension, because the library uses ESM.

Set up the socket

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

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

sock.ev.on('creds.update', saveCreds);
sock.ev.on('connection.update', ({ connection, lastDisconnect }) => {
  if (connection === 'close') {
    const shouldReconnect =
      lastDisconnect?.error?.output?.statusCode !== DisconnectReason.loggedOut;
    if (shouldReconnect) {
      // recreate the socket here
    }
  }
});

Keep a reference to the same sock. Builders need it for media uploads and message delivery.

Quick verification

import { VERSION } from './lib/MessageBuilder.js';

console.log(VERSION); // 4.8

If imports fail because of sharp or fluent-ffmpeg, check the following:

  • sharp — make sure the platform binary is available. On Alpine Linux, install vips-dev if needed.
  • ffmpeg — fluent-ffmpeg requires an ffmpeg binary on PATH. On Debian/Ubuntu: apt install ffmpeg.
  • ESM — do not mix require() with files that use export.

Suggested folder structure

bot/
├── lib/
│   ├── MessageBuilder.js
│   └── MessageBuilderEnums.js
├── handlers/
│   ├── command.js
│   └── message.js
├── auth_info/
├── index.js
└── package.json

Continue with Quickstart to send your first message.