WPPConnect/WA-JS: Exporting WhatsApp Web Functions for Automation

Summary
WPPConnect/WA-JS is an open-source TypeScript project designed to export functions from WhatsApp Web. It enables developers to create custom interactions, automate tasks, and build powerful integrations for customer service, media sending, and more. With a comprehensive API, it simplifies the process of interacting with WhatsApp Web programmatically.
Repository Info
Tags
Click on any tag to explore related repositories
Introduction
WPPConnect/WA-JS is an open-source TypeScript project dedicated to exporting core functions from WhatsApp Web. This powerful tool empowers developers to build sophisticated automation solutions, custom interactions, and seamless integrations with WhatsApp. Whether you're looking to create customer service bots, automate media sending, or implement intelligent recognition systems, WA-JS provides the foundational capabilities. With a vibrant community, boasting over 580 stars and 170 forks on GitHub, it stands as a robust and actively maintained resource for WhatsApp Web automation.
Installation
To get started with WPPConnect/WA-JS, you can follow these simple steps:
First, install the project dependencies:
npm install
Next, build the JavaScript files. For production, use:
npm run build:prd
For development, you can use npm run build:dev
.
To launch a local browser with automatic injection for testing:
npm run launch:local
Examples
WPPConnect/WA-JS is designed to be injected into the browser where WhatsApp Web is running. Here are common ways to utilize it:
Using TamperMonkey or GreaseMonkey:
For browser extensions, you can use a user script to inject wppconnect-wa.js
:
// ==UserScript==
// @name WA-JS Teste
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Simple example of WA-JS
// @author You
// @match https://web.whatsapp.com/*
// @icon https://www.google.com/s2/favicons?domain=whatsapp.com
// @require https://github.com/wppconnect-team/wa-js/releases/download/nightly/wppconnect-wa.js
// @grant none
// ==/UserScript==
/* globals WPP */
(function () {
'use strict';
WPP.webpack.onReady(function () {
alert('Ready to use WPPConnect WA-JS');
});
// Your code here...
})();
Using Playwright for Headless Automation:
For programmatic control in Node.js environments, Playwright is an excellent choice:
import * as playwright from 'playwright-chromium';
async function start() {
const browser = await playwright.chromium.launch();
const page = await browser.newPage();
await page.goto('https://web.whatsapp.com/');
await page.addScriptTag({
path: require.resolve('@wppconnect/wa-js'),
});
// Wait WA-JS load
await page.waitForFunction(() => window.WPP?.isReady);
// Evaluating code: See https://playwright.dev/docs/evaluating/
const isAuthenticated: string = await page.evaluate(() =>
WPP.conn.isAuthenticated()
);
// Sending message: See https://playwright.dev/docs/evaluating/
const sendResult: string = await page.evaluate(
(to, message) => WPP.chat.sendTextMessage(to, message),
to,
message
);
}
start();
Why Use WPPConnect/WA-JS?
WPPConnect/WA-JS offers a robust and flexible solution for anyone looking to interact with WhatsApp Web programmatically. Its key advantages include:
- Comprehensive API: Access a wide range of WhatsApp functionalities, including connection status (
WPP.conn
), chat operations (WPP.chat.sendTextMessage
,WPP.chat.getChat
), contact management (WPP.contact.getContact
,WPP.contact.blockContact
), and group interactions (WPP.group.createGroup
,WPP.group.addParticipant
). - Event-Driven Architecture: Respond to real-time events, such as new messages, using
WPP.chat.on('chat.new_message')
, enabling dynamic and responsive applications. - Flexible Integration: Easily integrate with various environments, from browser user scripts (TamperMonkey, GreaseMonkey) to headless browser automation tools like Playwright.
- Open-Source and Community Support: Benefit from an active open-source community, continuous development, and a wealth of shared knowledge and examples.
- Powerful Automation: Build sophisticated bots and automation workflows for customer support, marketing, data extraction, and more, leveraging the full power of WhatsApp Web.