Compare commits

..

1 Commits

Author SHA1 Message Date
dependabot[bot]
1499ea503e chore(deps): bump node-fetch from 2.6.7 to 3.3.0
Bumps [node-fetch](https://github.com/node-fetch/node-fetch) from 2.6.7 to 3.3.0.
- [Release notes](https://github.com/node-fetch/node-fetch/releases)
- [Commits](https://github.com/node-fetch/node-fetch/compare/v2.6.7...v3.3.0)

---
updated-dependencies:
- dependency-name: node-fetch
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-11-26 09:28:42 +00:00
12 changed files with 53 additions and 277 deletions

3
.github/FUNDING.yml vendored
View File

@@ -1,3 +0,0 @@
github: [pedroslopez, PurpShell]
ko_fi: pedroslopez
custom: ["paypal.me/psla", "buymeacoff.ee/pedroslopez"]

View File

@@ -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

View File

@@ -197,27 +197,6 @@ client.on('message', async msg => {
client.sendMessage(msg.from, list);
} else if (msg.body === '!reaction') {
msg.react('👍');
} else if (msg.body.startsWith('!vote ')) {
if (msg.hasQuotedMsg) {
const quotedMsg = await msg.getQuotedMessage();
if (quotedMsg.type === 'poll_creation') {
const options = msg.body.slice(6).split('//');
const voteCount = {};
for (const pollVote of quotedMsg.pollVotes) {
for (const selectedOption of pollVote.selectedOptions) {
if (!voteCount[selectedOption]) voteCount[selectedOption] = 0;
voteCount[selectedOption]++;
}
}
const voteCountStr = Object.entries(voteCount).map(([vote, number]) => ` -${vote}: ${number}`).join('\n');
quotedMsg.reply(
`Voting to poll ${quotedMsg.body}, with options: ${options.join(', ')}\ncurrent vote count:\n${voteCountStr}`
);
quotedMsg.vote(options);
} else {
msg.reply('Usage: !vote TEST1//TEST2');
}
}
}
});
@@ -274,23 +253,10 @@ client.on('group_update', (notification) => {
console.log('update', notification);
});
client.on('poll_vote', (vote) => {
console.log(`Vote received, from ${vote.sender}, ${vote.selectedOptions.map(a => ` - ${a}`).join('\n')}`);
});
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);
});

33
index.d.ts vendored
View File

@@ -2,7 +2,6 @@
import { EventEmitter } from 'events'
import { RequestInit } from 'node-fetch'
import * as puppeteer from 'puppeteer'
import PollVote from './src/structures/PollVote'
declare namespace WAWebJS {
@@ -269,12 +268,6 @@ declare namespace WAWebJS {
/** Emitted when the RemoteAuth session is saved successfully on the external Database */
on(event: 'remote_session_saved', listener: () => void): this
/** Emitted when a poll vote is received */
on(event: 'poll_vote', listener: (
/** The poll vote */
vote: PollVote
) => void): this
}
/** Current connection information */
@@ -513,8 +506,7 @@ declare namespace WAWebJS {
DISCONNECTED = 'disconnected',
STATE_CHANGED = 'change_state',
BATTERY_CHANGED = 'change_battery',
REMOTE_SESSION_SAVED = 'remote_session_saved',
POLL_VOTE = 'poll_vote'
REMOTE_SESSION_SAVED = 'remote_session_saved'
}
/** Group notification types */
@@ -577,7 +569,6 @@ declare namespace WAWebJS {
PROTOCOL = 'protocol',
REACTION = 'reaction',
TEMPLATE_BUTTON_REPLY = 'template_button_reply',
POLL_CREATION = 'poll_creation',
}
/** Client status */
@@ -730,10 +721,6 @@ declare namespace WAWebJS {
selectedRowId?: string,
/** Returns message in a raw format */
rawData: object,
/** Avaiaible poll voting options */
pollOptions: string[],
/** The current poll votes, refresh with .refreshPollVotes() */
pollVotes: PollVote[],
/*
* Reloads this Message object's data in-place with the latest values from WhatsApp Web.
* Note that the Message must still be in the web app cache for this to work, otherwise will return null.
@@ -779,15 +766,6 @@ declare namespace WAWebJS {
* Gets the payment details associated with a given message
*/
getPayment: () => Promise<Payment>,
/**
* Refreshes the current poll votes, only works with a poll_creation message
*/
refreshPollVotes: () => Promise<void>,
/**
* Vote on the poll, only works with a poll_creation message
* @param {Array<string>} selectedOptions The selected options from .pollOptions
*/
vote: (selectedOptions: string[]) => Promise<void>,
}
/** ID that represents a message */
@@ -1348,9 +1326,6 @@ declare namespace WAWebJS {
webClientShouldHandle: boolean,
/** Object with participants */
participants: object
/** Reject the call */
reject: () => Promise<void>
}
/** Message type List */
@@ -1386,12 +1361,6 @@ declare namespace WAWebJS {
senderId: string
ack?: number
}
export class PollVote {
selectedOptions: string[]
sender: string
senderTimestampMs: number
}
}
export = WAWebJS

