mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-18 03:29:14 +00:00
Compare commits
21 Commits
pedroslope
...
patch-part
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
48a3a03cdc | ||
|
|
288a572af6 | ||
|
|
9b659a26fa | ||
|
|
f0c7a0b0c2 | ||
|
|
53b8c1d967 | ||
|
|
56ec18a67c | ||
|
|
3775fd7c3e | ||
|
|
4247257850 | ||
|
|
374a6c505f | ||
|
|
1f80a86962 | ||
|
|
a9bbc0ed99 | ||
|
|
b99aa61dcc | ||
|
|
4ffd83015e | ||
|
|
510d44dc3e | ||
|
|
02ad3e0fd0 | ||
|
|
6ae8c42816 | ||
|
|
7fc72fe149 | ||
|
|
e980bf9b07 | ||
|
|
8e6314212d | ||
|
|
eb0d000159 | ||
|
|
cf5c5e4ec1 |
7
index.d.ts
vendored
7
index.d.ts
vendored
@@ -1108,11 +1108,11 @@ declare namespace WAWebJS {
|
|||||||
|
|
||||||
/** Promotes or demotes participants by IDs to regular users or admins */
|
/** Promotes or demotes participants by IDs to regular users or admins */
|
||||||
export type ChangeParticipantsPermissions =
|
export type ChangeParticipantsPermissions =
|
||||||
(participantIds: Array<string>) => Promise<{ status: number }>
|
(participantIds: Array<string>, sleep?: number) => Promise<{ status: number }>
|
||||||
|
|
||||||
/** Adds or removes a list of participants by ID to the group */
|
/** Adds or removes a list of participants by ID to the group */
|
||||||
export type ChangeGroupParticipants =
|
export type ChangeGroupParticipants =
|
||||||
(participantIds: Array<string>) => Promise<{
|
(participantIds: Array<string>, sleep?: number) => Promise<{
|
||||||
status: number;
|
status: number;
|
||||||
participants: Array<{
|
participants: Array<{
|
||||||
[key: string]: {
|
[key: string]: {
|
||||||
@@ -1326,6 +1326,9 @@ declare namespace WAWebJS {
|
|||||||
webClientShouldHandle: boolean,
|
webClientShouldHandle: boolean,
|
||||||
/** Object with participants */
|
/** Object with participants */
|
||||||
participants: object
|
participants: object
|
||||||
|
|
||||||
|
/** Reject the call */
|
||||||
|
reject: () => Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Message type List */
|
/** Message type List */
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ const moduleRaid = require('@pedroslopez/moduleraid/moduleraid');
|
|||||||
|
|
||||||
const Util = require('./util/Util');
|
const Util = require('./util/Util');
|
||||||
const InterfaceController = require('./util/InterfaceController');
|
const InterfaceController = require('./util/InterfaceController');
|
||||||
const { getIndexForVersion } = require('./util/VersionResolver');
|
|
||||||
const { WhatsWebURL, DefaultOptions, Events, WAState } = require('./util/Constants');
|
const { WhatsWebURL, DefaultOptions, Events, WAState } = require('./util/Constants');
|
||||||
const { ExposeStore, LoadUtils } = require('./util/Injected');
|
const { ExposeStore, LoadUtils } = require('./util/Injected');
|
||||||
const ChatFactory = require('./factories/ChatFactory');
|
const ChatFactory = require('./factories/ChatFactory');
|
||||||
@@ -109,7 +108,6 @@ class Client extends EventEmitter {
|
|||||||
this.pupPage = page;
|
this.pupPage = page;
|
||||||
|
|
||||||
await this.authStrategy.afterBrowserInitialized();
|
await this.authStrategy.afterBrowserInitialized();
|
||||||
await this.initVersionOverride();
|
|
||||||
|
|
||||||
await page.goto(WhatsWebURL, {
|
await page.goto(WhatsWebURL, {
|
||||||
waitUntil: 'load',
|
waitUntil: 'load',
|
||||||
@@ -564,22 +562,6 @@ class Client extends EventEmitter {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async initVersionOverride() {
|
|
||||||
const version = this.options.webVersion;
|
|
||||||
await this.pupPage.setRequestInterception(true);
|
|
||||||
this.pupPage.on('request', async (req) => {
|
|
||||||
if(req.url() === WhatsWebURL) {
|
|
||||||
req.respond({
|
|
||||||
status: 200,
|
|
||||||
contentType: 'text/html',
|
|
||||||
body: await getIndexForVersion(version)
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
req.continue();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes the client
|
* Closes the client
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -62,7 +62,15 @@ class Call extends Base {
|
|||||||
|
|
||||||
return super._patch(data);
|
return super._patch(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reject the call
|
||||||
|
*/
|
||||||
|
async reject() {
|
||||||
|
return this.client.pupPage.evaluate((peerJid, id) => {
|
||||||
|
return window.WWebJS.rejectCall(peerJid, id);
|
||||||
|
}, this.from, this.id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Call;
|
module.exports = Call;
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const Chat = require('./Chat');
|
const Chat = require('./Chat');
|
||||||
|
const Util = require('../util/Util');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Group participant information
|
* Group participant information
|
||||||
@@ -52,57 +53,65 @@ class GroupChat extends Chat {
|
|||||||
get participants() {
|
get participants() {
|
||||||
return this.groupMetadata.participants;
|
return this.groupMetadata.participants;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal function to change a number of participant's state..
|
||||||
|
* @param {string} type (promote|demote|add|remove)
|
||||||
|
*/
|
||||||
|
async _changeParticipants(participantIds, type, sleep = null) {
|
||||||
|
return await this.client.pupPage.evaluate(async (chatId, participantIds, type, sleep) => {
|
||||||
|
if (type != 'add' && type != 'remove' && type != 'promote' && type != 'demote') return null;
|
||||||
|
const chatWid = window.Store.WidFactory.createWid(chatId);
|
||||||
|
const participantWids = participantIds.map(p => window.Store.WidFactory.createWid(p));
|
||||||
|
const status = [];
|
||||||
|
for (const participantWid of participantWids) {
|
||||||
|
status.push(await window.Store.GroupParticipants['send'+type.charAt(0).toUpperCase() + type.slice(1)+'Participants'](chatWid, [participantWid]));
|
||||||
|
if (sleep) {
|
||||||
|
await Util.sleep(sleep);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}, this.id._serialized, participantIds, type, sleep);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a list of participants by ID to the group
|
* Adds a list of participants by ID to the group
|
||||||
* @param {Array<string>} participantIds
|
* @param {Array<string>} participantIds
|
||||||
* @returns {Promise<Object>}
|
* @param {?number} default 100ms, amount to sleep in milliseconds before adding the next participant
|
||||||
|
* @returns {Promise<Array<Object>>}
|
||||||
*/
|
*/
|
||||||
async addParticipants(participantIds) {
|
async addParticipants(participantIds, sleep = 100) {
|
||||||
return await this.client.pupPage.evaluate((chatId, participantIds) => {
|
return this._changeParticipants(participantIds, 'add', sleep);
|
||||||
const chatWid = window.Store.WidFactory.createWid(chatId);
|
|
||||||
const participantWids = participantIds.map(p => window.Store.WidFactory.createWid(p));
|
|
||||||
return window.Store.GroupParticipants.sendAddParticipants(chatWid, participantWids);
|
|
||||||
}, this.id._serialized, participantIds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a list of participants by ID to the group
|
* Removes a list of participants by ID to the group
|
||||||
* @param {Array<string>} participantIds
|
* @param {Array<string>} participantIds
|
||||||
* @returns {Promise<Object>}
|
* @param {?number} default 100ms, amount to sleep in milliseconds before removing the next participant
|
||||||
|
* @returns {Promise<Array<Object>>}
|
||||||
*/
|
*/
|
||||||
async removeParticipants(participantIds) {
|
async removeParticipants(participantIds, sleep = 100) {
|
||||||
return await this.client.pupPage.evaluate((chatId, participantIds) => {
|
return this._changeParticipants(participantIds, 'remove', sleep);
|
||||||
const chatWid = window.Store.WidFactory.createWid(chatId);
|
|
||||||
const participantWids = participantIds.map(p => window.Store.WidFactory.createWid(p));
|
|
||||||
return window.Store.GroupParticipants.sendRemoveParticipants(chatWid, participantWids);
|
|
||||||
}, this.id._serialized, participantIds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Promotes participants by IDs to admins
|
* Promote participants to admins by IDs
|
||||||
* @param {Array<string>} participantIds
|
* @param {Array<string>} participantIds
|
||||||
* @returns {Promise<{ status: number }>} Object with status code indicating if the operation was successful
|
* @param {?number} default 100ms, amount to sleep in milliseconds before promoting the next participant
|
||||||
|
* @returns {Promise<Array<Object>>}
|
||||||
*/
|
*/
|
||||||
async promoteParticipants(participantIds) {
|
async promoteParticipants(participantIds, sleep = 100) {
|
||||||
return await this.client.pupPage.evaluate((chatId, participantIds) => {
|
return this._changeParticipants(participantIds, 'promote', sleep);
|
||||||
const chatWid = window.Store.WidFactory.createWid(chatId);
|
|
||||||
const participantWids = participantIds.map(p => window.Store.WidFactory.createWid(p));
|
|
||||||
return window.Store.GroupParticipants.sendPromoteParticipants(chatWid, participantWids);
|
|
||||||
}, this.id._serialized, participantIds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Demotes participants by IDs to regular users
|
* Demotes admins to regular participants by IDs
|
||||||
* @param {Array<string>} participantIds
|
* @param {Array<string>} participantIds
|
||||||
* @returns {Promise<{ status: number }>} Object with status code indicating if the operation was successful
|
* @param {?number} default 100ms, amount to sleep in milliseconds before demoting the next participant
|
||||||
|
* @returns {Promise<Array<Object>>}
|
||||||
*/
|
*/
|
||||||
async demoteParticipants(participantIds) {
|
async demoteParticipants(participantIds, sleep = 100) {
|
||||||
return await this.client.pupPage.evaluate((chatId, participantIds) => {
|
return this._changeParticipants(participantIds, 'demote', sleep);
|
||||||
const chatWid = window.Store.WidFactory.createWid(chatId);
|
|
||||||
const participantWids = participantIds.map(p => window.Store.WidFactory.createWid(p));
|
|
||||||
return window.Store.GroupParticipants.sendDemoteParticipants(chatWid, participantWids);
|
|
||||||
}, this.id._serialized, participantIds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -231,4 +240,4 @@ class GroupChat extends Chat {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = GroupChat;
|
module.exports = GroupChat;
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ exports.DefaultOptions = {
|
|||||||
headless: true,
|
headless: true,
|
||||||
defaultViewport: null
|
defaultViewport: null
|
||||||
},
|
},
|
||||||
webVersion: '2.2244.6',
|
|
||||||
authTimeoutMs: 0,
|
authTimeoutMs: 0,
|
||||||
qrMaxRetries: 0,
|
qrMaxRetries: 0,
|
||||||
takeoverOnConflict: false,
|
takeoverOnConflict: false,
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ exports.ExposeStore = (moduleRaidStr) => {
|
|||||||
window.Store.ReplyUtils = window.mR.findModule('canReplyMsg').length > 0 && window.mR.findModule('canReplyMsg')[0];
|
window.Store.ReplyUtils = window.mR.findModule('canReplyMsg').length > 0 && window.mR.findModule('canReplyMsg')[0];
|
||||||
window.Store.MsgActionChecks = window.mR.findModule('canSenderRevokeMsg')[0];
|
window.Store.MsgActionChecks = window.mR.findModule('canSenderRevokeMsg')[0];
|
||||||
window.Store.QuotedMsg = window.mR.findModule('getQuotedMsgObj')[0];
|
window.Store.QuotedMsg = window.mR.findModule('getQuotedMsgObj')[0];
|
||||||
|
window.Store.Socket = window.mR.findModule('deprecatedSendIq')[0];
|
||||||
|
window.Store.SocketWap = window.mR.findModule('wap')[0];
|
||||||
window.Store.StickerTools = {
|
window.Store.StickerTools = {
|
||||||
...window.mR.findModule('toWebpSticker')[0],
|
...window.mR.findModule('toWebpSticker')[0],
|
||||||
...window.mR.findModule('addWebpMetadata')[0]
|
...window.mR.findModule('addWebpMetadata')[0]
|
||||||
@@ -602,4 +604,21 @@ exports.LoadUtils = () => {
|
|||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
window.WWebJS.rejectCall = async (peerJid, id) => {
|
||||||
|
peerJid = peerJid.split('@')[0] + '@s.whatsapp.net';
|
||||||
|
let userId = window.Store.User.getMaybeMeUser().user + '@s.whatsapp.net';
|
||||||
|
const stanza = window.Store.SocketWap.wap('call', {
|
||||||
|
id: window.Store.SocketWap.generateId(),
|
||||||
|
from: window.Store.SocketWap.USER_JID(userId),
|
||||||
|
to: window.Store.SocketWap.USER_JID(peerJid),
|
||||||
|
}, [
|
||||||
|
window.Store.SocketWap.wap('reject', {
|
||||||
|
'call-id': id,
|
||||||
|
'call-creator': window.Store.SocketWap.USER_JID(peerJid),
|
||||||
|
count: '0',
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
await window.Store.Socket.deprecatedCastStanza(stanza);
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -181,6 +181,10 @@ class Util {
|
|||||||
static setFfmpegPath(path) {
|
static setFfmpegPath(path) {
|
||||||
ffmpeg.setFfmpegPath(path);
|
ffmpeg.setFfmpegPath(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static sleep(ms) {
|
||||||
|
return new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Util;
|
module.exports = Util;
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
const fetch = require('node-fetch');
|
|
||||||
|
|
||||||
const VERSION_ARCHIVE_URL = 'https://archive.wwebjs.dev/web-index';
|
|
||||||
|
|
||||||
class VersionResolveError extends Error { }
|
|
||||||
|
|
||||||
const getIndexForVersion = async (version) => {
|
|
||||||
const cachedRes = await fetch(`${VERSION_ARCHIVE_URL}/${version}`);
|
|
||||||
if(!cachedRes.ok) throw new VersionResolveError(`Couldn't load app for version ${version} from the archive`);
|
|
||||||
return cachedRes.text();
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
VersionResolveError,
|
|
||||||
getIndexForVersion
|
|
||||||
};
|
|
||||||
@@ -18,24 +18,15 @@ const getCurrentVersion = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateInFile = (filePath, oldVersion, newVersion) => {
|
|
||||||
const originalFile = fs.readFileSync(filePath);
|
|
||||||
const newFile = originalFile.toString().replaceAll(oldVersion, newVersion);
|
|
||||||
|
|
||||||
fs.writeFileSync(filePath, newFile);
|
|
||||||
};
|
|
||||||
|
|
||||||
const updateVersion = async (oldVersion, newVersion) => {
|
const updateVersion = async (oldVersion, newVersion) => {
|
||||||
const filesToUpdate = [
|
const readmePath = '../../README.md';
|
||||||
'../../src/util/Constants.js',
|
|
||||||
'../../README.md',
|
const readme = fs.readFileSync(readmePath);
|
||||||
];
|
const newReadme = readme.toString().replaceAll(oldVersion, newVersion);
|
||||||
|
|
||||||
for (const file of filesToUpdate) {
|
fs.writeFileSync(readmePath, newReadme);
|
||||||
updateInFile(file, oldVersion, newVersion);
|
fs.writeFileSync('./.version', newVersion);
|
||||||
}
|
|
||||||
|
|
||||||
fs.writeFileSync('./.version', newVersion);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user