@juzi/whatsapp-web.js
Advanced tools
Comparing version 1.20.0 to 1.21.1
@@ -1,2 +0,2 @@ | ||
const { Client, Location, List, Buttons, LocalAuth } = require('./index'); | ||
const { Client, Location, List, Buttons, LocalAuth, UrlLink, MessageMedia, ProductMessage } = require('./index'); | ||
@@ -9,3 +9,3 @@ const client = new Client({ | ||
headless: false | ||
} | ||
}, | ||
}); | ||
@@ -33,3 +33,3 @@ | ||
client.on('ready', () => { | ||
client.on('ready', async () => { | ||
console.log('READY'); | ||
@@ -206,2 +206,47 @@ }); | ||
msg.react('👍'); | ||
} else if (msg.body === '!edit') { | ||
if (msg.hasQuotedMsg) { | ||
const quotedMsg = await msg.getQuotedMessage(); | ||
if (quotedMsg.fromMe) { | ||
quotedMsg.edit(msg.body.replace('!edit', '')); | ||
} else { | ||
msg.reply('I can only edit my own messages'); | ||
} | ||
} | ||
} else if (msg.body === '!updatelabels') { | ||
const chat = await msg.getChat(); | ||
await chat.changeLabels([0, 1]); | ||
} else if (msg.body === '!addlabels') { | ||
const chat = await msg.getChat(); | ||
let labels = (await chat.getLabels()).map(l => l.id); | ||
labels.push('0'); | ||
labels.push('1'); | ||
await chat.changeLabels(labels); | ||
} else if (msg.body === '!removelabels') { | ||
const chat = await msg.getChat(); | ||
await chat.changeLabels([]); | ||
} else if (msg.body === '!businesscontact') { | ||
const contact = await client.getContactById('14692648170@c.us'); | ||
client.sendMessage(msg.from, contact); | ||
} else if (msg.body === '!product') { | ||
client.sendMessage(msg.from, new ProductMessage( | ||
'14692648170@s.whatsapp.net', | ||
'9931928273499772', | ||
'title', | ||
'description', | ||
await MessageMedia.fromUrl('https://x.boardgamearena.net/data/themereleases/current/games/arknova/230622-0954/img/animals/A523_DomesticRabbit.jpg'), | ||
)); | ||
} else if (msg.body === '!store') { | ||
client.sendMessage(msg.from, 'https://wa.me/c/14692648170'); | ||
} else if (msg.body === '!contact') { | ||
const contact = await client.getContactById('8613812345678@c.us'); | ||
client.sendMessage(msg.from, contact); | ||
} else if (msg.body === '!link') { | ||
const urlLink = new UrlLink( | ||
'https://www.baidu.com', | ||
'百度', | ||
'百度一下,你也不知道', | ||
await MessageMedia.fromUrl('https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png') | ||
); | ||
client.sendMessage(msg.from, urlLink); | ||
} | ||
@@ -208,0 +253,0 @@ }); |
@@ -77,2 +77,5 @@ | ||
getLabels(): Promise<Label[]> | ||
/** Change labels in chats */ | ||
addOrRemoveLabels(labelIds: Array<number|string>, chatIds: Array<string>): Promise<void> | ||
@@ -252,2 +255,12 @@ /** Get Label instance by ID */ | ||
/** Emitted when an ack event occurrs on message type */ | ||
on(event: 'message_edit', listener: ( | ||
/** The message that was affected */ | ||
message: Message, | ||
/** New text message */ | ||
newBody: String, | ||
/** Prev text message */ | ||
prevBody: String | ||
) => void): this | ||
/** Emitted when a chat unread count changes */ | ||
@@ -379,2 +392,6 @@ on(event: 'unread_count', listener: ( | ||
authStrategy?: AuthStrategy, | ||
/** The version of WhatsApp Web to use. Use options.webVersionCache to configure how the version is retrieved. */ | ||
webVersion?: string, | ||
/** Determines how to retrieve the WhatsApp Web version specified in options.webVersion. */ | ||
webVersionCache?: WebCacheOptions, | ||
/** How many times should the qrcode be refreshed before giving up | ||
@@ -407,2 +424,20 @@ * @default 0 (disabled) */ | ||
export interface LocalWebCacheOptions { | ||
type: 'local', | ||
path?: string, | ||
strict?: boolean | ||
} | ||
export interface RemoteWebCacheOptions { | ||
type: 'remote', | ||
remotePath: string, | ||
strict?: boolean | ||
} | ||
export interface NoWebCacheOptions { | ||
type: 'none' | ||
} | ||
export type WebCacheOptions = NoWebCacheOptions | LocalWebCacheOptions | RemoteWebCacheOptions; | ||
/** | ||
@@ -561,2 +596,3 @@ * Base class which all authentication strategies extend | ||
MESSAGE_ACK = 'message_ack', | ||
MESSAGE_EDIT = 'message_edit', | ||
MEDIA_UPLOADED = 'media_uploaded', | ||
@@ -639,2 +675,7 @@ CONTACT_CHANGED = 'contact_changed', | ||
/** Message subtypes */ | ||
export enum MessageSubtypes { | ||
URL_LINK = 'url', | ||
} | ||
/** Client status */ | ||
@@ -752,2 +793,6 @@ export enum Status { | ||
location: Location, | ||
/** UrlLink information contained in the message, if the message is type "url" */ | ||
urlLink: UrlLink, | ||
/** ProductMessage information contained in the message, if the message is type "product" */ | ||
productMessage: ProductMessage, | ||
/** List of vCards contained in the message */ | ||
@@ -786,2 +831,6 @@ vCards: string[], | ||
productId?: string, | ||
/** Last edit time */ | ||
latestEditSenderTimestampMs?: number, | ||
/** Last edit message author */ | ||
latestEditMsgKey?: MessageId, | ||
/** Message buttons */ | ||
@@ -844,2 +893,4 @@ dynamicReplyButtons?: object, | ||
getReactions: () => Promise<ReactionList[]>, | ||
/** Edits the current message */ | ||
edit: (content: MessageContent, options?: MessageEditOptions) => Promise<Message | null>, | ||
} | ||
@@ -864,2 +915,21 @@ | ||
export class UrlLink { | ||
url: string | ||
title?: string | null | ||
description?: string | null | ||
thumbnailData?: string | null | ||
constructor(url: string, title: string, description: string, thumbnailMedia: MessageMedia) | ||
} | ||
export class ProductMessage { | ||
businessOwnerJid: string | ||
productId: string | ||
title?: string | null | ||
description?: string | null | ||
thumbnailMedia: MessageMedia | ||
constructor(businessOwnerJid, productId, title, description, thumbnailMedia) | ||
} | ||
export interface Label { | ||
@@ -911,2 +981,12 @@ /** Label name */ | ||
/** Options for editing a message */ | ||
export interface MessageEditOptions { | ||
/** Show links preview. Has no effect on multi-device accounts. */ | ||
linkPreview?: boolean | ||
/** Contacts that are being mentioned in the message */ | ||
mentions?: Contact[] | ||
/** Extra options */ | ||
extra?: any | ||
} | ||
export interface MediaFromURLOptions { | ||
@@ -945,3 +1025,3 @@ client?: Client | ||
export type MessageContent = string | MessageMedia | Location | Contact | Contact[] | List | Buttons | ||
export type MessageContent = string | MessageMedia | Location | Contact | Contact[] | List | Buttons | UrlLink | ProductMessage | ||
@@ -1137,2 +1217,4 @@ /** | ||
getLabels: () => Promise<Label[]> | ||
/** Add or remove labels to this Chat */ | ||
changeLabels: (labelIds: Array<string | number>) => Promise<void> | ||
} | ||
@@ -1139,0 +1221,0 @@ |
@@ -21,2 +21,4 @@ 'use strict'; | ||
Location: require('./src/structures/Location'), | ||
UrlLink: require('./src/structures/UrlLink'), | ||
ProductMessage: require('./src/structures/ProductMessage'), | ||
ProductMetadata: require('./src/structures/ProductMetadata'), | ||
@@ -23,0 +25,0 @@ List: require('./src/structures/List'), |
{ | ||
"name": "@juzi/whatsapp-web.js", | ||
"version": "1.20.0", | ||
"version": "1.21.1", | ||
"description": "Library for interacting with the WhatsApp Web API ", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
@@ -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.2306.7](https://img.shields.io/badge/WhatsApp_Web-2.2306.7-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.2322.15](https://img.shields.io/badge/WhatsApp_Web-2.2322.15-brightgreen.svg) [![Discord Chat](https://img.shields.io/discord/698610475432411196.svg?logo=discord)](https://discord.gg/H7DqQs4) | ||
@@ -3,0 +3,0 @@ # whatsapp-web.js |
@@ -18,3 +18,4 @@ 'use strict'; | ||
const ContactFactory = require('./factories/ContactFactory'); | ||
const { ClientInfo, Message, MessageMedia, Contact, Location, GroupNotification, Label, Call, Buttons, List, Reaction, Chat } = require('./structures'); | ||
const WebCacheFactory = require('./webCache/WebCacheFactory'); | ||
const { ClientInfo, Message, MessageMedia, Contact, Location, UrlLink, ProductMessage, GroupNotification, Label, Call, Buttons, List, Reaction, Chat } = require('./structures'); | ||
const LegacySessionAuth = require('./authStrategies/LegacySessionAuth'); | ||
@@ -28,2 +29,4 @@ const NoAuth = require('./authStrategies/NoAuth'); | ||
* @param {AuthStrategy} options.authStrategy - Determines how to save and restore sessions. Will use LegacySessionAuth if options.session is set. Otherwise, NoAuth will be used. | ||
* @param {string} options.webVersion - The version of WhatsApp Web to use. Use options.webVersionCache to configure how the version is retrieved. | ||
* @param {object} options.webVersionCache - Determines how to retrieve the WhatsApp Web version. Defaults to a local cache (LocalWebCache) that falls back to latest if the requested version is not found. | ||
* @param {number} options.authTimeoutMs - Timeout for authentication selector in puppeteer | ||
@@ -125,2 +128,3 @@ * @param {object} options.puppeteer - Puppeteer launch options. View docs here: https://github.com/puppeteer/puppeteer/ | ||
await this.authStrategy.afterBrowserInitialized(); | ||
await this.initWebVersionCache(); | ||
@@ -596,2 +600,17 @@ await page.goto(WhatsWebURL, { | ||
await page.exposeFunction('onEditMessageEvent', (msg, newBody, prevBody) => { | ||
if(msg.type === 'revoked'){ | ||
return; | ||
} | ||
/** | ||
* Emitted when messages are edited | ||
* @event Client#message_edit | ||
* @param {Message} message | ||
* @param {string} newBody | ||
* @param {string} prevBody | ||
*/ | ||
this.emit(Events.MESSAGE_EDIT, new Message(this, msg), newBody, prevBody); | ||
}); | ||
await page.evaluate(() => { | ||
@@ -603,2 +622,3 @@ window.Store.Msg.on('change', (msg) => { window.onChangeMessageEvent(window.WWebJS.getMessageModel(msg)); }); | ||
window.Store.Msg.on('remove', (msg) => { if (msg.isNewMsg) window.onRemoveMessageEvent(window.WWebJS.getMessageModel(msg)); }); | ||
window.Store.Msg.on('change:body', (msg, newBody, prevBody) => { window.onEditMessageEvent(window.WWebJS.getMessageModel(msg), newBody, prevBody); }); | ||
window.Store.AppState.on('change:state', (_AppState, state) => { window.onAppStateChangedEvent(state); }); | ||
@@ -656,2 +676,31 @@ window.Store.Conn.on('change:battery', (state) => { window.onBatteryStateChangedEvent(state); }); | ||
async initWebVersionCache() { | ||
const { type: webCacheType, ...webCacheOptions } = this.options.webVersionCache; | ||
const webCache = WebCacheFactory.createWebCache(webCacheType, webCacheOptions); | ||
const requestedVersion = this.options.webVersion; | ||
const versionContent = await webCache.resolve(requestedVersion); | ||
if(versionContent) { | ||
await this.pupPage.setRequestInterception(true); | ||
this.pupPage.on('request', async (req) => { | ||
if(req.url() === WhatsWebURL) { | ||
req.respond({ | ||
status: 200, | ||
contentType: 'text/html', | ||
body: versionContent | ||
}); | ||
} else { | ||
req.continue(); | ||
} | ||
}); | ||
} else { | ||
this.pupPage.on('response', async (res) => { | ||
if(res.ok() && res.url() === WhatsWebURL) { | ||
await webCache.persist(await res.text()); | ||
} | ||
}); | ||
} | ||
} | ||
/** | ||
@@ -727,7 +776,7 @@ * Closes the client | ||
*/ | ||
/** | ||
* Send a message to a specific chatId | ||
* @param {string} chatId | ||
* @param {string|MessageMedia|Location|Contact|Array<Contact>|Buttons|List} content | ||
* @param {string|MessageMedia|Location|UrlLink|ProductMessage|Contact|Array<Contact>|Buttons|List} content | ||
* @param {MessageSendOptions} [options] - Options used when sending the message | ||
@@ -738,2 +787,6 @@ * | ||
async sendMessage(chatId, content, options = {}) { | ||
if (options.mentions && options.mentions.some(possiblyContact => possiblyContact instanceof Contact)) { | ||
console.warn('Mentions with an array of Contact are now deprecated. See more at https://github.com/pedroslopez/whatsapp-web.js/pull/2166.'); | ||
options.mentions = options.mentions.map(a => a.id._serialized); | ||
} | ||
let internalOptions = { | ||
@@ -748,3 +801,3 @@ linkPreview: options.linkPreview === false ? undefined : true, | ||
parseVCards: options.parseVCards === false ? false : true, | ||
mentionedJidList: Array.isArray(options.mentions) ? options.mentions.map(contact => contact.id._serialized) : [], | ||
mentionedJidList: Array.isArray(options.mentions) ? options.mentions : [], | ||
extraOptions: options.extra | ||
@@ -778,4 +831,20 @@ }; | ||
content = ''; | ||
} else if (content instanceof UrlLink) { | ||
internalOptions.urlLink = content; | ||
content = ''; | ||
} else if (content instanceof ProductMessage) { | ||
const productData = (await Util.queryProduct(content.businessOwnerJid, content.productId, this.pupPage)).data; | ||
internalOptions.productMessage = { | ||
title: content.title, | ||
description: content.description, | ||
businessOwnerJid: content.businessOwnerJid, | ||
productId: content.productId, | ||
retailerId: productData.retailer_id, | ||
currency: productData.currency, | ||
price: Number(productData.price), | ||
url: productData.url, | ||
thumbnailMedia: content.thumbnailMedia, | ||
}; | ||
} | ||
if (internalOptions.sendMediaAsSticker && internalOptions.attachment) { | ||
@@ -806,3 +875,3 @@ internalOptions.attachment = await Util.formatToWebpSticker( | ||
} | ||
/** | ||
@@ -1333,4 +1402,33 @@ * Searches for messages | ||
} | ||
/** | ||
* Change labels in chats | ||
* @param {Array<number|string>} labelIds | ||
* @param {Array<string>} chatIds | ||
* @returns {Promise<void>} | ||
*/ | ||
async addOrRemoveLabels(labelIds, chatIds) { | ||
return this.pupPage.evaluate(async (labelIds, chatIds) => { | ||
if (['smba', 'smbi'].indexOf(window.Store.Conn.platform) === -1) { | ||
throw '[LT01] Only Whatsapp business'; | ||
} | ||
const labels = window.WWebJS.getLabels().filter(e => labelIds.find(l => l == e.id) !== undefined); | ||
const chats = window.Store.Chat.filter(e => chatIds.includes(e.id._serialized)); | ||
let actions = labels.map(label => ({id: label.id, type: 'add'})); | ||
chats.forEach(chat => { | ||
(chat.labels || []).forEach(n => { | ||
if (!actions.find(e => e.id == n)) { | ||
actions.push({id: n, type: 'remove'}); | ||
} | ||
}); | ||
}); | ||
return await window.Store.Label.addOrRemoveLabels(actions, chats); | ||
}, labelIds, chatIds); | ||
} | ||
} | ||
module.exports = Client; |
@@ -89,3 +89,3 @@ 'use strict'; | ||
* Send a message to this chat | ||
* @param {string|MessageMedia|Location} content | ||
* @param {string|MessageMedia|Location|UrlLink|ProductMessage} content | ||
* @param {MessageSendOptions} [options] | ||
@@ -265,4 +265,13 @@ * @returns {Promise<Message>} Message that was just sent | ||
} | ||
/** | ||
* Add or remove labels to this Chat | ||
* @param {Array<number|string>} labelIds | ||
* @returns {Promise<void>} | ||
*/ | ||
async changeLabels(labelIds) { | ||
return this.client.addOrRemoveLabels(labelIds, [this.id._serialized]); | ||
} | ||
} | ||
module.exports = Chat; |
@@ -94,3 +94,3 @@ 'use strict'; | ||
* | ||
* @param {string|MessageMedia|Location} content | ||
* @param {string|MessageMedia|Location|UrlLink|ProductMessage} content | ||
* @param {object} options | ||
@@ -97,0 +97,0 @@ * @returns {Promise<Message>} |
@@ -9,2 +9,4 @@ module.exports = { | ||
Location: require('./Location'), | ||
UrlLink: require('./UrlLink'), | ||
ProductMessage: require('./ProductMessage'), | ||
Message: require('./Message'), | ||
@@ -11,0 +13,0 @@ MessageMedia: require('./MessageMedia'), |
@@ -6,6 +6,9 @@ 'use strict'; | ||
const Location = require('./Location'); | ||
const UrlLink = require('./UrlLink'); | ||
const ProductMessage = require('./ProductMessage'); | ||
const Order = require('./Order'); | ||
const Payment = require('./Payment'); | ||
const Reaction = require('./Reaction'); | ||
const {MessageTypes} = require('../util/Constants'); | ||
const {MessageTypes, MessageSubtypes} = require('../util/Constants'); | ||
const {Contact} = require('./Contact'); | ||
@@ -157,2 +160,14 @@ /** | ||
/** | ||
* UrlLink information contained in the message, if the message is type "text" and subtype is "url" | ||
* @type {UrlLink} | ||
*/ | ||
this.urlLink = data.type === MessageTypes.TEXT && data.subtype === MessageSubtypes.URL_LINK ? new UrlLink(data.body, data.title, data.description, new MessageMedia('image/jpg', data.thumbnail, 'thumbnail.jpg', 0)) : undefined; | ||
/** | ||
* ProductMessage information contained in the message, if the message is type "product" | ||
* @type {ProductMessage} | ||
*/ | ||
this.productMessage = data.type === MessageTypes.PRODUCT ? new ProductMessage(data.businessOwnerJid, data.productId, data.title, data.description) : undefined; | ||
/** | ||
* List of vCards contained in the message. | ||
@@ -229,2 +244,12 @@ * @type {Array<string>} | ||
/** Last edit time */ | ||
if (data.latestEditSenderTimestampMs) { | ||
this.latestEditSenderTimestampMs = data.latestEditSenderTimestampMs; | ||
} | ||
/** Last edit message author */ | ||
if (data.latestEditMsgKey) { | ||
this.latestEditMsgKey = data.latestEditMsgKey; | ||
} | ||
/** | ||
@@ -330,3 +355,3 @@ * Links included in the message. | ||
* | ||
* @param {string|MessageMedia|Location} content | ||
* @param {string|MessageMedia|Location|UrlLink} content | ||
* @param {string} [chatId] | ||
@@ -583,4 +608,40 @@ * @param {MessageSendOptions} [options] | ||
} | ||
/** | ||
* Edits the current message. | ||
* @param {string} content | ||
* @param {MessageEditOptions} [options] - Options used when editing the message | ||
* @returns {Promise<?Message>} | ||
*/ | ||
async edit(content, options = {}) { | ||
if (options.mentions && options.mentions.some(possiblyContact => possiblyContact instanceof Contact)) { | ||
options.mentions = options.mentions.map(a => a.id._serialized); | ||
} | ||
let internalOptions = { | ||
linkPreview: options.linkPreview === false ? undefined : true, | ||
mentionedJidList: Array.isArray(options.mentions) ? options.mentions : [], | ||
extraOptions: options.extra | ||
}; | ||
if (!this.fromMe) { | ||
return null; | ||
} | ||
const messageEdit = await this.client.pupPage.evaluate(async (msgId, message, options) => { | ||
let msg = window.Store.Msg.get(msgId); | ||
if (!msg) return null; | ||
let catEdit = (msg.type === 'chat' && window.Store.MsgActionChecks.canEditText(msg)); | ||
if (catEdit) { | ||
const msgEdit = await window.WWebJS.editMessage(msg, message, options); | ||
return msgEdit.serialize(); | ||
} | ||
return null; | ||
}, this.id._serialized, content, internalOptions); | ||
if (messageEdit) { | ||
return new Message(this.client, messageEdit); | ||
} | ||
return null; | ||
} | ||
} | ||
module.exports = Message; |
@@ -10,2 +10,6 @@ 'use strict'; | ||
}, | ||
webVersion: '2.2322.15', | ||
webVersionCache: { | ||
type: 'local', | ||
}, | ||
authTimeoutMs: 0, | ||
@@ -48,2 +52,3 @@ qrMaxRetries: 0, | ||
MESSAGE_ACK: 'message_ack', | ||
MESSAGE_EDIT: 'message_edit', | ||
UNREAD_COUNT: 'unread_count', | ||
@@ -111,2 +116,12 @@ MESSAGE_REACTION: 'message_reaction', | ||
/** | ||
* Message subtypes | ||
* @readonly | ||
* @enum {string} | ||
*/ | ||
exports.MessageSubtypes = { | ||
URL_LINK: 'url' | ||
}; | ||
/** | ||
* Group notification types | ||
@@ -113,0 +128,0 @@ * @readonly |
@@ -34,2 +34,3 @@ 'use strict'; | ||
window.Store.SendMessage = window.mR.findModule('addAndSendMsgToChat')[0]; | ||
window.Store.EditMessage = window.mR.findModule('addAndSendMessageEdit')[0]; | ||
window.Store.SendSeen = window.mR.findModule('sendSeen')[0]; | ||
@@ -123,3 +124,6 @@ window.Store.User = window.mR.findModule('getMaybeMeUser')[0]; | ||
}); | ||
if (options.caption){ | ||
attOptions.caption = options.caption; | ||
} | ||
content = options.sendMediaAsSticker ? undefined : attOptions.preview; | ||
@@ -163,6 +167,41 @@ | ||
let contact = window.Store.Contact.get(options.contactCard); | ||
let vcardStr; | ||
let contactName; | ||
if (typeof contact.isBusiness === 'boolean') { | ||
// contact loaded | ||
if (contact.isBusiness) { | ||
vcardStr = 'BEGIN:VCARD\n' + | ||
'VERSION:3.0\n' + | ||
`N:;${contact.verifiedName};;;\n` + | ||
`FN:${contact.verifiedName}\n` + | ||
`X-WA-BIZ-NAME:${contact.verifiedName}\n` + | ||
(contact.businessProfile.description ? `X-WA-BIZ-DESCRIPTION:${contact.businessProfile.description}\n` : '') + | ||
`ORG:${contact.verifiedName};\n` + | ||
`TEL;type=CELL;type=VOICE;waid=${contact.id.user}:${window.Store.NumberInfo.formatPhone(contact.id.user)}\n` + | ||
'END:VCARD'; | ||
} else { | ||
vcardStr = window.Store.VCard.vcardFromContactModel(contact).vcard; | ||
contactName = contact.formattedName; | ||
} | ||
} else { | ||
// contact not loaded | ||
const result = await window.Store.QueryExist(contact.id); | ||
if (!result || !result.biz) { | ||
vcardStr = window.Store.VCard.vcardFromContactModel(contact).vcard; | ||
contactName = contact.formattedName; | ||
} else { | ||
vcardStr = 'BEGIN:VCARD\n' + | ||
'VERSION:3.0\n' + | ||
`N:;${result.bizInfo.verifiedName.name};;;\n` + | ||
`FN:${result.bizInfo.verifiedName.name}\n` + | ||
`X-WA-BIZ-NAME:${result.bizInfo.verifiedName.name}\n` + | ||
`ORG:${result.bizInfo.verifiedName.name};\n` + | ||
`TEL;type=CELL;type=VOICE;waid=${result.wid.user}:${window.Store.NumberInfo.formatPhone(result.wid.user)}\n` + | ||
'END:VCARD'; | ||
} | ||
} | ||
vcardOptions = { | ||
body: window.Store.VCard.vcardFromContactModel(contact).vcard, | ||
body: vcardStr, | ||
type: 'vcard', | ||
vcardFormattedName: contact.formattedName | ||
vcardFormattedName: contactName, | ||
}; | ||
@@ -249,2 +288,50 @@ delete options.contactCard; | ||
let urlLinkOptions = {}; | ||
if(options.urlLink) { | ||
urlLinkOptions = { | ||
type: 'chat', | ||
subtype: 'url', | ||
thumbnail: options.urlLink.thumbnailData, | ||
body: options.urlLink.url, | ||
canonicalUrl: options.urlLink.url, | ||
matchedText: options.urlLink.url, | ||
title: options.urlLink.title, | ||
description: options.urlLink.description, | ||
}; | ||
} | ||
let productOptions = {}; | ||
if(options.productMessage) { | ||
const fileData = await window.WWebJS.processMediaData(options.productMessage.thumbnailMedia, { | ||
forceVoice: false, | ||
forceDocument: false, | ||
forceGif: false | ||
}); | ||
productOptions = { | ||
type: 'product', | ||
title: options.productMessage.title, | ||
description: options.productMessage.description, | ||
businessOwnerJid: options.productMessage.businessOwnerJid, | ||
productId: options.productMessage.productId, | ||
retailerId: options.productMessage.retailerId, | ||
url: options.productMessage.url, | ||
currencyCode: options.productMessage.currency, | ||
priceAmount1000: options.productMessage.price, | ||
body: fileData.__x_preview, | ||
filehash: fileData.__x_filehash, | ||
encFilehash: fileData.__x_encFilehash, | ||
size: fileData.__x_size, | ||
mediaKey: fileData.__x_mediaKey, | ||
mediaKeyTimestamp: fileData.__x_mediaKeyTimestamp, | ||
width: fileData.__x_fullWidth, | ||
height: fileData.__x_fullHeight, | ||
mimetype: fileData.__x_mediaBlob._blob.type, | ||
isViewOnce: false, | ||
staticUrl: '', | ||
deprecatedMms3Url: fileData.deprecatedMms3Url, | ||
directPath: fileData.__x_directPath, | ||
productImageCount: 1, | ||
}; | ||
} | ||
const meUser = window.Store.User.getMaybeMeUser(); | ||
@@ -287,2 +374,4 @@ const isMD = window.Store.MDBackend; | ||
...listOptions, | ||
...urlLinkOptions, | ||
...productOptions, | ||
...extraOptions | ||
@@ -294,3 +383,37 @@ }; | ||
}; | ||
window.WWebJS.editMessage = async (msg, content, options = {}) => { | ||
const extraOptions = options.extraOptions || {}; | ||
delete options.extraOptions; | ||
if (options.mentionedJidList) { | ||
options.mentionedJidList = options.mentionedJidList.map(cId => window.Store.Contact.get(cId).id); | ||
} | ||
if (options.linkPreview) { | ||
options.linkPreview = null; | ||
// Not supported yet by WhatsApp Web on MD | ||
if(!window.Store.MDBackend) { | ||
const link = window.Store.Validators.findLink(content); | ||
if (link) { | ||
const preview = await window.Store.Wap.queryLinkPreview(link.url); | ||
preview.preview = true; | ||
preview.subtype = 'url'; | ||
options = { ...options, ...preview }; | ||
} | ||
} | ||
} | ||
const internalOptions = { | ||
...options, | ||
...extraOptions | ||
}; | ||
await window.Store.EditMessage.sendMessageEdit(msg, content, internalOptions); | ||
return window.Store.Msg.get(msg.id._serialized); | ||
}; | ||
window.WWebJS.toStickerData = async (mediaInfo) => { | ||
@@ -297,0 +420,0 @@ if (mediaInfo.mimetype == 'image/webp') return mediaInfo; |
@@ -184,4 +184,11 @@ 'use strict'; | ||
} | ||
static async queryProduct(ownerId, productId, pupPage) { | ||
return pupPage.evaluate((ownerId, productId) => { | ||
const ownerWid = window.Store.WidFactory.createWid(ownerId); | ||
return window.Store.QueryProduct.queryProduct(ownerWid, productId); | ||
}, ownerId, productId); | ||
} | ||
} | ||
module.exports = Util; |
Copyleft License
License(Experimental) Copyleft license information was found
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found
Found 1 instance in 1 package
286413
50
6679
3
6
2