diff --git a/docs/Base.html b/docs/Base.html index a586e3a..25eb78d 100644 --- a/docs/Base.html +++ b/docs/Base.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.14.1 » Class: Base + whatsapp-web.js 1.15.0 » Class: Base @@ -15,7 +15,7 @@ @@ -50,7 +50,7 @@ diff --git a/docs/BusinessContact.html b/docs/BusinessContact.html index 0e8a591..7beafe6 100644 --- a/docs/BusinessContact.html +++ b/docs/BusinessContact.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.14.1 » Class: BusinessContact + whatsapp-web.js 1.15.0 » Class: BusinessContact @@ -15,7 +15,7 @@ @@ -104,11 +104,17 @@
getAbout()
+
getChat()
+
+
-
getChat()
+
getCountryCode()
+
+
+
getFormattedNumber()
getProfilePicUrl()
@@ -263,6 +269,24 @@
async
+

getCountryCode() → Promise containing string

+

Returns the contact's countrycode, (1541859685@c.us) => (1)

+
+
Inherited from
+
Contact#getCountryCode
+
Returns
+
+
+
async
+

getFormattedNumber() → Promise containing string

+

Returns the contact's formatted phone number, (12345678901@c.us) => (+1 (234) 5678-901)

+
+
Inherited from
+
Contact#getFormattedNumber
+
Returns
+
+
+
async

getProfilePicUrl() → Promise containing string

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

@@ -290,7 +314,7 @@
diff --git a/docs/Buttons.html b/docs/Buttons.html new file mode 100644 index 0000000..41ae8fd --- /dev/null +++ b/docs/Buttons.html @@ -0,0 +1,248 @@ + + + + + + + whatsapp-web.js 1.15.0 » Class: Buttons + + + + + + + + +
+
+
+
+ +
+
+

Properties

+
+
+
+
body
+
+
+
buttons
+
+
+
+
+
+
+
footer
+
+
+
title
+
+
+
+
+
+
+
+
+
+

Method

+
+
+
+
_format(buttons)
+
+
+
+
+
+
+
+
+
+
+
+
+

new Buttons(body, buttons, title, footer)

+
+

Parameters

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

body

+
+

 

+
+

 

+
+
+

buttons

+
+

 

+
+

 

+
+
+

title

+
+

 

+
+

 

+
+

Value can be null.

+
+

footer

+
+

 

+
+

 

+
+

Value can be null.

+
+
+
+
+
+
+

Properties

+
+

body +  (string or MessageMedia)

+

Message body

+
+
+

buttons +  Array of Array of string

+

buttons of message

+
+
+ +

footer of message

+
+
+

title +  string

+

title of message

+
+
+
+

Method

+
+

_format(buttons) → Array of Array of string

+

Creates button array from simple array

+
+

+ Example +

+
+
Input: [{id:'customId',body:'button1'},{body:'button2'},{body:'button3'},{body:'button4'}]
+Returns: [{ buttonId:'customId',buttonText:{'displayText':'button1'},type: 1 },{buttonId:'n3XKsL',buttonText:{'displayText':'button2'},type:1},{buttonId:'NDJk0a',buttonText:{'displayText':'button3'},type:1}]
+
+
+
+

Parameter

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

buttons

+
+

Array of Array of string

+
+

 

+
+
+
+
+
Returns
+
+

Array of Array of string 

+
+
+
+
+
+
+ +
+
+
+ +
+ + + + + + + + + \ No newline at end of file diff --git a/docs/Call.html b/docs/Call.html index f97ab11..0556635 100644 --- a/docs/Call.html +++ b/docs/Call.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.14.1 » Class: Call + whatsapp-web.js 1.15.0 » Class: Call @@ -15,7 +15,7 @@ @@ -144,7 +144,7 @@
diff --git a/docs/Chat.html b/docs/Chat.html index 9a80eb8..1e9d32d 100644 --- a/docs/Chat.html +++ b/docs/Chat.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.14.1 » Class: Chat + whatsapp-web.js 1.15.0 » Class: Chat @@ -15,7 +15,7 @@ @@ -334,7 +334,7 @@
async

mute(unmuteDate)

-

Mutes this chat until a specified date

+

Mutes this chat forever, unless a date is specified

Parameter

@@ -358,7 +358,8 @@

 

@@ -477,7 +478,7 @@
diff --git a/docs/Client.html b/docs/Client.html index 2eb1f80..3d5c66b 100644 --- a/docs/Client.html +++ b/docs/Client.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.14.1 » Class: Client + whatsapp-web.js 1.15.0 » Class: Client @@ -15,7 +15,7 @@ @@ -26,7 +26,7 @@ + + + + +
-

Date at which the Chat will be unmuted

+

Date at which the Chat will be unmuted, leave as is to mute forever

+

Value can be null.

+

qrMaxRetries

+
+

 

+
+

 

+
+

How many times should the qrcode be refreshed before giving up

+

restartOnAuthFail

@@ -674,6 +697,15 @@
async
+

getBlockedContacts() → Promise containing Array of Contact

+

Gets all blocked contacts by host account

+
+
Returns
+
+

Promise containing Array of Contact 

+
+
+
async

getChatById(chatId) → Promise containing Chat

Get chat instance by ID

@@ -840,6 +872,82 @@
async
+

getCountryCode(number) → Promise containing string

+

Get the country code of a WhatsApp ID.

+
+

Parameter

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

number

+
+

string

+
+

 

+
+

Number or ID

+
+
+
+
Returns
+
+

