diff --git a/docs/Base.html b/docs/Base.html index 395a725..b716975 100644 --- a/docs/Base.html +++ b/docs/Base.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.11.2 » Class: Base + whatsapp-web.js 1.12.0 » Class: Base @@ -15,7 +15,7 @@ @@ -50,7 +50,7 @@ diff --git a/docs/BusinessContact.html b/docs/BusinessContact.html index 492d007..390e9a4 100644 --- a/docs/BusinessContact.html +++ b/docs/BusinessContact.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.11.2 » Class: BusinessContact + whatsapp-web.js 1.12.0 » Class: BusinessContact @@ -15,7 +15,7 @@ @@ -101,22 +101,27 @@
block()
-
getChat()
+
getAbout()
-
getProfilePicUrl()
+
getChat()
-
unblock()
+
getProfilePicUrl()
+
+
unblock()
+
+
+
@@ -239,6 +244,15 @@
async
+

getAbout() → Promise containing nullable string

+

Gets the Contact's current "about" info. Returns null if you don't have permission to read their status.

+
+
Inherited from
+
Contact#getAbout
+
Returns
+
+
+
async

getChat() → Promise containing Chat

Returns the Chat that corresponds to this Contact. Will return null when getting chat for currently logged in user.

@@ -276,7 +290,7 @@ diff --git a/docs/Chat.html b/docs/Chat.html index 0027af9..b953633 100644 --- a/docs/Chat.html +++ b/docs/Chat.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.11.2 » Class: Chat + whatsapp-web.js 1.12.0 » Class: Chat @@ -15,7 +15,7 @@ @@ -101,11 +101,17 @@
fetchMessages(searchOptions)
+
getContact()
+
+
-
getContact()
+
getLabels()
+
+
+
markUnread()
mute(unmuteDate)
@@ -315,6 +321,20 @@
async
+

getLabels() → Promise containing Array of Label

+

Returns array of all Labels assigned to this Chat

+
+
Returns
+
+

Promise containing Array of Label 

+
+
+
async
+

markUnread()

+

Mark this chat as unread

+
+
+
async

mute(unmuteDate)

Mutes this chat until a specified date

@@ -463,7 +483,7 @@
diff --git a/docs/Client.html b/docs/Client.html index 5fea963..a29002c 100644 --- a/docs/Client.html +++ b/docs/Client.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.11.2 » Class: Client + whatsapp-web.js 1.12.0 » Class: Client @@ -15,7 +15,7 @@ @@ -26,7 +26,7 @@
+
getLabelById(labelId)
+
+
+
getLabels()
+
+
+
getNumberId(number)
+
+
getProfilePicUrl(contactId)
@@ -104,19 +119,22 @@
logout()
+
markChatUnread(chatId)
+
+
muteChat(chatId, unmuteDate)
-
pinChat()
-
-
-
resetState()
-
-
+
pinChat()
+
+
+
resetState()
+
+
sendMessage(chatId, content[, options])
@@ -426,6 +444,20 @@

User agent to use in puppeteer

+ + +

ffmpegPath

+ + +

 

+ + +

 

+ + +

Ffmpeg path to use when formating videos to webp while sending stickers

+ + @@ -616,6 +648,43 @@
async
+

getChatLabels(chatId) → Promise containing Array of Label

+

Get all Labels assigned to a chat

+
+

Parameter

+ + + + + + + + + + + + + + + + + +
NameTypeOptionalDescription
+

chatId

+
+

string

+
+

 

+
+
+
+
+
Returns
+
+

Promise containing Array of Label 

+
+
+
async

getChats() → Promise containing Array of Chat

Get all current chat instances

@@ -625,6 +694,43 @@
async
+

getChatsByLabelId(labelId) → Promise containing Array of Chat

+

Get all Chats for a specific Label

+
+

Parameter

+ + + + + + + + + + + + + + + + + +
NameTypeOptionalDescription
+

labelId

+
+

string

+
+

 

+
+
+
+
+
Returns
+
+

Promise containing Array of Chat 

+
+
+
async

getContactById(contactId) → Promise containing Contact

Get contact instance by ID

@@ -710,6 +816,91 @@
async
+

getLabelById(labelId) → Promise containing Label

+

Get Label instance by ID

+
+

Parameter

+ + + + + + + + + + + + + + + + + +
NameTypeOptionalDescription
+

labelId

+
+

string

+
+

 

+
+
+
+
+
Returns
+
+

Promise containing Label 

+
+
+
async
+

getLabels() → Promise containing Array of Label

+

Get all current Labels

+
+
Returns
+
+

Promise containing Array of Label 

+
+
+
async
+

getNumberId(number) → Promise containing (Object or null)

+

Get the registered WhatsApp ID for a number. + Will return null if the number is not registered on WhatsApp.

+
+

Parameter

+ + + + + + + + + + + + + + + + + +
NameTypeOptionalDescription
+

number

+
+

string

+
+

 

+
+

Number or ID ("@c.us" will be automatically appended if not specified)

+
+
+
+
Returns
+
+

Promise containing (Object or null) 

+
+
+
async

getProfilePicUrl(contactId) → Promise containing string

Returns the contact ID's profile picture URL, if privacy settings allow it

@@ -814,6 +1005,40 @@
async
+

markChatUnread(chatId)

+

Mark the Chat as unread

+
+

Parameter

+ + + + + + + + + + + + + + + + + +
NameTypeOptionalDescription
+

chatId

+
+

string

+
+

 

+
+

ID of the chat that will be marked as unread

+
+
+
+
+
async

muteChat(chatId, unmuteDate)

Mutes the Chat until a specified date

