From 288a572af6c4794cc6d28127d60327a176b929d4 Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Thu, 22 Dec 2022 21:02:49 +0200 Subject: [PATCH 1/3] feat: Implement Call Rejection + Introduction of Socket API (#1882) * Initial stage * ESLint * eslint is annoying * fix: distinguish Wap from Socket's Wap --- index.d.ts | 3 +++ src/structures/Call.js | 10 +++++++++- src/util/Injected.js | 19 +++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 76ac264..4da695e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1326,6 +1326,9 @@ declare namespace WAWebJS { webClientShouldHandle: boolean, /** Object with participants */ participants: object + + /** Reject the call */ + reject: () => Promise } /** Message type List */ diff --git a/src/structures/Call.js b/src/structures/Call.js index 1e6644d..0e48989 100644 --- a/src/structures/Call.js +++ b/src/structures/Call.js @@ -62,7 +62,15 @@ class Call extends Base { 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; \ No newline at end of file diff --git a/src/util/Injected.js b/src/util/Injected.js index 7ece210..a0a7b12 100644 --- a/src/util/Injected.js +++ b/src/util/Injected.js @@ -53,6 +53,8 @@ exports.ExposeStore = (moduleRaidStr) => { window.Store.ReplyUtils = window.mR.findModule('canReplyMsg').length > 0 && window.mR.findModule('canReplyMsg')[0]; window.Store.MsgActionChecks = window.mR.findModule('canSenderRevokeMsg')[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.mR.findModule('toWebpSticker')[0], ...window.mR.findModule('addWebpMetadata')[0] @@ -602,4 +604,21 @@ exports.LoadUtils = () => { 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); + }; }; From a7b77e15ed73a7f1901ead19ffa3060ec7fba5cf Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Fri, 23 Dec 2022 17:10:09 +0200 Subject: [PATCH 2/3] fix: Fix call event listener name + Added Call example (#1886) * fix: bugfix + example * relocate global variable --- example.js | 9 +++++++++ src/util/Constants.js | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/example.js b/example.js index 99dc7ea..9e5eec5 100644 --- a/example.js +++ b/example.js @@ -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); }); diff --git a/src/util/Constants.js b/src/util/Constants.js index d062c7a..4c22fa1 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -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' }; From 8655badc0f638530f42e22ed6b2bf3850bd520aa Mon Sep 17 00:00:00 2001 From: "Pedro S. Lopez" Date: Wed, 4 Jan 2023 17:15:35 -0400 Subject: [PATCH 3/3] Create FUNDING.yml (#1901) * Create FUNDING.yml * Update README.md --- .github/FUNDING.yml | 3 +++ README.md | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..4a3a146 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,3 @@ +github: [pedroslopez, PurpShell] +ko_fi: pedroslopez +custom: ["paypal.me/psla", "buymeacoff.ee/pedroslopez"] diff --git a/README.md b/README.md index 3824f63..242dc28 100644 --- a/README.md +++ b/README.md @@ -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