whatsapp-web.js 1.15.3 → 1.15.4
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/README.md +1 -1
- package/index.d.ts +4 -1
- package/package.json +7 -6
- package/src/Client.js +6 -1
- package/src/structures/List.js +2 -2
- package/src/structures/Message.js +6 -0
- package/src/structures/MessageMedia.js +16 -13
- package/src/structures/Payment.js +2 -1
- package/src/util/Injected.js +1 -2
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[](https://www.npmjs.com/package/whatsapp-web.js) [](https://depfu.com/github/pedroslopez/whatsapp-web.js?project_id=9765) ](https://www.npmjs.com/package/whatsapp-web.js) [](https://depfu.com/github/pedroslopez/whatsapp-web.js?project_id=9765)  [](https://discord.gg/H7DqQs4)
|
|
2
2
|
|
|
3
3
|
# whatsapp-web.js
|
|
4
4
|
A WhatsApp API client that connects through the WhatsApp Web browser app
|
package/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
import { EventEmitter } from 'events'
|
|
3
3
|
import { RequestInit } from 'node-fetch'
|
|
4
|
-
import puppeteer
|
|
4
|
+
import puppeteer from 'puppeteer'
|
|
5
5
|
|
|
6
6
|
declare namespace WAWebJS {
|
|
7
7
|
|
|
@@ -525,6 +525,8 @@ declare namespace WAWebJS {
|
|
|
525
525
|
broadcast: boolean,
|
|
526
526
|
/** Indicates if the message was a status update */
|
|
527
527
|
isStatus: boolean,
|
|
528
|
+
/** Indicates if the message is a Gif */
|
|
529
|
+
isGif: boolean,
|
|
528
530
|
/** ID for the Chat that this message was sent to, except if the message was sent by the current user */
|
|
529
531
|
from: string,
|
|
530
532
|
/** Indicates if the message was sent by the current user */
|
|
@@ -690,6 +692,7 @@ declare namespace WAWebJS {
|
|
|
690
692
|
|
|
691
693
|
export interface MediaFromURLOptions {
|
|
692
694
|
client?: Client
|
|
695
|
+
filename?: string
|
|
693
696
|
unsafeMime?: boolean
|
|
694
697
|
reqOptions?: RequestInit
|
|
695
698
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "whatsapp-web.js",
|
|
3
|
-
"version": "1.15.
|
|
3
|
+
"version": "1.15.4",
|
|
4
4
|
"description": "Library for interacting with the WhatsApp Web API ",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"typings": "./index.d.ts",
|
|
@@ -31,21 +31,22 @@
|
|
|
31
31
|
"@pedroslopez/moduleraid": "^5.0.2",
|
|
32
32
|
"fluent-ffmpeg": "^2.1.2",
|
|
33
33
|
"jsqr": "^1.3.1",
|
|
34
|
-
"mime": "^
|
|
34
|
+
"mime": "^3.0.0",
|
|
35
|
+
"node-fetch": "^2.6.5",
|
|
35
36
|
"node-webpmux": "^3.1.0",
|
|
36
|
-
"puppeteer": "^
|
|
37
|
+
"puppeteer": "^13.0.0",
|
|
37
38
|
"sharp": "^0.28.3"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
|
-
"@types/node-fetch": "^2.5.
|
|
41
|
+
"@types/node-fetch": "^2.5.12",
|
|
41
42
|
"chai": "^4.3.4",
|
|
42
43
|
"dotenv": "^10.0.0",
|
|
43
|
-
"eslint": "^
|
|
44
|
+
"eslint": "^8.4.1",
|
|
44
45
|
"eslint-plugin-mocha": "^9.0.0",
|
|
45
46
|
"jsdoc": "^3.6.4",
|
|
46
47
|
"jsdoc-baseline": "^0.1.5",
|
|
47
48
|
"mocha": "^9.0.2",
|
|
48
|
-
"sinon": "^
|
|
49
|
+
"sinon": "^12.0.1"
|
|
49
50
|
},
|
|
50
51
|
"engines": {
|
|
51
52
|
"node": ">=12.0.0"
|
package/src/Client.js
CHANGED
|
@@ -81,6 +81,11 @@ class Client extends EventEmitter {
|
|
|
81
81
|
this.pupBrowser = browser;
|
|
82
82
|
this.pupPage = page;
|
|
83
83
|
|
|
84
|
+
// remember me
|
|
85
|
+
await page.evaluateOnNewDocument(() => {
|
|
86
|
+
localStorage.setItem('remember-me', 'true');
|
|
87
|
+
});
|
|
88
|
+
|
|
84
89
|
if (this.options.session) {
|
|
85
90
|
await page.evaluateOnNewDocument(
|
|
86
91
|
session => {
|
|
@@ -170,7 +175,7 @@ class Client extends EventEmitter {
|
|
|
170
175
|
}
|
|
171
176
|
|
|
172
177
|
await page.evaluate(ExposeStore, moduleRaid.toString());
|
|
173
|
-
|
|
178
|
+
|
|
174
179
|
// Get session tokens
|
|
175
180
|
const localStorage = JSON.parse(await page.evaluate(() => {
|
|
176
181
|
return JSON.stringify(window.localStorage);
|
package/src/structures/List.js
CHANGED
|
@@ -57,7 +57,7 @@ class List {
|
|
|
57
57
|
*/
|
|
58
58
|
_format(sections){
|
|
59
59
|
if(!sections.length){throw '[LT02] List without sections';}
|
|
60
|
-
if(sections.length > 1){throw '[LT05]
|
|
60
|
+
if(sections.length > 1 && sections.filter(s => typeof s.title == 'undefined').length > 1){throw '[LT05] You can\'t have more than one empty title.';}
|
|
61
61
|
return sections.map( (section) =>{
|
|
62
62
|
if(!section.rows.length){throw '[LT03] Section without rows';}
|
|
63
63
|
return {
|
|
@@ -76,4 +76,4 @@ class List {
|
|
|
76
76
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
module.exports = List;
|
|
79
|
+
module.exports = List;
|
|
@@ -179,6 +179,12 @@ class Message extends Base {
|
|
|
179
179
|
*/
|
|
180
180
|
this.token = data.token ? data.token : undefined;
|
|
181
181
|
|
|
182
|
+
/**
|
|
183
|
+
* Indicates whether the message is a Gif
|
|
184
|
+
* @type {boolean}
|
|
185
|
+
*/
|
|
186
|
+
this.isGif = Boolean(data.isGif);
|
|
187
|
+
|
|
182
188
|
/** Title */
|
|
183
189
|
if (data.title) {
|
|
184
190
|
this.title = data.title;
|
|
@@ -50,29 +50,29 @@ class MessageMedia {
|
|
|
50
50
|
* Creates a MessageMedia instance from a URL
|
|
51
51
|
* @param {string} url
|
|
52
52
|
* @param {Object} [options]
|
|
53
|
-
* @param {
|
|
53
|
+
* @param {boolean} [options.unsafeMime=false]
|
|
54
|
+
* @param {string} [options.filename]
|
|
54
55
|
* @param {object} [options.client]
|
|
55
56
|
* @param {object} [options.reqOptions]
|
|
56
57
|
* @param {number} [options.reqOptions.size=0]
|
|
57
58
|
* @returns {Promise<MessageMedia>}
|
|
58
59
|
*/
|
|
59
60
|
static async fromUrl(url, options = {}) {
|
|
60
|
-
|
|
61
|
+
const pUrl = new URL(url);
|
|
62
|
+
let mimetype = mime.getType(pUrl.pathname);
|
|
61
63
|
|
|
62
|
-
if (!options.unsafeMime)
|
|
63
|
-
|
|
64
|
-
mimetype = mime.getType(pUrl.pathname);
|
|
65
|
-
|
|
66
|
-
if (!mimetype)
|
|
67
|
-
throw new Error('Unable to determine MIME type');
|
|
68
|
-
}
|
|
64
|
+
if (!mimetype && !options.unsafeMime)
|
|
65
|
+
throw new Error('Unable to determine MIME type using URL. Set unsafeMime to true to download it anyway.');
|
|
69
66
|
|
|
70
67
|
async function fetchData (url, options) {
|
|
71
68
|
const reqOptions = Object.assign({ headers: { accept: 'image/* video/* text/* audio/*' } }, options);
|
|
72
69
|
const response = await fetch(url, reqOptions);
|
|
73
70
|
const mime = response.headers.get('Content-Type');
|
|
74
|
-
let data = '';
|
|
75
71
|
|
|
72
|
+
const contentDisposition = response.headers.get('Content-Disposition');
|
|
73
|
+
const name = contentDisposition ? contentDisposition.match(/((?<=filename=")(.*)(?="))/) : null;
|
|
74
|
+
|
|
75
|
+
let data = '';
|
|
76
76
|
if (response.buffer) {
|
|
77
77
|
data = (await response.buffer()).toString('base64');
|
|
78
78
|
} else {
|
|
@@ -83,18 +83,21 @@ class MessageMedia {
|
|
|
83
83
|
data = btoa(data);
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
return { data, mime };
|
|
86
|
+
return { data, mime, name };
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
const res = options.client
|
|
90
90
|
? (await options.client.pupPage.evaluate(fetchData, url, options.reqOptions))
|
|
91
91
|
: (await fetchData(url, options.reqOptions));
|
|
92
92
|
|
|
93
|
+
const filename = options.filename ||
|
|
94
|
+
(res.name ? res.name[0] : (pUrl.pathname.split('/').pop() || 'file'));
|
|
95
|
+
|
|
93
96
|
if (!mimetype)
|
|
94
97
|
mimetype = res.mime;
|
|
95
98
|
|
|
96
|
-
return new MessageMedia(mimetype, res.data,
|
|
99
|
+
return new MessageMedia(mimetype, res.data, filename);
|
|
97
100
|
}
|
|
98
101
|
}
|
|
99
102
|
|
|
100
|
-
module.exports = MessageMedia;
|
|
103
|
+
module.exports = MessageMedia;
|
|
@@ -40,7 +40,6 @@ class Payment extends Base {
|
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
42
|
* The paymentStatus
|
|
43
|
-
* @type {number}
|
|
44
43
|
*
|
|
45
44
|
* Possible Status
|
|
46
45
|
* 0:UNKNOWN_STATUS
|
|
@@ -55,6 +54,8 @@ class Payment extends Base {
|
|
|
55
54
|
* 9:CANCELLED
|
|
56
55
|
* 10:WAITING_FOR_PAYER
|
|
57
56
|
* 11:WAITING
|
|
57
|
+
*
|
|
58
|
+
* @type {number}
|
|
58
59
|
*/
|
|
59
60
|
this.paymentStatus = data.paymentStatus;
|
|
60
61
|
|
package/src/util/Injected.js
CHANGED
|
@@ -5,7 +5,7 @@ exports.ExposeStore = (moduleRaidStr) => {
|
|
|
5
5
|
eval('var moduleRaid = ' + moduleRaidStr);
|
|
6
6
|
// eslint-disable-next-line no-undef
|
|
7
7
|
window.mR = moduleRaid();
|
|
8
|
-
window.Store = Object.assign({}, window.mR.findModule(
|
|
8
|
+
window.Store = Object.assign({}, window.mR.findModule(m => m.default && m.default.Chat)[0].default);
|
|
9
9
|
window.Store.AppState = window.mR.findModule('STREAM')[0].Socket;
|
|
10
10
|
window.Store.Conn = window.mR.findModule('Conn')[0].Conn;
|
|
11
11
|
window.Store.CryptoLib = window.mR.findModule('decryptE2EMedia')[0];
|
|
@@ -30,7 +30,6 @@ exports.ExposeStore = (moduleRaidStr) => {
|
|
|
30
30
|
window.Store.WidFactory = window.mR.findModule('createWid')[0];
|
|
31
31
|
window.Store.BlockContact = window.mR.findModule('blockContact')[0];
|
|
32
32
|
window.Store.GroupMetadata = window.mR.findModule((module) => module.default && module.default.handlePendingInvite)[0].default;
|
|
33
|
-
window.Store.Sticker = window.mR.findModule('Sticker')[0].default.Sticker;
|
|
34
33
|
window.Store.UploadUtils = window.mR.findModule((module) => (module.default && module.default.encryptAndUpload) ? module.default : null)[0].default;
|
|
35
34
|
window.Store.Label = window.mR.findModule('LabelCollection')[0].default;
|
|
36
35
|
window.Store.Features = window.mR.findModule('FEATURE_CHANGE_EVENT')[0].GK;
|