View File

@@ -21,15 +21,12 @@ module.exports = {
ProductMetadata: require('./src/structures/ProductMetadata'),
List: require('./src/structures/List'),
Buttons: require('./src/structures/Buttons'),
PollVote: require('./src/structures/PollVote'),
Call: require('./src/structures/Call'),
// Auth Strategies
NoAuth: require('./src/authStrategies/NoAuth'),
LocalAuth: require('./src/authStrategies/LocalAuth'),
RemoteAuth: require('./src/authStrategies/RemoteAuth'),
LegacySessionAuth: require('./src/authStrategies/LegacySessionAuth'),
...Constants
};

View File

@@ -33,7 +33,7 @@
"fluent-ffmpeg": "^2.1.2",
"jsqr": "^1.3.1",
"mime": "^3.0.0",
"node-fetch": "^2.6.5",
"node-fetch": "^3.3.0",
"node-webpmux": "^3.1.0",
"puppeteer": "^13.0.0"
},

View File

@@ -13,7 +13,6 @@ const ContactFactory = require('./factories/ContactFactory');
const { ClientInfo, Message, MessageMedia, Contact, Location, GroupNotification, Label, Call, Buttons, List, Reaction } = require('./structures');
const LegacySessionAuth = require('./authStrategies/LegacySessionAuth');
const NoAuth = require('./authStrategies/NoAuth');
const PollVote = require('./structures/PollVote');
/**
* Starting point for interacting with the WhatsApp Web API
@@ -46,7 +45,6 @@ const PollVote = require('./structures/PollVote');
* @fires Client#group_update
* @fires Client#disconnected
* @fires Client#change_state
* @fires
*/
class Client extends EventEmitter {
constructor(options = {}) {
@@ -85,14 +83,7 @@ class Client extends EventEmitter {
* Sets up events and requirements, kicks off authentication request
*/
async initialize() {
/**
* @type {puppeteer.Browser}
*/
let browser = null;
/**
* @type {puppeteer.Page}
*/
let page = null;
let [browser, page] = [null, null];
await this.authStrategy.beforeBrowserInitialized();
@@ -495,19 +486,6 @@ class Client extends EventEmitter {
this.emit(Events.INCOMING_CALL, cll);
});
await page.exposeFunction('onPollVote', (vote) => {
const vote_ = new PollVote(this, vote);
/**
* Emitted when a poll vote is received
* @event Client#poll_vote
* @param {object} vote
* @param {string} vote.sender Sender of the vote
* @param {number} vote.senderTimestampMs Timestamp the vote was sent
* @param {Array<string>} vote.selectedOptions Options selected
*/
this.emit(Events.POLL_VOTE, vote_);
});
await page.exposeFunction('onReaction', (reactions) => {
for (const reaction of reactions) {
/**
@@ -548,12 +526,7 @@ class Client extends EventEmitter {
}
}
});
window.Store.PollVote.on('add', (vote) => {
if (vote.parentMsgKey) vote.pollCreationMessage = window.Store.Msg.get(vote.parentMsgKey).serialize();
window.onPollVote(vote);
});
{
const module = window.Store.createOrUpdateReactionsModule;
const ogMethod = module.createOrUpdateReactions;

View File

@@ -62,15 +62,7 @@ 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;

View File

@@ -6,7 +6,6 @@ const Location = require('./Location');
const Order = require('./Order');
const Payment = require('./Payment');
const { MessageTypes } = require('../util/Constants');
const PollVote = require('./PollVote');
/**
* Represents a Message on WhatsApp
@@ -50,7 +49,7 @@ class Message extends Base {
* Message content
* @type {string}
*/
this.body = this.hasMedia ? data.caption || '' : data.body || data.pollName || '';
this.body = this.hasMedia ? data.caption || '' : data.body || '';
/**
* Message type
@@ -241,19 +240,6 @@ class Message extends Base {
this.selectedRowId = data.listResponse.singleSelectReply.selectedRowId;
}
if (this.type == MessageTypes.POLL_CREATION) {
/** Selectable poll options */
this.pollOptions = data.pollOptions.map(option => {
return option.name;
});
/** Current poll votes, refresh with Message.refreshPollVotes() */
this.pollVotes = data.pollVotes.map((pollVote) => {
return new PollVote(this.client, {...pollVote, pollCreationMessage: this});
});
}
return super._patch(data);
}
@@ -541,34 +527,6 @@ class Message extends Base {
}
return undefined;
}
/**
* Refresh the current poll votes
* @returns {Promise<void>}
*/
async refreshPollVotes() {
if (this.type != MessageTypes.POLL_CREATION) throw 'Invalid usage! Can only be used with a pollCreation message';
const pollVotes = await this.client.evaluate((parentMsgId) => {
return window.Store.PollVote.getForParent(parentMsgId).getModelsArray().map(a => a.serialize());
}, this.id);
this.pollVotes = pollVotes.map((pollVote) => {
return new PollVote(this.client, {...pollVote, pollCreationMessage: this});
});
return;
}
/**
* Vote to the poll.
* @param {Array<string>} selectedOptions Array of options selected.
* @returns {Promise<void>}
*/
async vote(selectedOptions) {
if (this.type != MessageTypes.POLL_CREATION) throw 'Invalid usage! Can only be used with a pollCreation message';
return this.client.evaluate((creationMsgId, selectedOptions) => {
window.WWebJS.votePoll(creationMsgId, selectedOptions);
}, this.id, selectedOptions);
}
}
module.exports = Message;

View File

@@ -1,36 +0,0 @@
'use strict';
const Message = require('./Message');
const Base = require('./Base');
/**
* Represents a Poll Vote on WhatsApp
* @extends {Base}
*/
class PollVote extends Base {
constructor(client, data) {
super(client);
if (data) this._patch(data);
}
_patch(data) {
/** The options selected in this Poll vote */
this.selectedOptions = data.selectedOptionLocalIds.filter(value => value == 1).map((value, selectedOptionLocalId) => {
return data.pollCreationMessage.pollOptions.find(a => a.localId == selectedOptionLocalId).name;
});
/** Sender of the Poll vote */
this.sender = data.sender._serialized;
/** Timestamp of the time it was sent in milliseconds */
this.senderTimestampMs = data.senderTimestampMs;
/** The poll creation message associated with the poll vote */
this.parentPollMessage = new Message(this.client, data.pollCreationMessage);
return super._patch(data);
}
}
module.exports = PollVote;

View File

@@ -51,9 +51,8 @@ exports.Events = {
DISCONNECTED: 'disconnected',
STATE_CHANGED: 'change_state',
BATTERY_CHANGED: 'change_battery',
INCOMING_CALL: 'call',
REMOTE_SESSION_SAVED: 'remote_session_saved',
POLL_VOTE: 'poll_vote'
INCOMING_CALL: 'incoming_call',
REMOTE_SESSION_SAVED: 'remote_session_saved'
};
/**
@@ -97,8 +96,6 @@ exports.MessageTypes = {
PROTOCOL: 'protocol',
REACTION: 'reaction',
TEMPLATE_BUTTON_REPLY: 'template_button_reply',
POLL_CREATION: 'poll_creation',
};
/**

View File

@@ -6,67 +6,63 @@ exports.ExposeStore = (moduleRaidStr) => {
// eslint-disable-next-line no-undef
window.mR = moduleRaid();
window.Store = Object.assign({}, window.mR.findModule(m => m.default && m.default.Chat)[0].default);
window.Store.AppState = window.mR.findModule('Socket')[0].Socket;
window.Store.Conn = window.mR.findModule('Conn')[0].Conn;
window.Store.BlockContact = window.mR.findModule('blockContact')[0];
window.Store.Call = window.mR.findModule('CallCollection')[0].CallCollection;
window.Store.ChatState = window.mR.findModule('sendChatStateComposing')[0];
window.Store.Cmd = window.mR.findModule('Cmd')[0].Cmd;
window.Store.Conn = window.mR.findModule('Conn')[0].Conn;
window.Store.ConversationMsgs = window.mR.findModule('loadEarlierMsgs')[0];
window.Store.createOrUpdateReactionsModule = window.mR.findModule('createOrUpdateReactions')[0];
window.Store.CryptoLib = window.mR.findModule('decryptE2EMedia')[0];
window.Store.DownloadManager = window.mR.findModule('downloadManager')[0].downloadManager;
window.Store.EphemeralFields = window.mR.findModule('getEphemeralFields')[0];
window.Store.Features = window.mR.findModule('FEATURE_CHANGE_EVENT')[0].LegacyPhoneFeatures;
window.Store.findCommonGroups = window.mR.findModule('findCommonGroups')[0].findCommonGroups;
window.Store.GroupMetadata = window.mR.findModule('GroupMetadata')[0].default.GroupMetadata;
window.Store.Invite = window.mR.findModule('sendJoinGroupViaInvite')[0];
window.Store.InviteInfo = window.mR.findModule('sendQueryGroupInvite')[0];
window.Store.Label = window.mR.findModule('LabelCollection')[0].LabelCollection;
window.Store.MediaPrep = window.mR.findModule('MediaPrep')[0];
window.Store.MediaObject = window.mR.findModule('getOrCreateMediaObject')[0];
window.Store.NumberInfo = window.mR.findModule('formattedPhoneNumber')[0];
window.Store.MediaTypes = window.mR.findModule('msgToMediaType')[0];
window.Store.MediaUpload = window.mR.findModule('uploadMedia')[0];
window.Store.MsgKey = window.mR.findModule((module) => module.default && module.default.fromString)[0].default;
window.Store.MessageInfo = window.mR.findModule('sendQueryMsgInfo')[0];
window.Store.OpaqueData = window.mR.findModule(module => module.default && module.default.createFromData)[0].default;
window.Store.QueryExist = window.mR.findModule('queryExists')[0].queryExists;
window.Store.QueryProduct = window.mR.findModule('queryProduct')[0];
window.Store.QueryOrder = window.mR.findModule('queryOrder')[0];
window.Store.SendClear = window.mR.findModule('sendClear')[0];
window.Store.SendDelete = window.mR.findModule('sendDelete')[0];
window.Store.SendMessage = window.mR.findModule('addAndSendMsgToChat')[0];
window.Store.SendSeen = window.mR.findModule('sendSeen')[0];
window.Store.User = window.mR.findModule('getMaybeMeUser')[0];
window.Store.UploadUtils = window.mR.findModule((module) => (module.default && module.default.encryptAndUpload) ? module.default : null)[0].default;
window.Store.UserConstructor = window.mR.findModule((module) => (module.default && module.default.prototype && module.default.prototype.isServer && module.default.prototype.isUser) ? module.default : null)[0].default;
window.Store.Validators = window.mR.findModule('findLinks')[0];
window.Store.VCard = window.mR.findModule('vcardFromContactModel')[0];
window.Store.WidFactory = window.mR.findModule('createWid')[0];
window.Store.ProfilePic = window.mR.findModule('profilePicResync')[0];
window.Store.PresenceUtils = window.mR.findModule('sendPresenceAvailable')[0];
window.Store.ChatState = window.mR.findModule('sendChatStateComposing')[0];
window.Store.GroupParticipants = window.mR.findModule('sendPromoteParticipants')[0];
window.Store.JoinInviteV4 = window.mR.findModule('sendJoinGroupViaInviteV4')[0];
window.Store.findCommonGroups = window.mR.findModule('findCommonGroups')[0].findCommonGroups;
window.Store.StatusUtils = window.mR.findModule('setMyStatus')[0];
window.Store.ConversationMsgs = window.mR.findModule('loadEarlierMsgs')[0];
window.Store.sendReactionToMsg = window.mR.findModule('sendReactionToMsg')[0].sendReactionToMsg;
window.Store.createOrUpdateReactionsModule = window.mR.findModule('createOrUpdateReactions')[0];
window.Store.EphemeralFields = window.mR.findModule('getEphemeralFields')[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.QuotedMsg = window.mR.findModule('getQuotedMsgObj')[0];
window.Store.StickerTools = {
...window.mR.findModule('toWebpSticker')[0],
...window.mR.findModule('addWebpMetadata')[0]
};
window.Store.GroupUtils = {
...window.mR.findModule('sendCreateGroup')[0],
...window.mR.findModule('sendSetGroupSubject')[0],
...window.mR.findModule('markExited')[0]
};
window.Store.Invite = window.mR.findModule('sendJoinGroupViaInvite')[0];
window.Store.InviteInfo = window.mR.findModule('sendQueryGroupInvite')[0];
window.Store.JoinInviteV4 = window.mR.findModule('sendJoinGroupViaInviteV4')[0];
window.Store.Label = window.mR.findModule('LabelCollection')[0].LabelCollection;
window.Store.MediaObject = window.mR.findModule('getOrCreateMediaObject')[0];
window.Store.MediaPrep = window.mR.findModule('MediaPrep')[0];
window.Store.MediaTypes = window.mR.findModule('msgToMediaType')[0];
window.Store.MediaUpload = window.mR.findModule('uploadMedia')[0];
window.Store.MessageInfo = window.mR.findModule('sendQueryMsgInfo')[0];
window.Store.MsgActionChecks = window.mR.findModule('canSenderRevokeMsg')[0];
window.Store.MsgKey = window.mR.findModule((module) => module.default && module.default.fromString)[0].default;
window.Store.NumberInfo = window.mR.findModule('formattedPhoneNumber')[0];
window.Store.OpaqueData = window.mR.findModule(module => module.default && module.default.createFromData)[0].default;
window.Store.PresenceUtils = window.mR.findModule('sendPresenceAvailable')[0];
window.Store.ProfilePic = window.mR.findModule('profilePicResync')[0];
window.Store.QueryExist = window.mR.findModule('queryExists')[0].queryExists;
window.Store.QueryOrder = window.mR.findModule('queryOrder')[0];
window.Store.QueryProduct = window.mR.findModule('queryProduct')[0];
window.Store.QuotedMsg = window.mR.findModule('getQuotedMsgObj')[0];
window.Store.ReplyUtils = window.mR.findModule('canReplyMsg').length > 0 && window.mR.findModule('canReplyMsg')[0];
window.Store.SendClear = window.mR.findModule('sendClear')[0];
window.Store.SendDelete = window.mR.findModule('sendDelete')[0];
window.Store.SendMessage = window.mR.findModule('addAndSendMsgToChat')[0];
window.Store.sendReactionToMsg = window.mR.findModule('sendReactionToMsg')[0].sendReactionToMsg;
window.Store.SendSeen = window.mR.findModule('sendSeen')[0];
window.Store.SendVote = window.mR.findModule('sendVote')[0];
window.Store.Socket = window.mR.findModule('deprecatedSendIq')[0];
window.Store.SocketWap = window.mR.findModule('wap')[0];
window.Store.StatusUtils = window.mR.findModule('setMyStatus')[0];
window.Store.StickerTools = {
...window.mR.findModule('toWebpSticker')[0],
...window.mR.findModule('addWebpMetadata')[0]
};
window.Store.UploadUtils = window.mR.findModule((module) => (module.default && module.default.encryptAndUpload) ? module.default : null)[0].default;
window.Store.User = window.mR.findModule('getMaybeMeUser')[0];
window.Store.UserConstructor = window.mR.findModule((module) => (module.default && module.default.prototype && module.default.prototype.isServer && module.default.prototype.isUser) ? module.default : null)[0].default;
window.Store.Validators = window.mR.findModule('findLinks')[0];
window.Store.VCard = window.mR.findModule('vcardFromContactModel')[0];
window.Store.WidFactory = window.mR.findModule('createWid')[0];
if (!window.Store.Chat._find) {
window.Store.Chat._find = e => {
@@ -406,10 +402,6 @@ exports.LoadUtils = () => {
msg.id = Object.assign({}, msg.id, { remote: msg.id.remote._serialized });
}
if (msg.type == 'poll_creation') {
msg.pollVotes = window.Store.PollVote.getForParent(msg.id).getModelsArray().map(a => a.serialize());
}
delete msg.pendingAckUpdate;
return msg;
@@ -610,33 +602,4 @@ 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);
};
window.WWebJS.votePoll = async (pollCreationMessageId, selectedOptions) => {
const msg = window.Store.Msg.get(pollCreationMessageId);
if (msg.type != 'poll_creation') throw 'Quoted message is not a poll creation message!';
let localIdSet = new Set();
msg.pollOptions.map(a => {
for (const option of selectedOptions) {
if (a.name == option) localIdSet.add(a.localId);
}
});
await window.Store.SendVote.sendVote(msg, localIdSet);
};
};