mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-18 11:39:14 +00:00
Compare commits
3 Commits
patch-part
...
auto-wa-we
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e2f31092a5 | ||
|
|
8655badc0f | ||
|
|
a7b77e15ed |
3
.github/FUNDING.yml
vendored
Normal file
3
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
github: [pedroslopez, PurpShell]
|
||||||
|
ko_fi: pedroslopez
|
||||||
|
custom: ["paypal.me/psla", "buymeacoff.ee/pedroslopez"]
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
[](https://www.npmjs.com/package/whatsapp-web.js) [](https://depfu.com/github/pedroslopez/whatsapp-web.js?project_id=9765)  [](https://discord.gg/H7DqQs4)
|
[](https://www.npmjs.com/package/whatsapp-web.js) [](https://depfu.com/github/pedroslopez/whatsapp-web.js?project_id=9765)  [](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 $100 in credit when you sign up (Referral)
|
- [Sign up for DigitalOcean](https://m.do.co/c/73f906a36ed4) and get $200 in credit when you sign up (Referral)
|
||||||
|
|
||||||
## Disclaimer
|
## Disclaimer
|
||||||
|
|
||||||
|
|||||||
@@ -257,6 +257,15 @@ 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
4
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]: {
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -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: 'incoming_call',
|
INCOMING_CALL: 'call',
|
||||||
REMOTE_SESSION_SAVED: 'remote_session_saved'
|
REMOTE_SESSION_SAVED: 'remote_session_saved'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
2.2245.9
|
2.2247.7
|
||||||
Reference in New Issue
Block a user