### Install Bot with Bun Source: https://zeative.github.io/zaileys/runtimes Use Bun to install and run your bot. This is a quick way to get started. ```bash npx tsx bot.ts ``` ```bash # or: node dist/bot.js ``` -------------------------------- ### Client Initialization Example Source: https://zeative.github.io/zaileys/getting-started Example of initializing a Zaileys client. This snippet demonstrates basic client setup. ```javascript const client = new Client() ``` -------------------------------- ### Package Manager Installation Examples Source: https://zeative.github.io/zaileys/storage Provides installation commands for the 'pg' package using npm, pnpm, yarn, and bun. Use the command corresponding to your project's package manager. ```bash self.__next_f.push([1,"55:[\"$\",\"$L8b\",null,{\"items\":[\"npm\",\"pnpm\",\"yarn\",\"bun\"],\"children\":[[\"$\",\"$L8c\",null,{\"children\":[[\"$\",\"h3\",null,{\"id\":\"npm-1\",\"style\":{\"visibility\":\"hidden\",\"width\":0,\"height\":0},\"children\":\"npm\"},[\"$\",\"div\",null,{\"data-pagefind-ignore\":\"all\",\"className\":\"nextra-code x:relative x:not-first:mt-6\",\"children\":[\"$undefined\",[\"$\",\"pre\",null,{\"className\":\"x:group x:focus-visible:nextra-focus x:overflow-x-auto x:subpixel-antialiased x:text-\\[.9em\\] x:bg-white x:dark:bg-black x:py-4 x:ring-1 x:ring-inset x:ring-gray-300 x:dark:ring-neutral-700 x:contrast-more:ring-gray-900 x:contrast-more:dark:ring-gray-50 x:contrast-more:contrast-150 x:rounded-md not-prose\",\"tabIndex\":\"0\",\"children\":[[\"$\",\"div\",null,{\"className\":\"x:group-hover:opacity-100 x:group-focus:opacity-100 x:opacity-0 x:transition x:focus-within:opacity-100 x:flex x:gap-1 x:absolute x:right-4 x:top-2\",\"children\":[[\"$\",\"$L79\",null,{\"children\":[\"$\",\"svg\",null,{\"viewBox\":\"0 0 24 24\",\"fill\":\"currentColor\",\"height\":\"1em\",\"children\":[\"$\",\"path\",null,{\"d\":\"M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3l3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z\"}]}]}]),[\"$\",\"code\",null,{\"className\":\"nextra-code\",\"dir\":\"ltr\",\"children\":[\"$\",\"span\",null,{\"children\":[[\"$\",\"span\",null,{\"style\":{\"--shiki-light\":\"#6F42C1\",\"--shiki-dark\":\"#B392F0\"},\"children\":\"npm\"},[\"$\",\"span\",null,{\"style\":{\"--shiki-light\":\"#032F62\",\"--shiki-dark\":\"#9ECBFF\"},\"children\":\" i\"},[\"$\",\"span\",null,{\"style\":{\"--shiki-light\":\"#032F62\",\"--shiki-dark\":\"#9ECBFF\"},\"children\":\" pg\"}]]}]}]}]}]}]],[\"$\",\"$L8c\",null,{\"children\":[[\"$\",\"h3\",null,{\"id\":\"pnpm-1\",\"style\":{\"visibility\":\"hidden\",\"width\":0,\"height\":0},\"children\":\"pnpm\"},[\"$\",\"div\",null,{\"data-pagefind-ignore\":\"all\",\"className\":\"nextra-code x:relative x:not-first:mt-6\",\"children\":[\"$undefined\",[\"$\",\"pre\",null,{\"className\":\"x:group x:focus-visible:nextra-focus x:overflow-x-auto x:subpixel-antialiased x:text-\\[.9em\\] x:bg-white x:dark:bg-black x:py-4 x:ring-1 x:ring-inset x:ring-gray-300 x:dark:ring-neutral-700 x:contrast-more:ring-gray-900 x:contrast-more:dark:ring-gray-50 x:contrast-more:contrast-150 x:rounded-md not-prose\",\"tabIndex\":\"0\",\"children\":[[\"$\",\"div\",null,{\"className\":\"x:group-hover:opacity-100 x:group-focus:opacity-100 x:opacity-0 x:transition x:focus-within:opacity-100 x:flex x:gap-1 x:absolute x:right-4 x:top-2\",\"children\":[[\"$\",\"$L79\",null,{\"children\":[\"$\",\"svg\",null,{\"viewBox\":\"0 0 24 24\",\"fill\":\"currentColor\",\"he ``` ```bash self.__next_f.push([1,"55:[\"$\",\"$L8b\",null,{\"items\":[\"npm\",\"pnpm\",\"yarn\",\"bun\"],\"children\":[[\"$\",\"$L8c\",null,{\"children\":[[\"$\",\"h3\",null,{\"id\":\"npm-1\",\"style\":{\"visibility\":\"hidden\",\"width\":0,\"height\":0},\"children\":\"npm\"},[\"$\",\"div\",null,{\"data-pagefind-ignore\":\"all\",\"className\":\"nextra-code x:relative x:not-first:mt-6\",\"children\":[\"$undefined\",[\"$\",\"pre\",null,{\"className\":\"x:group x:focus-visible:nextra-focus x:overflow-x-auto x:subpixel-antialiased x:text-\\[.9em\\] x:bg-white x:dark:bg-black x:py-4 x:ring-1 x:ring-inset x:ring-gray-300 x:dark:ring-neutral-700 x:contrast-more:ring-gray-900 x:contrast-more:dark:ring-gray-50 x:contrast-more:contrast-150 x:rounded-md not-prose\",\"tabIndex\":\"0\",\"children\":[[\"$\",\"div\",null,{\"className\":\"x:group-hover:opacity-100 x:group-focus:opacity-100 x:opacity-0 x:transition x:focus-within:opacity-100 x:flex x:gap-1 x:absolute x:right-4 x:top-2\",\"children\":[[\"$\",\"$L79\",null,{\"children\":[\"$\",\"svg\",null,{\"viewBox\":\"0 0 24 24\",\"fill\":\"currentColor\",\"height\":\"1em\",\"children\":[\"$\",\"path\",null,{\"d\":\"M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3l3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z\"}]}]}]),[\"$\",\"code\",null,{\"className\":\"nextra-code\",\"dir\":\"ltr\",\"children\":[\"$\",\"span\",null,{\"children\":[[\"$\",\"span\",null,{\"style\":{\"--shiki-light\":\"#6F42C1\",\"--shiki-dark\":\"#B392F0\"},\"children\":\"npm\"},[\"$\",\"span\",null,{\"style\":{\"--shiki-light\":\"#032F62\",\"--shiki-dark\":\"#9ECBFF\"},\"children\":\" i\"},[\"$\",\"span\",null,{\"style\":{\"--shiki-light\":\"#032F62\",\"--shiki-dark\":\"#9ECBFF\"},\"children\":\" pg\"}]]}]}]}]}]],[\"$\",\"$L8c\",null,{\"children\":[[\"$\",\"h3\",null,{\"id\":\"pnpm-1\",\"style\":{\"visibility\":\"hidden\",\"width\":0,\"height\":0},\"children\":\"pnpm\"},[\"$\",\"div\",null,{\"data-pagefind-ignore\":\"all\",\"className\":\"nextra-code x:relative x:not-first:mt-6\",\"children\":[\"$undefined\",[\"$\",\"pre\",null,{\"className\":\"x:group x:focus-visible:nextra-focus x:overflow-x-auto x:subpixel-antialiased x:text-\\[.9em\\] x:bg-white x:dark:bg-black x:py-4 x:ring-1 x:ring-inset x:ring-gray-300 x:dark:ring-neutral-700 x:contrast-more:ring-gray-900 x:contrast-more:dark:ring-gray-50 x:contrast-more:contrast-150 x:rounded-md not-prose\",\"tabIndex\":\"0\",\"children\":[[\"$\",\"div\",null,{\"className\":\"x:group-hover:opacity-100 x:group-focus:opacity-100 x:opacity-0 x:transition x:focus-within:opacity-100 x:flex x:gap-1 x:absolute x:right-4 x:top-2\",\"children\":[[\"$\",\"$L79\",null,{\"children\":[\"$\",\"svg\",null,{\"viewBox\":\"0 0 24 24\",\"fill\":\"currentColor\",\"he ``` ```bash self.__next_f.push([1,"55:[\"$\",\"$L8b\",null,{\"items\":[\"npm\",\"pnpm\",\"yarn\",\"bun\"],\"children\":[[\"$\",\"$L8c\",null,{\"children\":[[\"$\",\"h3\",null,{\"id\":\"npm-1\",\"style\":{\"visibility\":\"hidden\",\"width\":0,\"height\":0},\"children\":\"npm\"},[\"$\",\"div\",null,{\"data-pagefind-ignore\":\"all\",\"className\":\"nextra-code x:relative x:not-first:mt-6\",\"children\":[\"$undefined\",[\"$\",\"pre\",null,{\"className\":\"x:group x:focus-visible:nextra-focus x:overflow-x-auto x:subpixel-antialiased x:text-\\[.9em\\] x:bg-white x:dark:bg-black x:py-4 x:ring-1 x:ring-inset x:ring-gray-300 x:dark:ring-neutral-700 x:contrast-more:ring-gray-900 x:contrast-more:dark:ring-gray-50 x:contrast-more:contrast-150 x:rounded-md not-prose\",\"tabIndex\":\"0\",\"children\":[[\"$\",\"div\",null,{\"className\":\"x:group-hover:opacity-100 x:group-focus:opacity-100 x:opacity-0 x:transition x:focus-within:opacity-100 x:flex x:gap-1 x:absolute x:right-4 x:top-2\",\"children\":[[\"$\",\"$L79\",null,{\"children\":[\"$\",\"svg\",null,{\"viewBox\":\"0 0 24 24\",\"fill\":\"currentColor\",\"height\":\"1em\",\"children\":[\"$\",\"path\",null,{\"d\":\"M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3l3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z\"}]}]}]),[\"$\",\"code\",null,{\"className\":\"nextra-code\",\"dir\":\"ltr\",\"children\":[\"$\",\"span\",null,{\"children\":[[\"$\",\"span\",null,{\"style\":{\"--shiki-light\":\"#6F42C1\",\"--shiki-dark\":\"#B392F0\"},\"children\":\"npm\"},[\"$\",\"span\",null,{\"style\":{\"--shiki-light\":\"#032F62\",\"--shiki-dark\":\"#9ECBFF\"},\"children\":\" i\"},[\"$\",\"span\",null,{\"style\":{\"--shiki-light\":\"#032F62\",\"--shiki-dark\":\"#9ECBFF\"},\"children\":\" pg\"}]]}]}]}]}]],[\"$\",\"$L8c\",null,{\"children\":[[\"$\",\"h3\",null,{\"id\":\"pnpm-1\",\"style\":{\"visibility\":\"hidden\",\"width\":0,\"height\":0},\"children\":\"pnpm\"},[\"$\",\"div\",null,{\"data-pagefind-ignore\":\"all\",\"className\":\"nextra-code x:relative x:not-first:mt-6\",\"children\":[\"$undefined\",[\"$\",\"pre\",null,{\"className\":\"x:group x:focus-visible:nextra-focus x:overflow-x-auto x:subpixel-antialiased x:text-\\[.9em\\] x:bg-white x:dark:bg-black x:py-4 x:ring-1 x:ring-inset x:ring-gray-300 x:dark:ring-neutral-700 x:contrast-more:ring-gray-900 x:contrast-more:dark:ring-gray-50 x:contrast-more:contrast-150 x:rounded-md not-prose\",\"tabIndex\":\"0\",\"children\":[[\"$\",\"div\",null,{\"className\":\"x:group-hover:opacity-100 x:group-focus:opacity-100 x:opacity-0 x:transition x:focus-within:opacity-100 x:flex x:gap-1 x:absolute x:right-4 x:top-2\",\"children\":[[\"$\",\"$L79\",null,{\"children\":[\"$\",\"svg\",null,{\"viewBox\":\"0 0 24 24\",\"fill\":\"currentColor\",\"he ``` ```bash self.__next_f.push([1,"55:[\"$\",\"$L8b\",null,{\"items\":[\"npm\",\"pnpm\",\"yarn\",\"bun\"],\"children\":[[\"$\",\"$L8c\",null,{\"children\":[[\"$\",\"h3\",null,{\"id\":\"npm-1\",\"style\":{\"visibility\":\"hidden\",\"width\":0,\"height\":0},\"children\":\"npm\"},[\"$\",\"div\",null,{\"data-pagefind-ignore\":\"all\",\"className\":\"nextra-code x:relative x:not-first:mt-6\",\"children\":[\"$undefined\",[\"$\",\"pre\",null,{\"className\":\"x:group x:focus-visible:nextra-focus x:overflow-x-auto x:subpixel-antialiased x:text-\\[.9em\\] x:bg-white x:dark:bg-black x:py-4 x:ring-1 x:ring-inset x:ring-gray-300 x:dark:ring-neutral-700 x:contrast-more:ring-gray-900 x:contrast-more:dark:ring-gray-50 x:contrast-more:contrast-150 x:rounded-md not-prose\",\"tabIndex\":\"0\",\"children\":[[\"$\",\"div\",null,{\"className\":\"x:group-hover:opacity-100 x:group-focus:opacity-100 x:opacity-0 x:transition x:focus-within:opacity-100 x:flex x:gap-1 x:absolute x:right-4 x:top-2\",\"children\":[[\"$\",\"$L79\",null,{\"children\":[\"$\",\"svg\",null,{\"viewBox\":\"0 0 24 24\",\"fill\":\"currentColor\",\"height\":\"1em\",\"children\":[\"$\",\"path\",null,{\"d\":\"M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3l3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z\"}]}]}]),[\"$\",\"code\",null,{\"className\":\"nextra-code\",\"dir\":\"ltr\",\"children\":[\"$\",\"span\",null,{\"children\":[[\"$\",\"span\",null,{\"style\":{\"--shiki-light\":\"#6F42C1\",\"--shiki-dark\":\"#B392F0\"},\"children\":\"npm\"},[\"$\",\"span\",null,{\"style\":{\"--shiki-light\":\"#032F62\",\"--shiki-dark\":\"#9ECBFF\"},\"children\":\" i\"},[\"$\",\"span\",null,{\"style\":{\"--shiki-light\":\"#032F62\",\"--shiki-dark\":\"#9ECBFF\"},\"children\":\" pg\"}]]}]}]}]}]],[\"$\",\"$L8c\",null,{\"children\":[[\"$\",\"h3\",null,{\"id\":\"pnpm-1\",\"style\":{\"visibility\":\"hidden\",\"width\":0,\"height\":0},\"children\":\"pnpm\"},[\"$\",\"div\",null,{\"data-pagefind-ignore\":\"all\",\"className\":\"nextra-code x:relative x:not-first:mt-6\",\"children\":[\"$undefined\",[\"$\",\"pre\",null,{\"className\":\"x:group x:focus-visible:nextra-focus x:overflow-x-auto x:subpixel-antialiased x:text-\\[.9em\\] x:bg-white x:dark:bg-black x:py-4 x:ring-1 x:ring-inset x:ring-gray-300 x:dark:ring-neutral-700 x:contrast-more:ring-gray-900 x:contrast-more:dark:ring-gray-50 x:contrast-more:contrast-150 x:rounded-md not-prose\",\"tabIndex\":\"0\",\"children\":[[\"$\",\"div\",null,{\"className\":\"x:group-hover:opacity-100 x:group-focus:opacity-100 x:opacity-0 x:transition x:focus-within:opacity-100 x:flex x:gap-1 x:absolute x:right-4 x:top-2\",\"children\":[[\"$\",\"$L79\",null,{\"children\":[\"$\",\"svg\",null,{\"viewBox\":\"0 0 24 24\",\"fill\":\"currentColor\",\"he ``` -------------------------------- ### Fully Configured Client Example Source: https://zeative.github.io/zaileys/configuration Demonstrates a comprehensive client setup using SqliteAuthStore and SqliteMessageStore for authentication and message persistence. This example showcases a client exercising the full surface of ClientOptions. ```typescript import { Client, SqliteAuthStore, SqliteMessageStore } from "@/index"; const client = new Client({ auth: new SqliteAuthStore({ db: new Database("auth.db"), }), store: new SqliteMessageStore({ db: new Database("messages.db"), }), logger: console, }); ``` -------------------------------- ### Install Dependencies with pnpm Source: https://zeative.github.io/zaileys/installation Example of installing the 'pg' adapter using pnpm. This snippet shows the command for installing a specific database adapter. ```bash pnpm i pg # PostgreSQL adapter ``` -------------------------------- ### Client Configuration Example Source: https://zeative.github.io/zaileys/configuration This snippet shows how to configure a client to connect to a specific JID and handle events. It demonstrates checking if a JID starts with a certain prefix. ```javascript client.on('stanza', async (stanza) => { if (stanza.is('message') && stanza.attrs.type === 'chat') { const jid = stanza.attrs.from; if (jid.startsWith('banned: (jid) => jid.')) { return; } client.on('text', (text, ...rest) => { // Handle text messages }); } }); client.on('text', (text, ...rest) => { // Handle other text events }); ``` -------------------------------- ### Client Initialization and Connection Source: https://zeative.github.io/zaileys/installation Example of initializing a client and explicitly connecting. The connection can be started explicitly when you are ready to go online. ```javascript // When you are ready to go online, start the connection explicitly: // await client.connect() ``` -------------------------------- ### Create a smoke-test file Source: https://zeative.github.io/zaileys/installation Create a file to verify the installation. This example demonstrates basic usage and import. ```javascript import { Zailey } from "zaileys"; const zailey = new Zailey(); console.log(zailey); ``` -------------------------------- ### Install with Yarn Source: https://zeative.github.io/zaileys/installation Install dependencies using Yarn. This example shows adding a PostgreSQL adapter. ```bash yarn add pg # PostgreSQL adapters ``` -------------------------------- ### Redis Integration Example Source: https://zeative.github.io/zaileys/storage This snippet shows how to configure and use Redis as a storage backend for authentication and messaging. Ensure Redis is installed and running. ```javascript self.__next_f.push([1,"89:[\"$\",\"tr\",null,{\"children\":[[\"$\",\"td\",null,{\"children\":\"Redis\",\"className\":\"x:m-0 x:border x:border-gray-300 x:px-4 x:py-2 x:dark:border-gray-600\"}],[\"$\",\"td\",null,{\"children\":[\"$\",\"code\",null,{\"className\":\"nextra-code\",\"dir\":\"ltr\",\"children\":\"RedisAuthStore\"}],\"className\":\"x:m-0 x:border x:border-gray-300 x:px-4 x:py-2 x:dark:border-gray-600\"}],[\"$\",\"td\",null,{\"children\":[\"$\",\"code\",null,{\"className\":\"nextra-code\",\"dir\":\"ltr\",\"children\":\"RedisMessageStore\"}],\"className\":\"x:m-0 x:border x:border-gray-300 x:px-4 x:py-2 x:dark:border-gray-600\"}],[\"$\",\"td\",null,{\"children\":[\"$\",\"code\",null,{\"className\":\"nextra-code\",\"dir\":\"ltr\",\"children\":\"redis\"}],\"className\":\"x:m-0 x:border x:border-gray-300 x:px-4 x:py-2 x:dark:border-gray-600\"}]),\"className\":\"x:m-0 x:border-t x:border-gray-300 x:p-0 x:dark:border-gray-600 x:even:bg-gray-100 x:even:dark:bg-gray-600/20\"}\n"]) ``` -------------------------------- ### Install Dependencies with npm Source: https://zeative.github.io/zaileys/installation Example of installing the 'better-sqlite3' adapter using npm. This snippet shows the command for installing a specific database adapter. ```bash npm i better-sqlite3 # SQLite adapters ``` -------------------------------- ### Install pg with Bun Source: https://zeative.github.io/zaileys/storage Install the pg package using Bun. ```bash bun add pg ``` -------------------------------- ### Initialize Zaileys Client in Bun Source: https://zeative.github.io/zaileys/runtimes Example of how to import and initialize the Zaileys Client in a Bun environment. Ensure the 'zaileys' package is installed. ```typescript import { Client } from 'zaileys' const client = new Client({ authType: 'qr' }) await client.connect() ``` -------------------------------- ### Zaileys Storage Initialization Example Source: https://zeative.github.io/zaileys/storage Example of initializing Zaileys storage, demonstrating the use of configuration options. ```javascript new Zaileys({ connectionString: "postgres://user:password@host:port/database" }) new Zaileys({ pool: new pg.Pool() }) new Zaileys({ connectionString: "postgres://user:password@host:port/database", pool: new pg.Pool() }) new Zaileys() ``` -------------------------------- ### Initialize Bun Client Source: https://zeative.github.io/zaileys/runtimes Example of initializing a Zaileys client within a Bun runtime environment. This snippet demonstrates the basic setup for connecting to a service. ```javascript const { Client } = require('zaileys'); const client = new Client({ authType: 'pairing', phoneNumber: 628000000000, }); client.on('connection', ({ status }) => { console.log(status) }); ``` -------------------------------- ### Install redis with Bun Source: https://zeative.github.io/zaileys/storage Install the redis package using Bun. ```bash bun add redis ``` -------------------------------- ### Install Optional Database Drivers (bun) Source: https://zeative.github.io/zaileys/llms-full.txt Install the specific database driver required by your chosen storage adapter. Use bun for installation. ```bash bun add better-sqlite3 # or: pg | redis | convex ``` -------------------------------- ### Install Optional Database Drivers (npm) Source: https://zeative.github.io/zaileys/llms-full.txt Install the specific database driver required by your chosen storage adapter. Use npm for installation. ```bash npm install better-sqlite3 # or: pg | redis | convex ``` -------------------------------- ### Install Optional Database Drivers (yarn) Source: https://zeative.github.io/zaileys/llms-full.txt Install the specific database driver required by your chosen storage adapter. Use yarn for installation. ```bash yarn add better-sqlite3 # or: pg | redis | convex ``` -------------------------------- ### Install PostgreSQL Adapter Source: https://zeative.github.io/zaileys/installation Use npm to install the PostgreSQL adapter for Zaileys. ```bash npm install @zaileys/postgres # PostgreSQL adapters ``` -------------------------------- ### Install Sharp with Package Managers Source: https://zeative.github.io/zaileys/media Instructions for installing the 'sharp' image processing library using various package managers. ```bash bash npm i sharp ``` ```bash bash pnpm add sharp ``` ```bash bash yarn add sharp ``` ```bash bash bun add sharp ``` -------------------------------- ### Install Redis Adapter Source: https://zeative.github.io/zaileys/installation Use npm to install the Redis adapter for Zaileys. ```bash npm install @zaileys/redis # Redis adapters ``` -------------------------------- ### Install Convex Adapter Source: https://zeative.github.io/zaileys/installation Use npm to install the Convex adapter for Zaileys. ```bash npm install @zaileys/convex # Convex adapters ``` -------------------------------- ### Install pg with npm Source: https://zeative.github.io/zaileys/storage Install the pg package using npm. ```bash npm i pg ``` -------------------------------- ### Install pg with yarn Source: https://zeative.github.io/zaileys/storage Install the pg package using yarn. ```bash yarn add pg ``` -------------------------------- ### Install Bot with Yarn Source: https://zeative.github.io/zaileys/runtimes Use Yarn to add dependencies and run your bot. Ensure you have Yarn installed. ```bash yarn add ``` ```bash redis ``` -------------------------------- ### Install PostgreSQL Adapters with bun Source: https://zeative.github.io/zaileys/llms-full.txt Install the pg package using bun to enable PostgreSQL storage adapters. ```bash bun add pg # PostgreSQL adapters ``` -------------------------------- ### Install Zaileys with Bun Source: https://zeative.github.io/zaileys/runtimes Use Bun to install Zaileys. Ensure you are in the project directory. ```bash bun install zaileys ``` -------------------------------- ### Install npm package with Bun Source: https://zeative.github.io/zaileys/runtimes Use Bun to install npm packages. This is a common setup step for projects that rely on npm dependencies. ```bash bun install ``` -------------------------------- ### Full Zaileys Client Lifecycle Example Source: https://zeative.github.io/zaileys/llms-full.txt Demonstrates initializing a client, setting up event listeners for QR, reconnection, errors, connection, and text messages, and handling graceful shutdown. ```typescript const client = new Client({ sessionId: 'demo', autoConnect: false }) client.on('qr', ({ qrString }) => console.log('Scan QR:', qrString)) client.on('reconnecting', ({ attempt, delayMs }) => console.log(`reconnecting #${attempt} in ${delayMs}ms`), ) client.on('error', ({ error }) => console.error('client error:', error.message)) client.on('connect', async ({ me }) => { console.log('connected as', me.id) await client.presence.online() }) client.on('text', async (ctx) => { if (ctx.text?.toLowerCase() === 'ping') { const key = await client.send(ctx.roomId).text('pong') await client.react(key, '🏓') } }) await client.connect() // later, on shutdown: process.on('SIGINT', async () => { await client.disconnect() process.exit(0) }) ``` -------------------------------- ### Example Error Event Handling Source: https://zeative.github.io/zaileys/error-handling This example shows how to handle the 'error' event, specifically for the 'STORE_CONNECTION_FAILED' case. It logs a message indicating a missing dependency and suggests a command to install it. ```javascript break case 'STORE_CONNECTION_FAILED': console.error("Missing dependency:", err.message) // e.g. "Run: pnpm add convex" ``` -------------------------------- ### Wire into the Client Source: https://zeative.github.io/zaileys/storage Example demonstrating how to integrate the storage functionality into the client-side application. ```javascript import { ConvexReactClient } from "convex/react"; const m = new ConvexReactClient("https://capable-badger-77.convex.cloud"); export default m; ``` -------------------------------- ### Initialize PostgreSQL Pool and Client Source: https://zeative.github.io/zaileys/storage Demonstrates how to set up a connection pool and a client for PostgreSQL using Zaileys. Ensure the DATABASE_URL environment variable is set. ```javascript import { Pool } from 'pg'; import { Client, PostgresAuthStore } from 'zaileys'; // Pre-built pool — you own and close it const pool = new Pool({ connectionString: process.env.DATABASE_URL }); const client = new Client({ auth: new PostgresAuthStore({ pool }) }); ``` -------------------------------- ### Initialize Zaileys Client Source: https://zeative.github.io/zaileys/automation Demonstrates how to import and instantiate the Zaileys Client. Ensure the 'zaileys' package is installed. ```javascript import { Client } from 'zaileys' const client = new Client() const jid = '6281111111111@s.whatsapp.net' ``` -------------------------------- ### Bun Client Initialization Source: https://zeative.github.io/zaileys/llms-full.txt Example of initializing the Client in Bun with 'qr' authentication. ```typescript const client = new Client({ authType: 'qr' }) await client.connect() ``` -------------------------------- ### Client Initialization and Event Listeners Source: https://zeative.github.io/zaileys/events Demonstrates how to initialize a client and set up event listeners for 'text' and 'message' events. This is crucial for real-time communication handling. ```javascript 2E\",\"--shiki-dark\":\ ``` ```javascript #E1E4E8\"},\ ``` ```javascript children\":\"()\"}\\n]\ },\ ``` ```javascript fa:[\ ``` ```javascript $\",\ ``` ```javascript span\",null,{\"children\":[\ ``` ```javascript $\",\ ``` ```javascript span\",null,{\"style\":{\"--shiki-light\":\ ``` ```javascript #24292E\",\ ``` ```javascript --shiki-dark\":\ ``` ```javascript #E1E4E8\"},\ ``` ```javascript children\":\"client.\"}\\n],\ ``` ```javascript $\",\ ``` ```javascript span\",null,{\"style\":{\"--shiki-light\":\ ``` ```javascript #6F42C1\",\ ``` ```javascript --shiki-dark\":\ ``` ```javascript #B392F0\"},\ ``` ```javascript children\":\"on\"}\\n],\ ``` ```javascript $\",\ ``` ```javascript span\",null,{\"style\":{\"--shiki-light\":\ ``` ```javascript #24292E\",\ ``` ```javascript --shiki-dark\":\ ``` ```javascript #E1E4E8\"},\ ``` ```javascript children\":\"(\"}\\n],\ ``` ```javascript $\",\ ``` ```javascript span\",null,{\"style\":{\"--shiki-light\":\ ``` ```javascript #032F62\",\ ``` ```javascript --shiki-dark\":\ ``` ```javascript #9ECBFF\"},\ ``` ```javascript children\":\"'text'\"}\\n],\ ``` ```javascript $\",\ ``` ```javascript span\",null,{\"style\":{\"--shiki-light\":\ ``` ```javascript #24292E\",\ ``` ```javascript --shiki-dark\":\ ``` ```javascript #E1E4E8\"},\ ``` ```javascript children\":\", onText)\"}\\n]\ },\ ``` ```javascript fb:[\ ``` ```javascript $\",\ ``` ```javascript span\",null,{\"children\":[\ ``` ```javascript $\",\ ``` ```javascript span\",null,{\"style\":{\"--shiki-light\":\ ``` ```javascript #24292E\",\ ``` ```javascript --shiki-dark\":\ ``` ```javascript #E1E4E8\"},\ ``` ```javascript children\":\"client.\"}\\n],\ ``` ```javascript $\",\ ``` ```javascript span\",null,{\"style\":{\"--shiki-light\":\ ``` ```javascript #6F42C1\",\ ``` ```javascript --shiki-dark\":\ ``` ```javascript #B392F0\"},\ ``` ```javascript children\":\"on\"}\\n],\ ``` ```javascript $\",\ ``` ```javascript span\",null,{\"style\":{\"--shiki-light\":\ ``` ```javascript #24292E\",\ ``` ```javascript --shiki-dark\":\ ``` ```javascript #E1E4E8\"},\ ``` ```javascript children\":\"(\"}\\n],\ ``` ```javascript $\",\ ``` ```javascript span\",null,{\"style\":{\"--shiki-light\":\ ``` ```javascript #032F62\",\ ``` ```javascript --shiki-dark\":\ ``` ```javascript #9ECBFF\"},\ ``` ```javascript children\":\"'message'\"}\\n],\ ``` ```javascript $\",\ ``` ```javascript span\",null,{\"style\":{\"--shiki-light\":\ ``` ```javascript #24292E\",\ ``` ```javascript --shiki-dark\":\ ``` ```javascript #E1E4E8\"},\ ``` ```javascript children\":\", onMessage)\"}\\n]\ }\\n]\ }\\n ``` -------------------------------- ### Initialize Zaileys Client for Pairing Source: https://zeative.github.io/zaileys/configuration Instantiate the Zaileys client for pairing authentication. Ensure the 'zaileys' package is installed. This setup is used when initiating a pairing process. ```javascript import { Client } from 'zaileys' const client = new Client({ authType: 'pairing', phoneNumber: '628xxxxxxxxxx', }) ``` -------------------------------- ### Termux Installation Source: https://zeative.github.io/zaileys/installation Install Zaileys on Termux (Android). It installs as a normal Node.js project. ```bash — ``` -------------------------------- ### Initialize Bun Client Source: https://zeative.github.io/zaileys/runtimes Instantiate a new client for use with Bun. Ensure the '--node-modules-dir' flag is used when running with Deno. ```javascript const client = new Client({ authType: 'qr' }); await client.connect(); ``` -------------------------------- ### Install Peer Dependencies Source: https://zeative.github.io/zaileys/installation Install necessary peer dependencies using npm. These are not installed by default and are loaded lazily. ```bash npm install ``` -------------------------------- ### Initialize Media Class Source: https://zeative.github.io/zaileys/media Instantiate the Media class to begin processing. Ensure ffmpeg, sharp, and jimp are installed. ```javascript import { Media } from "@/lib/media"; const media = new Media(); ``` -------------------------------- ### Install redis with npm Source: https://zeative.github.io/zaileys/runtimes Install the redis adapter using npm. This is a peer dependency, so only install the driver for your specific backend. ```bash npm install redis # Redis ``` -------------------------------- ### Install better-sqlite3 with npm Source: https://zeative.github.io/zaileys/runtimes Install the better-sqlite3 adapter using npm. This is a peer dependency, so only install the driver for your specific backend. ```bash npm install better-sqlite3 # SQLite ``` -------------------------------- ### Client Initialization with Command Prefixes Source: https://zeative.github.io/zaileys/configuration Initializes a client with specified command prefixes to enable the command framework. Commands will be triggered by these prefixes. ```javascript const client = new Client({ commandPrefix: ['!', '.'], // other options }) ``` -------------------------------- ### Initialize Zaileys Client and Media Objects Source: https://zeative.github.io/zaileys/media Demonstrates how to import and instantiate the Client and Media classes from the 'zaileys' library. The Client is initialized with configuration, and the Media object is created with a file path. ```typescript import { Client, Media } from 'zaileys' const client = new Client({ /* ... */ }) const media = new Media('./assets/banner.png') const jpeg = await media.image.toJpeg() ``` -------------------------------- ### Install pg with npm Source: https://zeative.github.io/zaileys/runtimes Install the pg adapter for PostgreSQL using npm. This is a peer dependency, so only install the driver for your specific backend. ```bash npm install pg # Postgres ``` -------------------------------- ### Bun Runtime Example Source: https://zeative.github.io/zaileys/installation This snippet demonstrates how to run a bot using Bun, a fast JavaScript runtime. ```bash bun --bun run bot.ts ``` -------------------------------- ### Logging Middleware Setup Source: https://zeative.github.io/zaileys/commands This snippet shows how to set up and use a logging middleware with a client instance. It demonstrates the pattern for applying middleware to intercept and log requests or events. ```javascript iki-dark\":\"#005CC5\"},\"children\":\"const\"},{\"style\":{\"--shiki-light\":\"#24292E\",\"--shiki-dark\":\"#E1E4E8\"},\"children\":\" middleware \"},{\"style\":{\"--shiki-light\":\"#005CC5\",\"--shiki-dark\":\"#9ECBFF\"},\"children\":\"= \"},{\"style\":{\"--shiki-light\":\"#D73A49\",\"--shiki-dark\":\"#F97583\"},\"children\":\"async\"},{\"style\":{\"--shiki-light\":\"#24292E\",\"--shiki-dark\":\"#E1E4E8\"},\"children\":\" \"},{\"style\":{\"--shiki-light\":\"#6F42C1\",\"--shiki-dark\":\"#B392F0\"},\"children\":\"(ctx, next)\"}]}]}\\n ``` -------------------------------- ### Install Optional Database Drivers (pnpm) Source: https://zeative.github.io/zaileys/llms-full.txt Install the specific database driver required by your chosen storage adapter. Use pnpm for installation. ```bash pnpm add better-sqlite3 # or: pg | redis | convex ``` -------------------------------- ### Node.js Installation with pnpm Source: https://zeative.github.io/zaileys/runtimes This code block shows the command to install Zaileys using pnpm. It's a standard package installation command. ```bash pnpm install zaileys ``` -------------------------------- ### Full zaileys Client Configuration Example Source: https://zeative.github.io/zaileys/llms-full.txt A comprehensive example demonstrating the full range of ClientOptions, including session ID, authentication type, phone number, custom auth and store, command prefix, ignore self messages, citation settings, reconnect strategy, connection behavior, QR rendering, status logging, signal caching, custom logger, and Baileys socket options. ```typescript const client = new Client({ sessionId: 'production-bot', authType: 'pairing', phoneNumber: '628xxxxxxxxxx', auth: new SqliteAuthStore({ database: './zaileys.db' }), store: new SqliteMessageStore({ database: './zaileys.db' }), commandPrefix: ['/', '!'], ignoreMe: true, citation: { authors: ['628xxx@s.whatsapp.net'], banned: (jid) => jid.startsWith('62800'), }, reconnect: { maxAttempts: 20, initialDelayMs: 2000, maxDelayMs: 30000, jitterFactor: 0.25, }, autoConnect: true, qrTerminal: false, statusLog: true, cacheSignal: true, logger: { info: (...a) => console.log('[info]', ...a), warn: (...a) => console.warn('[warn]', ...a), error: (...a) => console.error('[error]', ...a), }, baileys: { browser: ['zaileys', 'Chrome', '1.0.0'], }, }) client.on('pairing-code', ({ code }) => console.log('Pairing code:', code)) client.on('connect', ({ me }) => console.log('Connected as', me.id)) client.command('ping', async (ctx) => { await ctx.reply('pong') }) ``` -------------------------------- ### Import and Construct Media Instance Source: https://zeative.github.io/zaileys/media Import the Media class from 'zaileys' and create a new instance by passing the input source. The input can be a URL, file path, base64 string, Buffer, or ArrayBuffer. Construction is lazy and cheap. ```javascript import { Media } from 'zaileys' const media = new Media(input) ``` -------------------------------- ### Example Code Block Source: https://zeative.github.io/zaileys/automation This is a generic code block example. ```javascript self.__next_f.push([ 1, "43:[\"$\",\"div\",null,{\"data-pagefind-ignore\":\"all\",\"className\":\"nextra-code x:relative x:not-first:mt-6\",\"children\":[\"$undefined\",[\"$\",\"pre\",null,{\"className\":\"x:group x:focus-visible:nextra-focus x:overflow-x-auto x:subpixel-antialiased x:text-\\.9em\" x:bg-white x:dark:bg-black x:py-4 x:ring-1 x:ring-inset x:ring-gray-300 x:dark:ring-neutral-700 x:contrast-more:ring-gray-900 x:contrast-more:dark:ring-gray-50 x:contrast-more:contrast-150 x:rounded-md not-prose\",\"tabIndex\":\"0\",\"children\":[[\"$\",\"div\",null,{\"className\":\"x:group-hover:opacity-100 x:group-focus:opacity-100 x:opacity-0 x:transition x:focus-within:opacity-100 x:flex x:gap-1 "}]}]}]}]] ``` -------------------------------- ### Install redis with yarn Source: https://zeative.github.io/zaileys/storage Install the redis package using yarn. ```bash yarn add redis ``` -------------------------------- ### Client Connection with Options Source: https://zeative.github.io/zaileys/configuration Shows how to connect a client with specific options, including command prefix and citation authors. ```javascript self.__next_f.push([1,"bc:[\"$\",\"span\",null,{\"children\":[[ \"$\",\"span\",null,{\"style\":{\"--shiki-light\":\"#6F42C1\",\"--shi ``` -------------------------------- ### Client Initialization with Manual Connection Source: https://zeative.github.io/zaileys/client Shows how to initialize the client with `autoConnect: false` and manually initiate the connection using `client.connect()`. This provides control over the connection lifecycle. ```javascript By default the constructor connects automatically (autoConnect: true). You can also drive the lifecycle yourself by passing autoConnect: false, and calling client.connect() when you are ready. See ``` -------------------------------- ### Install redis with pnpm Source: https://zeative.github.io/zaileys/storage Install the redis package using pnpm. ```bash pnpm add redis ``` -------------------------------- ### Install redis with npm Source: https://zeative.github.io/zaileys/storage Install the redis package using npm. ```bash npm i redis ``` -------------------------------- ### Initialize Client with QR Code (Deno) Source: https://zeative.github.io/zaileys/runtimes Example of initializing the Zaileys client using the 'qr' authentication method in Deno, specifying Zaileys via npm specifier. Requires --node-modules-dir. ```typescript import { Client } from 'npm:zaileys' const client = new Client({ authType: 'qr' }) await client.connect() ``` -------------------------------- ### Client Pairing Code Example Source: https://zeative.github.io/zaileys/client Demonstrates how to initiate a client connection using a pairing code and log the received code. This snippet shows the structure of the data received during pairing. ```javascript client.on('pairing-code', (code, expiresAt) => { console.log('Enter this code on WhatsApp:', code, expiresAt) }) ``` -------------------------------- ### Initialize Media Client Source: https://zeative.github.io/zaileys/media Initializes the Client for the Media API. Ensure the 'zaileys' library is installed. ```typescript import { Client, Media } from 'zaileys' const client = new Client({ /* ... */ }) ``` -------------------------------- ### Initialize Bun Client and Send Sticker Source: https://zeative.github.io/zaileys/media This snippet demonstrates initializing a Bun client and sending a sticker. Ensure you have the 'zaileys' library installed and replace placeholder values with your actual client options and JID. ```javascript import { Client, Media } from 'zaileys' const client = new Client({ /* ... */ }) const jid = '6281234567890@s.whatsapp.net' // Image → sticker const sticker = new Media('./assets/photo.jpg').sticker.create() await client.send(jid).sticker ``` -------------------------------- ### Presence Automation Example Source: https://zeative.github.io/zaileys/automation Example of accessing presence automation features. ```javascript client.presence ``` -------------------------------- ### Client Initialization with Browser Details Source: https://zeative.github.io/zaileys/configuration This example shows how to initialize the Zaileys client with specific browser details. This is useful for simulating a particular browser environment. ```javascript self.__next_f.push([1,"ce:[\"$\",\"span\",null,{\"children\":[[\"$\",\"span\",null,{\"style\":{\"--shiki-light\":\"#24292E\",\"--shiki-dark\":\"#E1E4E8\"},\"children\":\" browser: [\"}],\"$\",\"span\",null,{\"style\":{\"--shiki-light\":\"#032F62\",\"--shiki-dark\":\"#9ECBFF\"},\"children\":\"'zaileys'\"},\"$\",\"span\",null,{\"style\":{\"--shiki-light\":\"#24292E\",\"--shiki-dark\":\"#E1E4E8\"},\"children\":\", \"}],\"$\",\"span\",null,{\"style\":{\"--shiki-light\":\"#032F62\",\"--shiki-dark\":\"#9ECBFF\"},\"children\":\"'Chrome'\"},\"$\",\"span\",null,{\"style\":{\"--shiki-light\":\"#24292E\",\"--shiki-dark\":\"#E1E4E8\"},\"children\":\", \"}],\"$\",\"span\",null,{\"style\":{\"--shiki-light\":\"#032F62\",\"--shiki-dark\":\"#9ECBFF\"},\"children\":\"'1.0.0'\"},\"$\",\"span\",null,{\"style\":{\"--shiki-light\":\"#24292E\",\"--shiki-dark\":\"#E1E4E8\"},\"children\":\"], \"}]])}\"}] ``` -------------------------------- ### Install Storage Adapter Drivers (yarn) Source: https://zeative.github.io/zaileys/llms-full.txt Install the driver for your chosen storage backend when using yarn. If no driver is installed, Zaileys will default to file or in-memory storage adapters. ```bash yarn add better-sqlite3 yarn add pg yarn add redis ``` -------------------------------- ### Install Storage Adapter Drivers (npm) Source: https://zeative.github.io/zaileys/llms-full.txt Install the driver for your chosen storage backend when using npm. If no driver is installed, Zaileys will default to file or in-memory storage adapters. ```bash npm i better-sqlite3 # SQLite npm i pg # Postgres npm i redis # Redis ```