Compare commits

..

3 Commits

Author SHA1 Message Date
pedroslopez
e2f31092a5 Update supported WhatsApp Web version to v2.2247.7 2023-01-05 03:46:32 +00:00
Pedro S. Lopez
8655badc0f Create FUNDING.yml (#1901)
* Create FUNDING.yml

* Update README.md
2023-01-04 17:15:35 -04:00
Rajeh Taher
a7b77e15ed fix: Fix call event listener name + Added Call example (#1886)
* fix: bugfix + example

* relocate global variable
2022-12-23 12:10:09 -03:00
8 changed files with 53 additions and 54 deletions

3
.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1,3 @@
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.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)
[![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)
# whatsapp-web.js
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 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

View File

@@ -257,6 +257,15 @@ 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
View File

@@ -1108,11 +1108,11 @@ declare namespace WAWebJS {
/** Promotes or demotes participants by IDs to regular users or admins */
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 */
export type ChangeGroupParticipants =
(participantIds: Array<string>, sleep?: number) => Promise<{
(participantIds: Array<string>) => Promise<{
status: number;
participants: Array<{
[key: string]: {

View File

@@ -1,7 +1,6 @@
'use strict';
const Chat = require('./Chat');
const Util = require('../util/Util');
/**
* Group participant information
@@ -53,65 +52,57 @@ 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
* @param {?number} default 100ms, amount to sleep in milliseconds before adding the next participant
* @returns {Promise<Array<Object>>}
* @param {Array<string>} participantIds
* @returns {Promise<Object>}
*/
async addParticipants(participantIds, sleep = 100) {
return this._changeParticipants(participantIds, 'add', sleep);
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);
}
/**
* Removes a list of participants by ID to the group
* @param {Array<string>} participantIds
* @param {?number} default 100ms, amount to sleep in milliseconds before removing the next participant
* @returns {Promise<Array<Object>>}
* @param {Array<string>} participantIds
* @returns {Promise<Object>}
*/
async removeParticipants(participantIds, sleep = 100) {
return this._changeParticipants(participantIds, 'remove', sleep);
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);
}
/**
* 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>>}
* Promotes participants by IDs to admins
* @param {Array<string>} participantIds
* @returns {Promise<{ status: number }>} Object with status code indicating if the operation was successful
*/
async promoteParticipants(participantIds, sleep = 100) {
return this._changeParticipants(participantIds, 'promote', sleep);
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);
}
/**
* 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>>}
* 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
*/
async demoteParticipants(participantIds, sleep = 100) {
return this._changeParticipants(participantIds, 'demote', sleep);
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);
}
/**
@@ -240,4 +231,4 @@ class GroupChat extends Chat {
}
module.exports = GroupChat;
module.exports = GroupChat;

View File

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

View File

@@ -181,10 +181,6 @@ class Util {
static setFfmpegPath(path) {
ffmpeg.setFfmpegPath(path);
}
static sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
}
module.exports = Util;

View File

@@ -1 +1 @@
2.2245.9
2.2247.7