### Install and Import wa-multi-session Source: https://github.com/mimamch/wa-multi-session/blob/master/readme.md Instructions for installing the package via npm and importing the necessary classes using either ES Modules or CommonJS syntax. ```bash npm install wa-multi-session@latest ``` ```typescript import { Whatsapp, SQLiteAdapter } from "wa-multi-session"; ``` ```javascript const { Whatsapp, SQLiteAdapter } = require("wa-multi-session"); ``` -------------------------------- ### Complete Bot Example Source: https://context7.com/mimamch/wa-multi-session/llms.txt A full example demonstrating a command-based WhatsApp bot with multiple features, including message reception, command parsing, and sending various message types. ```APIDOC ## Complete Bot Example ### Description This code demonstrates a complete WhatsApp bot using the `wa-multi-session` library. It includes functionalities for handling incoming messages, processing commands like `!ping`, `!help`, `!poll`, and saving received images. ### Method N/A (This is a script example, not a specific API endpoint) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ## Starting a Session ### Description This section shows how to start a new WhatsApp session for the bot. ### Method N/A (Script execution) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Implement a Command-Based WhatsApp Bot Source: https://context7.com/mimamch/wa-multi-session/llms.txt This example demonstrates how to initialize a WhatsApp bot with a SQLite adapter, handle incoming messages, process commands like !ping and !poll, and save received media files. It utilizes the library's event-driven architecture to manage session states and message interactions. ```typescript import { Whatsapp, SQLiteAdapter } from "wa-multi-session"; import fs from "fs"; const whatsapp = new Whatsapp({ adapter: new SQLiteAdapter(), onConnecting: (sessionId) => console.log(`[${sessionId}] Connecting...`), onConnected: (sessionId) => console.log(`[${sessionId}] Ready!`), onDisconnected: (sessionId) => console.log(`[${sessionId}] Disconnected`), onMessageReceived: async (msg) => { if (msg.key.fromMe) return; const sender = msg.key.participant || msg.key.remoteJid!; const text = msg.message?.conversation || msg.message?.extendedTextMessage?.text || ""; const sessionId = msg.sessionId; await whatsapp.readMessage({ sessionId, key: msg.key }); const command = text.toLowerCase().trim(); if (command === "!ping") { await whatsapp.sendText({ sessionId, to: sender, text: "🏓 Pong!", answering: msg }); } else if (command === "!help") { await whatsapp.sendText({ sessionId, to: sender, text: "*Available Commands:*\n!ping - Check bot status\n!help - Show this help\n!poll - Create a sample poll\n!sticker - Get a sticker" }); } else if (command === "!poll") { await whatsapp.sendPoll({ sessionId, to: sender, poll: { name: "How's your day going?", values: ["Great! 😊", "Good 👍", "Okay 😐", "Not great 😕"], selectableCount: 1 } }); } else if (msg.message?.imageMessage) { const filename = `./media/img_${Date.now()}.jpg`; await msg.saveImage(filename); await whatsapp.sendText({ sessionId, to: sender, text: `✅ Image saved! File: ${filename}`, answering: msg }); } }, }); async function main() { console.log("Starting WhatsApp Bot..."); await whatsapp.startSession("bot-session", { printQR: true, onConnected: () => console.log("Bot is online!") }); } main().catch(console.error); ``` -------------------------------- ### Start WhatsApp Session with Pairing Code Source: https://context7.com/mimamch/wa-multi-session/llms.txt Starts a WhatsApp session using phone number pairing code authentication, which is currently in beta. This method is useful when QR code scanning is not feasible. It requires the phone number with the country code and provides a callback for receiving the pairing code. ```typescript const session = await whatsapp.startSessionWithPairingCode("session2", { // Phone number with country code (no + or spaces) phoneNumber: "6281234567890", // Callback when pairing code is received onPairingCode: (code) => { console.log(`Enter this code on your phone: ${code}`); // Code format: "XXXX-XXXX" - enter in WhatsApp > Linked Devices > Link with phone number }, onConnected: () => { console.log("Session connected via pairing code!"); }, onDisconnected: () => { console.log("Session disconnected"); } }); ``` -------------------------------- ### GET /isExist Source: https://context7.com/mimamch/wa-multi-session/llms.txt Verifies if a specific contact or group exists on WhatsApp. ```APIDOC ## GET /isExist ### Description Checks if a phone number is registered on WhatsApp or if a group JID is valid. ### Method GET ### Endpoint /isExist ### Parameters #### Query Parameters - **sessionId** (string) - Required - The active session identifier. - **to** (string) - Required - The JID or phone number to check. - **isGroup** (boolean) - Optional - Flag to check for group existence. ### Response #### Success Response (200) - **exists** (boolean) - Returns true if the contact/group exists. ``` -------------------------------- ### Manage WhatsApp Sessions Source: https://github.com/mimamch/wa-multi-session/blob/master/readme.md Methods to start sessions via QR code or pairing code, retrieve session IDs, and fetch session data by ID. ```typescript const session = await whatsapp.startSession("session1", { printQR: true }); const pairingSession = await whatsapp.startSessionWithPairingCode("mysessionid", { phoneNumber: "6281234567890", onPairingCode(code) { console.log(`Pairing Code: ${code}`); }, }); const sessions = await whatsapp.getSessionsIds(); const sessionData = await whatsapp.getSessionById("session1"); ``` -------------------------------- ### Send Messages and Media Source: https://github.com/mimamch/wa-multi-session/blob/master/readme.md Examples of sending various message types including text, images, videos, documents, voice notes, and polls. ```typescript await whatsapp.sendText({ sessionId: "session1", to: "6281234567890", text: "Hi!" }); const image = fs.readFileSync("./myimage.png"); await whatsapp.sendImage({ sessionId: "session1", to: "6281234567890", media: image, text: "Caption" }); await whatsapp.sendPoll({ sessionId: "session1", to: "6281234567890", poll: { name: "Q?", values: ["A", "B"], selectableCount: 1 } }); ``` -------------------------------- ### Start WhatsApp Session with QR Code Source: https://context7.com/mimamch/wa-multi-session/llms.txt Initiates a new WhatsApp session using QR code authentication. This method prints the QR code to the terminal by default and allows for per-session event callbacks. It returns a session object upon successful connection. ```typescript const session = await whatsapp.startSession("session1", { // Print QR code to terminal printQR: true, // Per-session callbacks onQRUpdated: (qr) => { console.log("QR Code updated, scan with WhatsApp"); }, onConnecting: () => { console.log("Connecting to WhatsApp..."); }, onConnected: () => { console.log("Session connected!"); }, onDisconnected: () => { console.log("Session disconnected"); }, onMessageReceived: (msg) => { console.log("Received:", msg.message?.conversation); }, onMessageUpdated: (data) => { console.log("Message status:", data.messageStatus); } }); // Session is ready when connected // QR code appears in terminal - scan with WhatsApp mobile app ``` -------------------------------- ### GET /getProfile Source: https://context7.com/mimamch/wa-multi-session/llms.txt Retrieves profile picture URL and status for a contact or group. ```APIDOC ## GET /getProfile ### Description Fetches the profile picture URL and status information for a given JID. ### Method GET ### Endpoint /getProfile ### Parameters #### Query Parameters - **sessionId** (string) - Required - The active session identifier. - **target** (string) - Required - The JID of the contact or group. ### Response #### Success Response (200) - **profilePictureUrl** (string) - URL of the profile image. - **status** (object) - Status text and timestamp. ``` -------------------------------- ### Get Profile Information - TypeScript Source: https://context7.com/mimamch/wa-multi-session/llms.txt Retrieves the profile picture URL and status message of a contact or group. Requires session ID and the target JID (Just-In-Time Identification). Returns null if information is unavailable. ```typescript const profile = await whatsapp.getProfile({ sessionId: "session1", target: "6281234567890@s.whatsapp.net", // JID format }); console.log("Profile Picture:", profile.profilePictureUrl); // Output: "https://pps.whatsapp.net/v/..." or null if not available console.log("Status:", profile.status); // Output: { status: "Hey there! I'm using WhatsApp", setAt: Date } or null ``` -------------------------------- ### Manage WhatsApp Sessions Source: https://context7.com/mimamch/wa-multi-session/llms.txt Provides methods for retrieving, inspecting, and deleting active WhatsApp sessions. You can get a list of all session IDs, retrieve specific session data including its status and socket availability, and delete a session to log out and remove its credentials. ```typescript // Get all active session IDs const sessionIds = await whatsapp.getSessionsIds(); console.log("Active sessions:", sessionIds); // Output: ["session1", "session2", "session3"] // Get specific session data const session = await whatsapp.getSessionById("session1"); if (session) { console.log("Session status:", session.status); // Status: "connecting" | "connected" | "disconnected" console.log("Socket available:", !!session.sock); } // Delete/logout a session (removes credentials) await whatsapp.deleteSession("session1"); console.log("Session deleted and logged out"); // Manually load sessions from storage await whatsapp.load(); ``` -------------------------------- ### Initialize WhatsApp Instance Source: https://github.com/mimamch/wa-multi-session/blob/master/readme.md Configures a new WhatsApp instance with a SQLite adapter and optional lifecycle event listeners for connection status. ```typescript const whatsapp = new Whatsapp({ adapter: new SQLiteAdapter(), onConnecting: (sessionId) => { console.log(`[${sessionId}] Connecting...`); }, onConnected: (sessionId) => { console.log(`[${sessionId}] Connected`); }, onDisconnected: (sessionId) => { console.log(`[${sessionId}] Disconnected`); }, }); ``` -------------------------------- ### Handle Incoming Messages and Media Source: https://github.com/mimamch/wa-multi-session/blob/master/readme.md Demonstrates how to listen for incoming messages, send automated replies, and save received media files to the local filesystem. ```typescript const whatsapp = new Whatsapp({ adapter: new SQLiteAdapter(), onMessageReceived: async (msg) => { if (msg.message?.imageMessage) msg.saveImage("./myimage.jpg"); if (msg.message?.conversation) { await whatsapp.sendText({ sessionId: msg.sessionId, to: msg.key.remoteJid!, text: "Received!" }); } } }); ``` -------------------------------- ### Configure SQLiteAdapter for Session Persistence Source: https://context7.com/mimamch/wa-multi-session/llms.txt Shows how to initialize the built-in SQLiteAdapter with default or custom paths and integrate it into the Whatsapp instance to persist session credentials and state. ```typescript import { SQLiteAdapter } from "wa-multi-session"; const customAdapter = new SQLiteAdapter({ databasePath: "/var/data/whatsapp/sessions.db" }); const whatsapp = new Whatsapp({ adapter: customAdapter, autoLoad: true }); ``` -------------------------------- ### Implement Custom Storage Adapter Source: https://context7.com/mimamch/wa-multi-session/llms.txt Provides a template for creating custom storage backends by extending the base Adapter class, illustrated with a Redis implementation for data persistence. ```typescript import { Adapter } from "wa-multi-session"; class RedisAdapter extends Adapter { private redis: RedisClient; constructor(redisUrl: string) { super(); this.redis = new RedisClient(redisUrl); } async writeData(sessionId: string, key: string, category: string, data: string): Promise { await this.redis.hSet(`wa:${sessionId}`, key, data); } async readData(sessionId: string, key: string): Promise { return await this.redis.hGet(`wa:${sessionId}`, key); } async deleteData(sessionId: string, key: string): Promise { await this.redis.hDel(`wa:${sessionId}`, key); } async clearData(sessionId: string): Promise { await this.redis.del(`wa:${sessionId}`); } async listSessions(): Promise { const keys = await this.redis.keys("wa:*"); return keys.map(k => k.replace("wa:", "")); } } ``` -------------------------------- ### Initialize Whatsapp Class Constructor Source: https://context7.com/mimamch/wa-multi-session/llms.txt Initializes the main Whatsapp class for managing multiple sessions. It requires a credential storage adapter (e.g., SQLiteAdapter) and supports various event callbacks for connection status and message handling. Dependencies include 'wa-multi-session' and 'SQLiteAdapter'. ```typescript import { Whatsapp, SQLiteAdapter } from "wa-multi-session"; const whatsapp = new Whatsapp({ // Required: Adapter for storing credentials adapter: new SQLiteAdapter({ databasePath: "./my_credentials/database.db" // Optional custom path }), // Optional: Auto-load existing sessions on startup (default: true) autoLoad: true, // Optional: Debug level for logging debugLevel: "silent", // "silent" | "fatal" | "error" | "warn" | "info" | "debug" | "trace" // Optional: Global event callbacks onConnecting: (sessionId) => { console.log(`[${sessionId}] Connecting...`); }, onConnected: (sessionId) => { console.log(`[${sessionId}] Connected successfully!`); }, onDisconnected: (sessionId) => { console.log(`[${sessionId}] Disconnected`); }, onQRUpdated: (data) => { console.log(`[${data.sessionId}] New QR Code: ${data.qr}`); }, onPairingCode: (sessionId, code) => { console.log(`[${sessionId}] Pairing Code: ${code}`); }, onMessageReceived: async (msg) => { console.log(`[${msg.sessionId}] New message from: ${msg.key.remoteJid}`); }, onMessageUpdated: (data) => { console.log(`[${data.sessionId}] Message status: ${data.messageStatus}`); // Status: "pending" | "server" | "delivered" | "read" | "played" | "error" } }); ``` -------------------------------- ### Handle Incoming WhatsApp Messages Source: https://context7.com/mimamch/wa-multi-session/llms.txt Demonstrates how to process incoming messages, filter out status updates, mark messages as read, echo text messages, and save various media types like images, videos, and documents. ```typescript const whatsapp = new Whatsapp({ adapter: new SQLiteAdapter(), onMessageReceived: async (msg) => { if (msg.key.fromMe || msg.key.remoteJid?.includes("status")) return; const sender = msg.key.participant || msg.key.remoteJid!; await whatsapp.readMessage({ sessionId: msg.sessionId, key: msg.key }); if (msg.message?.conversation || msg.message?.extendedTextMessage?.text) { const text = msg.message.conversation || msg.message.extendedTextMessage?.text; await whatsapp.sendTypingIndicator({ sessionId: msg.sessionId, to: sender, duration: 1000 }); await whatsapp.sendText({ sessionId: msg.sessionId, to: sender, text: `You said: ${text}`, answering: msg }); } if (msg.message?.imageMessage) await msg.saveImage("./downloads/received_image.jpg"); if (msg.message?.videoMessage) await msg.saveVideo("./downloads/received_video.mp4"); if (msg.message?.documentMessage) await msg.saveDocument("./downloads/received_document"); if (msg.message?.audioMessage) await msg.saveAudio("./downloads/received_audio.mp3"); }, onMessageUpdated: (data) => { console.log(`Message ${data.key.id} status: ${data.messageStatus}`); } }); ``` -------------------------------- ### Send Audio and Voice Notes - TypeScript Source: https://context7.com/mimamch/wa-multi-session/llms.txt Sends audio files either as regular audio files or as voice notes (push-to-talk style). Accepts file buffers or URLs. ```typescript import fs from "fs"; // Send as voice note (PTT - Push To Talk) const audioBuffer = fs.readFileSync("./audio/recording.mp3"); await whatsapp.sendAudio({ sessionId: "session1", to: "6281234567890", media: audioBuffer, asVoiceNote: true, // Send as voice note with waveform }); // Send as regular audio file await whatsapp.sendAudio({ sessionId: "session1", to: "6281234567890", media: audioBuffer, asVoiceNote: false, // Send as audio file }); // Send from URL await whatsapp.sendAudio({ sessionId: "session1", to: "6281234567890", media: "https://example.com/audio.mp3", asVoiceNote: true, }); ``` -------------------------------- ### POST /sendAudio Source: https://context7.com/mimamch/wa-multi-session/llms.txt Sends audio files, with an option to send as a voice note (PTT). ```APIDOC ## POST /sendAudio ### Description Sends audio content. Can be sent as a standard audio file or as a voice note. ### Method POST ### Endpoint /sendAudio ### Parameters #### Request Body - **sessionId** (string) - Required - The active session ID. - **to** (string) - Required - Recipient identifier. - **media** (buffer/string) - Required - Audio file buffer or URL. - **asVoiceNote** (boolean) - Optional - If true, sends as a push-to-talk voice note. ``` -------------------------------- ### POST /sendDocument Source: https://context7.com/mimamch/wa-multi-session/llms.txt Sends a document file with a specified filename and extension. ```APIDOC ## POST /sendDocument ### Description Sends a document file. The system automatically detects the MIME type based on the filename extension. ### Method POST ### Endpoint /sendDocument ### Parameters #### Request Body - **sessionId** (string) - Required - The active session ID. - **to** (string) - Required - Recipient identifier. - **media** (buffer/string) - Required - File buffer or URL. - **filename** (string) - Required - Name of the file including extension. - **text** (string) - Optional - Accompanying message text. ``` -------------------------------- ### Send Video Message - TypeScript Source: https://context7.com/mimamch/wa-multi-session/llms.txt Sends a video file with an optional caption. The video can be provided as a file buffer or a URL. ```typescript import fs from "fs"; // Send video from file const videoBuffer = fs.readFileSync("./videos/clip.mp4"); await whatsapp.sendVideo({ sessionId: "session1", to: "6281234567890", media: videoBuffer, text: "Check this video out!", }); // Send video from URL await whatsapp.sendVideo({ sessionId: "session1", to: "6281234567890", media: "https://example.com/video.mp4", text: "Video from URL", }); ``` -------------------------------- ### POST /sendImage Source: https://context7.com/mimamch/wa-multi-session/llms.txt Sends an image file or URL to a recipient with an optional caption. ```APIDOC ## POST /sendImage ### Description Sends an image using a file buffer or a public URL. ### Method POST ### Endpoint /sendImage ### Parameters #### Request Body - **sessionId** (string) - Required - The active session ID. - **to** (string) - Required - Recipient identifier. - **media** (buffer/string) - Required - Image file buffer or URL. - **text** (string) - Optional - Caption for the image. - **isGroup** (boolean) - Optional - Set to true for group messages. ### Request Example { "sessionId": "session1", "to": "6281234567890", "media": "https://example.com/image.jpg", "text": "Check this out!" } ``` -------------------------------- ### Send Sticker Message - TypeScript Source: https://context7.com/mimamch/wa-multi-session/llms.txt Sends a sticker image, with WebP format recommended. Stickers can be sent from file buffers or URLs, and can be used to reply to messages. ```typescript import fs from "fs"; // Send sticker from file const stickerBuffer = fs.readFileSync("./stickers/happy.webp"); await whatsapp.sendSticker({ sessionId: "session1", to: "6281234567890", media: stickerBuffer, }); // Send sticker from URL await whatsapp.sendSticker({ sessionId: "session1", to: "6281234567890", media: "https://example.com/sticker.webp", }); // Reply with sticker await whatsapp.sendSticker({ sessionId: "session1", to: "6281234567890", media: stickerBuffer, answering: originalMessage, }); ``` -------------------------------- ### POST /readMessage Source: https://context7.com/mimamch/wa-multi-session/llms.txt Marks a specific received message as read. ```APIDOC ## POST /readMessage ### Description Marks a received message as read, triggering the blue checkmark status. ### Method POST ### Endpoint /readMessage ### Request Body - **sessionId** (string) - Required - The active session identifier. - **key** (object) - Required - The unique message key object. ### Request Example { "sessionId": "session1", "key": { "id": "ABC12345" } } ``` -------------------------------- ### POST /sendTypingIndicator Source: https://context7.com/mimamch/wa-multi-session/llms.txt Displays a typing indicator to the recipient for a specified duration. ```APIDOC ## POST /sendTypingIndicator ### Description Displays the 'typing...' status to the recipient for a defined duration in milliseconds. ### Method POST ### Endpoint /sendTypingIndicator ### Request Body - **sessionId** (string) - Required - The active session identifier. - **to** (string) - Required - The recipient JID or phone number. - **duration** (number) - Required - Duration in milliseconds. ### Request Example { "sessionId": "session1", "to": "6281234567890", "duration": 3000 } ``` -------------------------------- ### Send Document File - TypeScript Source: https://context7.com/mimamch/wa-multi-session/llms.txt Sends a document file with a specified filename. The MIME type is automatically detected from the filename extension. Supports file buffers and URLs. ```typescript import fs from "fs"; // Send PDF document const pdfBuffer = fs.readFileSync("./docs/report.pdf"); await whatsapp.sendDocument({ sessionId: "session1", to: "6281234567890", media: pdfBuffer, filename: "quarterly_report.pdf", // Must include extension text: "Here's the report you requested", }); // Send Word document from URL await whatsapp.sendDocument({ sessionId: "session1", to: "6281234567890", media: "https://example.com/document.docx", filename: "contract.docx", text: "Please review this document", }); // Send spreadsheet to group const excelBuffer = fs.readFileSync("./data/sales.xlsx"); await whatsapp.sendDocument({ sessionId: "session1", to: "123456789012345678@g.us", isGroup: true, media: excelBuffer, filename: "sales_data.xlsx", }); ``` -------------------------------- ### POST /sendText Source: https://context7.com/mimamch/wa-multi-session/llms.txt Sends a plain text message to an individual contact or group, with optional support for quoting previous messages. ```APIDOC ## POST /sendText ### Description Sends a plain text message to a specific contact or group JID. ### Method POST ### Endpoint /sendText ### Parameters #### Request Body - **sessionId** (string) - Required - The ID of the active WhatsApp session. - **to** (string) - Required - The recipient phone number or group JID. - **text** (string) - Required - The message content. - **isGroup** (boolean) - Optional - Set to true if sending to a group. - **answering** (object) - Optional - The original message object to quote/reply to. ### Request Example { "sessionId": "session1", "to": "6281234567890", "text": "Hello!" } ### Response #### Success Response (200) - **status** (string) - Success status message. #### Response Example { "status": "success" } ``` -------------------------------- ### Send Image Message - TypeScript Source: https://context7.com/mimamch/wa-multi-session/llms.txt Sends an image with an optional caption. The image can be provided as a file buffer or a URL. Supports replying to messages. ```typescript import fs from "fs"; // Send image from file buffer const imageBuffer = fs.readFileSync("./photos/vacation.jpg"); await whatsapp.sendImage({ sessionId: "session1", to: "6281234567890", media: imageBuffer, text: "Check out this photo!", // Caption }); // Send image from URL await whatsapp.sendImage({ sessionId: "session1", to: "6281234567890", media: "https://example.com/image.jpg", text: "Image from the web", }); // Send to group with reply await whatsapp.sendImage({ sessionId: "session1", to: "123456789012345678@g.us", isGroup: true, media: imageBuffer, text: "Group photo", answering: messageToReply, }); ``` -------------------------------- ### Show Typing Indicator - TypeScript Source: https://context7.com/mimamch/wa-multi-session/llms.txt Displays a 'typing...' indicator to the recipient for a specified duration. Useful for enhancing user experience before sending a message. Requires session ID, recipient, and duration in milliseconds. ```typescript // Show typing for 3 seconds await whatsapp.sendTypingIndicator({ sessionId: "session1", to: "6281234567890", duration: 3000, // Duration in milliseconds }); // Use before sending message for natural feel await whatsapp.sendTypingIndicator({ sessionId: "session1", to: "6281234567890", duration: 2000, }); await whatsapp.sendText({ sessionId: "session1", to: "6281234567890", text: "I've been thinking about your question...", }); ``` -------------------------------- ### POST /sendPoll Source: https://context7.com/mimamch/wa-multi-session/llms.txt Creates and sends a poll message to a contact or group with configurable options. ```APIDOC ## POST /sendPoll ### Description Creates and sends a poll with multiple options to a specific recipient or group. ### Method POST ### Endpoint /sendPoll ### Request Body - **sessionId** (string) - Required - The active session identifier. - **to** (string) - Required - The recipient JID or phone number. - **isGroup** (boolean) - Optional - Set to true if sending to a group. - **poll** (object) - Required - Contains poll name, values (array), and selectableCount (number). ### Request Example { "sessionId": "session1", "to": "6281234567890", "poll": { "name": "Favorite language?", "values": ["JS", "Python"], "selectableCount": 1 } } ``` -------------------------------- ### Check Contact/Group Existence - TypeScript Source: https://context7.com/mimamch/wa-multi-session/llms.txt Verifies if a phone number is registered on WhatsApp or if a given group ID exists. Useful for validating recipients before sending messages to prevent errors. Requires session ID, recipient identifier, and a boolean indicating if it's a group. ```typescript // Check individual contact const contactExists = await whatsapp.isExist({ sessionId: "session1", to: "6281234567890", isGroup: false, }); console.log("Contact exists:", contactExists); // true or false // Check group const groupExists = await whatsapp.isExist({ sessionId: "session1", to: "123456789012345678@g.us", isGroup: true, }); console.log("Group exists:", groupExists); // Use before sending to avoid errors if (await whatsapp.isExist({ sessionId: "session1", to: "6281234567890" })) { await whatsapp.sendText({ sessionId: "session1", to: "6281234567890", text: "Hello!", }); } else { console.log("Number not registered on WhatsApp"); } ``` -------------------------------- ### Mark Message as Read - TypeScript Source: https://context7.com/mimamch/wa-multi-session/llms.txt Marks a received message as read, indicated by blue checkmarks. Requires session ID and the message key. Can be implemented within a message handler to automatically mark messages upon receipt. ```typescript // Mark single message as read await whatsapp.readMessage({ sessionId: "session1", key: receivedMessage.key, // proto.IMessageKey from received message }); // Example in message handler const whatsapp = new Whatsapp({ adapter: new SQLiteAdapter(), onMessageReceived: async (msg) => { // Mark as read immediately await whatsapp.readMessage({ sessionId: msg.sessionId, key: msg.key, }); // Process message... } }); ``` -------------------------------- ### Send Poll Message - TypeScript Source: https://context7.com/mimamch/wa-multi-session/llms.txt Creates and sends a poll message with single or multiple choice options. Requires session ID, recipient, and poll configuration including name, values, and selectable count. ```typescript await whatsapp.sendPoll({ sessionId: "session1", to: "6281234567890", poll: { name: "What's your favorite programming language?", values: ["JavaScript", "Python", "Go", "Rust", "TypeScript"], selectableCount: 1, // Only one choice allowed }, }); // Multiple choice poll await whatsapp.sendPoll({ sessionId: "session1", to: "123456789012345678@g.us", isGroup: true, poll: { name: "Which features should we prioritize?", values: ["Dark Mode", "Notifications", "Offline Mode", "Multi-language"], selectableCount: 3, // Allow up to 3 selections }, }); ``` -------------------------------- ### Send Text Message - TypeScript Source: https://context7.com/mimamch/wa-multi-session/llms.txt Sends a plain text message to an individual contact or group. Supports replying to messages by quoting them. ```typescript await whatsapp.sendText({ sessionId: "session1", to: "6281234567890", // Phone number with country code text: "Hello! This is a message from the server.", }); // Send to group await whatsapp.sendText({ sessionId: "session1", to: "123456789012345678@g.us", // Group JID isGroup: true, text: "Hello group members!", }); // Reply to a message (quote) await whatsapp.sendText({ sessionId: "session1", to: "6281234567890", text: "This is a reply to your message", answering: originalMessage, // The WAMessage to quote }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.