Promise containing string 

+
+
+
async
+

getFormattedNumber(number) → Promise containing string

+

Get the formatted number of a WhatsApp ID.

+
+

Parameter

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

number

+
+

string

+
+

 

+
+

Number or ID

+
+
+
+
Returns
+
+

Promise containing string 

+
+
+
async

getInviteInfo(inviteCode) → Promise containing object

Returns an object with information about the invite code's group

@@ -1102,7 +1210,7 @@
async

muteChat(chatId, unmuteDate)

-

Mutes the Chat until a specified date

+

Mutes this chat forever, unless a date is specified

Parameters

@@ -1140,7 +1248,8 @@

 

@@ -1298,7 +1407,7 @@

content

+ + + + + + + + @@ -275,12 +283,17 @@ client.initialize();
- BusinessContact#getProfilePicUrl() + BusinessContact#getCountryCode()
- BusinessContact#id + BusinessContact#getFormattedNumber() +
+
+
+
+ BusinessContact#getProfilePicUrl()
@@ -288,6 +301,11 @@ client.initialize();
+
+ BusinessContact#id +
+
+
BusinessContact#isBlocked
@@ -362,6 +380,55 @@ client.initialize();
+
+
+

Buttons

+
+ +
+
+
+ Buttons#body +
+
+
+
+ Buttons#buttons +
+
+
+
+
+
+
+
+ Buttons#footer +
+
+
+
+ Buttons#title +
+
+
+
+
+
+
+

Call

@@ -720,15 +787,15 @@ client.initialize();
- -
- +
+
Client#event:message_revoke_everyone
@@ -749,6 +816,11 @@ client.initialize();
+
+ Client#getBlockedContacts() +
+
+
Client#getChatById(chatId)
@@ -779,6 +851,16 @@ client.initialize();
+
+ Client#getCountryCode(number) +
+
+
+
+ Client#getFormattedNumber(number) +
+
+
Client#getInviteInfo(inviteCode)
@@ -809,15 +891,15 @@ client.initialize();
+
+
+ -
-
Client#info
@@ -988,11 +1070,25 @@ client.initialize();
+
+ Contact#getCountryCode() +
+
+
+
+ Contact#getFormattedNumber() +
+
+
Contact#getProfilePicUrl()
+
+
+
+
Contact#id
@@ -1003,10 +1099,6 @@ client.initialize();
-
-
-
-
Contact#isBusiness
@@ -1032,6 +1124,10 @@ client.initialize();
+
+
+
+
Contact#isUser
@@ -1042,10 +1138,6 @@ client.initialize();
-
-
-
-
Contact#name
@@ -1675,6 +1767,60 @@ client.initialize();
+
+
+

List

+
+ +
+
+
+ List#description +
+
+
+
+ List#footer +
+
+
+
+ List#sections +
+
+
+
+
+
+
+
+ List#title +
+
+
+
+
+
+
+

Location

@@ -1785,15 +1931,15 @@ client.initialize();
- -
- +
+
Message#getContact()
@@ -1814,6 +1960,11 @@ client.initialize();
+
+ Message#getPayment() +
+
+
Message#getQuotedMessage()
@@ -1854,15 +2005,15 @@ client.initialize();
-
-
- +
+
Message#location
@@ -2037,6 +2188,11 @@ client.initialize();
+
+ MessageTypes.BUTTONS_RESPONSE +
+
+
MessageTypes.CONTACT_CARD
@@ -2066,6 +2222,11 @@ client.initialize();
+
+ MessageTypes.LIST +
+
+
MessageTypes.LOCATION
@@ -2077,12 +2238,12 @@ client.initialize();
- MessageTypes.PRODUCT + MessageTypes.PAYMENT
- MessageTypes.REVOKED + MessageTypes.PRODUCT
@@ -2090,6 +2251,11 @@ client.initialize();
+
+ MessageTypes.REVOKED +
+
+
MessageTypes.STICKER
@@ -2164,6 +2330,65 @@ client.initialize();
+
+
+

Payment

+ +
+

PrivateChat

