mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-18 03:29:14 +00:00
Compare commits
4 Commits
pedroslope
...
fix-media-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b296f26cb1 | ||
|
|
8655badc0f | ||
|
|
a7b77e15ed | ||
|
|
288a572af6 |
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"]
|
||||||
@@ -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);
|
||||||
});
|
});
|
||||||
|
|||||||
3
index.d.ts
vendored
3
index.d.ts
vendored
@@ -1326,6 +1326,9 @@ 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,7 +6,6 @@ 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');
|
||||||
@@ -109,7 +108,6 @@ 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',
|
||||||
@@ -564,22 +562,6 @@ 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,7 +62,15 @@ 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;
|
||||||
@@ -7,7 +7,6 @@ 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,
|
||||||
@@ -52,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'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ 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]
|
||||||
@@ -265,6 +267,7 @@ exports.LoadUtils = () => {
|
|||||||
...ephemeralFields,
|
...ephemeralFields,
|
||||||
...locationOptions,
|
...locationOptions,
|
||||||
...attOptions,
|
...attOptions,
|
||||||
|
...(Object.keys(attOptions).length > 0 ? attOptions.toJSON() : {}),
|
||||||
...quotedMsgOptions,
|
...quotedMsgOptions,
|
||||||
...vcardOptions,
|
...vcardOptions,
|
||||||
...buttonOptions,
|
...buttonOptions,
|
||||||
@@ -602,4 +605,21 @@ 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);
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
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,24 +18,15 @@ const getCurrentVersion = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateInFile = (filePath, oldVersion, newVersion) => {
|
|
||||||
const originalFile = fs.readFileSync(filePath);
|
|
||||||
const newFile = originalFile.toString().replaceAll(oldVersion, newVersion);
|
|
||||||
|
|
||||||
fs.writeFileSync(filePath, newFile);
|
|
||||||
};
|
|
||||||
|
|
||||||
const updateVersion = async (oldVersion, newVersion) => {
|
const updateVersion = async (oldVersion, newVersion) => {
|
||||||
const filesToUpdate = [
|
const readmePath = '../../README.md';
|
||||||
'../../src/util/Constants.js',
|
|
||||||
'../../README.md',
|
const readme = fs.readFileSync(readmePath);
|
||||||
];
|
const newReadme = readme.toString().replaceAll(oldVersion, newVersion);
|
||||||
|
|
||||||
for (const file of filesToUpdate) {
|
fs.writeFileSync(readmePath, newReadme);
|
||||||
updateInFile(file, oldVersion, newVersion);
|
fs.writeFileSync('./.version', newVersion);
|
||||||
}
|
|
||||||
|
|
||||||
fs.writeFileSync('./.version', newVersion);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user