npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

talkyzap-wapp-api

v1.0.9

Published

WPPConnect/WA-JS is an open-source project with the aim of exporting functions from WhatsApp Web

Downloads

210

Readme

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 YouTube WhatsApp Group Telegram Group

Top Contributors (last 45 days) widget


Top Contributors (Last 45 days) widget

Check also our Public Dashboard powered by devActivity

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)

Some Available functions

General Functions

WPP.conn.connect - Connect to WhatsApp Web

WPP.conn.isAuthenticated - Check if the connection is authenticated

WPP.conn.logout - Logout from WhatsApp Web

Chat Functions

WPP.chat.sendTextMessage - Send a text message

WPP.chat.sendImageMessage - Send an image message

WPP.chat.sendVideoMessage - Send a video message

WPP.chat.sendFileMessage - Send a file message

WPP.chat.sendAudioMessage - Send an audio message

WPP.chat.getChat - Get chat details

WPP.chat.deleteMessage - Delete a message

Contact Functions

WPP.contact.getContact - Get contact details

WPP.contact.blockContact - Block a contact

WPP.contact.unblockContact - Unblock a contact

WPP.contact.getAllContacts - Get all contacts

Group Functions

WPP.group.createGroup - Create a new group

WPP.group.addParticipant - Add a participant to a group

WPP.group.removeParticipant - Remove a participant from a group.

WPP.group.promoteParticipant - Promote a participant to admin

WPP.group.demoteParticipant - Demote a participant from admin.

WPP.group.getGroupInfo - Get group information.

Events

WPP.chat.on('chat.new_message') - Event to dispatch on receive a new message

To see all events, check: https://wppconnect.io/wa-js/types/ev.EventTypes.html

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

# launch 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 = 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();

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.