@@ -1756,7 +1981,7 @@
diff --git a/docs/Client.js.html b/docs/Client.js.html index b643fb1..f3596fc 100644 --- a/docs/Client.js.html +++ b/docs/Client.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.11.2 » Source: Client.js + whatsapp-web.js 1.12.0 » Source: Client.js @@ -15,7 +15,7 @@ @@ -42,7 +42,7 @@ const { WhatsWebURL, DefaultOptions, Events, WAState } = require('./ut const { ExposeStore, LoadUtils } = require('./util/Injected'); const ChatFactory = require('./factories/ChatFactory'); const ContactFactory = require('./factories/ContactFactory'); -const { ClientInfo, Message, MessageMedia, Contact, Location, GroupNotification } = require('./structures'); +const { ClientInfo, Message, MessageMedia, Contact, Location, GroupNotification , Label } = require('./structures'); /** * Starting point for interacting with the WhatsApp Web API * @extends {EventEmitter} @@ -60,6 +60,7 @@ const { ClientInfo, Message, MessageMedia, Contact, Location, GroupNotification * @param {number} options.takeoverOnConflict - If another whatsapp web session is detected (another browser), take over the session in the current browser * @param {number} options.takeoverTimeoutMs - How much time to wait before taking over the session * @param {string} options.userAgent - User agent to use in puppeteer + * @param {string} options.ffmpegPath - Ffmpeg path to use when formating videos to webp while sending stickers * * @fires Client#qr * @fires Client#authenticated @@ -86,6 +87,8 @@ class Client extends EventEmitter { this.pupBrowser = null; this.pupPage = null; + + Util.setFfmpegPath(this.options.ffmpegPath); } /** @@ -451,6 +454,8 @@ class Client extends EventEmitter { * @typedef {Object} MessageSendOptions * @property {boolean} [linkPreview=true] - Show links preview * @property {boolean} [sendAudioAsVoice=false] - Send audio as voice message + * @property {boolean} [sendMediaAsSticker=false] - Send media as a sticker + * @property {boolean} [sendMediaAsDocument=false] - Send media as a document * @property {boolean} [parseVCards=true] - Automatically parse vCards and send them as contacts * @property {string} [caption] - Image or video caption * @property {string} [quotedMessageId] - Id of the message that is being quoted (or replied to) @@ -471,6 +476,8 @@ class Client extends EventEmitter { let internalOptions = { linkPreview: options.linkPreview === false ? undefined : true, sendAudioAsVoice: options.sendAudioAsVoice, + sendMediaAsSticker: options.sendMediaAsSticker, + sendMediaAsDocument: options.sendMediaAsDocument, caption: options.caption, quotedMessageId: options.quotedMessageId, parseVCards: options.parseVCards === false ? false : true, @@ -497,6 +504,10 @@ class Client extends EventEmitter { content = ''; } + if (internalOptions.sendMediaAsSticker && internalOptions.attachment) { + internalOptions.attachment = await Util.formatToWebpSticker(internalOptions.attachment); + } + const newMessage = await this.pupPage.evaluate(async (chatId, message, options, sendSeen) => { const chatWid = window.Store.WidFactory.createWid(chatId); const chat = await window.Store.Chat.find(chatWid); @@ -709,6 +720,17 @@ class Client extends EventEmitter { }, chatId); } + /** + * Mark the Chat as unread + * @param {string} chatId ID of the chat that will be marked as unread + */ + async markChatUnread(chatId) { + await this.pupPage.evaluate(async chatId => { + let chat = await window.Store.Chat.get(chatId); + await window.Store.Cmd.markChatUnread(chat, true); + }, chatId); + } + /** * Returns the contact ID's profile picture URL, if privacy settings allow it * @param {string} contactId the whatsapp user's ID @@ -743,6 +765,26 @@ class Client extends EventEmitter { }, id); } + /** + * Get the registered WhatsApp ID for a number. + * Will return null if the number is not registered on WhatsApp. + * @param {string} number Number or ID ("@c.us" will be automatically appended if not specified) + * @returns {Promise<Object|null>} + */ + async getNumberId(number) { + if(!number.endsWith('@c.us')) { + number += '@c.us'; + } + + try { + return await this.pupPage.evaluate(async numberId => { + return window.WWebJS.getNumberId(numberId); + }, number); + } catch(_) { + return null; + } + } + /** * Create a new group * @param {string} name group title @@ -780,6 +822,63 @@ class Client extends EventEmitter { return { gid: createRes.gid, missingParticipants }; } + /** + * Get all current Labels + * @returns {Promise<Array<Label>>} + */ + async getLabels() { + const labels = await this.pupPage.evaluate(async () => { + return window.WWebJS.getLabels(); + }); + + return labels.map(data => new Label(this , data)); + } + + /** + * Get Label instance by ID + * @param {string} labelId + * @returns {Promise<Label>} + */ + async getLabelById(labelId) { + const label = await this.pupPage.evaluate(async (labelId) => { + return window.WWebJS.getLabel(labelId); + }, labelId); + + return new Label(this, label); + } + + /** + * Get all Labels assigned to a chat + * @param {string} chatId + * @returns {Promise<Array<Label>>} + */ + async getChatLabels(chatId){ + const labels = await this.pupPage.evaluate(async (chatId) => { + return window.WWebJS.getChatLabels(chatId); + }, chatId); + + return labels.map(data => new Label(this, data)); + } + + /** + * Get all Chats for a specific Label + * @param {string} labelId + * @returns {Promise<Array<Chat>>} + */ + async getChatsByLabelId(labelId){ + const chatIds = await this.pupPage.evaluate(async (labelId) => { + const label = window.Store.Label.get(labelId); + const labelItems = label.labelItemCollection.models; + return labelItems.reduce((result, item) => { + if(item.parentType === 'Chat'){ + result.push(item.parentId); + } + return result; + },[]); + }, labelId); + + return Promise.all(chatIds.map(id => this.getChatById(id))); + } } module.exports = Client; @@ -793,7 +892,7 @@ module.exports = Client;
diff --git a/docs/ClientInfo.html b/docs/ClientInfo.html index 454ad68..48fb3ed 100644 --- a/docs/ClientInfo.html +++ b/docs/ClientInfo.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.11.2 » Class: ClientInfo + whatsapp-web.js 1.12.0 » Class: ClientInfo @@ -15,7 +15,7 @@ @@ -238,7 +238,7 @@
diff --git a/docs/Contact.html b/docs/Contact.html index 96687e1..60e555e 100644 --- a/docs/Contact.html +++ b/docs/Contact.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.11.2 » Class: Contact + whatsapp-web.js 1.12.0 » Class: Contact @@ -15,7 +15,7 @@ @@ -26,7 +26,7 @@
-
getProfilePicUrl()
+
getChat()
-
unblock()
+
getProfilePicUrl()
+
+
unblock()
+
+
+
@@ -129,7 +134,7 @@

Properties

id -  object

+  ContactId

ID that represents the contact

@@ -206,6 +211,15 @@
async
+

getAbout() → Promise containing nullable string

+

Gets the Contact's current "about" info. Returns null if you don't have permission to read their status.

+
+
Returns
+
+

Promise containing nullable string 

+
+
+
async

getChat() → Promise containing Chat

Returns the Chat that corresponds to this Contact. Will return null when getting chat for currently logged in user.

@@ -243,7 +257,7 @@ diff --git a/docs/GroupChat.html b/docs/GroupChat.html index 4d41a1d..937dcdb 100644 --- a/docs/GroupChat.html +++ b/docs/GroupChat.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.11.2 » Class: GroupChat + whatsapp-web.js 1.12.0 » Class: GroupChat @@ -15,7 +15,7 @@ @@ -26,7 +26,7 @@
@@ -110,6 +118,40 @@
async
+

openChatSearch(chatId)

+

Opens the Chat Search

+
+

Parameter

+ + + + + + + + + + + + + + + + + +
NameTypeOptionalDescription
+

chatId

+
+

string

+
+

 

+
+

ID of the chat search that will be opened

+
+
+
+
+
async

openChatWindow(chatId)

Opens the Chat Window

@@ -144,6 +186,40 @@
async
+

openChatWindowAt(msgId)

+

Opens or Scrolls the Chat Window to the position of the message

+
+

Parameter

+ + + + + + + + + + + + + + + + + +
NameTypeOptionalDescription
+

msgId

+
+

string

+
+

 

+
+

ID of the message that will be scrolled to

+
+
+
+
+
async

openMessageDrawer(msgId)

Opens the Message Drawer

@@ -187,7 +263,7 @@
diff --git a/docs/Label.html b/docs/Label.html new file mode 100644 index 0000000..8a7e6a7 --- /dev/null +++ b/docs/Label.html @@ -0,0 +1,178 @@ + + + + + + + whatsapp-web.js 1.12.0 » Class: Label + + + + + + + + +
+
+
+
+ +
+
+

Properties

+
+
+
+
hexColor
+
+
+
+
+
+
+
id
+
+
+
+
+
+
+
name
+
+
+
+
+
+
+
+

Method

+
+
+
+
getChats()
+
+
+
+
+
+
+
+
+
+
+
+
+

new Label(client, labelData)

+
+

Parameters

+ + + + + + + + + + + + + + + + + + + + + + + +
NameTypeOptionalDescription
+

client

+
+

 

+
+

 

+
+
+

labelData

+
+

 

+
+

 

+
+
+
+
+
+
+
+

Properties

+
+

hexColor +  string

+

Label hex color

+
+
+

id +  string

+

Label ID

+
+
+

name +  string

+

Label name

+
+
+
+

Method

+
+
async
+

getChats() → Promise containing Array of Chat

+

Get all chats that have been assigned this Label

+
+
Returns
+
+

Promise containing Array of Chat 

+
+
+
+
+
+
+ +
+
+
+ +
+ + + + + + + + + \ No newline at end of file diff --git a/docs/Location.html b/docs/Location.html index 76d0fcc..173018a 100644 --- a/docs/Location.html +++ b/docs/Location.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.11.2 » Class: Location + whatsapp-web.js 1.12.0 » Class: Location @@ -15,7 +15,7 @@ @@ -149,7 +149,7 @@
diff --git a/docs/Message.html b/docs/Message.html index 5107352..124d66d 100644 --- a/docs/Message.html +++ b/docs/Message.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.11.2 » Class: Message + whatsapp-web.js 1.12.0 » Class: Message @@ -15,7 +15,7 @@ @@ -57,13 +57,13 @@
fromMe
+
hasMedia
+
+
-
hasMedia
-
-
hasQuotedMsg
@@ -73,9 +73,15 @@
isForwarded
+
isStarred
+
+
isStatus
+
links
+
+
location
@@ -119,27 +125,36 @@
forward(chat)
+
getChat()
+
+
-
getQuotedMessage()
+
reply(content[, chatId][, options])
-
reply(content[, chatId][, options])
+
star()
+
+
+
unstar()
@@ -207,11 +222,21 @@

Indicates if the message was forwarded

+

isStarred +  boolean

+

Indicates if the message was starred

+
+

isStatus  boolean

Indicates if the message is a status update

+ +

Links included in the message.

+
+

location  Location

Location information contained in the message, if the message is type "location"

@@ -351,6 +376,15 @@
async
+

getInfo() → Promise containing nullable MessageInfo

+

Get information about message delivery status. May return null if the message does not exist or is not sent by you.

+
+
Returns
+
+

Promise containing nullable MessageInfo 

+
+
+
async

getMentions() → Promise containing Array of Contact

Returns the Contacts mentioned in this message

@@ -433,6 +467,16 @@

Promise containing Message 

+
async
+

star()

+

Stars this message

+
+
+
async
+

unstar()

+

Unstars this message

+
+
@@ -443,7 +487,7 @@ diff --git a/docs/MessageMedia.html b/docs/MessageMedia.html index f51824d..40429f4 100644 --- a/docs/MessageMedia.html +++ b/docs/MessageMedia.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.11.2 » Class: MessageMedia + whatsapp-web.js 1.12.0 » Class: MessageMedia @@ -15,7 +15,7 @@ @@ -208,7 +208,7 @@ diff --git a/docs/PrivateChat.html b/docs/PrivateChat.html index 144f97f..9b97ba1 100644 --- a/docs/PrivateChat.html +++ b/docs/PrivateChat.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.11.2 » Class: PrivateChat + whatsapp-web.js 1.12.0 » Class: PrivateChat @@ -15,7 +15,7 @@ @@ -101,11 +101,17 @@
fetchMessages(searchOptions)
+
getContact()
+
+
-
getContact()
+
getLabels()
+
+
+
markUnread()
mute(unmuteDate)
@@ -339,6 +345,22 @@
async
+

getLabels() → Promise containing Array of Label

+

Returns array of all Labels assigned to this Chat

+
+
Inherited from
+
Chat#getLabels
+
Returns
+
+
+
async
+

markUnread()

+

Mark this chat as unread

+
+
Inherited from
+
Chat#markUnread
+
+
async

mute(unmuteDate)

Mutes this chat until a specified date

@@ -497,7 +519,7 @@
diff --git a/docs/PrivateContact.html b/docs/PrivateContact.html index 2f5800b..4318993 100644 --- a/docs/PrivateContact.html +++ b/docs/PrivateContact.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.11.2 » Class: PrivateContact + whatsapp-web.js 1.12.0 » Class: PrivateContact @@ -15,7 +15,7 @@ @@ -98,22 +98,27 @@
block()
-
getChat()
+
getAbout()
-
getProfilePicUrl()
+
getChat()
-
unblock()
+
getProfilePicUrl()
+
+
unblock()
+
+
+
@@ -232,6 +237,15 @@
async
+

getAbout() → Promise containing nullable string

+

Gets the Contact's current "about" info. Returns null if you don't have permission to read their status.

+
+
Inherited from
+
Contact#getAbout
+
Returns
+
+
+
async

getChat() → Promise containing Chat

Returns the Chat that corresponds to this Contact. Will return null when getting chat for currently logged in user.

@@ -269,7 +283,7 @@ diff --git a/docs/Util.html b/docs/Util.html index 0651f63..3d3c266 100644 --- a/docs/Util.html +++ b/docs/Util.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.11.2 » Class: Util + whatsapp-web.js 1.12.0 » Class: Util @@ -15,7 +15,7 @@ @@ -26,7 +26,7 @@
+
+

Methods

+ +

new Util()

@@ -41,6 +68,159 @@
+

Methods

+
+
async static
+

formatImageToWebpSticker(media) → Promise containing MessageMedia

+

Formats a image to webp

+
+

Parameter

+ + + + + + + + + + + + + + + + + +
NameTypeOptionalDescription
+

media

+
+

MessageMedia

+
+

 

+
+
+
+
+
Returns
+
+

Promise containing MessageMedia  +

media in webp format

+

+
+
+
async static
+

formatToWebpSticker(media) → Promise containing MessageMedia

+

Formats a media to webp

+
+

Parameter

+ + + + + + + + + + + + + + + + + +
NameTypeOptionalDescription
+

media

+
+

MessageMedia

+
+

 

+
+
+
+
+
Returns
+
+

Promise containing MessageMedia  +

media in webp format

+

+
+
+
async static
+

formatVideoToWebpSticker(media) → Promise containing MessageMedia

+

Formats a video to webp

+
+

Parameter

+ + + + + + + + + + + + + + + + + +
NameTypeOptionalDescription
+

media

+
+

MessageMedia

+
+

 

+
+
+
+
+
Returns
+
+

Promise containing MessageMedia  +

media in webp format

+

+
+
+
static
+

setFfmpegPath(path)

+

Configure ffmpeg path

+
+

Parameter

+ + + + + + + + + + + + + + + + + +
NameTypeOptionalDescription
+

path

+
+

string

+
+

 

+
+
+
+
+
+
@@ -50,7 +230,7 @@ diff --git a/docs/global.html b/docs/global.html index af56184..87fec55 100644 --- a/docs/global.html +++ b/docs/global.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.11.2 » Globals + whatsapp-web.js 1.12.0 » Globals @@ -15,7 +15,7 @@ @@ -64,16 +64,27 @@
-

Abstract type

+

Abstract types

@@ -1024,8 +1035,230 @@
-

Abstract type

+

Abstract types

+

ContactId +  Object

+

ID that represents a contact

+
+

Properties

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeOptionalDescription
+

server

+
+

string

+
+

 

+
+
+

user

+
+

string

+
+

 

+
+
+

_serialized

+
+

string

+
+

 

+
+
+
+
+
+

GroupParticipant +  Object

+

Group participant information

+
+

Properties

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeOptionalDescription
+

id

+
+

ContactId

+
+

 

+
+
+

isAdmin

+
+

boolean

+
+

 

+
+
+

isSuperAdmin

+
+

boolean

+
+

 

+
+
+
+
+
+

MessageInfo +  Object

+

Message Info

+
+

Properties

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeOptionalDescription
+

delivery

+
+

Array of {id: ContactId, t: number}

+
+

 

+
+

Contacts to which the message has been delivered to

+
+

deliveryRemaining

+
+

number

+
+

 

+
+

Amount of people to whom the message has not been delivered to

+
+

played

+
+

Array of {id: ContactId, t: number}

+
+

 

+
+

Contacts who have listened to the voice message

+
+

playedRemaining

+
+

number

+
+

 

+
+

Amount of people who have not listened to the message

+
+

read

+
+

Array of {id: ContactId, t: number}

+
+

 

+
+

Contacts who have read the message

+
+

readRemaining

+
+

number

+
+

 

+
+

Amount of people who have not read the message

+
+
+
+

MessageSendOptions  Object

Message options.

@@ -1071,6 +1304,36 @@

Defaults to false.

+ + +

sendMediaAsSticker

+ + +

boolean

+ + +

Yes

+ + +

Send media as a sticker

+

Defaults to false.

+ + + + +

sendMediaAsDocument

+ + +

boolean

+ + +

Yes

+ + +

Send media as a document

+

Defaults to false.

+ +

parseVCards

@@ -1172,7 +1435,7 @@
diff --git a/docs/index.html b/docs/index.html index 2e92d96..7a2b854 100644 --- a/docs/index.html +++ b/docs/index.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.11.2 » Home + whatsapp-web.js 1.12.0 » Home @@ -15,7 +15,7 @@ @@ -27,7 +27,7 @@
+ -
-
BusinessContact#isBusiness
@@ -289,15 +294,15 @@ client.initialize();
+
+
+ -
-
BusinessContact#name
@@ -374,6 +379,11 @@ client.initialize();
+
+ Chat#getLabels() +
+
+
Chat#id
@@ -398,6 +408,11 @@ client.initialize();
+
+ Chat#markUnread() +
+
+
Chat#mute(unmuteDate)
@@ -592,10 +607,6 @@ client.initialize();
-
-
-
-
Client#event:message_ack
@@ -606,6 +617,10 @@ client.initialize();
+
+
+
+
Client#event:message_revoke_everyone
@@ -631,11 +646,21 @@ client.initialize();
+
+ Client#getChatLabels(chatId) +
+
+
Client#getChats()
+
+ Client#getChatsByLabelId(labelId) +
+
+
Client#getContactById(contactId)
@@ -651,6 +676,21 @@ client.initialize();
+
+ Client#getLabelById(labelId) +
+
+
+
+ Client#getLabels() +
+
+
+
+ Client#getNumberId(number) +
+
+
Client#getProfilePicUrl(contactId)
@@ -666,15 +706,15 @@ client.initialize();
+
+
+
+
Client#info
-
-
-
-
Client#initialize()
@@ -690,6 +730,11 @@ client.initialize();
+
+ Client#markChatUnread(chatId) +
+
+
Client#muteChat(chatId, unmuteDate)
@@ -820,6 +865,11 @@ client.initialize();
+
+ Contact#getAbout() +
+
+
Contact#getChat()
@@ -874,15 +924,15 @@ client.initialize();
-
-
- +
+
Contact#name
@@ -1083,6 +1133,11 @@ client.initialize();
+
+ GroupChat#getLabels() +
+
+
GroupChat#id
@@ -1112,6 +1167,11 @@ client.initialize();
+
+ GroupChat#markUnread() +
+
+
GroupChat#mute(unmuteDate)
@@ -1395,20 +1455,30 @@ client.initialize();
-
-
- +
@@ -1423,6 +1493,50 @@ client.initialize();
+
+
+

Label

+
+
+
+
+ Label(client, labelData) +
+
+
+
+ Label#getChats() +
+
+
+
+
+
+
+
+ Label#hexColor +
+
+
+
+ Label#id +
+
+
+
+
+
+
+
+ Label#name +
+
+
+
+
+
+
+

Location

@@ -1513,10 +1627,6 @@ client.initialize();
- -
-
-
Message#fromMe
@@ -1527,11 +1637,20 @@ client.initialize();
+
+
+
+
Message#getContact()
+
+ Message#getInfo() +
+
+
Message#getMentions()
@@ -1562,15 +1681,25 @@ client.initialize();
-
-
- +
+
Message#location
@@ -1591,6 +1720,11 @@ client.initialize();
+
+ Message#star() +
+
+
Message#timestamp
@@ -1606,6 +1740,11 @@ client.initialize();
+
+ Message#unstar() +
+
+
Message#vCards
@@ -1834,6 +1973,11 @@ client.initialize();
+
+ PrivateChat#getLabels() +
+
+
PrivateChat#id
@@ -1858,6 +2002,11 @@ client.initialize();
+
+ PrivateChat#markUnread() +
+
+
PrivateChat#mute(unmuteDate)
@@ -1953,6 +2102,11 @@ client.initialize();
+
+ PrivateContact#getAbout() +
+
+
PrivateContact#getChat()
@@ -2007,15 +2161,15 @@ client.initialize();
-
-
- +
+
PrivateContact#name
@@ -2091,14 +2245,34 @@ client.initialize();
+
+ Util.formatImageToWebpSticker(media) +
+
+
@@ -2192,7 +2366,7 @@ client.initialize(); diff --git a/docs/scripts/jsdoc-toc.js b/docs/scripts/jsdoc-toc.js index a472d9b..dd8d262 100644 --- a/docs/scripts/jsdoc-toc.js +++ b/docs/scripts/jsdoc-toc.js @@ -6,7 +6,7 @@ treeNode.tree({ autoEscape: false, closedIcon: '⇢', - data: [{"label":"Globals","id":"global","children":[]},{"label":"Base","id":"Base","children":[]},{"label":"BusinessContact","id":"BusinessContact","children":[]},{"label":"Chat","id":"Chat","children":[]},{"label":"Client","id":"Client","children":[]},{"label":"ClientInfo","id":"ClientInfo","children":[]},{"label":"Contact","id":"Contact","children":[]},{"label":"GroupChat","id":"GroupChat","children":[]},{"label":"GroupNotification","id":"GroupNotification","children":[]},{"label":"InterfaceController","id":"InterfaceController","children":[]},{"label":"Location","id":"Location","children":[]},{"label":"Message","id":"Message","children":[]},{"label":"MessageMedia","id":"MessageMedia","children":[]},{"label":"PrivateChat","id":"PrivateChat","children":[]},{"label":"PrivateContact","id":"PrivateContact","children":[]},{"label":"Util","id":"Util","children":[]}], + data: [{"label":"Globals","id":"global","children":[]},{"label":"Base","id":"Base","children":[]},{"label":"BusinessContact","id":"BusinessContact","children":[]},{"label":"Chat","id":"Chat","children":[]},{"label":"Client","id":"Client","children":[]},{"label":"ClientInfo","id":"ClientInfo","children":[]},{"label":"Contact","id":"Contact","children":[]},{"label":"GroupChat","id":"GroupChat","children":[]},{"label":"GroupNotification","id":"GroupNotification","children":[]},{"label":"InterfaceController","id":"InterfaceController","children":[]},{"label":"Label","id":"Label","children":[]},{"label":"Location","id":"Location","children":[]},{"label":"Message","id":"Message","children":[]},{"label":"MessageMedia","id":"MessageMedia","children":[]},{"label":"PrivateChat","id":"PrivateChat","children":[]},{"label":"PrivateContact","id":"PrivateContact","children":[]},{"label":"Util","id":"Util","children":[]}], openedIcon: ' ⇣', saveState: false, useContextMenu: false diff --git a/docs/structures_Base.js.html b/docs/structures_Base.js.html index 92be6e0..15b70e7 100644 --- a/docs/structures_Base.js.html +++ b/docs/structures_Base.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.11.2 » Source: structures/Base.js + whatsapp-web.js 1.12.0 » Source: structures/Base.js @@ -15,7 +15,7 @@ @@ -60,7 +60,7 @@ module.exports = Base; diff --git a/docs/structures_BusinessContact.js.html b/docs/structures_BusinessContact.js.html index 53e9ee9..5783679 100644 --- a/docs/structures_BusinessContact.js.html +++ b/docs/structures_BusinessContact.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.11.2 » Source: structures/BusinessContact.js + whatsapp-web.js 1.12.0 » Source: structures/BusinessContact.js @@ -15,7 +15,7 @@ @@ -59,7 +59,7 @@ module.exports = BusinessContact; diff --git a/docs/structures_Chat.js.html b/docs/structures_Chat.js.html index 456c935..a09be11 100644 --- a/docs/structures_Chat.js.html +++ b/docs/structures_Chat.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.11.2 » Source: structures/Chat.js + whatsapp-web.js 1.12.0 » Source: structures/Chat.js @@ -15,7 +15,7 @@ @@ -192,6 +192,13 @@ class Chat extends Base { return this.client.unmuteChat(this.id._serialized); } + /** + * Mark this chat as unread + */ + async markUnread(){ + return this.client.markChatUnread(this.id._serialized); + } + /** * Loads chat messages, sorted from earliest to latest. * @param {Object} searchOptions Options for searching messages. Right now only limit is supported. @@ -260,6 +267,14 @@ class Chat extends Base { async getContact() { return await this.client.getContactById(this.id._serialized); } + + /** + * Returns array of all Labels assigned to this Chat + * @returns {Promise<Array<Label>>} + */ + async getLabels() { + return this.client.getChatLabels(this.id._serialized); + } } module.exports = Chat; @@ -273,7 +288,7 @@ module.exports = Chat; diff --git a/docs/structures_ClientInfo.js.html b/docs/structures_ClientInfo.js.html index 5fd0a78..3d32289 100644 --- a/docs/structures_ClientInfo.js.html +++ b/docs/structures_ClientInfo.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.11.2 » Source: structures/ClientInfo.js + whatsapp-web.js 1.12.0 » Source: structures/ClientInfo.js @@ -15,7 +15,7 @@ @@ -108,7 +108,7 @@ module.exports = ClientInfo; diff --git a/docs/structures_Contact.js.html b/docs/structures_Contact.js.html index 91abbc4..e79b336 100644 --- a/docs/structures_Contact.js.html +++ b/docs/structures_Contact.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.11.2 » Source: structures/Contact.js + whatsapp-web.js 1.12.0 » Source: structures/Contact.js @@ -15,7 +15,7 @@ @@ -33,6 +33,14 @@ const Base = require('./Base'); +/** + * ID that represents a contact + * @typedef {Object} ContactId + * @property {string} server + * @property {string} user + * @property {string} _serialized + */ + /** * Represents a Contact on WhatsApp * @extends {Base} @@ -47,7 +55,7 @@ class Contact extends Base { _patch(data) { /** * ID that represents the contact - * @type {object} + * @type {ContactId} */ this.id = data.id; @@ -183,6 +191,21 @@ class Contact extends Base { return true; } + + /** + * Gets the Contact's current "about" info. Returns null if you don't have permission to read their status. + * @returns {Promise<?string>} + */ + async getAbout() { + const about = await this.client.pupPage.evaluate(async (contactId) => { + return window.Store.Wap.statusFind(contactId); + }, this.id._serialized); + + if (typeof about.status !== 'string') + return null; + + return about.status; + } } @@ -196,7 +219,7 @@ module.exports = Contact; diff --git a/docs/structures_GroupChat.js.html b/docs/structures_GroupChat.js.html index 3fd70e8..68795e4 100644 --- a/docs/structures_GroupChat.js.html +++ b/docs/structures_GroupChat.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.11.2 » Source: structures/GroupChat.js + whatsapp-web.js 1.12.0 » Source: structures/GroupChat.js @@ -15,7 +15,7 @@ @@ -33,6 +33,14 @@ const Chat = require('./Chat'); +/** + * Group participant information + * @typedef {Object} GroupParticipant + * @property {ContactId} id + * @property {boolean} isAdmin + * @property {boolean} isSuperAdmin + */ + /** * Represents a Group Chat on WhatsApp * @extends {Chat} @@ -46,6 +54,7 @@ class GroupChat extends Chat { /** * Gets the group owner + * @type {ContactId} */ get owner() { return this.groupMetadata.owner; @@ -69,7 +78,7 @@ class GroupChat extends Chat { /** * Gets the group participants - * @type {array} + * @type {Array<GroupParticipant>} */ get participants() { return this.groupMetadata.participants; @@ -78,6 +87,7 @@ class GroupChat extends Chat { /** * Adds a list of participants by ID to the group * @param {Array<string>} participantIds + * @returns {Promise<Object>} */ async addParticipants(participantIds) { return await this.client.pupPage.evaluate((chatId, participantIds) => { @@ -88,6 +98,7 @@ class GroupChat extends Chat { /** * Removes a list of participants by ID to the group * @param {Array<string>} participantIds + * @returns {Promise<Object>} */ async removeParticipants(participantIds) { return await this.client.pupPage.evaluate((chatId, participantIds) => { @@ -98,6 +109,7 @@ class GroupChat extends Chat { /** * Promotes participants by IDs to admins * @param {Array<string>} participantIds + * @returns {Promise<{ status: number }>} Object with status code indicating if the operation was successful */ async promoteParticipants(participantIds) { return await this.client.pupPage.evaluate((chatId, participantIds) => { @@ -108,6 +120,7 @@ class GroupChat extends Chat { /** * 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 */ async demoteParticipants(participantIds) { return await this.client.pupPage.evaluate((chatId, participantIds) => { @@ -118,6 +131,7 @@ class GroupChat extends Chat { /** * Updates the group subject * @param {string} subject + * @returns {Promise} */ async setSubject(subject) { let res = await this.client.pupPage.evaluate((chatId, subject) => { @@ -132,6 +146,7 @@ class GroupChat extends Chat { /** * Updates the group description * @param {string} description + * @returns {Promise} */ async setDescription(description) { let res = await this.client.pupPage.evaluate((chatId, description) => { @@ -178,6 +193,7 @@ class GroupChat extends Chat { /** * Gets the invite code for a specific group + * @returns {Promise<string>} Group's invite code */ async getInviteCode() { let res = await this.client.pupPage.evaluate(chatId => { @@ -193,6 +209,7 @@ class GroupChat extends Chat { /** * Invalidates the current group invite code and generates a new one + * @returns {Promise} */ async revokeInvite() { return await this.client.pupPage.evaluate(chatId => { @@ -202,6 +219,7 @@ class GroupChat extends Chat { /** * Makes the bot leave the group + * @returns {Promise} */ async leave() { return await this.client.pupPage.evaluate(chatId => { @@ -221,7 +239,7 @@ module.exports = GroupChat; diff --git a/docs/structures_GroupNotification.js.html b/docs/structures_GroupNotification.js.html index 4f89cef..73b17dc 100644 --- a/docs/structures_GroupNotification.js.html +++ b/docs/structures_GroupNotification.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.11.2 » Source: structures/GroupNotification.js + whatsapp-web.js 1.12.0 » Source: structures/GroupNotification.js @@ -15,7 +15,7 @@ @@ -143,7 +143,7 @@ module.exports = GroupNotification; diff --git a/docs/structures_Label.js.html b/docs/structures_Label.js.html new file mode 100644 index 0000000..c8c95d3 --- /dev/null +++ b/docs/structures_Label.js.html @@ -0,0 +1,103 @@ + + + + + + + whatsapp-web.js 1.12.0 » Source: structures/Label.js + + + + + + + + +
+
+
+ +
+ +
+
'use strict';
+
+const Base = require('./Base');
+// eslint-disable-next-line no-unused-vars
+const Chat = require('./Chat');
+
+/**
+ * WhatsApp Business Label information
+ */
+class Label extends Base {
+    /**
+     * @param {Base} client
+     * @param {object} labelData
+     */
+    constructor(client, labelData){
+        super(client);
+
+        if(labelData) this._patch(labelData);
+    }
+
+    _patch(labelData){
+        /**
+         * Label ID
+         * @type {string}
+         */
+        this.id = labelData.id;
+
+        /**
+         * Label name
+         * @type {string}
+         */
+        this.name = labelData.name;
+
+        /**
+         * Label hex color
+         * @type {string}
+         */
+        this.hexColor = labelData.hexColor;
+    }
+    /**
+     * Get all chats that have been assigned this Label
+     * @returns {Promise<Array<Chat>>}
+     */
+    async getChats(){
+        return this.client.getChatsByLabelId(this.id);
+    }
+
+}
+
+module.exports = Label;
+
+
+
+ +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/docs/structures_Location.js.html b/docs/structures_Location.js.html index 8363a38..f5d7073 100644 --- a/docs/structures_Location.js.html +++ b/docs/structures_Location.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.11.2 » Source: structures/Location.js + whatsapp-web.js 1.12.0 » Source: structures/Location.js @@ -15,7 +15,7 @@ @@ -71,7 +71,7 @@ module.exports = Location; diff --git a/docs/structures_Message.js.html b/docs/structures_Message.js.html index 1454e99..139a20e 100644 --- a/docs/structures_Message.js.html +++ b/docs/structures_Message.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.11.2 » Source: structures/Message.js + whatsapp-web.js 1.12.0 » Source: structures/Message.js @@ -15,7 +15,7 @@ @@ -124,6 +124,12 @@ class Message extends Base { */ this.isStatus = data.isStatusV3; + /** + * Indicates if the message was starred + * @type {boolean} + */ + this.isStarred = data.star; + /** * Indicates if the message was a broadcast * @type {boolean} @@ -164,6 +170,12 @@ class Message extends Base { this.mentionedIds = data.mentionedJidList; } + /** + * Links included in the message. + * @type {Array<string>} + */ + this.links = data.links; + return super._patch(data); } @@ -303,6 +315,62 @@ class Message extends Base { return window.Store.Cmd.sendDeleteMsgs(msg.chat, [msg], true); }, this.id._serialized, everyone); } + + /** + * Stars this message + */ + async star() { + await this.pupPage.evaluate((msgId) => { + let msg = window.Store.Msg.get(msgId); + + if (msg.canStar()) { + return msg.chat.sendStarMsgs([msg], true); + } + }, this.id._serialized); + } + + /** + * Unstars this message + */ + async unstar() { + await this.pupPage.evaluate((msgId) => { + let msg = window.Store.Msg.get(msgId); + + if (msg.canStar()) { + return msg.chat.sendStarMsgs([msg], false); + } + }, this.id._serialized); + } + + /** + * Message Info + * @typedef {Object} MessageInfo + * @property {Array<{id: ContactId, t: number}>} delivery Contacts to which the message has been delivered to + * @property {number} deliveryRemaining Amount of people to whom the message has not been delivered to + * @property {Array<{id: ContactId, t: number}>} played Contacts who have listened to the voice message + * @property {number} playedRemaining Amount of people who have not listened to the message + * @property {Array<{id: ContactId, t: number}>} read Contacts who have read the message + * @property {number} readRemaining Amount of people who have not read the message + */ + + /** + * Get information about message delivery status. May return null if the message does not exist or is not sent by you. + * @returns {Promise<?MessageInfo>} + */ + async getInfo() { + const info = await this.client.pupPage.evaluate(async (msgId) => { + const msg = window.Store.Msg.get(msgId); + if(!msg) return null; + + return await window.Store.Wap.queryMsgInfo(msg.id); + }, this.id._serialized); + + if(info.status) { + return null; + } + + return info; + } } module.exports = Message; @@ -316,7 +384,7 @@ module.exports = Message; diff --git a/docs/structures_MessageMedia.js.html b/docs/structures_MessageMedia.js.html index 22fa832..c856611 100644 --- a/docs/structures_MessageMedia.js.html +++ b/docs/structures_MessageMedia.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.11.2 » Source: structures/MessageMedia.js + whatsapp-web.js 1.12.0 » Source: structures/MessageMedia.js @@ -15,7 +15,7 @@ @@ -86,7 +86,7 @@ module.exports = MessageMedia; diff --git a/docs/structures_PrivateChat.js.html b/docs/structures_PrivateChat.js.html index 37ea655..46a3e4d 100644 --- a/docs/structures_PrivateChat.js.html +++ b/docs/structures_PrivateChat.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.11.2 » Source: structures/PrivateChat.js + whatsapp-web.js 1.12.0 » Source: structures/PrivateChat.js @@ -15,7 +15,7 @@ @@ -51,7 +51,7 @@ module.exports = PrivateChat; diff --git a/docs/structures_PrivateContact.js.html b/docs/structures_PrivateContact.js.html index fb3a688..0545f3a 100644 --- a/docs/structures_PrivateContact.js.html +++ b/docs/structures_PrivateContact.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.11.2 » Source: structures/PrivateContact.js + whatsapp-web.js 1.12.0 » Source: structures/PrivateContact.js @@ -15,7 +15,7 @@ @@ -51,7 +51,7 @@ module.exports = PrivateContact; diff --git a/docs/util_Constants.js.html b/docs/util_Constants.js.html index 5b46f31..9b92066 100644 --- a/docs/util_Constants.js.html +++ b/docs/util_Constants.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.11.2 » Source: util/Constants.js + whatsapp-web.js 1.12.0 » Source: util/Constants.js @@ -15,7 +15,7 @@ @@ -44,7 +44,8 @@ exports.DefaultOptions = { authTimeoutMs: 45000, takeoverOnConflict: false, takeoverTimeoutMs: 0, - userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36' + userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36', + ffmpegPath: 'ffmpeg' }; /** @@ -173,7 +174,7 @@ exports.MessageAck = { diff --git a/docs/util_InterfaceController.js.html b/docs/util_InterfaceController.js.html index c1123da..7481dd9 100644 --- a/docs/util_InterfaceController.js.html +++ b/docs/util_InterfaceController.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.11.2 » Source: util/InterfaceController.js + whatsapp-web.js 1.12.0 » Source: util/InterfaceController.js @@ -15,7 +15,7 @@ @@ -62,6 +62,28 @@ class InterfaceController { }, chatId); } + /** + * Opens the Chat Search + * @param {string} chatId ID of the chat search that will be opened + */ + async openChatSearch(chatId) { + await this.pupPage.evaluate(async chatId => { + let chat = await window.Store.Chat.get(chatId); + await window.Store.Cmd.chatSearch(chat); + }, chatId); + } + + /** + * Opens or Scrolls the Chat Window to the position of the message + * @param {string} msgId ID of the message that will be scrolled to + */ + async openChatWindowAt(msgId) { + await this.pupPage.evaluate(async msgId => { + let msg = await window.Store.Msg.get(msgId); + await window.Store.Cmd.openChatAt(msg.chat, msg.chat.getSearchContext(msg)); + }, msgId); + } + /** * Opens the Message Drawer * @param {string} msgId ID of the message drawer that will be opened @@ -94,7 +116,7 @@ module.exports = InterfaceController; diff --git a/docs/util_Util.js.html b/docs/util_Util.js.html index e44c465..9daa888 100644 --- a/docs/util_Util.js.html +++ b/docs/util_Util.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.11.2 » Source: util/Util.js + whatsapp-web.js 1.12.0 » Source: util/Util.js @@ -15,7 +15,7 @@ @@ -31,6 +31,13 @@
'use strict';
 
+const sharp = require('sharp');
+const path = require('path');
+const Crypto = require('crypto');
+const { tmpdir } = require('os');
+const ffmpeg = require('fluent-ffmpeg');
+const fs = require('fs').promises;
+
 const has = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
 
 /**
@@ -61,6 +68,123 @@ class Util {
 
         return given;
     }
+
+    /**
+     * Formats a image to webp
+     * @param {MessageMedia} media
+     * 
+     * @returns {Promise<MessageMedia>} media in webp format
+     */
+    static async formatImageToWebpSticker(media) {
+        if (!media.mimetype.includes('image'))
+            throw new Error('media is not a image');
+      
+        if (media.mimetype.includes('webp')) {
+            return media;
+        }
+      
+        const buff = Buffer.from(media.data, 'base64');
+      
+        let sharpImg = sharp(buff);
+        sharpImg = sharpImg.webp();
+      
+        sharpImg = sharpImg.resize(512, 512, {
+            fit: 'contain',
+            background: { r: 0, g: 0, b: 0, alpha: 0 },
+        });
+      
+        let webpBase64 = (await sharpImg.toBuffer()).toString('base64');
+      
+        return {             
+            mimetype: 'image/webp',
+            data: webpBase64,
+            filename: media.filename,
+        };
+    }
+      
+    /**
+     * Formats a video to webp
+     * @param {MessageMedia} media
+     * 
+     * @returns {Promise<MessageMedia>} media in webp format
+     */
+    static async formatVideoToWebpSticker(media) {
+        if (!media.mimetype.includes('video'))
+            throw new Error('media is not a video');
+      
+        const videoType = media.mimetype.split('/')[1];
+
+        const tempFile = path.join(
+            tmpdir(),
+            `${Crypto.randomBytes(6).readUIntLE(0, 6).toString(36)}.webp`
+        );
+      
+        const stream = new (require('stream').Readable)();
+        const buffer = Buffer.from(
+            media.data.replace(`data:${media.mimetype};base64,`, ''),
+            'base64'
+        );
+        stream.push(buffer);
+        stream.push(null);
+
+        await new Promise((resolve, reject) => {
+            ffmpeg(stream)
+                .inputFormat(videoType)
+                .on('error', reject)
+                .on('end', () => resolve(true))
+                .addOutputOptions([
+                    '-vcodec',
+                    'libwebp',
+                    '-vf',
+                    // eslint-disable-next-line no-useless-escape
+                    'scale=\'iw*min(300/iw\,300/ih)\':\'ih*min(300/iw\,300/ih)\',format=rgba,pad=300:300:\'(300-iw)/2\':\'(300-ih)/2\':\'#00000000\',setsar=1,fps=10',
+                    '-loop',
+                    '0',
+                    '-ss',
+                    '00:00:00.0',
+                    '-t',
+                    '00:00:05.0',
+                    '-preset',
+                    'default',
+                    '-an',
+                    '-vsync',
+                    '0',
+                    '-s',
+                    '512:512',
+                ])
+                .toFormat('webp')
+                .save(tempFile);
+        });
+      
+        const data = await fs.readFile(tempFile, 'base64');
+        await fs.unlink(tempFile);
+      
+        return {             
+            mimetype: 'image/webp',
+            data: data,
+            filename: media.filename,
+        };
+    }
+      
+    /**
+     * Formats a media to webp
+     * @param {MessageMedia} media
+     * 
+     * @returns {Promise<MessageMedia>} media in webp format
+     */
+    static async formatToWebpSticker(media) {
+        if (media.mimetype.includes('image')) return this.formatImageToWebpSticker(media);
+        else if (media.mimetype.includes('video')) return this.formatVideoToWebpSticker(media);
+        else throw new Error('Invalid media format');
+    }
+
+    /**
+     * Configure ffmpeg path
+     * @param {string} path
+     */
+    static setFfmpegPath(path) {
+        ffmpeg.setFfmpegPath(path);
+    }
 }
 
 module.exports = Util;
@@ -73,7 +197,7 @@ module.exports = Util; diff --git a/package.json b/package.json index cab39c7..f9ac030 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "whatsapp-web.js", - "version": "1.11.2", + "version": "1.12.0", "description": "Library for interacting with the WhatsApp Web API ", "main": "./index.js", "typings": "./index.d.ts",