@@ -2349,11 +2574,25 @@ client.initialize();
+
+ PrivateContact#getCountryCode() +
+
+
+
+ PrivateContact#getFormattedNumber() +
+
+
PrivateContact#getProfilePicUrl()
+ +
+
+
PrivateContact#id
@@ -2364,10 +2603,6 @@ client.initialize();
-
-
-
-
PrivateContact#isBusiness
@@ -2393,6 +2628,10 @@ client.initialize();
+
+
+
+
PrivateContact#isUser
@@ -2403,10 +2642,6 @@ client.initialize();
-
-
-
-
PrivateContact#name
@@ -2701,7 +2936,7 @@ client.initialize();
diff --git a/docs/scripts/jsdoc-toc.js b/docs/scripts/jsdoc-toc.js index a57fd14..16181ee 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":"Call","id":"Call","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":"Order","id":"Order","children":[]},{"label":"PrivateChat","id":"PrivateChat","children":[]},{"label":"PrivateContact","id":"PrivateContact","children":[]},{"label":"Product","id":"Product","children":[]},{"label":"Util","id":"Util","children":[]}], + data: [{"label":"Globals","id":"global","children":[]},{"label":"Base","id":"Base","children":[]},{"label":"BusinessContact","id":"BusinessContact","children":[]},{"label":"Buttons","id":"Buttons","children":[]},{"label":"Call","id":"Call","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":"List","id":"List","children":[]},{"label":"Location","id":"Location","children":[]},{"label":"Message","id":"Message","children":[]},{"label":"MessageMedia","id":"MessageMedia","children":[]},{"label":"Order","id":"Order","children":[]},{"label":"PrivateChat","id":"PrivateChat","children":[]},{"label":"PrivateContact","id":"PrivateContact","children":[]},{"label":"Product","id":"Product","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 f7423c2..6ce5ea3 100644 --- a/docs/structures_Base.js.html +++ b/docs/structures_Base.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.14.1 » Source: structures/Base.js + whatsapp-web.js 1.15.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 d4d97ed..71c0007 100644 --- a/docs/structures_BusinessContact.js.html +++ b/docs/structures_BusinessContact.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.14.1 » Source: structures/BusinessContact.js + whatsapp-web.js 1.15.0 » Source: structures/BusinessContact.js @@ -15,7 +15,7 @@ @@ -59,7 +59,7 @@ module.exports = BusinessContact;
diff --git a/docs/structures_Buttons.js.html b/docs/structures_Buttons.js.html new file mode 100644 index 0000000..267e491 --- /dev/null +++ b/docs/structures_Buttons.js.html @@ -0,0 +1,121 @@ + + + + + + + whatsapp-web.js 1.15.0 » Source: structures/Buttons.js + + + + + + + + +
+
+
+ +
+ +
+
'use strict';
+
+const MessageMedia = require('./MessageMedia');
+const Util = require('../util/Util');
+
+/**
+ * Message type buttons
+ */
+class Buttons {
+    /**
+     * @param {string|MessageMedia} body
+     * @param {Array<Array<string>>} buttons
+     * @param {string?} title
+     * @param {string?} footer
+     */
+    constructor(body, buttons, title, footer) {
+        /**
+         * Message body
+         * @type {string|MessageMedia}
+         */
+        this.body = body;
+
+        /**
+         * title of message
+         * @type {string}
+         */
+        this.title = title;
+        
+        /**
+         * footer of message
+         * @type {string}
+         */
+        this.footer = footer;
+
+        if (body instanceof MessageMedia) {
+            this.type = 'media';
+            this.title = '';
+        }else{
+            this.type = 'chat';
+        }
+
+        /**
+         * buttons of message
+         * @type {Array<Array<string>>}
+         */
+        this.buttons = this._format(buttons);
+        if(!this.buttons.length){ throw '[BT01] No buttons';}
+                
+    }
+
+    /**
+     * Creates button array from simple array
+     * @param {Array<Array<string>>} buttons
+     * @returns {Array<Array<string>>}
+     * @example 
+     * Input: [{id:'customId',body:'button1'},{body:'button2'},{body:'button3'},{body:'button4'}]
+     * Returns: [{ buttonId:'customId',buttonText:{'displayText':'button1'},type: 1 },{buttonId:'n3XKsL',buttonText:{'displayText':'button2'},type:1},{buttonId:'NDJk0a',buttonText:{'displayText':'button3'},type:1}]
+     */
+    _format(buttons){
+        buttons = buttons.slice(0,3); // phone users can only see 3 buttons, so lets limit this
+        return buttons.map((btn) => {
+            return {'buttonId':btn.id ? btn.id : Util.generateHash(6),'buttonText':{'displayText':btn.body},'type':1};
+        });
+    }
+    
+}
+
+module.exports = Buttons;
+
+
+
+ +
+
+
+ +
+ + + + + + + + + \ No newline at end of file diff --git a/docs/structures_Call.js.html b/docs/structures_Call.js.html index be15ed7..939ec3c 100644 --- a/docs/structures_Call.js.html +++ b/docs/structures_Call.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.14.1 » Source: structures/Call.js + whatsapp-web.js 1.15.0 » Source: structures/Call.js @@ -15,7 +15,7 @@ @@ -106,7 +106,7 @@ module.exports = Call;
diff --git a/docs/structures_Chat.js.html b/docs/structures_Chat.js.html index 534e064..fd9c2d3 100644 --- a/docs/structures_Chat.js.html +++ b/docs/structures_Chat.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.14.1 » Source: structures/Chat.js + whatsapp-web.js 1.15.0 » Source: structures/Chat.js @@ -15,7 +15,7 @@ @@ -178,8 +178,8 @@ class Chat extends Base { } /** - * Mutes this chat until a specified date - * @param {Date} unmuteDate Date at which the Chat will be unmuted + * Mutes this chat forever, unless a date is specified + * @param {?Date} unmuteDate Date at which the Chat will be unmuted, leave as is to mute forever */ async mute(unmuteDate) { return this.client.muteChat(this.id._serialized, unmuteDate); @@ -288,7 +288,7 @@ module.exports = Chat;
diff --git a/docs/structures_ClientInfo.js.html b/docs/structures_ClientInfo.js.html index 60b2025..c5cbd87 100644 --- a/docs/structures_ClientInfo.js.html +++ b/docs/structures_ClientInfo.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.14.1 » Source: structures/ClientInfo.js + whatsapp-web.js 1.15.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 e65bff7..fbbeb42 100644 --- a/docs/structures_Contact.js.html +++ b/docs/structures_Contact.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.14.1 » Source: structures/Contact.js + whatsapp-web.js 1.15.0 » Source: structures/Contact.js @@ -15,7 +15,7 @@ @@ -139,7 +139,7 @@ class Contact extends Base { * @type {boolean} */ this.isBlocked = data.isBlocked; - + return super._patch(data); } @@ -151,6 +151,22 @@ class Contact extends Base { return await this.client.getProfilePicUrl(this.id._serialized); } + /** + * Returns the contact's formatted phone number, (12345678901@c.us) => (+1 (234) 5678-901) + * @returns {Promise<string>} + */ + async getFormattedNumber() { + return await this.client.getFormattedNumber(this.id._serialized); + } + + /** + * Returns the contact's countrycode, (1541859685@c.us) => (1) + * @returns {Promise<string>} + */ + async getCountryCode() { + return await this.client.getCountryCode(this.id._serialized); + } + /** * Returns the Chat that corresponds to this Contact. * Will return null when getting chat for currently logged in user. @@ -209,7 +225,8 @@ class Contact extends Base { } -module.exports = Contact; +module.exports = Contact; +
@@ -219,7 +236,7 @@ module.exports = Contact;
diff --git a/docs/structures_GroupChat.js.html b/docs/structures_GroupChat.js.html index 460cfeb..934b63d 100644 --- a/docs/structures_GroupChat.js.html +++ b/docs/structures_GroupChat.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.14.1 » Source: structures/GroupChat.js + whatsapp-web.js 1.15.0 » Source: structures/GroupChat.js @@ -15,7 +15,7 @@ @@ -239,7 +239,7 @@ module.exports = GroupChat;
diff --git a/docs/structures_GroupNotification.js.html b/docs/structures_GroupNotification.js.html index cd0b406..0107d73 100644 --- a/docs/structures_GroupNotification.js.html +++ b/docs/structures_GroupNotification.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.14.1 » Source: structures/GroupNotification.js + whatsapp-web.js 1.15.0 » Source: structures/GroupNotification.js @@ -15,7 +15,7 @@ @@ -74,7 +74,7 @@ class GroupNotification extends Base { * * @type {string} */ - this.chatId = typeof (data.from) === 'object' ? data.from._serialized : data.from; + this.chatId = typeof (data.to) === 'object' ? data.to._serialized : data.to; /** * ContactId for the user that produced the GroupNotification. @@ -143,7 +143,7 @@ module.exports = GroupNotification;
diff --git a/docs/structures_Label.js.html b/docs/structures_Label.js.html index 57413fe..25bbf4f 100644 --- a/docs/structures_Label.js.html +++ b/docs/structures_Label.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.14.1 » Source: structures/Label.js + whatsapp-web.js 1.15.0 » Source: structures/Label.js @@ -15,7 +15,7 @@ @@ -88,7 +88,7 @@ module.exports = Label;
diff --git a/docs/structures_List.js.html b/docs/structures_List.js.html new file mode 100644 index 0000000..47f5d5c --- /dev/null +++ b/docs/structures_List.js.html @@ -0,0 +1,132 @@ + + + + + + + whatsapp-web.js 1.15.0 » Source: structures/List.js + + + + + + + + +
+
+
+ +
+ +
+
'use strict';
+
+const Util = require('../util/Util');
+
+/**
+ * Message type List
+ */
+class List {
+    /**
+     * @param {string} body
+     * @param {string} buttonText
+     * @param {Array<any>} sections
+     * @param {string?} title
+     * @param {string?} footer
+     */
+    constructor(body, buttonText, sections, title, footer) {
+        /**
+         * Message body
+         * @type {string}
+         */
+        this.description = body;
+
+        /**
+         * List button text
+         * @type {string}
+         */
+        this.buttonText = buttonText;
+        
+        /**
+         * title of message
+         * @type {string}
+         */
+        this.title = title;
+        
+
+        /**
+         * footer of message
+         * @type {string}
+         */
+        this.footer = footer;
+
+        /**
+         * sections of message
+         * @type {Array<any>}
+         */
+        this.sections = this._format(sections);
+        
+    }
+    
+    /**
+     * Creates section array from simple array
+     * @param {Array<any>} sections
+     * @returns {Array<any>}
+     * @example
+     * Input: [{title:'sectionTitle',rows:[{id:'customId', title:'ListItem2', description: 'desc'},{title:'ListItem2'}]}}]
+     * Returns: [{'title':'sectionTitle','rows':[{'rowId':'customId','title':'ListItem1','description':'desc'},{'rowId':'oGSRoD','title':'ListItem2','description':''}]}]
+     */
+    _format(sections){
+        if(!sections.length){throw '[LT02] List without sections';}
+        if(sections.length > 1){throw '[LT05] Lists with more than one section are having problems';}
+        return sections.map( (section) =>{
+            if(!section.rows.length){throw '[LT03] Section without rows';}
+            return {
+                title: section.title ? section.title : undefined,
+                rows: section.rows.map( (row) => {
+                    if(!row.title){throw '[LT04] Row without title';}
+                    return {
+                        rowId: row.id ? row.id : Util.generateHash(6),
+                        title: row.title,
+                        description: row.description ? row.description : ''
+                    };
+                })
+            };
+        });
+    }
+    
+}
+
+module.exports = List;
+
+
+
+ +
+
+
+ +
+ + + + + + + + + \ No newline at end of file diff --git a/docs/structures_Location.js.html b/docs/structures_Location.js.html index f79ae42..89102dc 100644 --- a/docs/structures_Location.js.html +++ b/docs/structures_Location.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.14.1 » Source: structures/Location.js + whatsapp-web.js 1.15.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 de78faf..ced2f0a 100644 --- a/docs/structures_Message.js.html +++ b/docs/structures_Message.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.14.1 » Source: structures/Message.js + whatsapp-web.js 1.15.0 » Source: structures/Message.js @@ -15,7 +15,7 @@ @@ -35,6 +35,7 @@ const Base = require('./Base'); const MessageMedia = require('./MessageMedia'); const Location = require('./Location'); const Order = require('./Order'); +const Payment = require('./Payment'); const { MessageTypes } = require('../util/Constants'); /** @@ -236,6 +237,21 @@ class Message extends Base { */ this.links = data.links; + /** Buttons */ + if (data.dynamicReplyButtons) { + this.dynamicReplyButtons = data.dynamicReplyButtons; + } + + /** Selected Button Id **/ + if (data.selectedButtonId) { + this.selectedButtonId = data.selectedButtonId; + } + + /** Selected List row Id **/ + if (data.listResponse && data.listResponse.singleSelectReply.selectedRowId) { + this.selectedRowId = data.listResponse.singleSelectReply.selectedRowId; + } + return super._patch(data); } @@ -469,6 +485,21 @@ class Message extends Base { } return undefined; } + /** + * Gets the payment details associated with a given message + * @return {Promise<Payment>} + */ + async getPayment() { + if (this.type === MessageTypes.PAYMENT) { + const msg = await this.client.pupPage.evaluate(async (msgId) => { + const msg = window.Store.Msg.get(msgId); + if(!msg) return null; + return msg.serialize(); + }, this.id._serialized); + return new Payment(this.client, msg); + } + return undefined; + } } module.exports = Message; @@ -482,7 +513,7 @@ module.exports = Message;
diff --git a/docs/structures_MessageMedia.js.html b/docs/structures_MessageMedia.js.html index 687be18..eeaaf6b 100644 --- a/docs/structures_MessageMedia.js.html +++ b/docs/structures_MessageMedia.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.14.1 » Source: structures/MessageMedia.js + whatsapp-web.js 1.15.0 » Source: structures/MessageMedia.js @@ -15,7 +15,7 @@ @@ -138,7 +138,7 @@ module.exports = MessageMedia;
diff --git a/docs/structures_Order.js.html b/docs/structures_Order.js.html index d32088d..731a903 100644 --- a/docs/structures_Order.js.html +++ b/docs/structures_Order.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.14.1 » Source: structures/Order.js + whatsapp-web.js 1.15.0 » Source: structures/Order.js @@ -15,7 +15,7 @@ @@ -90,7 +90,7 @@ module.exports = Order;
diff --git a/docs/structures_Payment.js.html b/docs/structures_Payment.js.html new file mode 100644 index 0000000..83ad9af --- /dev/null +++ b/docs/structures_Payment.js.html @@ -0,0 +1,132 @@ + + + + + + + whatsapp-web.js 1.15.0 » Source: structures/Payment.js + + + + + + + + +
+
+
+ +
+ +
+
const Base = require('./Base');
+
+class Payment extends Base {
+    constructor(client, data) {
+        super(client);
+
+        if (data) this._patch(data);
+    }
+
+    _patch(data) {
+        /**
+         * The payment Id
+         * @type {object}
+         */
+        this.id = data.id;
+
+        /**
+         * The payment currency
+         * @type {string}
+         */
+        this.paymentCurrency = data.paymentCurrency;
+
+        /**
+         * The payment ammount ( R$ 1.00 = 1000 )
+         * @type {number}
+         */
+        this.paymentAmount1000 = data.paymentAmount1000;
+
+        /**
+         * The payment receiver
+         * @type {object}
+         */
+        this.paymentMessageReceiverJid = data.paymentMessageReceiverJid;
+
+        /**
+         * The payment transaction timestamp
+         * @type {number}
+         */
+        this.paymentTransactionTimestamp = data.paymentTransactionTimestamp;
+
+        /**
+         * The paymentStatus
+         * @type {number}
+         *
+         * Possible Status
+         * 0:UNKNOWN_STATUS
+         * 1:PROCESSING
+         * 2:SENT
+         * 3:NEED_TO_ACCEPT
+         * 4:COMPLETE
+         * 5:COULD_NOT_COMPLETE
+         * 6:REFUNDED
+         * 7:EXPIRED
+         * 8:REJECTED
+         * 9:CANCELLED
+         * 10:WAITING_FOR_PAYER
+         * 11:WAITING
+         */
+        this.paymentStatus = data.paymentStatus;
+
+        /**
+         * Integer that represents the payment Text
+         * @type {number}
+         */
+        this.paymentTxnStatus = data.paymentTxnStatus;
+
+        /**
+         * The note sent with the payment
+         * @type {string}
+         */
+        this.paymentNote = !data.paymentNoteMsg ? undefined : data.paymentNoteMsg.body ?  data.paymentNoteMsg.body : undefined ;
+
+        return super._patch(data);
+    }
+
+}
+
+module.exports = Payment;
+
+
+
+
+ +
+
+
+ +
+ + + + + + + + + \ No newline at end of file diff --git a/docs/structures_PrivateChat.js.html b/docs/structures_PrivateChat.js.html index 2427518..0fcd9a2 100644 --- a/docs/structures_PrivateChat.js.html +++ b/docs/structures_PrivateChat.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.14.1 » Source: structures/PrivateChat.js + whatsapp-web.js 1.15.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 592f8bf..11739e7 100644 --- a/docs/structures_PrivateContact.js.html +++ b/docs/structures_PrivateContact.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.14.1 » Source: structures/PrivateContact.js + whatsapp-web.js 1.15.0 » Source: structures/PrivateContact.js @@ -15,7 +15,7 @@ @@ -51,7 +51,7 @@ module.exports = PrivateContact;
diff --git a/docs/structures_Product.js.html b/docs/structures_Product.js.html index b8a39fb..6c02888 100644 --- a/docs/structures_Product.js.html +++ b/docs/structures_Product.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.14.1 » Source: structures/Product.js + whatsapp-web.js 1.15.0 » Source: structures/Product.js @@ -15,7 +15,7 @@ @@ -106,7 +106,7 @@ module.exports = Product;
diff --git a/docs/structures_ProductMetadata.js.html b/docs/structures_ProductMetadata.js.html index 54b2212..dc06478 100644 --- a/docs/structures_ProductMetadata.js.html +++ b/docs/structures_ProductMetadata.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.14.1 » Source: structures/ProductMetadata.js + whatsapp-web.js 1.15.0 » Source: structures/ProductMetadata.js @@ -15,7 +15,7 @@ @@ -63,7 +63,7 @@ module.exports = ProductMetadata;
diff --git a/docs/util_Constants.js.html b/docs/util_Constants.js.html index 65da58a..20e5168 100644 --- a/docs/util_Constants.js.html +++ b/docs/util_Constants.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.14.1 » Source: util/Constants.js + whatsapp-web.js 1.15.0 » Source: util/Constants.js @@ -15,7 +15,7 @@ @@ -42,6 +42,7 @@ exports.DefaultOptions = { qrTimeoutMs: 45000, qrRefreshIntervalMs: 20000, authTimeoutMs: 45000, + qrMaxRetries: 0, 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', @@ -105,7 +106,10 @@ exports.MessageTypes = { REVOKED: 'revoked', PRODUCT: 'product', UNKNOWN: 'unknown', - GROUP_INVITE: 'groups_v4_invite' + GROUP_INVITE: 'groups_v4_invite', + LIST: 'list', + BUTTONS_RESPONSE: 'buttons_response', + PAYMENT: 'payment' }; /** @@ -179,7 +183,7 @@ exports.MessageAck = {
diff --git a/docs/util_InterfaceController.js.html b/docs/util_InterfaceController.js.html index 697fa2b..0ab6037 100644 --- a/docs/util_InterfaceController.js.html +++ b/docs/util_InterfaceController.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.14.1 » Source: util/InterfaceController.js + whatsapp-web.js 1.15.0 » Source: util/InterfaceController.js @@ -15,7 +15,7 @@ @@ -160,7 +160,7 @@ module.exports = InterfaceController;
diff --git a/docs/util_Util.js.html b/docs/util_Util.js.html index c5edf7d..9e50877 100644 --- a/docs/util_Util.js.html +++ b/docs/util_Util.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.14.1 » Source: util/Util.js + whatsapp-web.js 1.15.0 » Source: util/Util.js @@ -15,7 +15,7 @@ @@ -242,7 +242,7 @@ module.exports = Util;
diff --git a/package.json b/package.json index 276998d..776241d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "whatsapp-web.js", - "version": "1.14.1", + "version": "1.15.0", "description": "Library for interacting with the WhatsApp Web API ", "main": "./index.js", "typings": "./index.d.ts",
-

Date when the chat will be unmuted

+

Date when the chat will be unmuted, leave as is to mute forever

+

Value can be null.

-

(string, MessageMedia, Location, Contact, or Array of Contact)

+

(string, MessageMedia, Location, Contact, Array of Contact, Buttons, or List)

 

@@ -2298,7 +2407,7 @@
diff --git a/docs/Client.js.html b/docs/Client.js.html index c89bf38..aa8e2ac 100644 --- a/docs/Client.js.html +++ b/docs/Client.js.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.14.1 » Source: Client.js + whatsapp-web.js 1.15.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 , Label, Call } = require('./structures'); +const { ClientInfo, Message, MessageMedia, Contact, Location, GroupNotification , Label, Call, Buttons, List} = require('./structures'); /** * Starting point for interacting with the WhatsApp Web API * @extends {EventEmitter} @@ -51,6 +51,7 @@ const { ClientInfo, Message, MessageMedia, Contact, Location, GroupNotification * @param {object} options.puppeteer - Puppeteer launch options. View docs here: https://github.com/puppeteer/puppeteer/ * @param {number} options.qrRefreshIntervalMs - Refresh interval for qr code (how much time to wait before checking if the qr code has changed) * @param {number} options.qrTimeoutMs - Timeout for qr code selector in puppeteer + * @param {number} options.qrMaxRetries - How many times should the qrcode be refreshed before giving up * @param {string} options.restartOnAuthFail - Restart client with a new session (i.e. use null 'session' var) if authentication fails * @param {object} options.session - Whatsapp session to restore. If not set, will start a new session * @param {string} options.session.WABrowserId @@ -131,7 +132,7 @@ class Client extends EventEmitter { timeout: 0, }); - const KEEP_PHONE_CONNECTED_IMG_SELECTOR = '[data-asset-intro-image-light="true"], [data-asset-intro-image-dark="true"]'; + const KEEP_PHONE_CONNECTED_IMG_SELECTOR = '[data-icon="intro-md-beta-logo-dark"], [data-icon="intro-md-beta-logo-light"], [data-asset-intro-image-light="true"], [data-asset-intro-image-dark="true"]'; if (this.options.session) { // Check if session restore was successfull @@ -158,6 +159,8 @@ class Client extends EventEmitter { } } else { + let qrRetries = 0; + const getQrCode = async () => { // Check if retry button is present var QR_RETRY_SELECTOR = 'div[data-ref] > span > button'; @@ -178,6 +181,14 @@ class Client extends EventEmitter { * @param {string} qr QR Code */ this.emit(Events.QR_RECEIVED, qr); + + if (this.options.qrMaxRetries > 0) { + qrRetries++; + if (qrRetries > this.options.qrMaxRetries) { + this.emit(Events.DISCONNECTED, 'Max qrcode retries reached'); + await this.destroy(); + } + } }; getQrCode(); this._qrRefreshInterval = setInterval(getQrCode, this.options.qrRefreshIntervalMs); @@ -217,6 +228,14 @@ class Client extends EventEmitter { // Check window.Store Injection await page.waitForFunction('window.Store != undefined'); + const isMD = await page.evaluate(() => { + return window.Store.Features.features.MD_BACKEND; + }); + + if(isMD) { + throw new Error('Multi-device is not yet supported by whatsapp-web.js. Please check out https://github.com/pedroslopez/whatsapp-web.js/pull/889 to follow the progress.'); + } + //Load util functions (serializers, helper functions) await page.evaluate(LoadUtils); @@ -510,7 +529,7 @@ class Client extends EventEmitter { /** * Send a message to a specific chatId * @param {string} chatId - * @param {string|MessageMedia|Location|Contact|Array<Contact>} content + * @param {string|MessageMedia|Location|Contact|Array<Contact>|Buttons|List} content * @param {MessageSendOptions} [options] - Options used when sending the message * * @returns {Promise<Message>} Message that was just sent @@ -547,6 +566,13 @@ class Client extends EventEmitter { } else if(Array.isArray(content) && content.length > 0 && content[0] instanceof Contact) { internalOptions.contactCardList = content.map(contact => contact.id._serialized); content = ''; + } else if(content instanceof Buttons){ + if(content.type !== 'chat'){internalOptions.attachment = content.body;} + internalOptions.buttons = content; + content = ''; + } else if(content instanceof List){ + internalOptions.list = content; + content = ''; } if (internalOptions.sendMediaAsSticker && internalOptions.attachment) { @@ -781,15 +807,16 @@ class Client extends EventEmitter { } /** - * Mutes the Chat until a specified date + * Mutes this chat forever, unless a date is specified * @param {string} chatId ID of the chat that will be muted - * @param {Date} unmuteDate Date when the chat will be unmuted + * @param {?Date} unmuteDate Date when the chat will be unmuted, leave as is to mute forever */ async muteChat(chatId, unmuteDate) { + unmuteDate = unmuteDate ? unmuteDate.getTime() / 1000 : -1; await this.pupPage.evaluate(async (chatId, timestamp) => { let chat = await window.Store.Chat.get(chatId); await chat.mute.mute(timestamp, !0); - }, chatId, unmuteDate.getTime() / 1000); + }, chatId, unmuteDate || -1); } /** @@ -855,10 +882,7 @@ class Client extends EventEmitter { * @returns {Promise<Object|null>} */ async getNumberId(number) { - if(!number.endsWith('@c.us')) { - number += '@c.us'; - } - + if (!number.endsWith('@c.us')) number += '@c.us'; try { return await this.pupPage.evaluate(async numberId => { return window.WWebJS.getNumberId(numberId); @@ -868,6 +892,33 @@ class Client extends EventEmitter { } } + /** + * Get the formatted number of a WhatsApp ID. + * @param {string} number Number or ID + * @returns {Promise<string>} + */ + async getFormattedNumber(number) { + if(!number.endsWith('@s.whatsapp.net')) number = number.replace('c.us', 's.whatsapp.net'); + if(!number.includes('@s.whatsapp.net')) number = `${number}@s.whatsapp.net`; + + return await this.pupPage.evaluate(async numberId => { + return window.Store.NumberInfo.formattedPhoneNumber(numberId); + }, number); + } + + /** + * Get the country code of a WhatsApp ID. + * @param {string} number Number or ID + * @returns {Promise<string>} + */ + async getCountryCode(number) { + number = number.replace(' ', '').replace('+', '').replace('@c.us', ''); + + return await this.pupPage.evaluate(async numberId => { + return window.Store.NumberInfo.findCC(numberId); + }, number); + } + /** * Create a new group * @param {string} name group title @@ -962,6 +1013,19 @@ class Client extends EventEmitter { return Promise.all(chatIds.map(id => this.getChatById(id))); } + + /** + * Gets all blocked contacts by host account + * @returns {Promise<Array<Contact>>} + */ + async getBlockedContacts() { + const blockedContacts = await this.pupPage.evaluate(() => { + let chatIds = window.Store.Blocklist.models.map(a => a.id._serialized); + return Promise.all(chatIds.map(id => window.WWebJS.getContact(id))); + }); + + return blockedContacts.map(contact => ContactFactory.create(this.client, contact)); + } } module.exports = Client; @@ -975,7 +1039,7 @@ module.exports = Client;
diff --git a/docs/ClientInfo.html b/docs/ClientInfo.html index c74d52e..5441821 100644 --- a/docs/ClientInfo.html +++ b/docs/ClientInfo.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.14.1 » Class: ClientInfo + whatsapp-web.js 1.15.0 » Class: ClientInfo @@ -15,7 +15,7 @@ @@ -235,7 +235,7 @@
diff --git a/docs/Contact.html b/docs/Contact.html index 2414ce2..40d43b5 100644 --- a/docs/Contact.html +++ b/docs/Contact.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.14.1 » Class: Contact + whatsapp-web.js 1.15.0 » Class: Contact @@ -15,7 +15,7 @@ @@ -101,11 +101,17 @@
getAbout()
+
getChat()
+
+
-
getChat()
+
getCountryCode()
+
+
+
getFormattedNumber()
getProfilePicUrl()
@@ -230,6 +236,24 @@
async
+

getCountryCode() → Promise containing string

+

Returns the contact's countrycode, (1541859685@c.us) => (1)

+
+
Returns
+
+

Promise containing string 

+
+
+
async
+

getFormattedNumber() → Promise containing string

+

Returns the contact's formatted phone number, (12345678901@c.us) => (+1 (234) 5678-901)

+
+
Returns
+
+

Promise containing string 

+
+
+
async

getProfilePicUrl() → Promise containing string

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

@@ -257,7 +281,7 @@
diff --git a/docs/GroupChat.html b/docs/GroupChat.html index 999e984..687655f 100644 --- a/docs/GroupChat.html +++ b/docs/GroupChat.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.14.1 » Class: GroupChat + whatsapp-web.js 1.15.0 » Class: GroupChat @@ -15,7 +15,7 @@ @@ -521,7 +521,7 @@
async

mute(unmuteDate)

-

Mutes this chat until a specified date

+

Mutes this chat forever, unless a date is specified

Parameter

@@ -545,7 +545,8 @@

 

@@ -916,7 +917,7 @@
diff --git a/docs/GroupNotification.html b/docs/GroupNotification.html index 77ea84d..aa07936 100644 --- a/docs/GroupNotification.html +++ b/docs/GroupNotification.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.14.1 » Class: GroupNotification + whatsapp-web.js 1.15.0 » Class: GroupNotification @@ -15,7 +15,7 @@ @@ -233,7 +233,7 @@
diff --git a/docs/InterfaceController.html b/docs/InterfaceController.html index ab7dcca..f3fe0e1 100644 --- a/docs/InterfaceController.html +++ b/docs/InterfaceController.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.14.1 » Class: InterfaceController + whatsapp-web.js 1.15.0 » Class: InterfaceController @@ -15,7 +15,7 @@ @@ -382,7 +382,7 @@
diff --git a/docs/Label.html b/docs/Label.html index bd63f09..7dab33f 100644 --- a/docs/Label.html +++ b/docs/Label.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.14.1 » Class: Label + whatsapp-web.js 1.15.0 » Class: Label @@ -15,7 +15,7 @@ @@ -163,7 +163,7 @@
diff --git a/docs/List.html b/docs/List.html new file mode 100644 index 0000000..a826c98 --- /dev/null +++ b/docs/List.html @@ -0,0 +1,271 @@ + + + + + + + whatsapp-web.js 1.15.0 » Class: List + + + + + + + + +
+
+
+
+ +
+
+

Properties

+
+
+
+
buttonText
+
+
+
description
+
+
+
+
+
+
+
footer
+
+
+
sections
+
+
+
+
+
+
+
title
+
+
+
+
+
+
+
+

Method

+
+
+
+
_format(sections)
+
+
+
+
+
+
+
+
+
+
+
+
+

new List(body, buttonText, sections, title, footer)

+
+

Parameters

+
-

Date at which the Chat will be unmuted

+

Date at which the Chat will be unmuted, leave as is to mute forever

+

Value can be null.

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

body

+
+

 

+
+

 

+
+
+

buttonText

+
+

 

+
+

 

+
+
+

sections

+
+

 

+
+

 

+
+
+

title

+
+

 

+
+

 

+
+

Value can be null.

+
+

footer

+
+

 

+
+

 

+
+

Value can be null.

+
+
+
+
+ +
+

Properties

+
+

buttonText +  string

+

List button text

+
+
+

description +  string

+

Message body

+
+
+ +

footer of message

+
+
+

sections +  Array of any

+

sections of message

+
+
+

title +  string

+

title of message

+
+
+
+

Method

+
+

_format(sections) → Array of any

+

Creates section array from simple array

+
+

+ Example +

+
+
Input: [{title:'sectionTitle',rows:[{id:'customId', title:'ListItem2', description: 'desc'},{title:'ListItem2'}]}}]
+Returns: [{'title':'sectionTitle','rows':[{'rowId':'customId','title':'ListItem1','description':'desc'},{'rowId':'oGSRoD','title':'ListItem2','description':''}]}]
+
+
+
+

Parameter

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

sections

+
+

Array of any

+
+

 

+
+
+
+
+
Returns
+
+

Array of any 

+
+
+
+
+
+ + + + +
+ +
+ + + + + + + + + \ No newline at end of file diff --git a/docs/Location.html b/docs/Location.html index 498a91e..50e393f 100644 --- a/docs/Location.html +++ b/docs/Location.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.14.1 » Class: Location + whatsapp-web.js 1.15.0 » Class: Location @@ -15,7 +15,7 @@ @@ -149,7 +149,7 @@
diff --git a/docs/Message.html b/docs/Message.html index 73fb22d..5d2c6f3 100644 --- a/docs/Message.html +++ b/docs/Message.html @@ -4,7 +4,7 @@ - whatsapp-web.js 1.14.1 » Class: Message + whatsapp-web.js 1.15.0 » Class: Message @@ -15,7 +15,7 @@ @@ -26,7 +26,7 @@
Send location
Send buttons
Send lists✅ (business accounts not supported)
Receive location