@juzi.bot/whatsapp-web.js
Advanced tools
Comparing version 1.15.6 to 1.15.7
@@ -446,2 +446,22 @@ | ||
GROUP_INVITE = 'groups_v4_invite', | ||
LIST = 'list', | ||
LIST_RESPONSE = 'list_response', | ||
BUTTONS_RESPONSE = 'buttons_response', | ||
PAYMENT = 'payment', | ||
BROADCAST_NOTIFICATION = 'broadcast_notification', | ||
CALL_LOG = 'call_log', | ||
CIPHERTEXT = 'ciphertext', | ||
DEBUG = 'debug', | ||
E2E_NOTIFICATION = 'e2e_notification', | ||
GP2 = 'gp2', | ||
GROUP_NOTIFICATION = 'group_notification', | ||
HSM = 'hsm', | ||
INTERACTIVE = 'interactive', | ||
NATIVE_FLOW = 'native_flow', | ||
NOTIFICATION = 'notification', | ||
NOTIFICATION_TEMPLATE = 'notification_template', | ||
OVERSIZED = 'oversized', | ||
PROTOCOL = 'protocol', | ||
REACTION = 'reaction', | ||
TEMPLATE_BUTTON_REPLY = 'template_button_reply', | ||
} | ||
@@ -531,2 +551,4 @@ | ||
isGif: boolean, | ||
/** Indicates if the message will disappear after it expires */ | ||
isEphemeral: boolean, | ||
/** ID for the Chat that this message was sent to, except if the message was sent by the current user */ | ||
@@ -915,6 +937,5 @@ from: string, | ||
/** | ||
* The amount of messages to return. | ||
* The amount of messages to return. If no limit is specified, the available messages will be returned. | ||
* Note that the actual number of returned messages may be smaller if there aren't enough messages in the conversation. | ||
* Set this to Infinity to load all messages. | ||
* @default 50 | ||
*/ | ||
@@ -1198,7 +1219,7 @@ limit?: number | ||
body: string | MessageMedia | ||
buttons: Array<Array<string>> | ||
buttons: Array<{ buttonId: string; buttonText: {displayText: string}; type: number }> | ||
title?: string | null | ||
footer?: string | null | ||
constructor(body: string, buttons: Array<Array<string>>, title?: string | null, footer?: string | null) | ||
constructor(body: string, buttons: Array<{ id?: string; body: string }>, title?: string | null, footer?: string | null) | ||
} | ||
@@ -1205,0 +1226,0 @@ } |
{ | ||
"name": "@juzi.bot/whatsapp-web.js", | ||
"version": "1.15.6", | ||
"version": "1.15.7", | ||
"description": "Library for interacting with the WhatsApp Web API ", | ||
@@ -8,3 +8,4 @@ "main": "./index.js", | ||
"scripts": { | ||
"test": "mocha tests", | ||
"test": "mocha tests --recursive", | ||
"test-single": "mocha", | ||
"shell": "node --experimental-repl-await ./shell.js", | ||
@@ -47,9 +48,9 @@ "generate-docs": "node_modules/.bin/jsdoc --configure .jsdoc.json --verbose" | ||
"chai": "^4.3.4", | ||
"dotenv": "^10.0.0", | ||
"dotenv": "^16.0.0", | ||
"eslint": "^8.4.1", | ||
"eslint-plugin-mocha": "^9.0.0", | ||
"eslint-plugin-mocha": "^10.0.3", | ||
"jsdoc": "^3.6.4", | ||
"jsdoc-baseline": "^0.1.5", | ||
"mocha": "^9.0.2", | ||
"sinon": "^12.0.1" | ||
"sinon": "^13.0.1" | ||
}, | ||
@@ -56,0 +57,0 @@ "engines": { |
@@ -1,2 +0,2 @@ | ||
[![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.2202.8](https://img.shields.io/badge/WhatsApp_Web-2.2202.8-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.2202.12](https://img.shields.io/badge/WhatsApp_Web-2.2202.12-brightgreen.svg) [![Discord Chat](https://img.shields.io/discord/698610475432411196.svg?logo=discord)](https://discord.gg/H7DqQs4) | ||
@@ -3,0 +3,0 @@ # whatsapp-web.js |
@@ -84,3 +84,3 @@ 'use strict'; | ||
page.setUserAgent(this.options.userAgent); | ||
await page.setUserAgent(this.options.userAgent); | ||
@@ -118,3 +118,3 @@ this.pupBrowser = browser; | ||
if (this.options.session) { | ||
// Check if session restore was successfull | ||
// Check if session restore was successful | ||
try { | ||
@@ -178,6 +178,18 @@ await page.waitForSelector(KEEP_PHONE_CONNECTED_IMG_SELECTOR, { timeout: this.options.authTimeoutMs }); | ||
// Wait for code scan | ||
await page.waitForSelector(KEEP_PHONE_CONNECTED_IMG_SELECTOR, { timeout: 0 }); | ||
clearInterval(this._qrRefreshInterval); | ||
this._qrRefreshInterval = undefined; | ||
try { | ||
await page.waitForSelector(KEEP_PHONE_CONNECTED_IMG_SELECTOR, { timeout: 0 }); | ||
clearInterval(this._qrRefreshInterval); | ||
this._qrRefreshInterval = undefined; | ||
} catch(error) { | ||
if ( | ||
error.name === 'ProtocolError' && | ||
error.message && | ||
error.message.match(/Target closed/) | ||
) { | ||
// something has called .destroy() while waiting | ||
return; | ||
} | ||
throw error; | ||
} | ||
} | ||
@@ -238,4 +250,2 @@ | ||
await page.exposeFunction('onAddMessageEvent', msg => { | ||
if (!msg.isNewMsg) return; | ||
if (msg.type === 'gp2') { | ||
@@ -425,3 +435,2 @@ const notification = new GroupNotification(this, msg); | ||
await page.evaluate(() => { | ||
window.Store.Msg.on('add', (msg) => { if (msg.isNewMsg) window.onAddMessageEvent(window.WWebJS.getMessageModel(msg)); }); | ||
window.Store.Msg.on('change', (msg) => { window.onChangeMessageEvent(window.WWebJS.getMessageModel(msg)); }); | ||
@@ -435,2 +444,12 @@ window.Store.Msg.on('change:type', (msg) => { window.onChangeMessageTypeEvent(window.WWebJS.getMessageModel(msg)); }); | ||
window.Store.Call.on('add', (call) => { window.onIncomingCall(call); }); | ||
window.Store.Msg.on('add', (msg) => { | ||
if (msg.isNewMsg) { | ||
if(msg.type === 'ciphertext') { | ||
// defer message event until ciphertext is resolved (type changed) | ||
msg.once('change:type', (_msg) => window.onAddMessageEvent(window.WWebJS.getMessageModel(_msg))); | ||
} else { | ||
window.onAddMessageEvent(window.WWebJS.getMessageModel(msg)); | ||
} | ||
} | ||
}); | ||
}); | ||
@@ -540,3 +559,3 @@ | ||
mentionedJidList: Array.isArray(options.mentions) ? options.mentions.map(contact => contact.id._serialized) : [], | ||
...options.extra | ||
extraOptions: options.extra | ||
}; | ||
@@ -749,3 +768,3 @@ | ||
await window.Store.Cmd.archiveChat(chat, true); | ||
return chat.archive; | ||
return true; | ||
}, chatId); | ||
@@ -762,3 +781,3 @@ } | ||
await window.Store.Cmd.archiveChat(chat, false); | ||
return chat.archive; | ||
return false; | ||
}, chatId); | ||
@@ -765,0 +784,0 @@ } |
@@ -7,2 +7,16 @@ 'use strict'; | ||
/** | ||
* Button spec used in Buttons constructor | ||
* @typedef {Object} ButtonSpec | ||
* @property {string=} id - Custom ID to set on the button. A random one will be generated if one is not passed. | ||
* @property {string} body - The text to show on the button. | ||
*/ | ||
/** | ||
* @typedef {Object} FormattedButtonSpec | ||
* @property {string} buttonId | ||
* @property {number} type | ||
* @property {Object} buttonText | ||
*/ | ||
/** | ||
* Message type buttons | ||
@@ -13,3 +27,3 @@ */ | ||
* @param {string|MessageMedia} body | ||
* @param {Array<Array<string>>} buttons | ||
* @param {ButtonSpec[]} buttons - See {@link ButtonSpec} | ||
* @param {string?} title | ||
@@ -46,3 +60,3 @@ * @param {string?} footer | ||
* buttons of message | ||
* @type {Array<Array<string>>} | ||
* @type {FormattedButtonSpec[]} | ||
*/ | ||
@@ -56,4 +70,4 @@ this.buttons = this._format(buttons); | ||
* Creates button array from simple array | ||
* @param {Array<Array<string>>} buttons | ||
* @returns {Array<Array<string>>} | ||
* @param {ButtonSpec[]} buttons | ||
* @returns {FormattedButtonSpec[]} | ||
* @example | ||
@@ -60,0 +74,0 @@ * Input: [{id:'customId',body:'button1'},{body:'button2'},{body:'button3'},{body:'button4'}] |
@@ -68,3 +68,3 @@ 'use strict'; | ||
* Indicates if the chat is muted or not | ||
* @type {number} | ||
* @type {boolean} | ||
*/ | ||
@@ -175,10 +175,7 @@ this.isMuted = data.isMuted; | ||
* @param {Object} searchOptions Options for searching messages. Right now only limit is supported. | ||
* @param {Number} [searchOptions.limit=50] The amount of messages to return. Note that the actual number of returned messages may be smaller if there aren't enough messages in the conversation. Set this to Infinity to load all messages. | ||
* @param {Number} [searchOptions.limit] The amount of messages to return. If no limit is specified, the available messages will be returned. Note that the actual number of returned messages may be smaller if there aren't enough messages in the conversation. Set this to Infinity to load all messages. | ||
* @returns {Promise<Array<Message>>} | ||
*/ | ||
async fetchMessages(searchOptions) { | ||
if (!searchOptions || !searchOptions.limit) { | ||
searchOptions = { limit: 50 }; | ||
} | ||
let messages = await this.client.pupPage.evaluate(async (chatId, limit) => { | ||
let messages = await this.client.pupPage.evaluate(async (chatId, searchOptions) => { | ||
const msgFilter = m => !m.isNotification; // dont include notification messages | ||
@@ -189,13 +186,18 @@ | ||
while (msgs.length < limit) { | ||
const loadedMessages = await chat.loadEarlierMsgs(); | ||
if (!loadedMessages) break; | ||
msgs = [...loadedMessages.filter(msgFilter), ...msgs]; | ||
if (searchOptions && searchOptions.limit > 0) { | ||
while (msgs.length < searchOptions.limit) { | ||
const loadedMessages = await chat.loadEarlierMsgs(); | ||
if (!loadedMessages) break; | ||
msgs = [...loadedMessages.filter(msgFilter), ...msgs]; | ||
} | ||
if (msgs.length > searchOptions.limit) { | ||
msgs.sort((a, b) => (a.t > b.t) ? 1 : -1); | ||
msgs = msgs.splice(msgs.length - searchOptions.limit); | ||
} | ||
} | ||
msgs.sort((a, b) => (a.t > b.t) ? 1 : -1); | ||
if (msgs.length > limit) msgs = msgs.splice(msgs.length - limit); | ||
return msgs.map(m => window.WWebJS.getMessageModel(m)); | ||
}, this.id._serialized, searchOptions.limit); | ||
}, this.id._serialized, searchOptions); | ||
@@ -202,0 +204,0 @@ return messages.map(m => new Message(this.client, m)); |
@@ -188,2 +188,8 @@ 'use strict'; | ||
/** | ||
* Indicates if the message will disappear after it expires | ||
* @type {boolean} | ||
*/ | ||
this.isEphemeral = data.isEphemeral; | ||
/** Title */ | ||
@@ -386,3 +392,3 @@ if (data.title) { | ||
if (everyone && msg.id.fromMe && msg.canRevoke()) { | ||
if (everyone && msg.id.fromMe && msg._canRevoke()) { | ||
return window.Store.Cmd.sendRevokeMsgs(msg.chat, [msg], true); | ||
@@ -389,0 +395,0 @@ } |
@@ -80,4 +80,21 @@ 'use strict'; | ||
LIST: 'list', | ||
LIST_RESPONSE: 'list_response', | ||
BUTTONS_RESPONSE: 'buttons_response', | ||
PAYMENT: 'payment' | ||
PAYMENT: 'payment', | ||
BROADCAST_NOTIFICATION: 'broadcast_notification', | ||
CALL_LOG: 'call_log', | ||
CIPHERTEXT: 'ciphertext', | ||
DEBUG: 'debug', | ||
E2E_NOTIFICATION: 'e2e_notification', | ||
GP2: 'gp2', | ||
GROUP_NOTIFICATION: 'group_notification', | ||
HSM: 'hsm', | ||
INTERACTIVE: 'interactive', | ||
NATIVE_FLOW: 'native_flow', | ||
NOTIFICATION: 'notification', | ||
NOTIFICATION_TEMPLATE: 'notification_template', | ||
OVERSIZED: 'oversized', | ||
PROTOCOL: 'protocol', | ||
REACTION: 'reaction', | ||
TEMPLATE_BUTTON_REPLY: 'template_button_reply', | ||
}; | ||
@@ -84,0 +101,0 @@ |
@@ -11,3 +11,2 @@ 'use strict'; | ||
window.Store.Conn = window.mR.findModule('Conn')[0].Conn; | ||
window.Store.CryptoLib = window.mR.findModule('decryptE2EMedia')[0]; | ||
window.Store.Wap = window.mR.findModule('queryLinkPreview')[0].default; | ||
@@ -35,3 +34,3 @@ window.Store.SendSeen = window.mR.findModule('sendSeen')[0]; | ||
window.Store.UploadUtils = window.mR.findModule((module) => (module.default && module.default.encryptAndUpload) ? module.default : null)[0].default; | ||
window.Store.Label = window.mR.findModule('LabelCollection')[0].default; | ||
window.Store.Label = window.mR.findModule('LabelCollection')[0].LabelCollection; | ||
window.Store.Features = window.mR.findModule('FEATURE_CHANGE_EVENT')[0].GK; | ||
@@ -159,3 +158,3 @@ window.Store.QueryOrder = window.mR.findModule('queryOrder')[0]; | ||
let extraOptions = {}; | ||
let buttonOptions = {}; | ||
if(options.buttons){ | ||
@@ -169,3 +168,3 @@ let caption; | ||
} | ||
extraOptions = { | ||
buttonOptions = { | ||
productHeaderImageRejected: false, | ||
@@ -183,2 +182,3 @@ isFromTemplate: false, | ||
let listOptions = {}; | ||
if(options.list){ | ||
@@ -188,4 +188,3 @@ if(window.Store.Conn.platform === 'smba' || window.Store.Conn.platform === 'smbi'){ | ||
} | ||
extraOptions = { | ||
...extraOptions, | ||
listOptions = { | ||
type: 'list', | ||
@@ -200,3 +199,3 @@ footer: options.list.footer, | ||
delete options.list; | ||
delete extraOptions.list.footer; | ||
delete listOptions.list.footer; | ||
} | ||
@@ -210,2 +209,11 @@ | ||
const extraOptions = options.extraOptions || {}; | ||
delete options.extraOptions; | ||
const ephemeralSettings = { | ||
ephemeralDuration: chat.isEphemeralSettingOn() ? chat.getEphemeralSetting() : undefined, | ||
ephemeralSettingTimestamp: chat.getEphemeralSettingTimestamp() || undefined, | ||
disappearingModeInitiator: chat.getDisappearingModeInitiator() || undefined, | ||
}; | ||
const message = { | ||
@@ -223,2 +231,3 @@ ...options, | ||
type: 'chat', | ||
...ephemeralSettings, | ||
...locationOptions, | ||
@@ -228,2 +237,4 @@ ...attOptions, | ||
...vcardOptions, | ||
...buttonOptions, | ||
...listOptions, | ||
...extraOptions | ||
@@ -327,2 +338,3 @@ }; | ||
msg.isEphemeral = message.isEphemeral; | ||
msg.isStatusV3 = message.isStatusV3; | ||
@@ -329,0 +341,0 @@ msg.links = (message.getLinks()).map(link => ({ |
AI detected security risk
Supply chain riskAI has determined that this package may contain potential security issues or vulnerabilities.
Found 1 instance in 1 package
202597
4936
2