mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-18 03:29:14 +00:00
Compare commits
20 Commits
fix-media-
...
patch-part
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
48a3a03cdc | ||
|
|
9b659a26fa | ||
|
|
f0c7a0b0c2 | ||
|
|
53b8c1d967 | ||
|
|
56ec18a67c | ||
|
|
3775fd7c3e | ||
|
|
4247257850 | ||
|
|
374a6c505f | ||
|
|
1f80a86962 | ||
|
|
a9bbc0ed99 | ||
|
|
b99aa61dcc | ||
|
|
4ffd83015e | ||
|
|
510d44dc3e | ||
|
|
02ad3e0fd0 | ||
|
|
6ae8c42816 | ||
|
|
7fc72fe149 | ||
|
|
e980bf9b07 | ||
|
|
8e6314212d | ||
|
|
eb0d000159 | ||
|
|
cf5c5e4ec1 |
3
.github/FUNDING.yml
vendored
3
.github/FUNDING.yml
vendored
@@ -1,3 +0,0 @@
|
||||
github: [pedroslopez, PurpShell]
|
||||
ko_fi: pedroslopez
|
||||
custom: ["paypal.me/psla", "buymeacoff.ee/pedroslopez"]
|
||||
@@ -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 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
|
||||
|
||||
|
||||
@@ -257,15 +257,6 @@ client.on('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) => {
|
||||
console.log('Client was logged out', reason);
|
||||
});
|
||||
|
||||
4
index.d.ts
vendored
4
index.d.ts
vendored
@@ -1108,11 +1108,11 @@ declare namespace WAWebJS {
|
||||
|
||||
/** Promotes or demotes participants by IDs to regular users or admins */
|
||||
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 */
|
||||
export type ChangeGroupParticipants =
|
||||
(participantIds: Array<string>) => Promise<{
|
||||
(participantIds: Array<string>, sleep?: number) => Promise<{
|
||||
status: number;
|
||||
participants: Array<{
|
||||
[key: string]: {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const Chat = require('./Chat');
|
||||
const Util = require('../util/Util');
|
||||
|
||||
/**
|
||||
* Group participant information
|
||||
@@ -52,57 +53,65 @@ class GroupChat extends Chat {
|
||||
get 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
|
||||
* @param {Array<string>} participantIds
|
||||
* @returns {Promise<Object>}
|
||||
* @param {Array<string>} participantIds
|
||||
* @param {?number} default 100ms, amount to sleep in milliseconds before adding the next participant
|
||||
* @returns {Promise<Array<Object>>}
|
||||
*/
|
||||
async addParticipants(participantIds) {
|
||||
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);
|
||||
async addParticipants(participantIds, sleep = 100) {
|
||||
return this._changeParticipants(participantIds, 'add', sleep);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a list of participants by ID to the group
|
||||
* @param {Array<string>} participantIds
|
||||
* @returns {Promise<Object>}
|
||||
* @param {Array<string>} participantIds
|
||||
* @param {?number} default 100ms, amount to sleep in milliseconds before removing the next participant
|
||||
* @returns {Promise<Array<Object>>}
|
||||
*/
|
||||
async removeParticipants(participantIds) {
|
||||
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);
|
||||
async removeParticipants(participantIds, sleep = 100) {
|
||||
return this._changeParticipants(participantIds, 'remove', sleep);
|
||||
}
|
||||
|
||||
/**
|
||||
* Promotes participants by IDs to admins
|
||||
* @param {Array<string>} participantIds
|
||||
* @returns {Promise<{ status: number }>} Object with status code indicating if the operation was successful
|
||||
* Promote participants to admins by IDs
|
||||
* @param {Array<string>} participantIds
|
||||
* @param {?number} default 100ms, amount to sleep in milliseconds before promoting the next participant
|
||||
* @returns {Promise<Array<Object>>}
|
||||
*/
|
||||
async promoteParticipants(participantIds) {
|
||||
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);
|
||||
async promoteParticipants(participantIds, sleep = 100) {
|
||||
return this._changeParticipants(participantIds, 'promote', sleep);
|
||||
}
|
||||
|
||||
/**
|
||||
* Demotes participants by IDs to regular users
|
||||
* @param {Array<string>} participantIds
|
||||
* @returns {Promise<{ status: number }>} Object with status code indicating if the operation was successful
|
||||
* Demotes admins to regular participants by IDs
|
||||
* @param {Array<string>} participantIds
|
||||
* @param {?number} default 100ms, amount to sleep in milliseconds before demoting the next participant
|
||||
* @returns {Promise<Array<Object>>}
|
||||
*/
|
||||
async demoteParticipants(participantIds) {
|
||||
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);
|
||||
async demoteParticipants(participantIds, sleep = 100) {
|
||||
return this._changeParticipants(participantIds, 'demote', sleep);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -231,4 +240,4 @@ class GroupChat extends Chat {
|
||||
|
||||
}
|
||||
|
||||
module.exports = GroupChat;
|
||||
module.exports = GroupChat;
|
||||
|
||||
@@ -51,7 +51,7 @@ exports.Events = {
|
||||
DISCONNECTED: 'disconnected',
|
||||
STATE_CHANGED: 'change_state',
|
||||
BATTERY_CHANGED: 'change_battery',
|
||||
INCOMING_CALL: 'call',
|
||||
INCOMING_CALL: 'incoming_call',
|
||||
REMOTE_SESSION_SAVED: 'remote_session_saved'
|
||||
};
|
||||
|
||||
|
||||
@@ -267,7 +267,6 @@ exports.LoadUtils = () => {
|
||||
...ephemeralFields,
|
||||
...locationOptions,
|
||||
...attOptions,
|
||||
...(Object.keys(attOptions).length > 0 ? attOptions.toJSON() : {}),
|
||||
...quotedMsgOptions,
|
||||
...vcardOptions,
|
||||
...buttonOptions,
|
||||
|
||||
@@ -181,6 +181,10 @@ class Util {
|
||||
static setFfmpegPath(path) {
|
||||
ffmpeg.setFfmpegPath(path);
|
||||
}
|
||||
|
||||
static sleep(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Util;
|
||||
|
||||
Reference in New Issue
Block a user