Skip to content

Commit

Permalink
Farewell, Webpack! Re-injection, Pairing Code login, and 2.24x jumbof…
Browse files Browse the repository at this point in the history
…ix (pedroslopez#2816)

* fix(webpack-exodus): Added the new patch

* fix(webpack-exodus): Fixed v2.3000.x and v2.24

* chore(webpack-exodus): eslint

* fix(webpack-exodus): Fixed Store

* fix(webpack-exodus): slight store fix

* chore(webpack-exodus): fix example so that I don't crash on every load

* chore: eslint fix

* fix(webpack-exodus): prevent confusion with build systems

* fix(webpack-exodus): Add proper groups module

* fix(webpack-exodus): Fix order queries

* fix(webpack-exodus): Bad export name

* feat(webpack-exodus): Re-injection, No more selectors, Pairing Code auth

* fix(webpack-exodus): Eslint and better login/logout handling

* fix(webpack-exodus): 2.24 compatibility

* revert testing options

* chore(webpack-exodus): ESLint

* chore(webpack-exodus): final eslint tweak (did not commit with last commit for some reason)

* style: fix broken link in readme file

* fix(webpack-exodus): Fix forwarding messages

* fix(webpack-exodus): finish forwarding function

* Making the ESLint god happy

* Fix window.Store.ProfilePic.profilePicFind is not a function error (pedroslopez#3001)

* Change window.Store.ProfilePic.profilePicFind to window.Store.ProfilePic.requestProfilePicFromServer

* Prevent breaking v2.2x

* refactor: make it more readable

---------

Co-authored-by: alechkos <[email protected]>

* Sanitize, improves and fixes

* make ESList god happy

* fix getInviteCode for group (pedroslopez#3007) (pedroslopez#3029)

* fix getInviteCode for group (pedroslopez#3007)

* move changes to proper getInviteCode method.

* style fix

* refactor: add try-catch in a case the user is not a group admin

* refactor: handle promise properly

---------

Co-authored-by: Sven Neumann <[email protected]>
Co-authored-by: alechkos <[email protected]>

* fixes

* Update LocalWebCache.js

* fix delete on 2.3000 (pedroslopez#3048)

* fix delete on 2.3000

* fix compareWwebVersions

* fix: use proper comparison operator

---------

Co-authored-by: alechkos <[email protected]>

* Implement bot invoking capabilities (pedroslopez#3009)

* Implement bot invoking capabilities

* Update index.d.ts

* Eslint

* Webpack exodus fix message_reaction event (pedroslopez#3099)

* exposed WAWebAddonReactionTableMode

* capture reaction using WAWebAddonReactionTableMode

* move compareWwebVersions and check version before trying to expose new store

* message_reaction on example.js (pedroslopez#3102)

* handle message_reaction event on example.js

* log wweb version on ready

* fix reactions on pvt chats (pedroslopez#3104)

* New group function

* new group settings

* Update Client.js

---------

Co-authored-by: alechkos <[email protected]>
Co-authored-by: tuyuribr <[email protected]>
Co-authored-by: Seow Zhen Jun <[email protected]>
Co-authored-by: Sven <[email protected]>
Co-authored-by: Sven Neumann <[email protected]>
Co-authored-by: Jorge Rocha Gualtieri <[email protected]>
Co-authored-by: Mateus Mercer <[email protected]>
  • Loading branch information
8 people authored Jul 24, 2024
1 parent 24b11b7 commit 13ce571
Show file tree
Hide file tree
Showing 14 changed files with 986 additions and 777 deletions.
33 changes: 29 additions & 4 deletions example.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,30 @@ const client = new Client({
// proxyAuthentication: { username: 'username', password: 'password' },
puppeteer: {
// args: ['--proxy-server=proxy-server-that-requires-authentication.example.com'],
headless: false
headless: false,
}
});

// client initialize does not finish at ready now.
client.initialize();

client.on('loading_screen', (percent, message) => {
console.log('LOADING SCREEN', percent, message);
});

client.on('qr', (qr) => {
// Pairing code only needs to be requested once
let pairingCodeRequested = false;
client.on('qr', async (qr) => {
// NOTE: This event will not be fired if a session is specified.
console.log('QR RECEIVED', qr);

// paiuting code example
const pairingCodeEnabled = false;
if (pairingCodeEnabled && !pairingCodeRequested) {
const pairingCode = await client.requestPairingCode('96170100100'); // enter the target phone number
console.log('Pairing code enabled, code: '+ pairingCode);
pairingCodeRequested = true;
}
});

client.on('authenticated', () => {
Expand All @@ -29,8 +40,18 @@ client.on('auth_failure', msg => {
console.error('AUTHENTICATION FAILURE', msg);
});

client.on('ready', () => {
client.on('ready', async () => {
console.log('READY');
const debugWWebVersion = await client.getWWebVersion();
console.log(`WWebVersion = ${debugWWebVersion}`);

client.pupPage.on('pageerror', function(err) {
console.log('Page error: ' + err.toString());
});
client.pupPage.on('error', function(err) {
console.log('Page error: ' + err.toString());
});

});

client.on('message', async msg => {
Expand Down Expand Up @@ -418,7 +439,7 @@ client.on('message', async msg => {
requesterIds: ['[email protected]', '[email protected]'],
sleep: null
});
} else {
} else if (msg.body === '!pinmsg') {
/**
* Pins a message in a chat, a method takes a number in seconds for the message to be pinned.
* WhatsApp default values for duration to pass to the method are:
Expand Down Expand Up @@ -595,6 +616,10 @@ client.on('group_membership_request', async (notification) => {
await client.rejectGroupMembershipRequests(notification.chatId, notification.author);
});

client.on('message_reaction', async (reaction) => {
console.log('REACTION RECEIVED', reaction);
});

client.on('vote_update', (vote) => {
/** The vote that was affected: */
console.log(vote);
Expand Down
16 changes: 15 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { EventEmitter } from 'events'
import { RequestInit } from 'node-fetch'
import * as puppeteer from 'puppeteer'
import InterfaceController from './src/util/InterfaceController'

declare namespace WAWebJS {

Expand All @@ -17,6 +18,9 @@ declare namespace WAWebJS {
/** Puppeteer browser running WhatsApp Web */
pupBrowser?: puppeteer.Browser

/** Client interactivity interface */
interface?: InterfaceController

/**Accepts an invitation to join a group */
acceptInvite(inviteCode: string): Promise<string>

Expand Down Expand Up @@ -111,6 +115,14 @@ declare namespace WAWebJS {
*/
muteChat(chatId: string, unmuteDate?: Date): Promise<void>

/**
* Request authentication via pairing code instead of QR code
* @param phoneNumber - Phone number in international, symbol-free format (e.g. 12025550108 for US, 551155501234 for Brazil)
* @param showNotification - Show notification to pair on phone number
* @returns {Promise<string>} - Returns a pairing code in format "ABCDEFGH"
*/
requestPairingCode(phoneNumber: string, showNotification = true): Promise<string>

/** Force reset of connection state for the client */
resetState(): Promise<void>

Expand Down Expand Up @@ -215,7 +227,7 @@ declare namespace WAWebJS {
/** Emitted when the client has been disconnected */
on(event: 'disconnected', listener: (
/** reason that caused the disconnect */
reason: WAState | "NAVIGATION"
reason: WAState | "LOGOUT"
) => void): this

/** Emitted when a user joins the chat via invite link or is added by an admin */
Expand Down Expand Up @@ -1097,6 +1109,8 @@ declare namespace WAWebJS {
}[]
/** Send 'seen' status */
sendSeen?: boolean
/** Bot Wid when doing a bot mention like @Meta AI */
invokedBotWid?: string
/** Media to be sent */
media?: MessageMedia
/** Extra options */
Expand Down
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ module.exports = {
NoAuth: require('./src/authStrategies/NoAuth'),
LocalAuth: require('./src/authStrategies/LocalAuth'),
RemoteAuth: require('./src/authStrategies/RemoteAuth'),
LegacySessionAuth: require('./src/authStrategies/LegacySessionAuth'),

...Constants
};
Loading

0 comments on commit 13ce571

Please sign in to comment.