Compare commits

..

41 Commits

Author SHA1 Message Date
Pedro Lopez
3cbf1e9c2f chore: mark version v1.4.0 2020-04-05 23:39:22 -04:00
Aliyss Snow
93a617336a feat: battery percentage changed event (#126)
New "change_battery" event is triggered when the battery percentage changes. Has current battery percentage and charging state as object param.

Co-authored-by: Pedro S. Lopez <pedroslopez@me.com>
2020-04-05 23:36:03 -04:00
kurob1993
1780436b93 fix: make pupBrowser and pupPage available sooner (#137)
* move this.pupBrowser variable to line 51 to resolve not being able to close the browser when it is not connected to the internet

* move pupPage along with pupBrowser

Co-authored-by: Pedro S. Lopez <pedroslopez@me.com>
2020-04-05 23:04:03 -04:00
Pedro Lopez
7acbd3d800 fix: properly set chatId
This was causing errors when using the .reply() function
2020-04-05 22:57:59 -04:00
Pedro Lopez
67435b2244 fix: group events were not being triggered 2020-04-05 22:57:36 -04:00
Pedro Lopez
743ac93f6e feat: allow setting timeouts via options 2020-04-03 01:49:16 -04:00
Pedro Lopez
0a7412cf17 feat: create groups
close #131
2020-04-03 01:45:06 -04:00
Pedro Lopez
d1e357d23b chore: bump version v1.3.1-post 2020-04-02 02:35:36 -04:00
Pedro Lopez
3610cef926 chore(docs): mark v1.3.1 2020-04-02 02:33:44 -04:00
Pedro Lopez
4e5eeace2f chore: mark v1.3.1 2020-04-02 02:33:17 -04:00
Pedro Lopez
6c43a2d2ed fix: increase timeouts
close #130
2020-04-02 02:30:50 -04:00
Pedro Lopez
001c045c08 fix: only return undefined for ERROR_* media states
This was causing a regression as of 1.2.5 that caused media files sent by the client to not be properly downloaded
cc #111 @stevefold
2020-04-02 02:24:12 -04:00
Pedro S. Lopez
c3ba79464b Update README.md 2020-03-31 12:43:03 -04:00
Pedro Lopez
237331b656 chore: bump version to v1.3.0-post 2020-03-29 23:59:05 -04:00
Pedro Lopez
9d0b58a847 chore: mark version v1.3.0 2020-03-29 23:51:49 -04:00
Pedro Lopez
842c4f0e06 feat: check if ID is a valid whatsapp user
close #120
2020-03-29 22:58:08 -04:00
Pedro Lopez
2dddc781c5 fix: initialize takes no params 2020-03-29 21:47:47 -04:00
Pedro S. Lopez
d8cd2d1d83 chore: updated whatsapp web version 2020-03-23 18:59:53 -04:00
Pedro Lopez
80d5783f22 feat: new event for when media is uploaded
Messages created by the current client don't have attatched media on message_create because it is still being uploaded and sent. This event allows you to detect when the media has been properly sent so it can be downloaded.

close #111
2020-03-22 20:38:26 -04:00
Pedro Lopez
cb54487197 feat: add ack to message model
close #108
2020-03-22 20:00:53 -04:00
Steven L
d08b343815 Added "restartOnAuthFail" as an option (#112)
- When true, the sessions passed is discarded when reinitialized.
2020-03-22 19:52:46 -04:00
Pedro Lopez
ec1a80dfb4 chore: bump version to v1.2.5-post 2020-03-15 15:36:57 -04:00
Pedro Lopez
56ed020d65 chore: mark version v1.2.5 2020-03-15 15:32:37 -04:00
Pedro Lopez
25b96378c7 fix: properly handle unresolved media 2020-03-15 15:29:56 -04:00
Pedro S. Lopez
5934ec531f fix: return undefined when attempting to download nonexistent media
This could occur when the user has deleted the media and it can no longer be downloaded.
2020-03-15 15:20:50 -04:00
Pedro Lopez
65542f6025 chore/fix: update requires for new moduleraid package
For got to do this on the previous release
2020-03-15 02:05:20 -04:00
Pedro Lopez
00c603e623 chore: use published moduleraid
Pulling this from github was causing confusion and issues on installation for users that did not have git installed. I have published the library myself for now, but should be changed back to the official library when an official release is made.
2020-03-15 02:03:11 -04:00
Pedro Lopez
bcd18428eb chore: bump version to v1.2.4-post 2020-03-14 17:46:33 -04:00
Pedro Lopez
995abbf4a6 chore: mark version v1.2.4 2020-03-14 17:43:31 -04:00
Pedro Lopez
8599a6d918 fix: properly download media if it has not been loaded
This issue occurred when attempting to download media from old messages.
2020-03-14 17:37:59 -04:00
Pedro Lopez
5e9deff8a9 chore: bump version v1.2.3-post 2020-03-13 17:54:22 -04:00
Pedro Lopez
539849732c chore: mark version v1.2.1 2020-03-13 17:46:39 -04:00
Pedro Lopez
4fe7fa93b9 fix: delegate all event handlers
Attaching these events directly to puppeteer functions apparently blocks and causes CPU usage to go up, slowing everything down.

related #88, 8bdecad
2020-03-13 17:44:20 -04:00
Pedro Lopez
2820d3e72a chore: bump version to v1.2.2-post 2020-03-13 00:18:30 -04:00
Pedro Lopez
cde5719bb6 chrore: mark version v1.2.2 2020-03-13 00:13:46 -04:00
Pedro Lopez
8bdecadba4 fix: don't call event handler for new messages directly to puppeteer
This was creating performance issues, specially on startup when the initial set of messages were being loaded for a client with many chats.
2020-03-13 00:09:43 -04:00
Pedro Lopez
b41414cfbf chore: bump version to 1.2.1-post 2020-03-05 21:23:48 -04:00
Pedro Lopez
c61f447a93 chore: mark version v1.2.1 2020-03-05 21:20:53 -04:00
Pedro Lopez
49aacec4a7 fix: correctly splice and merge fetched messages
This was eliminating messages in the middle of the array instead of eliminating older messages to reach the specified limit.

close #97
2020-03-05 21:18:10 -04:00
Pedro S. Lopez
d7a3e1a9a3 chore: update supported whatsapp web version 2020-03-02 23:57:24 -04:00
Pedro Lopez
e14b49c5df chore: bump version to v1.2.0-post 2020-03-01 15:14:06 -04:00
41 changed files with 698 additions and 180 deletions

View File

@@ -1,4 +1,4 @@
[![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 0.4.930](https://img.shields.io/badge/WhatsApp_Web-0.4.930-brightgreen.svg)
[![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 0.4.2088](https://img.shields.io/badge/WhatsApp_Web-0.4.2088-brightgreen.svg)
# whatsapp-web.js
A WhatsApp API client that connects through the WhatsApp Web browser app
@@ -46,7 +46,7 @@ Take a look at [example.js](https://github.com/pedroslopez/whatsapp-web.js/blob/
| Send messages | ✅ |
| Receive messages | ✅ |
| Send media (images/audio/documents) | ✅ |
| Send media (video) | ✅ (requires google chrome) |
| Send media (video) | ✅ [(requires google chrome)](https://github.com/pedroslopez/whatsapp-web.js/issues/78#issuecomment-592723583) |
| Send stickers | _pending_ |
| Receive media (images/audio/video/documents) | ✅ |
| Send contact cards | _pending_ |
@@ -68,9 +68,34 @@ Something missing? Make an issue and let us know!
## Links
* [Documentation](https://pedroslopez.me/whatsapp-web.js) _(preview)_
* [Reference](https://pedroslopez.me/whatsapp-web.js)
* [Guide](https://waguide.pedroslopez.me/) _(work in progress)_
* [GitHub](https://github.com/pedroslopez/whatsapp-web.js)
## Contributing
Pull requests are welcome! If you see something you'd like to add, please do. For drastic changes, please open an issue first.
## Donating
You can support the maintainer of this project through the link below
[![Support via PayPal](https://cdn.rawgit.com/twolfson/paypal-github-button/1.0.0/dist/button.svg)](https://www.paypal.me/psla/)
## Disclaimer
This project is not affiliated, associated, authorized, endorsed by, or in any way officially connected with WhatsApp or any of its subsidiaries or its affiliates. The official WhatsApp website can be found at https://whatsapp.com. "WhatsApp" as well as related names, marks, emblems and images are registered trademarks of their respective owners.
## License
Copyright 2019 Pedro S Lopez
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this project except in compliance with the License.
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.3">
<meta charset="utf-8">
<title>whatsapp-web.js 1.2.0 &raquo; Class: Base</title>
<title>whatsapp-web.js 1.4.0 &raquo; Class: Base</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
@@ -15,7 +15,7 @@
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>2.<wbr>0</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>4.<wbr>0</a>
</div>
</div>
</nav>
@@ -50,7 +50,7 @@
<footer id="jsdoc-footer" class="jsdoc-footer">
<div id="jsdoc-footer-container">
<p>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on March 1, 2020.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on April 5, 2020.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.3">
<meta charset="utf-8">
<title>whatsapp-web.js 1.2.0 &raquo; Class: BusinessContact</title>
<title>whatsapp-web.js 1.4.0 &raquo; Class: BusinessContact</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
@@ -15,7 +15,7 @@
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>2.<wbr>0</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>4.<wbr>0</a>
</div>
</div>
</nav>
@@ -227,7 +227,7 @@
<footer id="jsdoc-footer" class="jsdoc-footer">
<div id="jsdoc-footer-container">
<p>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on March 1, 2020.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on April 5, 2020.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.3">
<meta charset="utf-8">
<title>whatsapp-web.js 1.2.0 &raquo; Class: Chat</title>
<title>whatsapp-web.js 1.4.0 &raquo; Class: Chat</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
@@ -15,7 +15,7 @@
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>2.<wbr>0</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>4.<wbr>0</a>
</div>
</div>
</nav>
@@ -350,7 +350,7 @@
<footer id="jsdoc-footer" class="jsdoc-footer">
<div id="jsdoc-footer-container">
<p>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on March 1, 2020.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on April 5, 2020.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.3">
<meta charset="utf-8">
<title>whatsapp-web.js 1.2.0 &raquo; Class: Client</title>
<title>whatsapp-web.js 1.4.0 &raquo; Class: Client</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
@@ -15,7 +15,7 @@
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>2.<wbr>0</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>4.<wbr>0</a>
</div>
</div>
</nav>
@@ -26,7 +26,7 @@
<header class="page-header">
<div class="symbol-detail-labels"><span class="label label-kind">class</span></div>
<h1><small></small><span class="symbol-name">Client</span></h1>
<p class="source-link">Source: <a href="Client.js.html#source-line-33">Client.<wbr>js:33</a></p>
<p class="source-link">Source: <a href="Client.js.html#source-line-35">Client.<wbr>js:35</a></p>
<div class="symbol-classdesc">
<p>Starting point for interacting with the WhatsApp Web API</p>
</div>
@@ -45,6 +45,9 @@
<dt><a href="Client.html#archiveChat">archiveChat()</a></dt>
<dd>
</dd>
<dt><a href="Client.html#createGroup">createGroup(name, participants)</a></dt>
<dd>
</dd>
<dt><a href="Client.html#destroy">destroy()</a></dt>
<dd>
</dd>
@@ -70,6 +73,9 @@
<dt><a href="Client.html#initialize">initialize()</a></dt>
<dd>
</dd>
<dt><a href="Client.html#isRegisteredUser">isRegisteredUser()</a></dt>
<dd>
</dd>
<dt><a href="Client.html#resetState">resetState()</a></dt>
<dd>
</dd>
@@ -104,6 +110,9 @@
<dt><a href="Client.html#event:authenticated">authenticated</a></dt>
<dd>
</dd>
<dt><a href="Client.html#event:change_battery">change_battery</a></dt>
<dd>
</dd>
<dt><a href="Client.html#event:change_state">change_state</a></dt>
<dd>
</dd>
@@ -123,6 +132,9 @@
<dt><a href="Client.html#event:group_update">group_update</a></dt>
<dd>
</dd>
<dt><a href="Client.html#event:media_uploaded">media_uploaded</a></dt>
<dd>
</dd>
<dt><a href="Client.html#event:message">message</a></dt>
<dd>
</dd>
@@ -168,11 +180,13 @@
<dd><a href="Client.html#event:message_create">Client#event:message_create</a></dd>
<dd><a href="Client.html#event:message_revoke_me">Client#event:message_revoke_me</a></dd>
<dd><a href="Client.html#event:message_revoke_everyone">Client#event:message_revoke_everyone</a></dd>
<dd><a href="Client.html#event:media_uploaded">Client#event:media_uploaded</a></dd>
<dd><a href="Client.html#event:group_join">Client#event:group_join</a></dd>
<dd><a href="Client.html#event:group_leave">Client#event:group_leave</a></dd>
<dd><a href="Client.html#event:group_update">Client#event:group_update</a></dd>
<dd><a href="Client.html#event:disconnected">Client#event:disconnected</a></dd>
<dd><a href="Client.html#event:change_state">Client#event:change_state</a></dd>
<dd><a href="Client.html#event:change_battery">Client#event:change_battery</a></dd>
</dl>
</section>
<section>
@@ -222,6 +236,67 @@
</dd>
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="createGroup"><span class="symbol-name">createGroup</span><span class="signature"><span class="signature-params">(name, participants)</span>&nbsp;&rarr; <span class="signature-returns"> (Object, string, or Object with string properties)</span></span></h3>
<p>Create a new group</p>
<section>
<h4>Parameters</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>name</p>
</td>
<td>
<p>string</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>group title</p>
</td>
</tr>
<tr>
<td>
<p>participants</p>
</td>
<td>
<p>Array of (<a href="Contact.html">Contact</a> or string)</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>an array of Contacts or contact IDs to add to the group</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Object</code> <p>createRes</p>
</p>
</dd>
<dd>
<p><code>string</code> <p>createRes.gid - ID for the group that was just created</p>
</p>
</dd>
<dd>
<p><code>Object with string properties</code> <p>createRes.missingParticipants - participants that were not added to the group. Keys represent the ID for participant that was not added and its value is a status code that represents the reason why participant could not be added. This is usually 403 if the user's privacy settings don't allow you to add them to groups.</p>
</p>
</dd>
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="destroy"><span class="symbol-name">destroy</span><span class="signature"><span class="signature-params">()</span></span></h3>
<p>Closes the client</p>
<dl class="dl-compact">
@@ -333,6 +408,15 @@
<dl class="dl-compact">
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="isRegisteredUser"><span class="symbol-name">isRegisteredUser</span><span class="signature"><span class="signature-params">()</span>&nbsp;&rarr; <span class="signature-returns"> Promise containing Boolean</span></span></h3>
<p>Check if a given ID is registered in whatsapp</p>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Promise containing Boolean</code> </p>
</dd>
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="resetState"><span class="symbol-name">resetState</span><span class="signature"><span class="signature-params">()</span></span></h3>
<p>Force reset of connection state for the client</p>
<dl class="dl-compact">
@@ -550,6 +634,79 @@
</section>
<dl class="dl-compact">
</dl>
<h3 id="event:change_battery"><span class="symbol-name">change_battery</span></h3>
<p>Emitted when the battery percentage for the attached device changes</p>
<section>
<h4>Parameters</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>batteryInfo</p>
</td>
<td>
<p>object</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>Values in <code>batteryInfo</code> have the following properties:</p>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>battery</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>The current battery percentage</p>
</td>
</tr>
<tr>
<td>
<p>plugged</p>
</td>
<td>
<p>boolean</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>Indicates if the phone is plugged in (true) or not (false)</p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
</dl>
<h3 id="event:change_state"><span class="symbol-name">change_state</span></h3>
<p>Emitted when the connection state changes</p>
<section>
@@ -715,6 +872,39 @@
</section>
<dl class="dl-compact">
</dl>
<h3 id="event:media_uploaded"><span class="symbol-name">media_uploaded</span></h3>
<p>Emitted when media has been uploaded for a message sent by the client.</p>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>message</p>
</td>
<td>
<p><a href="Message.html">Message</a></p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>The message with media that was uploaded</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
</dl>
<h3 id="event:message"><span class="symbol-name">message</span></h3>
<p>Emitted when a new message is received.</p>
<section>
@@ -957,7 +1147,7 @@
<footer id="jsdoc-footer" class="jsdoc-footer">
<div id="jsdoc-footer-container">
<p>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on March 1, 2020.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on April 5, 2020.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.3">
<meta charset="utf-8">
<title>whatsapp-web.js 1.2.0 &raquo; Source: Client.js</title>
<title>whatsapp-web.js 1.4.0 &raquo; Source: Client.js</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
@@ -15,7 +15,7 @@
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>2.<wbr>0</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>4.<wbr>0</a>
</div>
</div>
</nav>
@@ -33,7 +33,7 @@
const EventEmitter &#x3D; require(&#x27;events&#x27;);
const puppeteer &#x3D; require(&#x27;puppeteer&#x27;);
const moduleRaid &#x3D; require(&#x27;moduleraid/moduleraid&#x27;);
const moduleRaid &#x3D; require(&#x27;@pedroslopez/moduleraid/moduleraid&#x27;);
const jsQR &#x3D; require(&#x27;jsqr&#x27;);
const Util &#x3D; require(&#x27;./util/Util&#x27;);
@@ -41,7 +41,7 @@ const { WhatsWebURL, UserAgent, DefaultOptions, Events, WAState } &#x3D; require
const { ExposeStore, LoadUtils } &#x3D; require(&#x27;./util/Injected&#x27;);
const ChatFactory &#x3D; require(&#x27;./factories/ChatFactory&#x27;);
const ContactFactory &#x3D; require(&#x27;./factories/ContactFactory&#x27;);
const { ClientInfo, Message, MessageMedia, Location, GroupNotification } &#x3D; require(&#x27;./structures&#x27;);
const { ClientInfo, Message, MessageMedia, Contact, Location, GroupNotification } &#x3D; require(&#x27;./structures&#x27;);
/**
* Starting point for interacting with the WhatsApp Web API
* @extends {EventEmitter}
@@ -54,11 +54,13 @@ const { ClientInfo, Message, MessageMedia, Location, GroupNotification } &#x3D;
* @fires Client#message_create
* @fires Client#message_revoke_me
* @fires Client#message_revoke_everyone
* @fires Client#media_uploaded
* @fires Client#group_join
* @fires Client#group_leave
* @fires Client#group_update
* @fires Client#disconnected
* @fires Client#change_state
* @fires Client#change_battery
*/
class Client extends EventEmitter {
constructor(options &#x3D; {}) {
@@ -78,6 +80,9 @@ class Client extends EventEmitter {
const page &#x3D; (await browser.pages())[0];
page.setUserAgent(UserAgent);
this.pupBrowser &#x3D; browser;
this.pupPage &#x3D; page;
if (this.options.session) {
await page.evaluateOnNewDocument(
session &#x3D;&gt; {
@@ -96,7 +101,7 @@ class Client extends EventEmitter {
if (this.options.session) {
// Check if session restore was successfull
try {
await page.waitForSelector(KEEP_PHONE_CONNECTED_IMG_SELECTOR, { timeout: 15000 });
await page.waitForSelector(KEEP_PHONE_CONNECTED_IMG_SELECTOR, { timeout: this.options.authTimeoutMs });
} catch (err) {
if (err.name &#x3D;&#x3D;&#x3D; &#x27;TimeoutError&#x27;) {
/**
@@ -106,7 +111,11 @@ class Client extends EventEmitter {
*/
this.emit(Events.AUTHENTICATION_FAILURE, &#x27;Unable to log in. Are the session details valid?&#x27;);
browser.close();
if (this.options.restartOnAuthFail) {
// session restore failed so try again but without session to force new authentication
this.options.session &#x3D; null;
this.initialize();
}
return;
}
@@ -125,7 +134,7 @@ class Client extends EventEmitter {
// Wait for QR Code
const QR_CANVAS_SELECTOR &#x3D; &#x27;canvas&#x27;;
await page.waitForSelector(QR_CANVAS_SELECTOR);
await page.waitForSelector(QR_CANVAS_SELECTOR, { timeout: this.options.qrTimeoutMs });
const qrImgData &#x3D; await page.$eval(QR_CANVAS_SELECTOR, canvas &#x3D;&gt; [].slice.call(canvas.getContext(&#x27;2d&#x27;).getImageData(0, 0, 264, 264).data));
const qr &#x3D; jsQR(qrImgData, 264, 264).data;
/**
@@ -136,7 +145,7 @@ class Client extends EventEmitter {
this.emit(Events.QR_RECEIVED, qr);
};
getQrCode();
let retryInterval &#x3D; setInterval(getQrCode, 20000); // check for qr code every 20 seconds
let retryInterval &#x3D; setInterval(getQrCode, this.options.qrRefreshIntervalMs);
// Wait for code scan
await page.waitForSelector(KEEP_PHONE_CONNECTED_IMG_SELECTOR, { timeout: 0 });
@@ -286,7 +295,19 @@ class Client extends EventEmitter {
});
await page.exposeFunction(&#x27;onAppStateChangedEvent&#x27;, (_AppState, state) &#x3D;&gt; {
await page.exposeFunction(&#x27;onMessageMediaUploadedEvent&#x27;, (msg) &#x3D;&gt; {
const message &#x3D; new Message(this, msg);
/**
* Emitted when media has been uploaded for a message sent by the client.
* @event Client#media_uploaded
* @param {Message} message The message with media that was uploaded
*/
this.emit(Events.MEDIA_UPLOADED, message);
});
await page.exposeFunction(&#x27;onAppStateChangedEvent&#x27;, (state) &#x3D;&gt; {
/**
* Emitted when the connection state changes
@@ -307,17 +328,30 @@ class Client extends EventEmitter {
}
});
await page.evaluate(() &#x3D;&gt; {
window.Store.Msg.on(&#x27;add&#x27;, window.onAddMessageEvent);
window.Store.Msg.on(&#x27;change&#x27;, window.onChangeMessageEvent);
window.Store.Msg.on(&#x27;change:type&#x27;, window.onChangeMessageTypeEvent);
window.Store.Msg.on(&#x27;change:ack&#x27;, window.onMessageAckEvent);
window.Store.Msg.on(&#x27;remove&#x27;, window.onRemoveMessageEvent);
window.Store.AppState.on(&#x27;change:state&#x27;, window.onAppStateChangedEvent);
await page.exposeFunction(&#x27;onBatteryStateChangedEvent&#x27;, (state) &#x3D;&gt; {
const { battery, plugged } &#x3D; state;
/**
* Emitted when the battery percentage for the attached device changes
* @event Client#change_battery
* @param {object} batteryInfo
* @param {number} batteryInfo.battery - The current battery percentage
* @param {boolean} batteryInfo.plugged - Indicates if the phone is plugged in (true) or not (false)
*/
this.emit(Events.BATTERY_CHANGED, { battery, plugged });
});
this.pupBrowser &#x3D; browser;
this.pupPage &#x3D; page;
await page.evaluate(() &#x3D;&gt; {
window.Store.Msg.on(&#x27;add&#x27;, (msg) &#x3D;&gt; { if(msg.isNewMsg) window.onAddMessageEvent(msg); });
window.Store.Msg.on(&#x27;change&#x27;, (msg) &#x3D;&gt; { window.onChangeMessageEvent(msg); });
window.Store.Msg.on(&#x27;change:type&#x27;, (msg) &#x3D;&gt; { window.onChangeMessageTypeEvent(msg); });
window.Store.Msg.on(&#x27;change:ack&#x27;, (msg, ack) &#x3D;&gt; { window.onMessageAckEvent(msg, ack); });
window.Store.Msg.on(&#x27;change:isUnsentMedia&#x27;, (msg, unsent) &#x3D;&gt; { if(msg.id.fromMe &amp;amp;&amp;amp; !unsent) window.onMessageMediaUploadedEvent(msg); });
window.Store.Msg.on(&#x27;remove&#x27;, (msg) &#x3D;&gt; { if(msg.isNewMsg) window.onRemoveMessageEvent(msg); });
window.Store.AppState.on(&#x27;change:state&#x27;, (_AppState, state) &#x3D;&gt; { window.onAppStateChangedEvent(state); });
window.Store.Conn.on(&#x27;change:battery&#x27;, (state) &#x3D;&gt; { window.onBatteryStateChangedEvent(state); });
});
/**
* Emitted when the client has initialized and is ready to receive messages.
@@ -520,6 +554,54 @@ class Client extends EventEmitter {
});
}
/**
* Check if a given ID is registered in whatsapp
* @returns {Promise&amp;lt;Boolean&gt;}
*/
async isRegisteredUser(id) {
return await this.pupPage.evaluate(async (id) &#x3D;&gt; {
let result &#x3D; await window.Store.Wap.queryExist(id);
return result.jid !&#x3D;&#x3D; undefined;
}, id);
}
/**
* Create a new group
* @param {string} name group title
* @param {Array&amp;lt;Contact|string&gt;} participants an array of Contacts or contact IDs to add to the group
* @returns {Object} createRes
* @returns {string} createRes.gid - ID for the group that was just created
* @returns {Object.&amp;lt;string,string&gt;} createRes.missingParticipants - participants that were not added to the group. Keys represent the ID for participant that was not added and its value is a status code that represents the reason why participant could not be added. This is usually 403 if the user&#x27;s privacy settings don&#x27;t allow you to add them to groups.
*/
async createGroup(name, participants) {
if(!Array.isArray(participants) || participants.length &#x3D;&#x3D; 0) {
throw &#x27;You need to add at least one other participant to the group&#x27;;
}
if(participants.every(c &#x3D;&gt; c instanceof Contact)) {
participants &#x3D; participants.map(c &#x3D;&gt; c.id._serialized);
}
const createRes &#x3D; await this.pupPage.evaluate(async (name, participantIds) &#x3D;&gt; {
const res &#x3D; await window.Store.Wap.createGroup(name, participantIds);
console.log(res);
if(!res.status &#x3D;&#x3D;&#x3D; 200) {
throw &#x27;An error occurred while creating the group!&#x27;;
}
return res;
}, name, participants);
const missingParticipants &#x3D; createRes.participants.reduce(((missing, c) &#x3D;&gt; {
const id &#x3D; Object.keys(c)[0];
const statusCode &#x3D; c[id].code;
if(statusCode !&#x3D; 200) return Object.assign(missing, {[id]: statusCode});
return missing;
}), {});
return { gid: createRes.gid, missingParticipants};
}
}
module.exports &#x3D; Client;
@@ -533,7 +615,7 @@ module.exports &#x3D; Client;
<footer id="jsdoc-footer" class="jsdoc-footer">
<div id="jsdoc-footer-container">
<p>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on March 1, 2020.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on April 5, 2020.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.3">
<meta charset="utf-8">
<title>whatsapp-web.js 1.2.0 &raquo; Class: ClientInfo</title>
<title>whatsapp-web.js 1.4.0 &raquo; Class: ClientInfo</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
@@ -15,7 +15,7 @@
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>2.<wbr>0</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>4.<wbr>0</a>
</div>
</div>
</nav>
@@ -187,7 +187,7 @@
<footer id="jsdoc-footer" class="jsdoc-footer">
<div id="jsdoc-footer-container">
<p>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on March 1, 2020.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on April 5, 2020.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.3">
<meta charset="utf-8">
<title>whatsapp-web.js 1.2.0 &raquo; Class: Contact</title>
<title>whatsapp-web.js 1.4.0 &raquo; Class: Contact</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
@@ -15,7 +15,7 @@
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>2.<wbr>0</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>4.<wbr>0</a>
</div>
</div>
</nav>
@@ -196,7 +196,7 @@
<footer id="jsdoc-footer" class="jsdoc-footer">
<div id="jsdoc-footer-container">
<p>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on March 1, 2020.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on April 5, 2020.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.3">
<meta charset="utf-8">
<title>whatsapp-web.js 1.2.0 &raquo; Class: GroupChat</title>
<title>whatsapp-web.js 1.4.0 &raquo; Class: GroupChat</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
@@ -15,7 +15,7 @@
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>2.<wbr>0</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>4.<wbr>0</a>
</div>
</div>
</nav>
@@ -726,7 +726,7 @@
<footer id="jsdoc-footer" class="jsdoc-footer">
<div id="jsdoc-footer-container">
<p>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on March 1, 2020.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on April 5, 2020.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.3">
<meta charset="utf-8">
<title>whatsapp-web.js 1.2.0 &raquo; Class: GroupNotification</title>
<title>whatsapp-web.js 1.4.0 &raquo; Class: GroupNotification</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
@@ -15,7 +15,7 @@
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>2.<wbr>0</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>4.<wbr>0</a>
</div>
</div>
</nav>
@@ -233,7 +233,7 @@
<footer id="jsdoc-footer" class="jsdoc-footer">
<div id="jsdoc-footer-container">
<p>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on March 1, 2020.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on April 5, 2020.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.3">
<meta charset="utf-8">
<title>whatsapp-web.js 1.2.0 &raquo; Class: Location</title>
<title>whatsapp-web.js 1.4.0 &raquo; Class: Location</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
@@ -15,7 +15,7 @@
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>2.<wbr>0</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>4.<wbr>0</a>
</div>
</div>
</nav>
@@ -149,7 +149,7 @@
<footer id="jsdoc-footer" class="jsdoc-footer">
<div id="jsdoc-footer-container">
<p>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on March 1, 2020.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on April 5, 2020.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.3">
<meta charset="utf-8">
<title>whatsapp-web.js 1.2.0 &raquo; Class: Message</title>
<title>whatsapp-web.js 1.4.0 &raquo; Class: Message</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
@@ -15,7 +15,7 @@
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>2.<wbr>0</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>4.<wbr>0</a>
</div>
</div>
</nav>
@@ -39,6 +39,9 @@
<div class="summary-content">
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="Message.html#ack">ack</a></dt>
<dd>
</dd>
<dt><a href="Message.html#author">author</a></dt>
<dd>
</dd>
@@ -51,13 +54,13 @@
<dt><a href="Message.html#from">from</a></dt>
<dd>
</dd>
<dt><a href="Message.html#fromMe">fromMe</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="Message.html#fromMe">fromMe</a></dt>
<dd>
</dd>
<dt><a href="Message.html#hasMedia">hasMedia</a></dt>
<dd>
</dd>
@@ -70,13 +73,13 @@
<dt><a href="Message.html#isForwarded">isForwarded</a></dt>
<dd>
</dd>
<dt><a href="Message.html#location">location</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="Message.html#location">location</a></dt>
<dd>
</dd>
<dt><a href="Message.html#mentionedIds">mentionedIds</a></dt>
<dd>
</dd>
@@ -142,6 +145,11 @@
<section>
<h2>Properties</h2>
<section>
<h3 id="ack"><span class="symbol-name">ack</span><small class="property-type">
&nbsp;<a href="global.html#MessageAck">MessageAck</a></small></h3>
<p>ACK status for the message</p>
<dl class="dl-compact">
</dl>
<h3 id="author"><span class="symbol-name">author</span><small class="property-type">
&nbsp;string</small></h3>
<p>If the message was sent to a group, this field will contain the user that sent the message.</p>
@@ -371,7 +379,7 @@
<footer id="jsdoc-footer" class="jsdoc-footer">
<div id="jsdoc-footer-container">
<p>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on March 1, 2020.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on April 5, 2020.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.3">
<meta charset="utf-8">
<title>whatsapp-web.js 1.2.0 &raquo; Class: MessageMedia</title>
<title>whatsapp-web.js 1.4.0 &raquo; Class: MessageMedia</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
@@ -15,7 +15,7 @@
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>2.<wbr>0</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>4.<wbr>0</a>
</div>
</div>
</nav>
@@ -152,7 +152,7 @@
<footer id="jsdoc-footer" class="jsdoc-footer">
<div id="jsdoc-footer-container">
<p>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on March 1, 2020.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on April 5, 2020.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.3">
<meta charset="utf-8">
<title>whatsapp-web.js 1.2.0 &raquo; Class: PrivateChat</title>
<title>whatsapp-web.js 1.4.0 &raquo; Class: PrivateChat</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
@@ -15,7 +15,7 @@
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>2.<wbr>0</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>4.<wbr>0</a>
</div>
</div>
</nav>
@@ -378,7 +378,7 @@
<footer id="jsdoc-footer" class="jsdoc-footer">
<div id="jsdoc-footer-container">
<p>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on March 1, 2020.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on April 5, 2020.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.3">
<meta charset="utf-8">
<title>whatsapp-web.js 1.2.0 &raquo; Class: PrivateContact</title>
<title>whatsapp-web.js 1.4.0 &raquo; Class: PrivateContact</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
@@ -15,7 +15,7 @@
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>2.<wbr>0</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>4.<wbr>0</a>
</div>
</div>
</nav>
@@ -220,7 +220,7 @@
<footer id="jsdoc-footer" class="jsdoc-footer">
<div id="jsdoc-footer-container">
<p>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on March 1, 2020.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on April 5, 2020.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.3">
<meta charset="utf-8">
<title>whatsapp-web.js 1.2.0 &raquo; Class: Util</title>
<title>whatsapp-web.js 1.4.0 &raquo; Class: Util</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
@@ -15,7 +15,7 @@
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>2.<wbr>0</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>4.<wbr>0</a>
</div>
</div>
</nav>
@@ -50,7 +50,7 @@
<footer id="jsdoc-footer" class="jsdoc-footer">
<div id="jsdoc-footer-container">
<p>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on March 1, 2020.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on April 5, 2020.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.3">
<meta charset="utf-8">
<title>whatsapp-web.js 1.2.0 &raquo; Globals</title>
<title>whatsapp-web.js 1.4.0 &raquo; Globals</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
@@ -15,7 +15,7 @@
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>2.<wbr>0</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>4.<wbr>0</a>
</div>
</div>
</nav>
@@ -247,6 +247,19 @@
<td>
</td>
</tr>
<tr>
<td>
<p>MEDIA_UPLOADED</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>GROUP_JOIN</p>
@@ -325,6 +338,19 @@
<td>
</td>
</tr>
<tr>
<td>
<p>BATTERY_CHANGED</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
</tbody>
</table>
</section>
@@ -991,7 +1017,7 @@
<footer id="jsdoc-footer" class="jsdoc-footer">
<div id="jsdoc-footer-container">
<p>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on March 1, 2020.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on April 5, 2020.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.3">
<meta charset="utf-8">
<title>whatsapp-web.js 1.2.0 &raquo; Home</title>
<title>whatsapp-web.js 1.4.0 &raquo; Home</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
@@ -15,7 +15,7 @@
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>2.<wbr>0</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>4.<wbr>0</a>
</div>
</div>
</nav>
@@ -27,11 +27,11 @@
<div id="jsdoc-main" role="main">
<header class="page-header">
<h1>
whatsapp-web.js 1.2.0
whatsapp-web.js 1.4.0
</h1>
</header>
<article>
<p><a href="https://www.npmjs.com/package/whatsapp-web.js"><img src="https://img.shields.io/npm/v/whatsapp-web.js.svg" alt="npm"></a> <a href="https://depfu.com/github/pedroslopez/whatsapp-web.js?project_id=9765"><img src="https://badges.depfu.com/badges/4a65a0de96ece65fdf39e294e0c8dcba/overview.svg" alt="Depfu"></a> <img src="https://img.shields.io/badge/WhatsApp_Web-0.4.930-brightgreen.svg" alt="WhatsApp_Web 0.4.930"></p>
<p><a href="https://www.npmjs.com/package/whatsapp-web.js"><img src="https://img.shields.io/npm/v/whatsapp-web.js.svg" alt="npm"></a> <a href="https://depfu.com/github/pedroslopez/whatsapp-web.js?project_id=9765"><img src="https://badges.depfu.com/badges/4a65a0de96ece65fdf39e294e0c8dcba/overview.svg" alt="Depfu"></a> <img src="https://img.shields.io/badge/WhatsApp_Web-0.4.2088-brightgreen.svg" alt="WhatsApp_Web 0.4.2088"></p>
<h1>whatsapp-web.js</h1>
<p>A WhatsApp API client that connects through the WhatsApp Web browser app</p>
<p>It uses Puppeteer to run a real instance of Whatsapp Web to avoid getting blocked.</p>
@@ -84,7 +84,7 @@ client.initialize();
</tr>
<tr>
<td>Send media (video)</td>
<td>✅ (requires google chrome)</td>
<td><a href="https://github.com/pedroslopez/whatsapp-web.js/issues/78#issuecomment-592723583">(requires google chrome)</a></td>
</tr>
<tr>
<td>Send stickers</td>
@@ -155,11 +155,27 @@ client.initialize();
<p>Something missing? Make an issue and let us know!</p>
<h2>Links</h2>
<ul>
<li><a href="https://pedroslopez.me/whatsapp-web.js">Documentation</a> <em>(preview)</em></li>
<li><a href="https://pedroslopez.me/whatsapp-web.js">Reference</a></li>
<li><a href="https://waguide.pedroslopez.me/">Guide</a> <em>(work in progress)</em></li>
<li><a href="https://github.com/pedroslopez/whatsapp-web.js">GitHub</a></li>
</ul>
<h2>Contributing</h2>
<p>Pull requests are welcome! If you see something you'd like to add, please do. For drastic changes, please open an issue first.</p>
<h2>Donating</h2>
<p>You can support the maintainer of this project through the link below</p>
<p><a href="https://www.paypal.me/psla/"><img src="https://cdn.rawgit.com/twolfson/paypal-github-button/1.0.0/dist/button.svg" alt="Support via PayPal"></a></p>
<h2>Disclaimer</h2>
<p>This project is not affiliated, associated, authorized, endorsed by, or in any way officially connected with WhatsApp or any of its subsidiaries or its affiliates. The official WhatsApp website can be found at https://whatsapp.com. &quot;WhatsApp&quot; as well as related names, marks, emblems and images are registered trademarks of their respective owners.</p>
<h2>License</h2>
<p>Copyright 2019 Pedro S Lopez</p>
<p>Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
you may not use this project except in compliance with the License.
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.</p>
<p>Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.</p>
</article>
<div class="symbol-index">
<section>
@@ -444,6 +460,11 @@ client.initialize();
</dt>
<dd>
</dd>
<dt class="symbol-index-name">
<a href="Client.html#createGroup" class="!symbol-index-name">Client#<wbr>createGroup(name, participants)</a>
</dt>
<dd>
</dd>
<dt class="symbol-index-name">
<a href="Client.html#destroy" class="!symbol-index-name">Client#<wbr>destroy()</a>
</dt>
@@ -459,6 +480,11 @@ client.initialize();
</dt>
<dd>
</dd>
<dt class="symbol-index-name">
<a href="Client.html#event:change_battery" class="!symbol-index-name">Client#<wbr>event:change_battery</a>
</dt>
<dd>
</dd>
<dt class="symbol-index-name">
<a href="Client.html#event:change_state" class="!symbol-index-name">Client#<wbr>event:change_state</a>
</dt>
@@ -474,20 +500,25 @@ client.initialize();
</dt>
<dd>
</dd>
<dt class="symbol-index-name">
<a href="Client.html#event:group_leave" class="!symbol-index-name">Client#<wbr>event:group_leave</a>
</dt>
<dd>
</dd>
</dl>
</div>
<div class="symbol-index-column">
<dl class="symbol-index-list">
<dt class="symbol-index-name">
<a href="Client.html#event:group_leave" class="!symbol-index-name">Client#<wbr>event:group_leave</a>
</dt>
<dd>
</dd>
<dt class="symbol-index-name">
<a href="Client.html#event:group_update" class="!symbol-index-name">Client#<wbr>event:group_update</a>
</dt>
<dd>
</dd>
<dt class="symbol-index-name">
<a href="Client.html#event:media_uploaded" class="!symbol-index-name">Client#<wbr>event:media_uploaded</a>
</dt>
<dd>
</dd>
<dt class="symbol-index-name">
<a href="Client.html#event:message" class="!symbol-index-name">Client#<wbr>event:message</a>
</dt>
@@ -528,15 +559,15 @@ client.initialize();
</dt>
<dd>
</dd>
</dl>
</div>
<div class="symbol-index-column">
<dl class="symbol-index-list">
<dt class="symbol-index-name">
<a href="Client.html#getChats" class="!symbol-index-name">Client#<wbr>getChats()</a>
</dt>
<dd>
</dd>
</dl>
</div>
<div class="symbol-index-column">
<dl class="symbol-index-list">
<dt class="symbol-index-name">
<a href="Client.html#getContactById" class="!symbol-index-name">Client#<wbr>getContactById(contactId)</a>
</dt>
@@ -557,6 +588,11 @@ client.initialize();
</dt>
<dd>
</dd>
<dt class="symbol-index-name">
<a href="Client.html#isRegisteredUser" class="!symbol-index-name">Client#<wbr>isRegisteredUser()</a>
</dt>
<dd>
</dd>
<dt class="symbol-index-name">
<a href="Client.html#resetState" class="!symbol-index-name">Client#<wbr>resetState()</a>
</dt>
@@ -736,6 +772,11 @@ client.initialize();
</dt>
<dd>
</dd>
<dt class="symbol-index-name">
<a href="global.html#Events#.BATTERY_CHANGED" class="!symbol-index-name">Events.<wbr>BATTERY_CHANGED</a>
</dt>
<dd>
</dd>
<dt class="symbol-index-name">
<a href="global.html#Events#.DISCONNECTED" class="!symbol-index-name">Events.<wbr>DISCONNECTED</a>
</dt>
@@ -760,6 +801,11 @@ client.initialize();
</dt>
<dd>
</dd>
<dt class="symbol-index-name">
<a href="global.html#Events#.MEDIA_UPLOADED" class="!symbol-index-name">Events.<wbr>MEDIA_UPLOADED</a>
</dt>
<dd>
</dd>
<dt class="symbol-index-name">
<a href="global.html#Events#.MESSAGE_ACK" class="!symbol-index-name">Events.<wbr>MESSAGE_ACK</a>
</dt>
@@ -1186,6 +1232,11 @@ client.initialize();
</dt>
<dd>
</dd>
<dt class="symbol-index-name">
<a href="Message.html#ack" class="!symbol-index-name">Message#<wbr>ack</a>
</dt>
<dd>
</dd>
<dt class="symbol-index-name">
<a href="Message.html#author" class="!symbol-index-name">Message#<wbr>author</a>
</dt>
@@ -1216,15 +1267,15 @@ client.initialize();
</dt>
<dd>
</dd>
</dl>
</div>
<div class="symbol-index-column">
<dl class="symbol-index-list">
<dt class="symbol-index-name">
<a href="Message.html#fromMe" class="!symbol-index-name">Message#<wbr>fromMe</a>
</dt>
<dd>
</dd>
</dl>
</div>
<div class="symbol-index-column">
<dl class="symbol-index-list">
<dt class="symbol-index-name">
<a href="Message.html#getChat" class="!symbol-index-name">Message#<wbr>getChat()</a>
</dt>
@@ -1260,15 +1311,15 @@ client.initialize();
</dt>
<dd>
</dd>
</dl>
</div>
<div class="symbol-index-column">
<dl class="symbol-index-list">
<dt class="symbol-index-name">
<a href="Message.html#isForwarded" class="!symbol-index-name">Message#<wbr>isForwarded</a>
</dt>
<dd>
</dd>
</dl>
</div>
<div class="symbol-index-column">
<dl class="symbol-index-list">
<dt class="symbol-index-name">
<a href="Message.html#location" class="!symbol-index-name">Message#<wbr>location</a>
</dt>
@@ -1815,7 +1866,7 @@ client.initialize();
<footer id="jsdoc-footer" class="jsdoc-footer">
<div id="jsdoc-footer-container">
<p>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on March 1, 2020.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on April 5, 2020.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.3">
<meta charset="utf-8">
<title>whatsapp-web.js 1.2.0 &raquo; Source: structures/Base.js</title>
<title>whatsapp-web.js 1.4.0 &raquo; Source: structures/Base.js</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
@@ -15,7 +15,7 @@
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>2.<wbr>0</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>4.<wbr>0</a>
</div>
</div>
</nav>
@@ -60,7 +60,7 @@ module.exports &#x3D; Base;</code></pre>
<footer id="jsdoc-footer" class="jsdoc-footer">
<div id="jsdoc-footer-container">
<p>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on March 1, 2020.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on April 5, 2020.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.3">
<meta charset="utf-8">
<title>whatsapp-web.js 1.2.0 &raquo; Source: structures/BusinessContact.js</title>
<title>whatsapp-web.js 1.4.0 &raquo; Source: structures/BusinessContact.js</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
@@ -15,7 +15,7 @@
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>2.<wbr>0</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>4.<wbr>0</a>
</div>
</div>
</nav>
@@ -59,7 +59,7 @@ module.exports &#x3D; BusinessContact;</code></pre>
<footer id="jsdoc-footer" class="jsdoc-footer">
<div id="jsdoc-footer-container">
<p>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on March 1, 2020.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on April 5, 2020.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.3">
<meta charset="utf-8">
<title>whatsapp-web.js 1.2.0 &raquo; Source: structures/Chat.js</title>
<title>whatsapp-web.js 1.4.0 &raquo; Source: structures/Chat.js</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
@@ -15,7 +15,7 @@
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>2.<wbr>0</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>4.<wbr>0</a>
</div>
</div>
</nav>
@@ -162,14 +162,14 @@ class Chat extends Base {
while(msgs.length &amp;lt; limit) {
const loadedMessages &#x3D; await chat.loadEarlierMsgs();
if(!loadedMessages) break;
msgs &#x3D; [...msgs, ...loadedMessages.filter(msgFilter)];
msgs &#x3D; [...loadedMessages.filter(msgFilter), ...msgs];
}
return msgs.splice(0, limit).map(m &#x3D;&gt; m.serialize());
msgs.sort((a, b) &#x3D;&gt; (a.t &gt; b.t) ? 1 : -1);
return msgs.splice(msgs.length - limit).map(m &#x3D;&gt; m.serialize());
}, this.id._serialized, searchOptions.limit);
messages.sort((a, b) &#x3D;&gt; (a.t &gt; b.t) ? 1 : -1);
return messages.map(m &#x3D;&gt; new Message(this.client, m));
}
@@ -215,7 +215,7 @@ module.exports &#x3D; Chat;
<footer id="jsdoc-footer" class="jsdoc-footer">
<div id="jsdoc-footer-container">
<p>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on March 1, 2020.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on April 5, 2020.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.3">
<meta charset="utf-8">
<title>whatsapp-web.js 1.2.0 &raquo; Source: structures/ClientInfo.js</title>
<title>whatsapp-web.js 1.4.0 &raquo; Source: structures/ClientInfo.js</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
@@ -15,7 +15,7 @@
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>2.<wbr>0</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>4.<wbr>0</a>
</div>
</div>
</nav>
@@ -89,7 +89,7 @@ module.exports &#x3D; ClientInfo;</code></pre>
<footer id="jsdoc-footer" class="jsdoc-footer">
<div id="jsdoc-footer-container">
<p>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on March 1, 2020.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on April 5, 2020.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.3">
<meta charset="utf-8">
<title>whatsapp-web.js 1.2.0 &raquo; Source: structures/Contact.js</title>
<title>whatsapp-web.js 1.4.0 &raquo; Source: structures/Contact.js</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
@@ -15,7 +15,7 @@
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>2.<wbr>0</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>4.<wbr>0</a>
</div>
</div>
</nav>
@@ -153,7 +153,7 @@ module.exports &#x3D; Contact;</code></pre>
<footer id="jsdoc-footer" class="jsdoc-footer">
<div id="jsdoc-footer-container">
<p>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on March 1, 2020.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on April 5, 2020.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.3">
<meta charset="utf-8">
<title>whatsapp-web.js 1.2.0 &raquo; Source: structures/GroupChat.js</title>
<title>whatsapp-web.js 1.4.0 &raquo; Source: structures/GroupChat.js</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
@@ -15,7 +15,7 @@
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>2.<wbr>0</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>4.<wbr>0</a>
</div>
</div>
</nav>
@@ -209,7 +209,7 @@ module.exports &#x3D; GroupChat;</code></pre>
<footer id="jsdoc-footer" class="jsdoc-footer">
<div id="jsdoc-footer-container">
<p>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on March 1, 2020.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on April 5, 2020.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.3">
<meta charset="utf-8">
<title>whatsapp-web.js 1.2.0 &raquo; Source: structures/GroupNotification.js</title>
<title>whatsapp-web.js 1.4.0 &raquo; Source: structures/GroupNotification.js</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
@@ -15,7 +15,7 @@
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>2.<wbr>0</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>4.<wbr>0</a>
</div>
</div>
</nav>
@@ -74,7 +74,7 @@ class GroupNotification extends Base {
*
* @type {string}
*/
this.chatId &#x3D; typeof (data.to) &#x3D;&#x3D;&#x3D; &#x27;object&#x27; ? data.to._serialized : data.to;
this.chatId &#x3D; typeof (data.from) &#x3D;&#x3D;&#x3D; &#x27;object&#x27; ? data.from._serialized : data.from;
/**
* ContactId for the user that produced the GroupNotification.
@@ -143,7 +143,7 @@ module.exports &#x3D; GroupNotification;
<footer id="jsdoc-footer" class="jsdoc-footer">
<div id="jsdoc-footer-container">
<p>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on March 1, 2020.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on April 5, 2020.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.3">
<meta charset="utf-8">
<title>whatsapp-web.js 1.2.0 &raquo; Source: structures/Location.js</title>
<title>whatsapp-web.js 1.4.0 &raquo; Source: structures/Location.js</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
@@ -15,7 +15,7 @@
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>2.<wbr>0</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>4.<wbr>0</a>
</div>
</div>
</nav>
@@ -71,7 +71,7 @@ module.exports &#x3D; Location;</code></pre>
<footer id="jsdoc-footer" class="jsdoc-footer">
<div id="jsdoc-footer-container">
<p>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on March 1, 2020.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on April 5, 2020.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.3">
<meta charset="utf-8">
<title>whatsapp-web.js 1.2.0 &raquo; Source: structures/Message.js</title>
<title>whatsapp-web.js 1.4.0 &raquo; Source: structures/Message.js</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
@@ -15,7 +15,7 @@
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>2.<wbr>0</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>4.<wbr>0</a>
</div>
</div>
</nav>
@@ -54,6 +54,12 @@ class Message extends Base {
*/
this.id &#x3D; data.id;
/**
* ACK status for the message
* @type {MessageAck}
*/
this.ack &#x3D; data.ack;
/**
* Indicates if the message has media available for download
* @type {boolean}
@@ -217,8 +223,19 @@ class Message extends Base {
return undefined;
}
const {data, mimetype, filename} &#x3D; await this.client.pupPage.evaluate(async (msgId) &#x3D;&gt; {
const result &#x3D; await this.client.pupPage.evaluate(async (msgId) &#x3D;&gt; {
const msg &#x3D; window.Store.Msg.get(msgId);
if(msg.mediaData.mediaStage !&#x3D; &#x27;RESOLVED&#x27;) {
// try to resolve media
await msg.downloadMedia(true, 1);
}
if(msg.mediaData.mediaStage.includes(&#x27;ERROR&#x27;)) {
// media could not be downloaded
return undefined;
}
const buffer &#x3D; await window.WWebJS.downloadBuffer(msg.clientUrl);
const decrypted &#x3D; await window.Store.CryptoLib.decryptE2EMedia(msg.type, buffer, msg.mediaKey, msg.mimetype);
const data &#x3D; await window.WWebJS.readBlobAsync(decrypted._blob);
@@ -231,7 +248,8 @@ class Message extends Base {
}, this.id._serialized);
return new MessageMedia(mimetype, data, filename);
if(!result) return undefined;
return new MessageMedia(result.mimetype, result.data, result.filename);
}
/**
@@ -262,7 +280,7 @@ module.exports &#x3D; Message;
<footer id="jsdoc-footer" class="jsdoc-footer">
<div id="jsdoc-footer-container">
<p>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on March 1, 2020.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on April 5, 2020.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.3">
<meta charset="utf-8">
<title>whatsapp-web.js 1.2.0 &raquo; Source: structures/MessageMedia.js</title>
<title>whatsapp-web.js 1.4.0 &raquo; Source: structures/MessageMedia.js</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
@@ -15,7 +15,7 @@
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>2.<wbr>0</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>4.<wbr>0</a>
</div>
</div>
</nav>
@@ -69,7 +69,7 @@ module.exports &#x3D; MessageMedia;</code></pre>
<footer id="jsdoc-footer" class="jsdoc-footer">
<div id="jsdoc-footer-container">
<p>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on March 1, 2020.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on April 5, 2020.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.3">
<meta charset="utf-8">
<title>whatsapp-web.js 1.2.0 &raquo; Source: structures/PrivateChat.js</title>
<title>whatsapp-web.js 1.4.0 &raquo; Source: structures/PrivateChat.js</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
@@ -15,7 +15,7 @@
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>2.<wbr>0</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>4.<wbr>0</a>
</div>
</div>
</nav>
@@ -51,7 +51,7 @@ module.exports &#x3D; PrivateChat;</code></pre>
<footer id="jsdoc-footer" class="jsdoc-footer">
<div id="jsdoc-footer-container">
<p>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on March 1, 2020.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on April 5, 2020.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.3">
<meta charset="utf-8">
<title>whatsapp-web.js 1.2.0 &raquo; Source: structures/PrivateContact.js</title>
<title>whatsapp-web.js 1.4.0 &raquo; Source: structures/PrivateContact.js</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
@@ -15,7 +15,7 @@
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>2.<wbr>0</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>4.<wbr>0</a>
</div>
</div>
</nav>
@@ -51,7 +51,7 @@ module.exports &#x3D; PrivateContact;</code></pre>
<footer id="jsdoc-footer" class="jsdoc-footer">
<div id="jsdoc-footer-container">
<p>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on March 1, 2020.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on April 5, 2020.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.3">
<meta charset="utf-8">
<title>whatsapp-web.js 1.2.0 &raquo; Source: util/Constants.js</title>
<title>whatsapp-web.js 1.4.0 &raquo; Source: util/Constants.js</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
@@ -15,7 +15,7 @@
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>2.<wbr>0</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>4.<wbr>0</a>
</div>
</div>
</nav>
@@ -39,7 +39,10 @@ exports.DefaultOptions &#x3D; {
puppeteer: {
headless: true
},
session: false
session: false,
qrTimeoutMs: 45000,
qrRefreshIntervalMs: 20000,
authTimeoutMs: 45000,
};
/**
@@ -67,12 +70,14 @@ exports.Events &#x3D; {
MESSAGE_REVOKED_EVERYONE: &#x27;message_revoke_everyone&#x27;,
MESSAGE_REVOKED_ME: &#x27;message_revoke_me&#x27;,
MESSAGE_ACK: &#x27;message_ack&#x27;,
MEDIA_UPLOADED: &#x27;media_uploaded&#x27;,
GROUP_JOIN: &#x27;group_join&#x27;,
GROUP_LEAVE: &#x27;group_leave&#x27;,
GROUP_UPDATE: &#x27;group_update&#x27;,
QR_RECEIVED: &#x27;qr&#x27;,
DISCONNECTED: &#x27;disconnected&#x27;,
STATE_CHANGED: &#x27;change_state&#x27;,
BATTERY_CHANGED: &#x27;change_battery&#x27;
};
/**
@@ -166,7 +171,7 @@ exports.MessageAck &#x3D; {
<footer id="jsdoc-footer" class="jsdoc-footer">
<div id="jsdoc-footer-container">
<p>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on March 1, 2020.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on April 5, 2020.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.3">
<meta charset="utf-8">
<title>whatsapp-web.js 1.2.0 &raquo; Source: util/Util.js</title>
<title>whatsapp-web.js 1.4.0 &raquo; Source: util/Util.js</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
@@ -15,7 +15,7 @@
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>2.<wbr>0</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>4.<wbr>0</a>
</div>
</div>
</nav>
@@ -73,7 +73,7 @@ module.exports &#x3D; Util;</code></pre>
<footer id="jsdoc-footer" class="jsdoc-footer">
<div id="jsdoc-footer-container">
<p>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on March 1, 2020.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.3 on April 5, 2020.
</p>
</div>
</footer>

View File

@@ -237,6 +237,12 @@ client.on('group_update', (notification) => {
console.log('update', notification);
});
client.on('change_battery', (batteryInfo) => {
// Battery percentage for attached device has changed
const { battery, plugged } = batteryInfo;
console.log(`Battery: ${battery}% - Charging? ${plugged}`);
});
client.on('disconnected', (reason) => {
console.log('Client was logged out', reason);
});

17
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{
"name": "whatsapp-web.js",
"version": "1.0.2-post",
"version": "1.2.4-post",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@@ -30,6 +30,11 @@
"integrity": "sha512-0fKu/QqildpXmPVaRBoXOlyBb3MC+J0A66x97qEfLOMkn3u6nfY5esWogQwi/K0BjASYy4DbnsEWnpNL6qT5Mw==",
"dev": true
},
"@pedroslopez/moduleraid": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/@pedroslopez/moduleraid/-/moduleraid-4.1.0.tgz",
"integrity": "sha512-+2OYf1IDLhZlOY3QEwGfZJKfM/uPB3lw9zedl3eqEMtod73r1R7TUnmlh8S7hM8uLUcrWXMnJ9TrMbxXeV1pZg=="
},
"@types/mime-types": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/@types/mime-types/-/mime-types-2.1.0.tgz",
@@ -42,9 +47,9 @@
"dev": true
},
"acorn": {
"version": "7.1.0",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.0.tgz",
"integrity": "sha512-kL5CuoXA/dgxlBbVrflsflzQ3PAas7RYZB52NOm/6839iVYJgKMJ3cQJD+t2i5+qFa8h3MDpEOJiS64E8JLnSQ==",
"version": "7.1.1",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.1.tgz",
"integrity": "sha512-add7dgA5ppRPxCFJoAGfMDi7PIBXq1RtGo7BhbLaxwrXPOmw8gq48Y9ozT01hUKy9byMjlR20EJhu5zlkErEkg==",
"dev": true
},
"acorn-jsx": {
@@ -1016,10 +1021,6 @@
"minimist": "0.0.8"
}
},
"moduleraid": {
"version": "git+https://github.com/pixeldesu/moduleRaid.git#113b90ec709f5d4601db8d5e96b1155aa772ae97",
"from": "git+https://github.com/pixeldesu/moduleRaid.git"
},
"ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",

View File

@@ -1,6 +1,6 @@
{
"name": "whatsapp-web.js",
"version": "1.2.0",
"version": "1.4.0",
"description": "Library for interacting with the WhatsApp Web API ",
"main": "./index.js",
"scripts": {
@@ -26,8 +26,8 @@
},
"homepage": "https://github.com/pedroslopez/whatsapp-web.js#readme",
"dependencies": {
"@pedroslopez/moduleraid": "^4.1.0",
"jsqr": "^1.2.0",
"moduleraid": "git+https://github.com/pixeldesu/moduleRaid.git",
"puppeteer": "^2.1.1"
},
"devDependencies": {

View File

@@ -2,7 +2,7 @@
const EventEmitter = require('events');
const puppeteer = require('puppeteer');
const moduleRaid = require('moduleraid/moduleraid');
const moduleRaid = require('@pedroslopez/moduleraid/moduleraid');
const jsQR = require('jsqr');
const Util = require('./util/Util');
@@ -10,7 +10,7 @@ const { WhatsWebURL, UserAgent, DefaultOptions, Events, WAState } = require('./u
const { ExposeStore, LoadUtils } = require('./util/Injected');
const ChatFactory = require('./factories/ChatFactory');
const ContactFactory = require('./factories/ContactFactory');
const { ClientInfo, Message, MessageMedia, Location, GroupNotification } = require('./structures');
const { ClientInfo, Message, MessageMedia, Contact, Location, GroupNotification } = require('./structures');
/**
* Starting point for interacting with the WhatsApp Web API
* @extends {EventEmitter}
@@ -23,11 +23,13 @@ const { ClientInfo, Message, MessageMedia, Location, GroupNotification } = requi
* @fires Client#message_create
* @fires Client#message_revoke_me
* @fires Client#message_revoke_everyone
* @fires Client#media_uploaded
* @fires Client#group_join
* @fires Client#group_leave
* @fires Client#group_update
* @fires Client#disconnected
* @fires Client#change_state
* @fires Client#change_battery
*/
class Client extends EventEmitter {
constructor(options = {}) {
@@ -47,6 +49,9 @@ class Client extends EventEmitter {
const page = (await browser.pages())[0];
page.setUserAgent(UserAgent);
this.pupBrowser = browser;
this.pupPage = page;
if (this.options.session) {
await page.evaluateOnNewDocument(
session => {
@@ -65,7 +70,7 @@ class Client extends EventEmitter {
if (this.options.session) {
// Check if session restore was successfull
try {
await page.waitForSelector(KEEP_PHONE_CONNECTED_IMG_SELECTOR, { timeout: 15000 });
await page.waitForSelector(KEEP_PHONE_CONNECTED_IMG_SELECTOR, { timeout: this.options.authTimeoutMs });
} catch (err) {
if (err.name === 'TimeoutError') {
/**
@@ -75,7 +80,11 @@ class Client extends EventEmitter {
*/
this.emit(Events.AUTHENTICATION_FAILURE, 'Unable to log in. Are the session details valid?');
browser.close();
if (this.options.restartOnAuthFail) {
// session restore failed so try again but without session to force new authentication
this.options.session = null;
this.initialize();
}
return;
}
@@ -94,7 +103,7 @@ class Client extends EventEmitter {
// Wait for QR Code
const QR_CANVAS_SELECTOR = 'canvas';
await page.waitForSelector(QR_CANVAS_SELECTOR);
await page.waitForSelector(QR_CANVAS_SELECTOR, { timeout: this.options.qrTimeoutMs });
const qrImgData = await page.$eval(QR_CANVAS_SELECTOR, canvas => [].slice.call(canvas.getContext('2d').getImageData(0, 0, 264, 264).data));
const qr = jsQR(qrImgData, 264, 264).data;
/**
@@ -105,7 +114,7 @@ class Client extends EventEmitter {
this.emit(Events.QR_RECEIVED, qr);
};
getQrCode();
let retryInterval = setInterval(getQrCode, 20000); // check for qr code every 20 seconds
let retryInterval = setInterval(getQrCode, this.options.qrRefreshIntervalMs);
// Wait for code scan
await page.waitForSelector(KEEP_PHONE_CONNECTED_IMG_SELECTOR, { timeout: 0 });
@@ -255,7 +264,19 @@ class Client extends EventEmitter {
});
await page.exposeFunction('onAppStateChangedEvent', (_AppState, state) => {
await page.exposeFunction('onMessageMediaUploadedEvent', (msg) => {
const message = new Message(this, msg);
/**
* Emitted when media has been uploaded for a message sent by the client.
* @event Client#media_uploaded
* @param {Message} message The message with media that was uploaded
*/
this.emit(Events.MEDIA_UPLOADED, message);
});
await page.exposeFunction('onAppStateChangedEvent', (state) => {
/**
* Emitted when the connection state changes
@@ -276,17 +297,30 @@ class Client extends EventEmitter {
}
});
await page.evaluate(() => {
window.Store.Msg.on('add', window.onAddMessageEvent);
window.Store.Msg.on('change', window.onChangeMessageEvent);
window.Store.Msg.on('change:type', window.onChangeMessageTypeEvent);
window.Store.Msg.on('change:ack', window.onMessageAckEvent);
window.Store.Msg.on('remove', window.onRemoveMessageEvent);
window.Store.AppState.on('change:state', window.onAppStateChangedEvent);
await page.exposeFunction('onBatteryStateChangedEvent', (state) => {
const { battery, plugged } = state;
/**
* Emitted when the battery percentage for the attached device changes
* @event Client#change_battery
* @param {object} batteryInfo
* @param {number} batteryInfo.battery - The current battery percentage
* @param {boolean} batteryInfo.plugged - Indicates if the phone is plugged in (true) or not (false)
*/
this.emit(Events.BATTERY_CHANGED, { battery, plugged });
});
this.pupBrowser = browser;
this.pupPage = page;
await page.evaluate(() => {
window.Store.Msg.on('add', (msg) => { if(msg.isNewMsg) window.onAddMessageEvent(msg); });
window.Store.Msg.on('change', (msg) => { window.onChangeMessageEvent(msg); });
window.Store.Msg.on('change:type', (msg) => { window.onChangeMessageTypeEvent(msg); });
window.Store.Msg.on('change:ack', (msg, ack) => { window.onMessageAckEvent(msg, ack); });
window.Store.Msg.on('change:isUnsentMedia', (msg, unsent) => { if(msg.id.fromMe && !unsent) window.onMessageMediaUploadedEvent(msg); });
window.Store.Msg.on('remove', (msg) => { if(msg.isNewMsg) window.onRemoveMessageEvent(msg); });
window.Store.AppState.on('change:state', (_AppState, state) => { window.onAppStateChangedEvent(state); });
window.Store.Conn.on('change:battery', (state) => { window.onBatteryStateChangedEvent(state); });
});
/**
* Emitted when the client has initialized and is ready to receive messages.
@@ -489,6 +523,54 @@ class Client extends EventEmitter {
});
}
/**
* Check if a given ID is registered in whatsapp
* @returns {Promise<Boolean>}
*/
async isRegisteredUser(id) {
return await this.pupPage.evaluate(async (id) => {
let result = await window.Store.Wap.queryExist(id);
return result.jid !== undefined;
}, id);
}
/**
* Create a new group
* @param {string} name group title
* @param {Array<Contact|string>} participants an array of Contacts or contact IDs to add to the group
* @returns {Object} createRes
* @returns {string} createRes.gid - ID for the group that was just created
* @returns {Object.<string,string>} createRes.missingParticipants - participants that were not added to the group. Keys represent the ID for participant that was not added and its value is a status code that represents the reason why participant could not be added. This is usually 403 if the user's privacy settings don't allow you to add them to groups.
*/
async createGroup(name, participants) {
if(!Array.isArray(participants) || participants.length == 0) {
throw 'You need to add at least one other participant to the group';
}
if(participants.every(c => c instanceof Contact)) {
participants = participants.map(c => c.id._serialized);
}
const createRes = await this.pupPage.evaluate(async (name, participantIds) => {
const res = await window.Store.Wap.createGroup(name, participantIds);
console.log(res);
if(!res.status === 200) {
throw 'An error occurred while creating the group!';
}
return res;
}, name, participants);
const missingParticipants = createRes.participants.reduce(((missing, c) => {
const id = Object.keys(c)[0];
const statusCode = c[id].code;
if(statusCode != 200) return Object.assign(missing, {[id]: statusCode});
return missing;
}), {});
return { gid: createRes.gid, missingParticipants};
}
}
module.exports = Client;

View File

@@ -131,14 +131,14 @@ class Chat extends Base {
while(msgs.length < limit) {
const loadedMessages = await chat.loadEarlierMsgs();
if(!loadedMessages) break;
msgs = [...msgs, ...loadedMessages.filter(msgFilter)];
msgs = [...loadedMessages.filter(msgFilter), ...msgs];
}
return msgs.splice(0, limit).map(m => m.serialize());
msgs.sort((a, b) => (a.t > b.t) ? 1 : -1);
return msgs.splice(msgs.length - limit).map(m => m.serialize());
}, this.id._serialized, searchOptions.limit);
messages.sort((a, b) => (a.t > b.t) ? 1 : -1);
return messages.map(m => new Message(this.client, m));
}

View File

@@ -43,7 +43,7 @@ class GroupNotification extends Base {
*
* @type {string}
*/
this.chatId = typeof (data.to) === 'object' ? data.to._serialized : data.to;
this.chatId = typeof (data.from) === 'object' ? data.from._serialized : data.from;
/**
* ContactId for the user that produced the GroupNotification.

View File

@@ -23,6 +23,12 @@ class Message extends Base {
*/
this.id = data.id;
/**
* ACK status for the message
* @type {MessageAck}
*/
this.ack = data.ack;
/**
* Indicates if the message has media available for download
* @type {boolean}
@@ -186,8 +192,19 @@ class Message extends Base {
return undefined;
}
const {data, mimetype, filename} = await this.client.pupPage.evaluate(async (msgId) => {
const result = await this.client.pupPage.evaluate(async (msgId) => {
const msg = window.Store.Msg.get(msgId);
if(msg.mediaData.mediaStage != 'RESOLVED') {
// try to resolve media
await msg.downloadMedia(true, 1);
}
if(msg.mediaData.mediaStage.includes('ERROR')) {
// media could not be downloaded
return undefined;
}
const buffer = await window.WWebJS.downloadBuffer(msg.clientUrl);
const decrypted = await window.Store.CryptoLib.decryptE2EMedia(msg.type, buffer, msg.mediaKey, msg.mimetype);
const data = await window.WWebJS.readBlobAsync(decrypted._blob);
@@ -200,7 +217,8 @@ class Message extends Base {
}, this.id._serialized);
return new MessageMedia(mimetype, data, filename);
if(!result) return undefined;
return new MessageMedia(result.mimetype, result.data, result.filename);
}
/**

View File

@@ -10,4 +10,5 @@ module.exports = {
MessageMedia: require('./MessageMedia'),
PrivateChat: require('./PrivateChat'),
PrivateContact: require('./PrivateContact'),
GroupNotification: require('./GroupNotification')
};

View File

@@ -8,7 +8,10 @@ exports.DefaultOptions = {
puppeteer: {
headless: true
},
session: false
session: false,
qrTimeoutMs: 45000,
qrRefreshIntervalMs: 20000,
authTimeoutMs: 45000,
};
/**
@@ -36,12 +39,14 @@ exports.Events = {
MESSAGE_REVOKED_EVERYONE: 'message_revoke_everyone',
MESSAGE_REVOKED_ME: 'message_revoke_me',
MESSAGE_ACK: 'message_ack',
MEDIA_UPLOADED: 'media_uploaded',
GROUP_JOIN: 'group_join',
GROUP_LEAVE: 'group_leave',
GROUP_UPDATE: 'group_update',
QR_RECEIVED: 'qr',
DISCONNECTED: 'disconnected',
STATE_CHANGED: 'change_state',
BATTERY_CHANGED: 'change_battery'
};
/**