mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-18 03:29:14 +00:00
Compare commits
20 Commits
add-polls
...
patch-part
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
48a3a03cdc | ||
|
|
9b659a26fa | ||
|
|
f0c7a0b0c2 | ||
|
|
53b8c1d967 | ||
|
|
56ec18a67c | ||
|
|
3775fd7c3e | ||
|
|
4247257850 | ||
|
|
374a6c505f | ||
|
|
1f80a86962 | ||
|
|
a9bbc0ed99 | ||
|
|
b99aa61dcc | ||
|
|
4ffd83015e | ||
|
|
510d44dc3e | ||
|
|
02ad3e0fd0 | ||
|
|
6ae8c42816 | ||
|
|
7fc72fe149 | ||
|
|
e980bf9b07 | ||
|
|
8e6314212d | ||
|
|
eb0d000159 | ||
|
|
cf5c5e4ec1 |
3
.github/FUNDING.yml
vendored
3
.github/FUNDING.yml
vendored
@@ -1,3 +0,0 @@
|
||||
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 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
|
||||
|
||||
|
||||
34
example.js
34
example.js
@@ -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);
|
||||
});
|
||||
|
||||
34
index.d.ts
vendored
34
index.d.ts
vendored
@@ -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 */
|
||||
@@ -1130,11 +1108,11 @@ declare namespace WAWebJS {
|
||||
|
||||
/** Promotes or demotes participants by IDs to regular users or admins */
|
||||
export type ChangeParticipantsPermissions =
|
||||
(participantIds: Array<string>) => Promise<{ status: number }>
|
||||
(participantIds: Array<string>, sleep?: number) => Promise<{ status: number }>
|
||||
|
||||
/** Adds or removes a list of participants by ID to the group */
|
||||
export type ChangeGroupParticipants =
|
||||
(participantIds: Array<string>) => Promise<{
|
||||
(participantIds: Array<string>, sleep?: number) => Promise<{
|
||||
status: number;
|
||||
participants: Array<{
|
||||
[key: string]: {
|
||||
@@ -1386,12 +1364,6 @@ declare namespace WAWebJS {
|
||||
senderId: string
|
||||
ack?: number
|
||||
}
|
||||
|
||||
export class PollVote {
|
||||
selectedOptions: string[]
|
||||
sender: string
|
||||
senderTimestampMs: number
|
||||
}
|
||||
}
|
||||
|
||||
export = WAWebJS
|
||||
|
||||
5
index.js
5
index.js
@@ -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
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const Chat = require('./Chat');
|
||||
const Util = require('../util/Util');
|
||||
|
||||
/**
|
||||
* Group participant information
|
||||
@@ -52,57 +53,65 @@ 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
|
||||
* @returns {Promise<Object>}
|
||||
* @param {Array<string>} participantIds
|
||||
* @param {?number} default 100ms, amount to sleep in milliseconds before adding the next participant
|
||||
* @returns {Promise<Array<Object>>}
|
||||
*/
|
||||
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);
|
||||
async addParticipants(participantIds, sleep = 100) {
|
||||
return this._changeParticipants(participantIds, 'add', sleep);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a list of participants by ID to the group
|
||||
* @param {Array<string>} participantIds
|
||||
* @returns {Promise<Object>}
|
||||
* @param {Array<string>} participantIds
|
||||
* @param {?number} default 100ms, amount to sleep in milliseconds before removing the next participant
|
||||
* @returns {Promise<Array<Object>>}
|
||||
*/
|
||||
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);
|
||||
async removeParticipants(participantIds, sleep = 100) {
|
||||
return this._changeParticipants(participantIds, 'remove', sleep);
|
||||
}
|
||||
|
||||
/**
|
||||
* Promotes participants by IDs to admins
|
||||
* @param {Array<string>} participantIds
|
||||
* @returns {Promise<{ status: number }>} Object with status code indicating if the operation was successful
|
||||
* 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>>}
|
||||
*/
|
||||
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);
|
||||
async promoteParticipants(participantIds, sleep = 100) {
|
||||
return this._changeParticipants(participantIds, 'promote', sleep);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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>>}
|
||||
*/
|
||||
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);
|
||||
async demoteParticipants(participantIds, sleep = 100) {
|
||||
return this._changeParticipants(participantIds, 'demote', sleep);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -231,4 +240,4 @@ class GroupChat extends Chat {
|
||||
|
||||
}
|
||||
|
||||
module.exports = GroupChat;
|
||||
module.exports = GroupChat;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
@@ -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',
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,67 +6,65 @@ 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.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]
|
||||
};
|
||||
|
||||
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 +404,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;
|
||||
@@ -627,16 +621,4 @@ exports.LoadUtils = () => {
|
||||
]);
|
||||
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);
|
||||
};
|
||||
};
|
||||
|
||||
@@ -181,6 +181,10 @@ class Util {
|
||||
static setFfmpegPath(path) {
|
||||
ffmpeg.setFfmpegPath(path);
|
||||
}
|
||||
|
||||
static sleep(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Util;
|
||||
|
||||
Reference in New Issue
Block a user