WPPConnect/WA-JS is an open-source project with the aim of exporting functions from WhatsApp Web
npm install @wppconnect/wa-js







> WPPConnect/WA-JS is an open-source project with the aim of exporting functions from WhatsApp Web, which can be used to support the creation of any interaction, such as customer service, media sending, intelligence recognition based on phrases and many other things, use your imagination...





This project extracts some functions of WhatsApp sources.
After build, this project generates a file dist/wppconnect-wa.js to be used for injection in WhatsApp Web. When injected, it will expose a global variable named WPP.
Some parts of WPP variable:
- WPP.webpack - Scripts to export WhatsApp functions.
- WPP.whatsapp - Only exported WhatsApp functions.
- WPP.chat - Chat functions and events.
- ...
There are convention names for some exported modules:
- ...Model - Class for data structure (ClassModel, MsgModel)
- ...Collection - Class for collection of models (ChatCollection, MsgCollection)
- ...Store - Default and global instance of a collection (ChatStore, MsgStore)
WPP.conn.connect - Connect to WhatsApp WebWPP.conn.isAuthenticated - Check if the connection is authenticated
WPP.conn.logout - Logout from WhatsApp Web
WPP.conn.getBuildConstants - Current WhatsApp build constants
For the most up-to-date list of available functions, launch the project locally and run this in your browser console:
Object.keys(WPP.conn).sort()
WPP.chat.sendTextMessage - Send a text messageWPP.chat.sendFileMessage - Send a file message (medias in general [video, audio, image, pdf])
WPP.chat.get - Get chat details
WPP.chat.deleteMessage - Delete a message
For the most up-to-date list of available functions, launch the project locally and run this in your browser console:
Object.keys(WPP.chat).sort()
WPP.contact.get - Get contact detailsWPP.contact.getAllContacts - Get all contacts
WPP.contact.getStatus - Get status (about field in profile)
WPP.contact.getCommonGroups - Get groups in common with one contact
WPP.contact.getPnLidEntry - Get PN (Phone Number), Lid and Contact from local cache
For the most up-to-date list of available functions, launch the project locally and run this in your browser console:
Object.keys(WPP.contact).sort()
WPP.blocklist.blockContact - Block a contact
WPP.blocklist.unblockContact - Unblock a contact
WPP.blocklist.all - All blocked contacts
WPP.blocklist.isBlocked - Check if contact is blocked
For the most up-to-date list of available functions, launch the project locally and run this in your browser console:
Object.keys(WPP.blocklist).sort()
WPP.group.create - Create a new group
WPP.group.canAdd - Check if contact can be added to group
WPP.group.addParticipants - Add participants to a group
WPP.group.removeParticipants - Remove participants from a group.
WPP.group.canPromote - Check if contact can be promoted
WPP.group.promoteParticipants - Promote participants to admin
WPP.group.canDemote - Check if contact can be demoted
WPP.group.demoteParticipants - Demote participants from admin.
WPP.group.getGroupInfoFromInviteCode - Get group information from an invitation link or an invite code.
WPP.group.getAllGroups - Get all groups
For the most up-to-date list of available functions, launch the project locally and run this in your browser console:
Object.keys(WPP.group).sort()
WPP.chat.on('chat.new_message') - Event to dispatch on receive a new messageTo see all events, check: https://wppconnect.io/wa-js/types/ev.EventTypes.html
Steps to run locally:
``bashinstall the dependencies
npm install
Note: to run specific versions run:
`sh
npm run wa-source:cleannpm run build:prd
WA_VERSION="2.3000.1029560485" npm run launch:local
`To debug or inspect
wa-source folder, format the files to be easier to understand`sh
npm run wa-source:format
`$3
To compare changes between two WhatsApp Web versions, use the helper script:
Note: You need to run locally in multiple versions to download the scripts to wa-source folder, otherwise will not have anything to compare. To do it use:
WA_VERSION="`bash
Compare two versions (overview of module differences)
./scripts/compare-wa-versions.sh 2.3000.1031980585 2.3000.1031992593Compare a specific module between versions
./scripts/compare-wa-versions.sh 2.3000.1031980585 2.3000.1031992593 WAWebUpdateUnreadChatActionList available versions
./scripts/compare-wa-versions.sh
`This is useful for:
- Tracking API changes between WhatsApp Web updates
- Identifying when function signatures changed
- Finding new or removed modules
How to use this project
Basically, you need to inject the
wppconnect-wa.js file into the browser after WhatsApp page load.$3
`javascript
// ==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...
})();
`$3
`typescript
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();
``Copyright 2021 WPPConnect Team
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.