whatsapp-web.js 1.24.0 → 1.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/example.js +29 -4
- package/index.d.ts +15 -1
- package/index.js +0 -1
- package/package.json +1 -1
- package/src/Client.js +535 -529
- package/src/authStrategies/LocalAuth.js +4 -1
- package/src/structures/GroupChat.js +12 -4
- package/src/structures/Message.js +6 -5
- package/src/util/Injected/AuthStore/AuthStore.js +17 -0
- package/src/util/Injected/AuthStore/LegacyAuthStore.js +22 -0
- package/src/util/Injected/LegacyStore.js +146 -0
- package/src/util/Injected/Store.js +166 -0
- package/src/util/{Injected.js → Injected/Utils.js} +31 -154
- package/src/webCache/LocalWebCache.js +3 -6
- package/src/authStrategies/LegacySessionAuth.js +0 -72
package/example.js
CHANGED
|
@@ -5,19 +5,30 @@ const client = new Client({
|
|
|
5
5
|
// proxyAuthentication: { username: 'username', password: 'password' },
|
|
6
6
|
puppeteer: {
|
|
7
7
|
// args: ['--proxy-server=proxy-server-that-requires-authentication.example.com'],
|
|
8
|
-
headless: false
|
|
8
|
+
headless: false,
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
|
|
12
|
+
// client initialize does not finish at ready now.
|
|
12
13
|
client.initialize();
|
|
13
14
|
|
|
14
15
|
client.on('loading_screen', (percent, message) => {
|
|
15
16
|
console.log('LOADING SCREEN', percent, message);
|
|
16
17
|
});
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
// Pairing code only needs to be requested once
|
|
20
|
+
let pairingCodeRequested = false;
|
|
21
|
+
client.on('qr', async (qr) => {
|
|
19
22
|
// NOTE: This event will not be fired if a session is specified.
|
|
20
23
|
console.log('QR RECEIVED', qr);
|
|
24
|
+
|
|
25
|
+
// paiuting code example
|
|
26
|
+
const pairingCodeEnabled = false;
|
|
27
|
+
if (pairingCodeEnabled && !pairingCodeRequested) {
|
|
28
|
+
const pairingCode = await client.requestPairingCode('96170100100'); // enter the target phone number
|
|
29
|
+
console.log('Pairing code enabled, code: '+ pairingCode);
|
|
30
|
+
pairingCodeRequested = true;
|
|
31
|
+
}
|
|
21
32
|
});
|
|
22
33
|
|
|
23
34
|
client.on('authenticated', () => {
|
|
@@ -29,8 +40,18 @@ client.on('auth_failure', msg => {
|
|
|
29
40
|
console.error('AUTHENTICATION FAILURE', msg);
|
|
30
41
|
});
|
|
31
42
|
|
|
32
|
-
client.on('ready', () => {
|
|
43
|
+
client.on('ready', async () => {
|
|
33
44
|
console.log('READY');
|
|
45
|
+
const debugWWebVersion = await client.getWWebVersion();
|
|
46
|
+
console.log(`WWebVersion = ${debugWWebVersion}`);
|
|
47
|
+
|
|
48
|
+
client.pupPage.on('pageerror', function(err) {
|
|
49
|
+
console.log('Page error: ' + err.toString());
|
|
50
|
+
});
|
|
51
|
+
client.pupPage.on('error', function(err) {
|
|
52
|
+
console.log('Page error: ' + err.toString());
|
|
53
|
+
});
|
|
54
|
+
|
|
34
55
|
});
|
|
35
56
|
|
|
36
57
|
client.on('message', async msg => {
|
|
@@ -418,7 +439,7 @@ client.on('message', async msg => {
|
|
|
418
439
|
requesterIds: ['number1@c.us', 'number2@c.us'],
|
|
419
440
|
sleep: null
|
|
420
441
|
});
|
|
421
|
-
} else {
|
|
442
|
+
} else if (msg.body === '!pinmsg') {
|
|
422
443
|
/**
|
|
423
444
|
* Pins a message in a chat, a method takes a number in seconds for the message to be pinned.
|
|
424
445
|
* WhatsApp default values for duration to pass to the method are:
|
|
@@ -595,6 +616,10 @@ client.on('group_membership_request', async (notification) => {
|
|
|
595
616
|
await client.rejectGroupMembershipRequests(notification.chatId, notification.author);
|
|
596
617
|
});
|
|
597
618
|
|
|
619
|
+
client.on('message_reaction', async (reaction) => {
|
|
620
|
+
console.log('REACTION RECEIVED', reaction);
|
|
621
|
+
});
|
|
622
|
+
|
|
598
623
|
client.on('vote_update', (vote) => {
|
|
599
624
|
/** The vote that was affected: */
|
|
600
625
|
console.log(vote);
|
package/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { EventEmitter } from 'events'
|
|
3
3
|
import { RequestInit } from 'node-fetch'
|
|
4
4
|
import * as puppeteer from 'puppeteer'
|
|
5
|
+
import InterfaceController from './src/util/InterfaceController'
|
|
5
6
|
|
|
6
7
|
declare namespace WAWebJS {
|
|
7
8
|
|
|
@@ -17,6 +18,9 @@ declare namespace WAWebJS {
|
|
|
17
18
|
/** Puppeteer browser running WhatsApp Web */
|
|
18
19
|
pupBrowser?: puppeteer.Browser
|
|
19
20
|
|
|
21
|
+
/** Client interactivity interface */
|
|
22
|
+
interface?: InterfaceController
|
|
23
|
+
|
|
20
24
|
/**Accepts an invitation to join a group */
|
|
21
25
|
acceptInvite(inviteCode: string): Promise<string>
|
|
22
26
|
|
|
@@ -111,6 +115,14 @@ declare namespace WAWebJS {
|
|
|
111
115
|
*/
|
|
112
116
|
muteChat(chatId: string, unmuteDate?: Date): Promise<void>
|
|
113
117
|
|
|
118
|
+
/**
|
|
119
|
+
* Request authentication via pairing code instead of QR code
|
|
120
|
+
* @param phoneNumber - Phone number in international, symbol-free format (e.g. 12025550108 for US, 551155501234 for Brazil)
|
|
121
|
+
* @param showNotification - Show notification to pair on phone number
|
|
122
|
+
* @returns {Promise<string>} - Returns a pairing code in format "ABCDEFGH"
|
|
123
|
+
*/
|
|
124
|
+
requestPairingCode(phoneNumber: string, showNotification = true): Promise<string>
|
|
125
|
+
|
|
114
126
|
/** Force reset of connection state for the client */
|
|
115
127
|
resetState(): Promise<void>
|
|
116
128
|
|
|
@@ -215,7 +227,7 @@ declare namespace WAWebJS {
|
|
|
215
227
|
/** Emitted when the client has been disconnected */
|
|
216
228
|
on(event: 'disconnected', listener: (
|
|
217
229
|
/** reason that caused the disconnect */
|
|
218
|
-
reason: WAState | "
|
|
230
|
+
reason: WAState | "LOGOUT"
|
|
219
231
|
) => void): this
|
|
220
232
|
|
|
221
233
|
/** Emitted when a user joins the chat via invite link or is added by an admin */
|
|
@@ -1097,6 +1109,8 @@ declare namespace WAWebJS {
|
|
|
1097
1109
|
}[]
|
|
1098
1110
|
/** Send 'seen' status */
|
|
1099
1111
|
sendSeen?: boolean
|
|
1112
|
+
/** Bot Wid when doing a bot mention like @Meta AI */
|
|
1113
|
+
invokedBotWid?: string
|
|
1100
1114
|
/** Media to be sent */
|
|
1101
1115
|
media?: MessageMedia
|
|
1102
1116
|
/** Extra options */
|
package/index.js
CHANGED
|
@@ -27,7 +27,6 @@ module.exports = {
|
|
|
27
27
|
NoAuth: require('./src/authStrategies/NoAuth'),
|
|
28
28
|
LocalAuth: require('./src/authStrategies/LocalAuth'),
|
|
29
29
|
RemoteAuth: require('./src/authStrategies/RemoteAuth'),
|
|
30
|
-
LegacySessionAuth: require('./src/authStrategies/LegacySessionAuth'),
|
|
31
30
|
|
|
32
31
|
...Constants
|
|
33
32
|
};
|