Compare commits

..

20 Commits

Author SHA1 Message Date
Rajeh Taher
48a3a03cdc Merge branch 'main' into patch-participants 2022-12-23 09:54:14 +02:00
Rajeh Taher
9b659a26fa Merge branch 'main' into patch-participants 2022-11-08 18:00:33 +02:00
Rajeh Taher
f0c7a0b0c2 Merge branch 'main' into patch-participants 2022-10-22 22:36:50 +03:00
Rajeh Taher
53b8c1d967 Merge branch 'main' into patch-participants 2022-10-10 01:55:56 +03:00
Rajeh Taher
56ec18a67c Update GroupChat.js 2022-10-10 01:55:32 +03:00
Rajeh Taher
3775fd7c3e Merge branch 'main' into patch-participants 2022-09-29 20:20:17 +03:00
Rajeh Taher
4247257850 ERROR/ESLINT 2022-08-10 19:55:06 +03:00
Rajeh Taher
374a6c505f Merge branch 'main' into patch-participants 2022-08-10 19:53:50 +03:00
Rajeh Taher
1f80a86962 Update GroupChat.js 2022-08-09 13:50:56 +03:00
Rajeh Taher
a9bbc0ed99 Update GroupChat.js 2022-08-09 13:42:03 +03:00
Rajeh Taher
b99aa61dcc Merge branch 'main' into patch-participants 2022-08-09 13:22:23 +03:00
Rajeh Taher
4ffd83015e eslint!! 2022-07-07 18:57:34 +03:00
Rajeh Taher
510d44dc3e a 2022-07-07 18:53:20 +03:00
Rajeh Taher
02ad3e0fd0 add sleep 2022-07-07 18:49:19 +03:00
Rajeh Taher
6ae8c42816 fixing ESLint errors 2022-07-07 18:30:26 +03:00
Rajeh Taher
7fc72fe149 Merge branch 'main' into patch-participants 2022-07-07 18:23:18 +03:00
Rajeh Taher
e980bf9b07 Merge branch 'main' into patch-participants 2022-02-09 10:57:41 +02:00
Rajeh Taher
8e6314212d Merge branch 'main' into patch-participants 2022-02-06 21:35:24 +02:00
Rajeh Taher
eb0d000159 fixes 🎉 2022-01-29 01:58:14 +02:00
Rajeh Taher
cf5c5e4ec1 Update GroupChat.js 2022-01-29 01:54:30 +02:00
8 changed files with 54 additions and 53 deletions

3
.github/FUNDING.yml vendored
View File

@@ -1,3 +0,0 @@
github: [pedroslopez, PurpShell]
ko_fi: pedroslopez
custom: ["paypal.me/psla", "buymeacoff.ee/pedroslopez"]

View File

@@ -1,4 +1,4 @@
[![npm](https://img.shields.io/npm/v/whatsapp-web.js.svg)](https://www.npmjs.com/package/whatsapp-web.js) [![Depfu](https://badges.depfu.com/badges/4a65a0de96ece65fdf39e294e0c8dcba/overview.svg)](https://depfu.com/github/pedroslopez/whatsapp-web.js?project_id=9765) ![WhatsApp_Web 2.2247.7](https://img.shields.io/badge/WhatsApp_Web-2.2247.7-brightgreen.svg) [![Discord Chat](https://img.shields.io/discord/698610475432411196.svg?logo=discord)](https://discord.gg/H7DqQs4) [![npm](https://img.shields.io/npm/v/whatsapp-web.js.svg)](https://www.npmjs.com/package/whatsapp-web.js) [![Depfu](https://badges.depfu.com/badges/4a65a0de96ece65fdf39e294e0c8dcba/overview.svg)](https://depfu.com/github/pedroslopez/whatsapp-web.js?project_id=9765) ![WhatsApp_Web 2.2245.9](https://img.shields.io/badge/WhatsApp_Web-2.2245.9-brightgreen.svg) [![Discord Chat](https://img.shields.io/discord/698610475432411196.svg?logo=discord)](https://discord.gg/H7DqQs4)
# whatsapp-web.js # whatsapp-web.js
A WhatsApp API client that connects through the WhatsApp Web browser app A WhatsApp API client that connects through the WhatsApp Web browser app
@@ -94,7 +94,7 @@ You can support the maintainer of this project through the links below
- [Support via GitHub Sponsors](https://github.com/sponsors/pedroslopez) - [Support via GitHub Sponsors](https://github.com/sponsors/pedroslopez)
- [Support via PayPal](https://www.paypal.me/psla/) - [Support via PayPal](https://www.paypal.me/psla/)
- [Sign up for DigitalOcean](https://m.do.co/c/73f906a36ed4) and get $200 in credit when you sign up (Referral) - [Sign up for DigitalOcean](https://m.do.co/c/73f906a36ed4) and get $100 in credit when you sign up (Referral)
## Disclaimer ## Disclaimer

View File

@@ -257,15 +257,6 @@ client.on('change_state', state => {
console.log('CHANGE STATE', state ); console.log('CHANGE STATE', state );
}); });
// Change to false if you don't want to reject incoming calls
let rejectCalls = true;
client.on('call', async (call) => {
console.log('Call received, rejecting. GOTO Line 261 to disable', call);
if (rejectCalls) await call.reject();
await client.sendMessage(call.from, `[${call.fromMe ? 'Outgoing' : 'Incoming'}] Phone call from ${call.from}, type ${call.isGroup ? 'group' : ''} ${call.isVideo ? 'video' : 'audio'} call. ${rejectCalls ? 'This call was automatically rejected by the script.' : ''}`);
});
client.on('disconnected', (reason) => { client.on('disconnected', (reason) => {
console.log('Client was logged out', reason); console.log('Client was logged out', reason);
}); });

4
index.d.ts vendored
View File

@@ -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]: {

View File

@@ -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;

View File

@@ -51,7 +51,7 @@ exports.Events = {
DISCONNECTED: 'disconnected', DISCONNECTED: 'disconnected',
STATE_CHANGED: 'change_state', STATE_CHANGED: 'change_state',
BATTERY_CHANGED: 'change_battery', BATTERY_CHANGED: 'change_battery',
INCOMING_CALL: 'call', INCOMING_CALL: 'incoming_call',
REMOTE_SESSION_SAVED: 'remote_session_saved' REMOTE_SESSION_SAVED: 'remote_session_saved'
}; };

View File

@@ -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;

View File

@@ -1 +1 @@
2.2247.7 2.2245.9