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 artificial and many other things, use your imagination...
Our online channels
How does it work
This project extract some functions of WhatsApp sources, that uses webpack.
After build, this project generate a file dist/wppconnect-wa.js
to be used for injection in WhatsApp Web. When injected, it will explose a global variable named WPP
.
Some parts of WPP
variable:
WPP.webpack
- Scripts to exports WhatsApp functions.WPP.whatsapp
- Only exported WhatsApp functions.WPP.chat
- Chat functions and events.- ...
Exported WhatsApp modules
There are a convection name 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
)
Development
Steps to run locally:
npm install
npm run wa-source
npm run build:prd
npm run launch:local
How to use this project
Basicaly, you need to inject the wppconnect-wa.js
file into the browser after WhatsApp page load.
TamperMonkey or GreaseMonkey
(function () {
'use strict';
WPP.webpack.onReady(function () {
alert('Ready to use WPPConnect WA-JS');
});
})();
Playwright
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'),
});
await page.waitForFunction(() => window.WPP?.isReady);
const isAuthenticated: string = await page.evaluate(() =>
WPP.conn.isAuthenticated()
);
const sendResult: string = await page.evaluate(
(to, message) => WPP.chat.sendTextMessage(to, message),
to,
message
);
}
start();
License
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.