mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-18 11:39:14 +00:00
Compare commits
2 Commits
patch-part
...
pedroslope
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8afe71d959 | ||
|
|
afb0b5d7d3 |
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>, sleep?: number) => Promise<{ status: number }>
|
(participantIds: Array<string>) => 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>, sleep?: number) => Promise<{
|
(participantIds: Array<string>) => Promise<{
|
||||||
status: number;
|
status: number;
|
||||||
participants: Array<{
|
participants: Array<{
|
||||||
[key: string]: {
|
[key: string]: {
|
||||||
@@ -1326,9 +1326,6 @@ 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,6 +6,7 @@ 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');
|
||||||
@@ -108,6 +109,7 @@ 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',
|
||||||
@@ -562,6 +564,22 @@ 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,15 +62,7 @@ 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,7 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const Chat = require('./Chat');
|
const Chat = require('./Chat');
|
||||||
const Util = require('../util/Util');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Group participant information
|
* Group participant information
|
||||||
@@ -53,65 +52,57 @@ 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
|
||||||
* @param {?number} default 100ms, amount to sleep in milliseconds before adding the next participant
|
* @returns {Promise<Object>}
|
||||||
* @returns {Promise<Array<Object>>}
|
|
||||||
*/
|
*/
|
||||||
async addParticipants(participantIds, sleep = 100) {
|
async addParticipants(participantIds) {
|
||||||
return this._changeParticipants(participantIds, 'add', sleep);
|
return await this.client.pupPage.evaluate((chatId, participantIds) => {
|
||||||
|
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
|
||||||
* @param {?number} default 100ms, amount to sleep in milliseconds before removing the next participant
|
* @returns {Promise<Object>}
|
||||||
* @returns {Promise<Array<Object>>}
|
|
||||||
*/
|
*/
|
||||||
async removeParticipants(participantIds, sleep = 100) {
|
async removeParticipants(participantIds) {
|
||||||
return this._changeParticipants(participantIds, 'remove', sleep);
|
return await this.client.pupPage.evaluate((chatId, participantIds) => {
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Promote participants to admins by IDs
|
* Promotes participants by IDs to admins
|
||||||
* @param {Array<string>} participantIds
|
* @param {Array<string>} participantIds
|
||||||
* @param {?number} default 100ms, amount to sleep in milliseconds before promoting the next participant
|
* @returns {Promise<{ status: number }>} Object with status code indicating if the operation was successful
|
||||||
* @returns {Promise<Array<Object>>}
|
|
||||||
*/
|
*/
|
||||||
async promoteParticipants(participantIds, sleep = 100) {
|
async promoteParticipants(participantIds) {
|
||||||
return this._changeParticipants(participantIds, 'promote', sleep);
|
return await this.client.pupPage.evaluate((chatId, participantIds) => {
|
||||||
|
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 admins to regular participants by IDs
|
* Demotes participants by IDs to regular users
|
||||||
* @param {Array<string>} participantIds
|
* @param {Array<string>} participantIds
|
||||||
* @param {?number} default 100ms, amount to sleep in milliseconds before demoting the next participant
|
* @returns {Promise<{ status: number }>} Object with status code indicating if the operation was successful
|
||||||
* @returns {Promise<Array<Object>>}
|
|
||||||
*/
|
*/
|
||||||
async demoteParticipants(participantIds, sleep = 100) {
|
async demoteParticipants(participantIds) {
|
||||||
return this._changeParticipants(participantIds, 'demote', sleep);
|
return await this.client.pupPage.evaluate((chatId, participantIds) => {
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -240,4 +231,4 @@ class GroupChat extends Chat {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = GroupChat;
|
module.exports = GroupChat;
|
||||||
@@ -7,6 +7,7 @@ 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,8 +53,6 @@ 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]
|
||||||
@@ -604,21 +602,4 @@ 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,10 +181,6 @@ 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;
|
||||||
|
|||||||
16
src/util/VersionResolver.js
Normal file
16
src/util/VersionResolver.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
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,15 +18,24 @@ const getCurrentVersion = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateVersion = async (oldVersion, newVersion) => {
|
const updateInFile = (filePath, oldVersion, newVersion) => {
|
||||||
const readmePath = '../../README.md';
|
const originalFile = fs.readFileSync(filePath);
|
||||||
|
const newFile = originalFile.toString().replaceAll(oldVersion, newVersion);
|
||||||
const readme = fs.readFileSync(readmePath);
|
|
||||||
const newReadme = readme.toString().replaceAll(oldVersion, newVersion);
|
|
||||||
|
|
||||||
fs.writeFileSync(readmePath, newReadme);
|
fs.writeFileSync(filePath, newFile);
|
||||||
fs.writeFileSync('./.version', newVersion);
|
};
|
||||||
|
|
||||||
|
const updateVersion = async (oldVersion, newVersion) => {
|
||||||
|
const filesToUpdate = [
|
||||||
|
'../../src/util/Constants.js',
|
||||||
|
'../../README.md',
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const file of filesToUpdate) {
|
||||||
|
updateInFile(file, oldVersion, newVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.writeFileSync('./.version', newVersion);
|
||||||
};
|
};
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user