Giter VIP home page Giter VIP logo

wa-js's Introduction

WPPConnect/WA-JS

npm version Downloads Average time to resolve an issue Percentage of issues still open

Build Status Build Status Lint Status release-it

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

Discord Telegram Group WhatsApp Group YouTube

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:

# install the depencencies
npm install

# download whatsapp javascript and prettify (optional)
npm run wa-source

# build javascript files
npm run build:prd # or build:dev for development

# lauch a local browser with automatic injection
npm run launch:local

# or only run in VSCode

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

// ==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...
})();

Playwright

import * as playwright from 'playwright-chromium';

async function start() {
  const browser = await playwright.chromium.launch();
  const page = 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.auth.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();

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.

wa-js's People

Contributors

renovate[bot] avatar edgardmessias avatar dependabot[bot] avatar github-actions[bot] avatar icleitoncosta avatar renat473 avatar renovate-bot avatar ghsgabriel avatar moskoweb avatar edupoli avatar igordepaula avatar keyurboss avatar rhutikcodes avatar rustystriker avatar saifallak avatar vphelipe avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.