@another-trial/whatsapp-web.js 1.34.5-alpha.6 → 1.34.6
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/index.d.ts +5 -0
- package/package.json +2 -2
- package/publish.sh +2 -2
- package/src/Client.js +19 -12
- package/src/authStrategies/RemoteAuth.js +49 -41
- package/src/structures/Chat.js +1 -1
- package/src/util/Injected/Store.js +4 -2
- package/src/util/Injected/Utils.js +17 -9
package/index.d.ts
CHANGED
|
@@ -876,6 +876,8 @@ declare namespace WAWebJS {
|
|
|
876
876
|
AUTHENTICATED = 'authenticated',
|
|
877
877
|
AUTHENTICATION_FAILURE = 'auth_failure',
|
|
878
878
|
READY = 'ready',
|
|
879
|
+
CHAT_REMOVED = 'chat_removed',
|
|
880
|
+
CHAT_ARCHIVED = 'chat_archived',
|
|
879
881
|
MESSAGE_RECEIVED = 'message',
|
|
880
882
|
MESSAGE_CIPHERTEXT = 'message_ciphertext',
|
|
881
883
|
MESSAGE_CREATE = 'message_create',
|
|
@@ -883,6 +885,8 @@ declare namespace WAWebJS {
|
|
|
883
885
|
MESSAGE_REVOKED_ME = 'message_revoke_me',
|
|
884
886
|
MESSAGE_ACK = 'message_ack',
|
|
885
887
|
MESSAGE_EDIT = 'message_edit',
|
|
888
|
+
UNREAD_COUNT = 'unread_count',
|
|
889
|
+
MESSAGE_REACTION = 'message_reaction',
|
|
886
890
|
MEDIA_UPLOADED = 'media_uploaded',
|
|
887
891
|
CONTACT_CHANGED = 'contact_changed',
|
|
888
892
|
GROUP_JOIN = 'group_join',
|
|
@@ -893,6 +897,7 @@ declare namespace WAWebJS {
|
|
|
893
897
|
QR_RECEIVED = 'qr',
|
|
894
898
|
CODE_RECEIVED = 'code',
|
|
895
899
|
LOADING_SCREEN = 'loading_screen',
|
|
900
|
+
CALL = 'call',
|
|
896
901
|
DISCONNECTED = 'disconnected',
|
|
897
902
|
STATE_CHANGED = 'change_state',
|
|
898
903
|
BATTERY_CHANGED = 'change_battery',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@another-trial/whatsapp-web.js",
|
|
3
|
-
"version": "1.34.
|
|
3
|
+
"version": "1.34.6",
|
|
4
4
|
"description": "Library for interacting with the WhatsApp Web API ",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"typings": "./index.d.ts",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"mime": "^3.0.0",
|
|
35
35
|
"node-fetch": "^2.6.9",
|
|
36
36
|
"node-webpmux": "3.1.7",
|
|
37
|
-
"puppeteer": "^
|
|
37
|
+
"puppeteer": "^24.31.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/node-fetch": "^2.5.12",
|
package/publish.sh
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
npm config set //registry.npmjs.org/:_authToken="
|
|
2
|
-
npm publish
|
|
1
|
+
npm config set //registry.npmjs.org/:_authToken="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"
|
|
2
|
+
npm publish --tag $1
|
package/src/Client.js
CHANGED
|
@@ -756,7 +756,10 @@ class Client extends EventEmitter {
|
|
|
756
756
|
window.Store.Msg.on('change:body change:caption', (msg, newBody, prevBody) => { window.onEditMessageEvent(window.WWebJS.getMessageModel(msg), newBody, prevBody); });
|
|
757
757
|
window.Store.AppState.on('change:state', (_AppState, state) => { window.onAppStateChangedEvent(state); });
|
|
758
758
|
window.Store.Conn.on('change:battery', (state) => { window.onBatteryStateChangedEvent(state); });
|
|
759
|
-
window.Store.Call
|
|
759
|
+
const callCollection = (window.Store && window.Store.Call) || (window.Store && window.Store.WAWebCallCollection);
|
|
760
|
+
if (callCollection && typeof callCollection.on === 'function') {
|
|
761
|
+
callCollection.on('add', (call) => { window.onIncomingCall(call); });
|
|
762
|
+
}
|
|
760
763
|
window.Store.Chat.on('remove', async (chat) => { window.onRemoveChatEvent(await window.WWebJS.getChatModel(chat)); });
|
|
761
764
|
window.Store.Chat.on('change:archive', async (chat, currState, prevState) => { window.onArchiveChatEvent(await window.WWebJS.getChatModel(chat), currState, prevState); });
|
|
762
765
|
window.Store.Msg.on('add', (msg) => {
|
|
@@ -873,7 +876,11 @@ class Client extends EventEmitter {
|
|
|
873
876
|
* Closes the client
|
|
874
877
|
*/
|
|
875
878
|
async destroy() {
|
|
876
|
-
|
|
879
|
+
const browser = this.pupBrowser;
|
|
880
|
+
const isConnected = browser?.isConnected?.();
|
|
881
|
+
if (isConnected) {
|
|
882
|
+
await browser.close();
|
|
883
|
+
}
|
|
877
884
|
await this.authStrategy.destroy();
|
|
878
885
|
}
|
|
879
886
|
|
|
@@ -2408,15 +2415,14 @@ class Client extends EventEmitter {
|
|
|
2408
2415
|
async saveOrEditAddressbookContact(phoneNumber, firstName, lastName, syncToAddressbook = false)
|
|
2409
2416
|
{
|
|
2410
2417
|
return await this.pupPage.evaluate(async (phoneNumber, firstName, lastName, syncToAddressbook) => {
|
|
2411
|
-
return await window.Store.AddressbookContactUtils.saveContactAction(
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
);
|
|
2418
|
+
return await window.Store.AddressbookContactUtils.saveContactAction({
|
|
2419
|
+
'firstName' : firstName,
|
|
2420
|
+
'lastName' : lastName,
|
|
2421
|
+
'phoneNumber' : phoneNumber,
|
|
2422
|
+
'prevPhoneNumber' : phoneNumber,
|
|
2423
|
+
'syncToAddressbook': syncToAddressbook,
|
|
2424
|
+
'username' : undefined
|
|
2425
|
+
});
|
|
2420
2426
|
}, phoneNumber, firstName, lastName, syncToAddressbook);
|
|
2421
2427
|
}
|
|
2422
2428
|
|
|
@@ -2428,7 +2434,8 @@ class Client extends EventEmitter {
|
|
|
2428
2434
|
async deleteAddressbookContact(phoneNumber)
|
|
2429
2435
|
{
|
|
2430
2436
|
return await this.pupPage.evaluate(async (phoneNumber) => {
|
|
2431
|
-
|
|
2437
|
+
const wid = window.Store.WidFactory.createWid(phoneNumber);
|
|
2438
|
+
return await window.Store.AddressbookContactUtils.deleteContactAction({phoneNumber: wid});
|
|
2432
2439
|
}, phoneNumber);
|
|
2433
2440
|
}
|
|
2434
2441
|
|
|
@@ -102,24 +102,34 @@ class RemoteAuth extends BaseAuthStrategy {
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
async storeRemoteSession(options) {
|
|
105
|
-
/* Compress & Store Session */
|
|
106
105
|
const pathExists = await this.isValidPath(this.userDataDir);
|
|
107
|
-
if (pathExists)
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
await
|
|
112
|
-
|
|
113
|
-
force: true,
|
|
114
|
-
maxRetries: this.rmMaxRetries,
|
|
115
|
-
}).catch(() => {});
|
|
106
|
+
if (!pathExists) return;
|
|
107
|
+
|
|
108
|
+
let compressedSessionPath;
|
|
109
|
+
try {
|
|
110
|
+
compressedSessionPath = await this.compressSession();
|
|
111
|
+
await this.store.save({ session: path.join(this.dataPath, this.sessionName) });
|
|
116
112
|
if(options && options.emit) this.client.emit(Events.REMOTE_SESSION_SAVED);
|
|
113
|
+
} finally {
|
|
114
|
+
const paths = [
|
|
115
|
+
this.tempDir,
|
|
116
|
+
...(compressedSessionPath ? [compressedSessionPath] : [])
|
|
117
|
+
];
|
|
118
|
+
await Promise.allSettled(
|
|
119
|
+
paths.map((p) =>
|
|
120
|
+
fs.promises.rm(p, {
|
|
121
|
+
recursive: true,
|
|
122
|
+
force: true,
|
|
123
|
+
maxRetries: this.rmMaxRetries,
|
|
124
|
+
})
|
|
125
|
+
)
|
|
126
|
+
);
|
|
117
127
|
}
|
|
118
128
|
}
|
|
119
129
|
|
|
120
130
|
async extractRemoteSession() {
|
|
121
131
|
const pathExists = await this.isValidPath(this.userDataDir);
|
|
122
|
-
const compressedSessionPath = `${this.sessionName}.zip
|
|
132
|
+
const compressedSessionPath = path.join(this.dataPath, `${this.sessionName}.zip`);
|
|
123
133
|
const sessionExists = await this.store.sessionExists({session: this.sessionName});
|
|
124
134
|
if (pathExists) {
|
|
125
135
|
await fs.promises.rm(this.userDataDir, {
|
|
@@ -142,27 +152,34 @@ class RemoteAuth extends BaseAuthStrategy {
|
|
|
142
152
|
}
|
|
143
153
|
|
|
144
154
|
async compressSession() {
|
|
145
|
-
const
|
|
146
|
-
const
|
|
155
|
+
const stageDefaultPath = path.join(this.tempDir, 'Default');
|
|
156
|
+
const userDataDefaultPath = path.join(this.userDataDir, 'Default');
|
|
147
157
|
|
|
148
|
-
await fs.
|
|
149
|
-
await this.
|
|
150
|
-
return new Promise((resolve, reject) => {
|
|
151
|
-
archive
|
|
152
|
-
.directory(this.tempDir, false)
|
|
153
|
-
.on('error', err => reject(err))
|
|
154
|
-
.pipe(stream);
|
|
158
|
+
await fs.emptyDir(stageDefaultPath);
|
|
159
|
+
await this.copyByRequiredDirs(userDataDefaultPath, stageDefaultPath);
|
|
155
160
|
|
|
156
|
-
|
|
161
|
+
const archive = archiver('zip');
|
|
162
|
+
const outPath = path.join(this.dataPath, `${this.sessionName}.zip`);
|
|
163
|
+
const out = fs.createWriteStream(outPath);
|
|
164
|
+
|
|
165
|
+
await new Promise((resolve, reject) => {
|
|
166
|
+
out.once('close', resolve);
|
|
167
|
+
out.once('error', reject);
|
|
168
|
+
archive.once('error', reject);
|
|
169
|
+
|
|
170
|
+
archive.pipe(out);
|
|
171
|
+
archive.directory(this.tempDir, false);
|
|
157
172
|
archive.finalize();
|
|
158
173
|
});
|
|
174
|
+
return outPath;
|
|
159
175
|
}
|
|
160
176
|
|
|
161
177
|
async unCompressSession(compressedSessionPath) {
|
|
162
178
|
var stream = fs.createReadStream(compressedSessionPath);
|
|
163
179
|
await new Promise((resolve, reject) => {
|
|
164
180
|
stream.pipe(unzipper.Extract({
|
|
165
|
-
path: this.userDataDir
|
|
181
|
+
path: this.userDataDir,
|
|
182
|
+
concurrency: 10
|
|
166
183
|
}))
|
|
167
184
|
.on('error', err => reject(err))
|
|
168
185
|
.on('finish', () => resolve());
|
|
@@ -170,25 +187,16 @@ class RemoteAuth extends BaseAuthStrategy {
|
|
|
170
187
|
await fs.promises.unlink(compressedSessionPath);
|
|
171
188
|
}
|
|
172
189
|
|
|
173
|
-
async
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
await fs.promises.rm(dirElement, {
|
|
184
|
-
recursive: true,
|
|
185
|
-
force: true,
|
|
186
|
-
maxRetries: this.rmMaxRetries,
|
|
187
|
-
}).catch(() => {});
|
|
188
|
-
} else {
|
|
189
|
-
await fs.promises.unlink(dirElement).catch(() => {});
|
|
190
|
-
}
|
|
191
|
-
}
|
|
190
|
+
async copyByRequiredDirs(from, to) {
|
|
191
|
+
for (const d of this.requiredDirs) {
|
|
192
|
+
const src = path.join(from, d);
|
|
193
|
+
if (await this.isValidPath(src)) {
|
|
194
|
+
const dest = path.join(to, path.basename(src));
|
|
195
|
+
await fs.promises.cp(src, dest, {
|
|
196
|
+
recursive: true,
|
|
197
|
+
force: true,
|
|
198
|
+
errorOnExist: false
|
|
199
|
+
});
|
|
192
200
|
}
|
|
193
201
|
}
|
|
194
202
|
}
|
package/src/structures/Chat.js
CHANGED
|
@@ -206,7 +206,7 @@ class Chat extends Base {
|
|
|
206
206
|
|
|
207
207
|
if (searchOptions && searchOptions.limit > 0) {
|
|
208
208
|
while (msgs.length < searchOptions.limit) {
|
|
209
|
-
const loadedMessages = await window.Store.ConversationMsgs.loadEarlierMsgs(chat);
|
|
209
|
+
const loadedMessages = await window.Store.ConversationMsgs.loadEarlierMsgs(chat,chat.msgs);
|
|
210
210
|
if (!loadedMessages || !loadedMessages.length) break;
|
|
211
211
|
msgs = [...loadedMessages.filter(msgFilter), ...msgs];
|
|
212
212
|
}
|
|
@@ -53,7 +53,10 @@ exports.ExposeStore = () => {
|
|
|
53
53
|
window.Store.MediaPrep = window.require('WAWebPrepRawMedia');
|
|
54
54
|
window.Store.MediaObject = window.require('WAWebMediaStorage');
|
|
55
55
|
window.Store.MediaTypes = window.require('WAWebMmsMediaTypes');
|
|
56
|
-
window.Store.MediaUpload =
|
|
56
|
+
window.Store.MediaUpload = {
|
|
57
|
+
...window.require('WAWebMediaMmsV4Upload'),
|
|
58
|
+
...window.require('WAWebStartMediaUploadQpl')
|
|
59
|
+
};
|
|
57
60
|
window.Store.MediaUpdate = window.require('WAWebMediaUpdateMsg');
|
|
58
61
|
window.Store.MsgKey = window.require('WAWebMsgKey');
|
|
59
62
|
window.Store.OpaqueData = window.require('WAWebMediaOpaqueData');
|
|
@@ -174,7 +177,6 @@ exports.ExposeStore = () => {
|
|
|
174
177
|
...window.require('WAWebNewsletterSubscribeAction'),
|
|
175
178
|
...window.require('WAWebNewsletterUnsubscribeAction'),
|
|
176
179
|
...window.require('WAWebNewsletterDirectorySearchAction'),
|
|
177
|
-
...window.require('WAWebNewsletterToggleMuteStateJob'),
|
|
178
180
|
...window.require('WAWebNewsletterGatingUtils'),
|
|
179
181
|
...window.require('WAWebNewsletterModelUtils'),
|
|
180
182
|
...window.require('WAWebMexAcceptNewsletterAdminInviteJob'),
|
|
@@ -13,7 +13,10 @@ exports.LoadUtils = () => {
|
|
|
13
13
|
const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
|
|
14
14
|
if (chat) {
|
|
15
15
|
window.Store.WAWebStreamModel.Stream.markAvailable();
|
|
16
|
-
await window.Store.SendSeen.sendSeen(
|
|
16
|
+
await window.Store.SendSeen.sendSeen({
|
|
17
|
+
chat: chat,
|
|
18
|
+
threadId: undefined
|
|
19
|
+
});
|
|
17
20
|
window.Store.WAWebStreamModel.Stream.markUnavailable();
|
|
18
21
|
return true;
|
|
19
22
|
}
|
|
@@ -428,7 +431,10 @@ exports.LoadUtils = () => {
|
|
|
428
431
|
blob: file,
|
|
429
432
|
type: 'sticker',
|
|
430
433
|
signal: controller.signal,
|
|
431
|
-
mediaKey
|
|
434
|
+
mediaKey,
|
|
435
|
+
uploadQpl: window.Store.MediaUpload.startMediaUploadQpl({
|
|
436
|
+
entryPoint: 'MediaUpload'
|
|
437
|
+
}),
|
|
432
438
|
});
|
|
433
439
|
|
|
434
440
|
const stickerInfo = {
|
|
@@ -446,7 +452,7 @@ exports.LoadUtils = () => {
|
|
|
446
452
|
|
|
447
453
|
window.WWebJS.processMediaData = async (mediaInfo, { forceSticker, forceGif, forceVoice, forceDocument, forceMediaHd, sendToChannel, sendToStatus }) => {
|
|
448
454
|
const file = window.WWebJS.mediaInfoToFile(mediaInfo);
|
|
449
|
-
const opaqueData = await window.Store.OpaqueData.createFromData(file,
|
|
455
|
+
const opaqueData = await window.Store.OpaqueData.createFromData(file, mediaInfo.mimetype);
|
|
450
456
|
const mediaParams = {
|
|
451
457
|
asSticker: forceSticker,
|
|
452
458
|
asGif: forceGif,
|
|
@@ -500,7 +506,7 @@ exports.LoadUtils = () => {
|
|
|
500
506
|
mimetype: mediaData.mimetype,
|
|
501
507
|
mediaObject,
|
|
502
508
|
mediaType,
|
|
503
|
-
...(sendToChannel ? { calculateToken: window.Store.SendChannelMessage.getRandomFilehash
|
|
509
|
+
...(sendToChannel ? { calculateToken: window.Store.SendChannelMessage.getRandomFilehash } : {})
|
|
504
510
|
};
|
|
505
511
|
|
|
506
512
|
const uploadedMedia = !sendToChannel
|
|
@@ -566,10 +572,10 @@ exports.LoadUtils = () => {
|
|
|
566
572
|
|
|
567
573
|
if (isChannel) {
|
|
568
574
|
try {
|
|
569
|
-
chat = window.Store.
|
|
575
|
+
chat = window.Store.WAWebNewsletterMetadataCollection.get(chatId);
|
|
570
576
|
if (!chat) {
|
|
571
577
|
await window.Store.ChannelUtils.loadNewsletterPreviewChat(chatId);
|
|
572
|
-
chat = await window.Store.
|
|
578
|
+
chat = await window.Store.WAWebNewsletterMetadataCollection.find(chatWid);
|
|
573
579
|
}
|
|
574
580
|
} catch (err) {
|
|
575
581
|
chat = null;
|
|
@@ -619,7 +625,7 @@ exports.LoadUtils = () => {
|
|
|
619
625
|
};
|
|
620
626
|
|
|
621
627
|
window.WWebJS.getChannels = async () => {
|
|
622
|
-
const channels = window.Store.
|
|
628
|
+
const channels = window.Store.WAWebNewsletterMetadataCollection.getModelsArray();
|
|
623
629
|
const channelPromises = channels?.map((channel) => window.WWebJS.getChatModel(channel, { isChannel: true }));
|
|
624
630
|
return await Promise.all(channelPromises);
|
|
625
631
|
};
|
|
@@ -639,7 +645,8 @@ exports.LoadUtils = () => {
|
|
|
639
645
|
if (chat.groupMetadata) {
|
|
640
646
|
model.isGroup = true;
|
|
641
647
|
const chatWid = window.Store.WidFactory.createWid(chat.id._serialized);
|
|
642
|
-
|
|
648
|
+
const groupMetadata = window.Store.GroupMetadata || window.Store.WAWebGroupMetadataCollection;
|
|
649
|
+
await groupMetadata.update(chatWid);
|
|
643
650
|
chat.groupMetadata.participants._models
|
|
644
651
|
.filter(x => x.id?._serialized?.endsWith('@lid'))
|
|
645
652
|
.forEach(x => x.contact?.phoneNumber && (x.id = x.contact.phoneNumber));
|
|
@@ -648,7 +655,8 @@ exports.LoadUtils = () => {
|
|
|
648
655
|
}
|
|
649
656
|
|
|
650
657
|
if (chat.newsletterMetadata) {
|
|
651
|
-
|
|
658
|
+
const newsletterMetadata = window.Store.NewsletterMetadataCollection || window.Store.WAWebNewsletterMetadataCollection;
|
|
659
|
+
await newsletterMetadata.update(chat.id);
|
|
652
660
|
model.channelMetadata = chat.newsletterMetadata.serialize();
|
|
653
661
|
model.channelMetadata.createdAtTs = chat.newsletterMetadata.creationTime;
|
|
654
662
|
}
|