### Client Pairing Example Source: https://zeative.github.io/zaileys/configuration Demonstrates how to pair two clients using a session ID. This setup logs the session ID to the console. ```javascript console.log(sessionId, 'ready as') ``` -------------------------------- ### Basic Middleware Setup Source: https://zeative.github.io/zaileys/configuration Example of setting up a basic asynchronous middleware function that receives context (ctx) and the next function in the chain. This is a common pattern for intercepting and processing requests. ```javascript Middleware = async (ctx, next) => { console.log(`[command] ${ctx.message.text}`) } ``` -------------------------------- ### Install PostgreSQL Adapter with Bun Source: https://zeative.github.io/zaileys/installation Use 'bun add' to install the pg adapter for Zaileys. ```bash bun add pg ``` -------------------------------- ### Complete Bot Example with Logging Middleware Source: https://zeative.github.io/zaileys/commands This example shows a complete bot structure, mirroring the command-bot.ts file. It includes a basic router setup with logging middleware and several commands. ```typescript import { Client, Middleware } from 'zaileys' const client = new Client({ // ... client options }) client.use(Middleware.logging()) client.command("ping", (ctx) => { ctx.reply("Pong!") }) client.command("help", (ctx) => { ctx.reply("Available commands: ping, help") }) client.run() ``` -------------------------------- ### Install npm Source: https://zeative.github.io/zaileys/installation Use this command to install npm, which is a prerequisite for installing Zaileys packages. ```bash npm install ``` -------------------------------- ### Install Redis Adapter with Bun Source: https://zeative.github.io/zaileys/installation Use 'bun add' to install the redis adapter for Zaileys. ```bash bun add redis ``` -------------------------------- ### Client Lifecycle Example Source: https://zeative.github.io/zaileys/client A complete example demonstrating the client lifecycle, including connection, event handling, and disconnection. ```javascript import { Client } from 'zaileys' const client = new Client({ // options }) client.on('message', message => { console.log('New message:', message) }) client.on('connect', async ({ me }) => { console.log('Client connected as', me.id) // Send a message after connecting await client.sendMessage('1234567890@s.whatsapp.net', { text: 'Hello from zaileys!' }) }) client.on('disconnect', reason => { console.log('Client disconnected:', reason) }) // Connect the client await client.connect() // Disconnect the client after some time setTimeout(async () => { await client.disconnect() console.log('Client disconnected gracefully') }, 60000) // Disconnect after 60 seconds ``` -------------------------------- ### Full Client Configuration Example Source: https://zeative.github.io/zaileys/configuration This example demonstrates a fully configured Zaileys client, exercising the complete range of ClientOptions. ```javascript const client = new Client({ auth: { // ... }, store: { // ... }, logger: { // ... }, syncFullHistory: false, }); ``` -------------------------------- ### Complete Client Lifecycle Example Source: https://zeative.github.io/zaileys/client A full example demonstrating the initialization of the Client and accessing community features. This serves as a comprehensive lifecycle illustration. ```javascript import { Client } from 'zaileys' const client = new Client({ sessionId: ``` -------------------------------- ### Client Initialization Example Source: https://zeative.github.io/zaileys/commands Example of how to initialize the Client with command prefixes. This sets up the client to recognize specific prefixes for command invocation. ```typescript const client = new Client({ commandPrefix: ['/', '!'] }); ``` -------------------------------- ### Install Optional Peer Dependencies for Storage Adapters (npm) Source: https://zeative.github.io/zaileys/installation Install optional storage adapter dependencies using npm. Install only the ones you use. ```bash npm i better-sqlite3 # SQLite adapters npm i pg # PostgreSQL adapters npm i redis # Redis adapters npm i convex # Convex adapters ``` -------------------------------- ### Install SQLite Adapter with Bun Source: https://zeative.github.io/zaileys/installation Use 'bun add' to install the better-sqlite3 adapter for Zaileys. ```bash bun add better-sqlite3 ``` -------------------------------- ### Install pg via npm Source: https://zeative.github.io/zaileys/runtimes Install the pg adapter using npm. This is for PostgreSQL databases. ```bash npm i pg # Postgres ``` -------------------------------- ### File Extension Example Source: https://zeative.github.io/zaileys/media Shows an example of the ext property, representing the file extension of the media file. ```json { "ext": "pdf" } ``` -------------------------------- ### Install Optional Peer Dependencies for Storage Adapters (pnpm) Source: https://zeative.github.io/zaileys/installation Install optional storage adapter dependencies using pnpm. Install only the ones you use. ```bash pnpm add better-sqlite3 # SQLite adapters pnpm add pg # PostgreSQL adapters pnpm add redis # Redis adapters pnpm add convex # Convex adapters ``` -------------------------------- ### Install PostgreSQL Adapter with npm Source: https://zeative.github.io/zaileys/installation Use this command to install the pg adapter for Zaileys using npm. ```bash npm install pg # PostgreSQL adapters ``` -------------------------------- ### Install Optional Peer Dependencies for Storage Adapters (Yarn) Source: https://zeative.github.io/zaileys/installation Install optional storage adapter dependencies using Yarn. Install only the ones you use. ```bash yarn add better-sqlite3 # SQLite adapters yarn add pg # PostgreSQL adapters yarn add redis # Redis adapters yarn add convex # Convex adapters ``` -------------------------------- ### Client Command Example Source: https://zeative.github.io/zaileys/commands Example of how to define and use a client command to fetch weather information. It shows how to access arguments and context. ```javascript client.command( 'weather', async (ctx) => { const city = ctx.args[0] if (!city) { ctx.reply('Please provide a city name.') return } try { const weatherData = await ctx.fetch( `https://wttr.in/${city}?format=j1` ) const data = JSON.parse(weatherData) const location = data.nearest_area[0].areaName[0].value const region = data.nearest_area[0].region[0].value const country = data.nearest_area[0].country[0].value const temp = data.current_condition[0].temp_C const condition = data.current_condition[0].weatherDesc[0].value ctx.reply( `Weather in ${location}, ${region}, ${country}: ${temp}°C, ${condition}` ) } catch (error) { console.error('Error fetching weather:', error) ctx.reply('Could not fetch weather data. Please try again later.') } } ) ``` -------------------------------- ### Install Sharp Image Accelerator with Bun Source: https://zeative.github.io/zaileys/installation Use 'bun add' to install the optional sharp image accelerator. ```bash bun add sharp ``` -------------------------------- ### Add PostgreSQL Adapter with npm Source: https://zeative.github.io/zaileys/installation Install the PostgreSQL adapter for Zaileys using 'npm install'. ```bash npm install pg ``` -------------------------------- ### Install Convex Adapter with Bun Source: https://zeative.github.io/zaileys/installation Use 'bun add' to install the convex adapter for Zaileys. ```bash bun add convex ``` -------------------------------- ### Add Redis Adapter with npm Source: https://zeative.github.io/zaileys/installation Install the Redis adapter for Zaileys using 'npm install'. ```bash npm install redis ``` -------------------------------- ### Install Redis Adapter with npm Source: https://zeative.github.io/zaileys/installation Use this command to install the redis adapter for Zaileys using npm. ```bash npm install redis # Redis adapters ``` -------------------------------- ### Install Redis Adapters with bun Source: https://zeative.github.io/zaileys/llms-full.txt Install the 'redis' package when using Redis storage adapters with bun. ```bash bun add redis # Redis adapters ``` -------------------------------- ### Install Convex Adapters with bun Source: https://zeative.github.io/zaileys/llms-full.txt Install the 'convex' package when using Convex storage adapters with bun. ```bash bun add convex # Convex adapters ``` -------------------------------- ### Add Convex Adapter with npm Source: https://zeative.github.io/zaileys/installation Install the Convex adapter for Zaileys using 'npm install'. ```bash npm install convex ``` -------------------------------- ### Install Sharp Image Accelerator with npm Source: https://zeative.github.io/zaileys/installation Use 'npm install' to add the optional sharp image accelerator. ```bash npm i sharp ``` -------------------------------- ### Install Convex Adapter with npm Source: https://zeative.github.io/zaileys/installation Use this command to install the convex adapter for Zaileys using npm. ```bash npm install convex # Convex adapters ``` -------------------------------- ### Bun Runtime Example Source: https://zeative.github.io/zaileys/runtimes Example of handling client connection events in Bun. This snippet logs the connection status. ```javascript client.on('connection', ({ status }) => { console.log(status) }) await client.connect() ``` -------------------------------- ### Add SQLite Adapter with npm Source: https://zeative.github.io/zaileys/installation Install the SQLite adapter for Zaileys using 'npm install'. ```bash npm install better-sqlite3 ``` -------------------------------- ### Install SQLite Adapter with npm Source: https://zeative.github.io/zaileys/installation Use this command to install the better-sqlite3 adapter for Zaileys using npm. ```bash npm install better-sqlite3 # SQLite adapters ``` -------------------------------- ### Install Sharp Image Accelerator with Yarn Source: https://zeative.github.io/zaileys/installation Use 'yarn add' to install the optional sharp image accelerator. ```bash yarn add sharp ``` -------------------------------- ### Basic String Join Example Source: https://zeative.github.io/zaileys/events A simple example demonstrating the use of the 'join' method with string literals. ```javascript const x = 1 ``` ```javascript join('`\n') ``` ```javascript ). ``` ```javascript { rich: ""} ``` ```javascript true ``` -------------------------------- ### Fully Configured Example Source: https://zeative.github.io/zaileys/configuration An example demonstrating a comprehensive client configuration with custom session ID, pairing authentication, custom storage, logger, and command prefix. ```javascript import { Client } from 'zaileys' import { FileAuthStore, RedisMessageStore } from 'zaileys/storage' import Pino from 'pino' const logger = Pino({ level: 'debug' }) const client = new Client({ sessionId: 'my-custom-session', authType: 'pairing', phoneNumber: '+1234567890', auth: new FileAuthStore({ sessionId: 'my-custom-session' }), store: new RedisMessageStore({ redis: { host: 'localhost', port: 6379 } }), logger: logger, commandPrefix: ['!'], ignoreMe: true, reconnect: { maxRetries: 5 }, autoConnect: true, qrTerminal: true, statusLog: true, cacheSignal: true, baileys: { browserDescription: ['MyBot', 'Windows', '10.0'] } }) ``` -------------------------------- ### Directive Block Example Source: https://zeative.github.io/zaileys/rich-responses An example of a directive block with a name and body lines. Each line in the body can optionally start with a list marker like '-' or '*'. ```markdown :::\nname\nbody line 1\nbody line 2\n::: ``` -------------------------------- ### Deploying Configuration with Environment Variables Source: https://zeative.github.io/zaileys/commands This example shows how to deploy a configuration, potentially specifying a target environment and a force flag. It also includes handling of optional parameters. ```javascript `Deploy ${env} to ${target} ${force ? '(forced)' : ''}` ``` -------------------------------- ### Send a message and get a reply Source: https://zeative.github.io/zaileys/configuration Example of sending a message and awaiting a reply from an author. ```javascript msg.reply("Hello, author!") ``` -------------------------------- ### Basic Logger Setup with Client Import Source: https://zeative.github.io/zaileys/configuration Illustrates the basic setup for a logger, including importing the Client class and defining essential logging methods. ```javascript import { Client } from "@zeabur/zaileys" ``` -------------------------------- ### Get Thumbnail Example Source: https://zeative.github.io/zaileys/api-reference Retrieves a thumbnail for a video. This is a direct method call on the video object. ```javascript const thumb = await m.video.thumbnail() ``` -------------------------------- ### Initialize Zaileys Client Source: https://zeative.github.io/zaileys/configuration Import the Client from the 'zaileys' package and initialize it with a session ID. This is the basic setup required to start using the library. ```javascript import { Client } from 'zaileys' const client = new Client({ sessionId: 'default' }) ``` -------------------------------- ### Initialize Zaileys Client with Session ID Source: https://zeative.github.io/zaileys/llms-full.txt Instantiate a new Zaileys client, specifying a session ID for authentication. This is a basic setup for starting a bot. ```typescript const client = new Client({ sessionId: 'default' }) ``` -------------------------------- ### Install better-sqlite3 with Bun Source: https://zeative.github.io/zaileys/troubleshooting Use 'bun add' to install the better-sqlite3 package. Alternatively, you can use 'pg' or 'redis' or 'convex'. ```bash bun add better-sqlite3 # or: pg | redis | convex ``` -------------------------------- ### Writing Files with Node.js Source: https://zeative.github.io/zaileys/events This example demonstrates how to use the `writeFile` function from Node.js's `fs/promises` module to write data to a file. Ensure Node.js is installed and the module is imported. ```javascript import { writeFile } from 'node:fs/promises' client.on('image', async (msg, match) => { const buffer = await msg.buffer() await writeFile('image.png', buffer) }) ``` -------------------------------- ### Basic Command Execution Example Source: https://zeative.github.io/zaileys/commands Shows a fundamental example of executing a command, 'deploy', using a client object. This snippet illustrates the basic structure for invoking commands. ```javascript client.command('deploy') ``` -------------------------------- ### Install Zaileys Package Source: https://zeative.github.io/zaileys/llms.txt Install the Zaileys package using npm. Import the Client class for use in your project. ```bash npm install zaileys ``` ```typescript import { Client } from 'zaileys' ``` -------------------------------- ### Instantiate Client with PostgresAuthStore Source: https://zeative.github.io/zaileys/storage Example of initializing the client with a PostgresAuthStore. The store manages authentication using a PostgreSQL database. ```javascript new Client([ ["$", "span", null, { "style": { "--shiki-light": "#D73A49", "--shiki-dark": "#F97583" }, "children": "new" }], ["$", "span", null, { "style": { "--shiki-light": "#6F42C1", "--shiki-dark": "#B392F0" }, "children": "Client" }], ["$", "span", null, { "style": { "--shiki-light": "#24292E", "--shiki-dark": "#E1E4E8" }, "children": "({ auth: " }], ["$", "span", null, { "style": { "--shiki-light": "#D73A49", "--shiki-dark": "#F97583" }, "children": "new" }], ["$", "span", null, { "style": { "--shiki-light": "#6F42C1", "--shiki-dark": "#B392F0" }, "children": "PostgresAuthStore" }], ["$", "span", null, { "style": { "--shiki-light": "#24292E", "--shiki-dark": "#E1E4E8" }, "children": "({ pool }) " }] ]) // when the store owns the pool it closes it on shutdown; a pool you pass in is yours to end() ``` -------------------------------- ### Rich Content Example with Formatting Source: https://zeative.github.io/zaileys/rich-responses Demonstrates a rich content example with specific formatting, including markdown-like elements and code snippets. ```json [ "$", "span", null, { "children": [ [ "$", "span", null, { "style": { "--shiki-light": "#032F62", "--shiki-dark": "#9ECBFF" }, "children": " '\*Rich reply example\* ✨'" } ], "," ] } ] ``` -------------------------------- ### Initialize Client with FileAuthStore and RedisMessageStore Source: https://zeative.github.io/zaileys/storage Example of initializing the Zaileys client using FileAuthStore for authentication and RedisMessageStore for message history. This setup is suitable for scenarios requiring persistent session data on disk and message history stored in Redis. ```javascript import { Client, FileAuthStore, RedisMessageStore } from 'zaileys' // Session on disk, history in Redis const client = new Client({ auth: new FileAuthStore({ basePath: "./" }), messageStore: new RedisMessageStore(), }) ``` -------------------------------- ### Initializing and Using the Zaileys Client Source: https://zeative.github.io/zaileys/api-reference Shows how to instantiate the Client with memory-based storage and event handlers for connection status and incoming messages. Includes basic message echoing logic. ```javascript import { Client, MemoryAuthStore, MemoryMessageStore } from 'zaileys' const client = new Client({ sessionId: 'main', auth: new MemoryAuthStore(), store: new MemoryMessageStore(), authType: 'qr', qrTerminal: true, }) client.on('connection', (s) => console.log(s.status)) client.on('message', (msg) => { if (msg.text() === 'ping') client.send(msg.chatId()).text('pong') }) ``` -------------------------------- ### Initialize Client with Session and Auth Source: https://zeative.github.io/zaileys/client Import the Client class and create a new instance. Configure session ID, authentication type, and reconnection settings. ```javascript import { Client } from 'zaileys' const client = new Client({ sessionId: 'support-bot', authType: 'qr', ignoreMe: true, reconnect: { maxAttempts: 10, initialDelayMs: 500 }, }) ``` -------------------------------- ### Install Sharp with npm Source: https://zeative.github.io/zaileys/media Use this command to install the 'sharp' package using npm. 'sharp' is recommended for faster image processing. ```bash bash npm i sharp ``` -------------------------------- ### Install Sharp Image Processor Source: https://zeative.github.io/zaileys/llms-full.txt Install the 'sharp' package for accelerated image processing. If 'sharp' is not installed, Zaileys will fall back to using 'jimp'. ```bash npm i sharp ``` ```bash pnpm add sharp ``` ```bash yarn add sharp ``` ```bash bun add sharp ``` -------------------------------- ### Install Redis with npm Source: https://zeative.github.io/zaileys/runtimes Use npm to install the Redis package. This command installs the Redis package and adds a comment indicating it's for Redis. ```bash $ npm i redis # Redis ``` -------------------------------- ### Full Lifecycle Client Example Source: https://zeative.github.io/zaileys/llms-full.txt Demonstrates the complete lifecycle of a client connection, including initialization, event subscriptions for QR, reconnection, errors, connection, and text messages. It also shows how to send a 'pong' response to a 'ping' message and how to handle 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) }) ``` -------------------------------- ### Basic Event Handling with Client Source: https://zeative.github.io/zaileys/llms-full.txt Shows how to initialize a client and subscribe to basic events like 'qr', 'connect', and 'text'. It logs connection information and replies to text messages. ```typescript const client = new Client() client.on('qr', ({ qrString }) => console.log('Scan QR:', qrString)) client.on('connect', ({ me }) => console.log('Connected as', me.id)) client.on('text', async (msg) => { console.log(msg.senderId, '|', msg.text) await msg.reply(`You said: ${msg.text}`) }) ``` -------------------------------- ### Bot Reply Example Source: https://zeative.github.io/zaileys/commands This snippet demonstrates how to use `ctx.reply()` to send a message in response to a command. It includes an example of dynamic message content. ```javascript await ctx.reply(`Weather in ${city}: sunny, 28 degrees`) ``` -------------------------------- ### SQLite Dependency Installation Source: https://zeative.github.io/zaileys/troubleshooting When using the SQLite auth/store adapter, ensure the 'better-sqlite3' package is installed. The error message will indicate if it's missing and provide the installation command. ```text better-sqlite3 belum terpasang. Run: pnpm add better-sqlite3 ``` ```text better-sqlite3 ``` -------------------------------- ### Install Storage Adapter Drivers (yarn) Source: https://zeative.github.io/zaileys/llms-full.txt Install the necessary 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 ``` -------------------------------- ### Initialize Client with Auth Store Source: https://zeative.github.io/zaileys/api-reference Demonstrates how to initialize the Client with a specific authentication store, such as SqliteAuthStore. This is useful for managing user credentials persistently. ```javascript import { Client, SqliteAuthStore } from 'zaileys' const client = new Client({ sessionId: 'main', auth: new SqliteAuthStore() }) ``` -------------------------------- ### Install Storage Adapter Drivers (npm) Source: https://zeative.github.io/zaileys/llms-full.txt Install the necessary 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 ``` -------------------------------- ### Handle Client Events and Connection States Source: https://zeative.github.io/zaileys/getting-started This example demonstrates how to listen for 'text' events from the client and handle various connection states. It covers states like idle, connecting, qr-pending, pairing-pending, connected, reconnecting, and disconnected. ```javascript client.on('text', async (msg) => { // Handle incoming text messages }) ``` -------------------------------- ### Async Client Send Example Source: https://zeative.github.io/zaileys/rich-responses Example of an asynchronous client send operation. ```javascript await client.send( // ... ); ``` -------------------------------- ### Broadcast Method Example Source: https://zeative.github.io/zaileys/automation Example of using the broadcast method with a promotional message. ```javascript broadcast("Promo: 20% off all items this weekend.") ``` -------------------------------- ### Install Storage Adapter Drivers (pnpm) Source: https://zeative.github.io/zaileys/llms-full.txt Install the necessary driver for your chosen storage backend when using pnpm. With pnpm, 'better-sqlite3' is listed under 'onlyBuiltDependencies' to ensure its native build runs during installation. ```bash pnpm add better-sqlite3 pnpm add pg pnpm add redis ``` -------------------------------- ### Install Convex Peer Dependency (npm) Source: https://zeative.github.io/zaileys/llms-full.txt Install the 'convex' package using npm. ```bash npm i convex ``` -------------------------------- ### Wire Storage C7 into the Client Source: https://zeative.github.io/zaileys/storage Example demonstrating how to integrate Storage C7 into your client application. This snippet shows the basic structure for wiring. ```javascript self.__next_f.push([ 1, "a2:[\"$\",\"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:tex ``` -------------------------------- ### Initialize Zaileys Client with SQLite Stores Source: https://zeative.github.io/zaileys/storage Demonstrates how to import and instantiate the Zaileys Client, configuring it with SQLite-based authentication and message stores. Ensure the 'zaileys' package is installed. ```typescript import { Client, SqliteAuthStore, SqliteMessageStore } from 'zaileys' const client = new Client({ auth: new SqliteAuthStore({ database: './auth.db' }), store: new SqliteMessageStore({ database: './history.db' }), }) ``` -------------------------------- ### Install Zaileys with pnpm Source: https://zeative.github.io/zaileys/installation Use this command to install the Zaileys package using pnpm. ```bash pnpm add zaileys ``` -------------------------------- ### Install Zaileys with npm Source: https://zeative.github.io/zaileys/installation Use this command to install the Zaileys package using npm. ```bash npm i zaileys ``` -------------------------------- ### Social Post Card Example Source: https://zeative.github.io/zaileys/rich-responses Example of how to structure data for a social post card. ```json ["$","div",null,{"className":"x:m-0 x:border x:border-gray-300 x:px-4 x:py-2 x:dark:border-gray-600"},["$","td",null,{"children":"LaTeX formula (see below)","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"}],["$","tr",null,{"children":[["$","td",null,{"children":["$","code",null,{"className":"nextra-code","dir":"ltr","children":"```lang ... ```"}]},"className":"x:m-0 x:border x:border-gray-300 x:px-4 x:py-2 x:dark:border-gray-600"}],["$","td",null,{"children":"syntax-highlighted code block","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"}],["$","tr",null,{"children":[["$","td",null,{"children":["$","code",null,{"className":"nextra-code","dir":"ltr","children":"| a | b |"}]," followed by ",["$","code",null,{"className":"nextra-code","dir":"ltr","children":"|---|"}]],"className":"x:m-0 x:border x:border-gray-300 x:px-4 x:py-2 x:dark:border-gray-600"}],["$","td",null,{"children":"table","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"}],["$","tr",null,{"children":[["$","td",null,{"children":["$","code",null,{"className":"nextra-code","dir":"ltr","children":"![alt](url)"}]}," on its own line"],"className":"x:m-0 x:border x:border-gray-300 x:px-4 x:py-2 x:dark:border-gray-600"}],["$","td",null,{"children":"image (consecutive image lines → gallery)","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"}]],"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"}]],"className":"x:m-0 x:border x:border-gray-300 x:px-4 x:py-2 x:dark:border-gray-600"}] ``` -------------------------------- ### Registering a 'help' command Source: https://zeative.github.io/zaileys/client Example of registering a 'help' command with aliases 'h' and '?'. This command is asynchronous and demonstrates basic command registration. ```javascript client.command("help|h|?", async (ctx) => { }); ``` -------------------------------- ### Client Initialization and Connection Source: https://zeative.github.io/zaileys/api-reference Details on how to create a new client instance and manage the connection to the service. The client automatically connects unless configured otherwise. ```APIDOC ## `Client` ### Description Represents a client for interacting with the Zaileys service. It handles connection management and event listening. ### Methods #### `new Client(opts?)` ##### Description Construct a client; auto-connects unless `autoConnect: false`. ##### Signature `(options?: ClientOptions): Promise` #### `connect()` ##### Description Open the WhatsApp connection (QR or pairing). ##### Signature `(): Promise` ``` -------------------------------- ### Install better-sqlite3 via npm Source: https://zeative.github.io/zaileys/runtimes Install the better-sqlite3 adapter using npm. This is for SQLite databases. ```bash npm i better-sqlite3 # SQLite ``` -------------------------------- ### Full Zaileys Client Configuration Example Source: https://zeative.github.io/zaileys/llms-full.txt A comprehensive example demonstrating the full surface of ClientOptions, including session ID, authentication, phone number, custom stores, command prefix, citation settings, reconnect strategy, connection behavior, logging, and Baileys socket configuration. ```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') }) ``` -------------------------------- ### Initialize Client with QR Code (Bun) Source: https://zeative.github.io/zaileys/runtimes Example of initializing the Zaileys client using the 'qr' authentication method in Bun. ```typescript import { Client } from 'zaileys' const client = new Client({ authType: 'qr' }) await client.connect() ``` -------------------------------- ### Timing and Logging with Client.use Source: https://zeative.github.io/zaileys/commands This snippet demonstrates how to use the client.use function to time an operation and log the start time. It's useful for performance monitoring or debugging. ```javascript // 1. Outermost: timing client.use(async (ctx, next) => { const start = Date.now() await next() console.log(` ${start}`) }) ``` -------------------------------- ### Instantiate Client with PostgreSQL and Redis Stores Source: https://zeative.github.io/zaileys/storage This snippet shows how to create a new client instance, configuring it with PostgreSQL for authentication and Redis for message storage. It requires the 'Client', 'PostgresAuthStore', and 'RedisMessageStore' classes, along with a 'pool' and 'redis' client. ```javascript const client = new Client({ auth: new PostgresAuthStore({ pool }), store: new RedisMessageStore({ client: redis, namespace: 'wa-store' }), }); ``` -------------------------------- ### Initialize Zaileys Client with Redis Source: https://zeative.github.io/zaileys/storage Example of initializing the Zaileys client with a Redis store. Ensure Redis is running at the specified URL. ```javascript self.__next_f.push([ 1, "2d:\n [\"$\",\"p\",null,{\"className\":\"x:not-first:mt-6 x:leading-7\",\"children\":[\"If you omit both options, Zaileys uses safe defaults — see \",[\"$\",\"a\",null,{\"href\":\"#defaults\",\"className\":\"x:focus-visible:nextra-focus x:text-primary-600 x:underline x:hover:no-underline x:decoration-from-font x:[text-underline-position:from-font]\",\"children\":\"Defaults\"}]},\". For where \",[\"$\",\"code\",null,{\"className\":\"nextra-code\",\"dir\":\"ltr\",\"children\":\"auth\"}]}, {\"className\":\"x:not-first:mt-6 x:leading-7\",\"children\":[\" and \",[\"$\",\"code\",null,{\"className\":\"nextra-code\",\"dir\":\"ltr\",\"children\":\"store\"}]}, {\"className\":\"x:not-first:mt-6 x:leading-7\",\"children\":[\" sit among the other client options, see \",[\"$\",\"$L1b\",null,{\"href\":\"/configuration\",\"className\":\"x:focus-visible:nextra-focus x:text-primary-600 x:underline x:hover:no-underline x:decoration-from-font x:[text-underline-position:from-font]\",\"children\":\"Configuration\"}]},\".\" ]]} ]) self.__next_f.push([ 1, "2e:[\"$\",\"h2\",null,{\"id\":\"the-two-store-types\",\"className\":\"x:tracking-tight x:text-slate-900 x:dark:text-slate-100 x:font-semibold x:target:animate-[fade-in_1.5s] x:mt-10 x:border-b x:pb-1 x:text-3xl nextra-border\",\"children\":[\"The two store types\",[\"$\",\"$L7c\",null,{\"id\":\"the-two-store-types\"}]}]\n" ]) self.__next_f.push([ 1, "2f:[\"$\",\"table\",null,{\"className\":\"x:block x:overflow-x-auto nextra-scrollbar x:not-first:mt-6 x:p-0\",\"children\":[[\"$\",\"thead\",null,{\"children\":[[\"$\",\"tr\",null,{\"children\":[[\"$\",\"th\",null,{\"children\":\"Concern\",\"className\":\"x:m-0 x:border x:border-gray-300 x:px-4 x:py-2 x:font-semibold x:dark:border-gray-600\"},{\"$\",\"th\",null,{\"children\":\"Interface\",\"className\":\"x:m-0 x:border x:border-gray-300 x:px-4 x:py-2 x:font-semibold x:dark:border-gray-600\"},{\"$\",\"th\",null,{\"children\":\"What it holds\",\"className\":\"x:m-0 x:border x:border-gray-300 x:px-4 x:py-2 x:font-semibold x:dark:border-gray-600\"},{\"$\",\"th\",null,{\"children\":\"When it is written\",\"className\":\"x:m-0 x:border x:border-gray-300 x:px-4 x:py-2 x:font-semibold x:dark:border-gray-600\"}]}]}]],[\"$\",\"tbody\",null,{\"children\":[[\"$\",\"tr\",null,{\"children\":[[\"$\",\"td\",null,{\"children\":\"Session\",\"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\":\"AuthStore\"}],\" (a.k.a. \",[\"$\",\"code\",null,{\"className\":\"nextra-code\",\"dir\":\"ltr\",\"children\":\"AuthStoreBundle\"}],\")\"},{\"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\":\"creds.json\"}],\"-style credentials + Signal keys (pre-keys, sessions, sender keys, app-state sync keys, …)\"}]}]}]}]}]]) ``` -------------------------------- ### Client Initialization with Options Source: https://zeative.github.io/zaileys/configuration Shows how to initialize a Zaileys client by passing a ClientOptions object. This allows customization of various aspects like authentication and storage. ```javascript import { Client } from 'zaileys' const client = new Client({ // options }) ``` -------------------------------- ### Rendering Login QR Code Source: https://zeative.github.io/zaileys/events This example demonstrates how to handle the 'qr' event to display a login QR code. It shows options for printing the raw string or using a QR terminal for scannable output. ```javascript client.on('qr', ({ qrString, qrTerminal }) => { if (qrTerminal) { // Render QR code to terminal } else { // Print raw QR string or use a custom QR library } }) ``` -------------------------------- ### Initialize and Connect Client Source: https://zeative.github.io/zaileys/llms-full.txt Initializes a new client instance and sets up a listener for the 'qr' event to display the QR code for authentication. ```typescript const client = new Client() client.on('qr', ({ qrString }) => console.log('Scan QR:', qrString)) ``` -------------------------------- ### 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 the Zaileys package via npm specifier. ```typescript import { Client } from 'npm:zaileys' const client = new Client({ authType: 'qr' }) await client.connect() ``` -------------------------------- ### Configuration Example Source: https://zeative.github.io/zaileys/commands This snippet shows how to configure theme and notification settings using ctx.json. It demonstrates type casting for theme (string) and notify (boolean). ```javascript const cfg = ctx.json as { theme: string; notify: boolean; } | undefined; if (!cfg) { await ctx.reply("$L97\n$L98\n$L99"); } $L9a $L9b $L9c $L9d ``` -------------------------------- ### Install PostgreSQL Adapters with bun Source: https://zeative.github.io/zaileys/llms-full.txt Install the 'pg' package when using PostgreSQL storage adapters with bun. ```bash bun add pg # PostgreSQL adapters ``` -------------------------------- ### Connect the Client Source: https://zeative.github.io/zaileys/interactive This code snippet shows the basic structure for connecting a client, likely involving setting up event listeners or initial connection logic. The example is truncated. ```javascript const client = new Client(); client.on('message', async (msg) => { // Handle message }); client.login(process.env.DISCORD_TOKEN); ``` -------------------------------- ### Install Convex Adapters with yarn Source: https://zeative.github.io/zaileys/llms-full.txt Install the 'convex' package when using Convex storage adapters with yarn. ```bash yarn add convex # Convex adapters ``` -------------------------------- ### Install Redis Adapters with yarn Source: https://zeative.github.io/zaileys/llms-full.txt Install the 'redis' package when using Redis storage adapters with yarn. ```bash yarn add redis # Redis adapters ``` -------------------------------- ### Install PostgreSQL Adapters with yarn Source: https://zeative.github.io/zaileys/llms-full.txt Install the 'pg' package when using PostgreSQL storage adapters with yarn. ```bash yarn add pg # PostgreSQL adapters ``` -------------------------------- ### Client Initialization and Navigation Source: https://zeative.github.io/zaileys/storage This snippet demonstrates the initialization of a client and the management of navigation elements, including dynamic updates to the navigation structure. It's used for setting up the client-side application flow. ```javascript self.__next_f.push([1,"1e:T49e,""])self.__next_f.push([1,"M26.0015 6.9529C24.0021 6.03845 21.8787 5.37198 19.6623 5C19.3833 5.48048 19.0733 6.13144 18.8563 6.64292C16.4989 6.30193 14.1585 6.30193 11.8336 6.64292C11.6166 6.13144 11.2911 5.48048 11.0276 5C8.79575 5.37198 6.67235 6.03845 4.6869 6.9529C0.672601 12.8736 -0.41235 18.6548 0.130124 24.3585C2.79599 26.2959 5.36889 27.4739 7.89682 28.2489C8.51679 27.4119 9.07477 26.5129 9.55525 25.5675C8.64079 25.2265 7.77283 24.808 6.93587 24.312C7.15286 24.1571 7.36986 23.9866 7.57135 23.8161C12.6241 26.1255 18.0969 26.1255 23.0876 23.8161C23.3046 23.9866 23.5061 24.1571 23.7231 24.312C22.8861 24.808 22.0182 25.2265 21.1037 25.5675C21.5842 26.5129 22.1422 27.4119 22.7621 28.2489C25.2885 27.4739 27.8769 26.2959 30.5288 24.3585C31.1952 17.7559 29.4733 12.0212 26.0015 6.9529ZM10.2527 20.8402C8.73376 20.8402 7.49382 19.4608 7.49382 17.7714C7.49382 16.082 8.70276 14.7025 10.2527 14.7025C11.7871 14.7025 13.0425 16.082 13.0115 17.7714C13.0115 19.4608 11.7871 20.8402 10.2527 20.8402ZM20.4373 20.8402C18.9183 20.8402 17.6768 19.4608 17.6768 17.7714C17.6768 16.082 18.8873 14.7025 20.4373 14.7025C21.9717 14.7025 23.2271 16.082 23.1961 17.7714C23.1961 19.4608 21.9872 20.8402 20.4373 20.8402Z"]) ``` ```javascript self.__next_f.push([1,"17:[\"$\",\"header\",null,{\"className\":\"nextra-navbar x:sticky x:top-0 x:z-30 x:w-full x:bg-transparent x:print:hidden x:max-md:.[nextra-banner:not([class$=hidden])~\u0026]:top-(--nextra-banner-height)\",\"children\":[[ \"$\",\"div\",null,{\"className\":\"nextra-navbar-blur x:absolute x:-z-1 x:size-full nextra-border x:border-b x:backdrop-blur-md x:bg-nextra-bg/70\"}],[\"$\",\"nav\",null,{\"style\":{\"height\":\"var(--nextra-navbar-height)\"}\",\"className\":\"x:mx-auto x:flex x:max-w-(--nextra-content-width) x:items-center x:gap-4 x:pl-[max(env(safe-area-inset-left),1.5rem)] x:pr-[max(env(safe-area-inset-right),1.5rem)] x:justify-end\",\"children\":[[ \"$\",\"$L1b\",null,{\"href\":\"/\",\"className\":\"x:flex x:items-center x:me-auto x:transition-opacity x:focus-visible:nextra-focus x:hover:opacity-75\",\"children\":[ \"$\",\"span\",null,{\"style\":{\"display\":\"inline-flex\",\"alignItems\":\"center\",\"gap\":\"0.5rem\"}\",\"children\":[[ \"$\",\"img\",null,{\"src\":\"/zaileys/zaileys-clean.png\",\"alt\":\"Zaileys\",\"width\":28,\"height\":28,\"style\":{\"borderRadius\":6}}\,[ \"$\",\"b\",null,{\"children\":\"Zaileys\"}]]}]}]],[ \"$\",\"$L1c\",null,{\"className\":\"\",\"children\":[[ \"$\",\"a\",null,{\"href\":\"https://github.com/zeative/zaileys\",\"target\":\"_blank\",\"rel\":\"noreferrer\",\"children\":[[ \"$\",\"svg\",null,{\"fill\":\"currentColor\",\"viewBox\":\"3 3 18 18\",\"height\":\"24\",\"children\":[ \"$\",\"path\",null,{\"d\":\"$1d\"}]}]],\"className\":\"x:focus-visible:nextra-focus\"}],[ \"$\",\"a\",null,{\"href\":\"https://discord.gg/KBHhTTVUc5\",\"target\":\"_blank\",\"rel\":\"noreferrer\",\"children\":[[ \"$\",\"svg\",null,{\"fill\":\"currentColor\",\"viewBox\":\"0 5 30.67 23.25\",\"width\":\"24\",\"children\":[ \"$\",\"path\",null,{\"d\":\"$1e\"}]}]],\"className\":\"x:focus-visible:nextra-focus\"}],[\"$L1f\",\"$L20\",\"$L21\"]]]}]]]}" ] ``` -------------------------------- ### Install SQLite Adapters with yarn Source: https://zeative.github.io/zaileys/llms-full.txt Install the 'better-sqlite3' package when using SQLite storage adapters with yarn. ```bash yarn add better-sqlite3 # SQLite adapters ``` -------------------------------- ### Install PostgreSQL Adapters with pnpm Source: https://zeative.github.io/zaileys/llms-full.txt Install the 'pg' package when using PostgreSQL storage adapters with pnpm. ```bash pnpm add pg # PostgreSQL adapters ``` -------------------------------- ### Install SQLite Adapters with pnpm Source: https://zeative.github.io/zaileys/llms-full.txt Install the 'better-sqlite3' package when using SQLite storage adapters with pnpm. ```bash pnpm add better-sqlite3 # SQLite adapters ``` -------------------------------- ### Initialize Client with Pairing (CommonJS) Source: https://zeative.github.io/zaileys/runtimes Example of initializing the Zaileys client using the 'pairing' authentication method in a CommonJS environment. ```javascript const { Client } = require('zaileys') const client = new Client({ authType: 'pairing', phoneNumber: 628000000000, }) client.on('connection', ({ status }) => console.log(status)) client.connect() ```