Compare commits

...

147 Commits

Author SHA1 Message Date
Pedro Lopez
2e4890d113 chore: mark version v1.16.4 2022-03-09 18:26:05 -04:00
Pedro Lopez
0bd8eb9d96 chore: mark version v1.16.4-alpha.0 2022-03-09 00:57:36 -04:00
Pedro S. Lopez
2718c1328c fix compatibility issues with WhatsApp Web 2.2208.7 (#1311)
* fix compatiblity issues with v2.2208.7

* remove expclusive test
2022-03-09 00:54:57 -04:00
Pedro Lopez
24f8b4622b chore: mark version v1.16.3 2022-03-06 23:30:20 -04:00
Pedro Lopez
9ab9c48f7b fix(typings): LegacySessionAuth restartOnAuthFail 2022-03-06 01:35:58 -04:00
༺ LᴇG̸ᴇɴD ༻
b96607338a getProfilePicture Fix => Evaluation failed: Error: Comms::sendIq called before startComms (#1264)
* Fix: Evaluation failed: Error: Comms::sendIq called before startComms

* [Requested Changes] - Only call Wap if we're not on MD & vice-versa

Co-authored-by: Joaquin Touris <joaquin@192.168.1.5>
2022-03-05 16:24:40 +02:00
Pedro S. Lopez
ea2cc81d47 add feature request form template 2022-03-05 02:30:49 -04:00
Clifford Fajardo
56644f4f03 add github ISSUE_TEMPLATE files (#1195)
* add github ISSUE_TEMPLATE files

* Update .github/ISSUE_TEMPLATE/config.yml

* Update .github/ISSUE_TEMPLATE/bug_report.yml

Co-authored-by: Rajeh Taher <rajeh@reforward.dev>

* apply updates per feedback that was given

* Update bug_report.yml

* Update bug_report.yml

* Update bug_report.yml

* Update bug_report.yml

* Update bug_report.yml

* Update bug_report.yml

Co-authored-by: clifford <cfajardo@linkedin.com>
Co-authored-by: Rajeh Taher <rajeh@reforward.dev>
Co-authored-by: Pedro S. Lopez <pedroslopez@me.com>
2022-03-05 02:26:49 -04:00
Pedro Lopez
fcb78a1cd4 chore: mark version v1.16.2 2022-03-01 23:23:26 -04:00
Fábio Dias
f88bd274be fix(LocalAuth): logout method (#1267)
The logout method was trying to use a function call passing the "dataDir" as the "this" reference
2022-03-01 23:15:08 -04:00
Alon Schwartzblat
c45fae5c15 Fix get order. (#1274)
* Fix get order.

* Fix types.
2022-03-01 23:08:27 -04:00
Pedro Lopez
1b75d0d243 fix(LocalAuth): only throw user-supplied userDataDir error if path is different
fix #1261
2022-03-01 22:25:22 -04:00
Filipe
cc78e9863d add typings for LocalAuth attributes (#1262) 2022-02-28 23:00:21 -04:00
inceabdullah
fc205ff530 fix: Cannot destructure property 'session' of 'undefined' as it is undefined. (#1259) 2022-02-28 22:59:54 -04:00
Pedro Lopez
6ab98a5365 chore: mark version v1.16.1 2022-02-28 00:51:59 -04:00
Pedro Lopez
3c24df085a add back deprecated info.me 2022-02-28 00:51:28 -04:00
Pedro Lopez
979e97ea42 chore: mark version v1.16.0 2022-02-27 23:30:03 -04:00
Pedro Lopez
1f4328c7a3 fix tests 2022-02-27 23:29:09 -04:00
Pedro Lopez
6691d25282 fix: message.getInfo() works for both MD and non-MD 2022-02-27 23:28:57 -04:00
Pedro S. Lopez
12d9735b73 Update README.md 2022-02-27 22:58:39 -04:00
SuperChang
ab5167c4ad fix: ChangeParticipantsPermissions typo in index.d.ts (#1206)
Co-authored-by: Pedro S. Lopez <pedroslopez@me.com>
2022-02-27 22:34:12 -04:00
YaronD
52c8336236 Added message duration in seconds (#1230)
Co-authored-by: Pedro S. Lopez <pedroslopez@me.com>
2022-02-27 22:30:47 -04:00
Pedro Lopez
9fe91692cf update tests to work with authStrategies 2022-02-27 22:18:54 -04:00
Pedro S. Lopez
f6de161c7d Auth Strategies (#1257)
* auth strategies

* default to no auth

* rename base auth strategy

* rename base strategy cont.

* refactor auth strategy methods and LocalAuth

* activate old session options even if is falsy value

* move restartOnAuthFail to LegacyAuthStrategy option

* add link to guide item

* update example/shell

* types
2022-02-27 22:02:49 -04:00
Rajeh Taher
0d55d40885 feat: Multi-device support (#889)
* 🚑 Added ready selector for multi-device

* SendMessage fix

* File management system and some fixes

* cleanup

* cleanup again

* eslint

* critical fix for reloading the same session

* Checking for valid folder name (regex)

* ESLint hotfix (regex escapes)

* Typings cleanup

* cleanup listener

* Multi-device Branch merge (#888)

* Duplicate

* qr fix and allow non-beta users to connect

* urgent: selector fix

* urgent: qr timeout fix

* fix

* Updated type so no TS error when sending list/buttons

* Update index.d.ts

* fix QueryExist for Multidevice (#928)

* creates isRegisteredUserBeta

* fix QueryExist

* fix Error: GROUP_JID: invalid jid type: Not an instance of WID issue (#926)

* fix Error: GROUP_JID: invalid jid type: Not an instance of WID issue

* clean code

* Cleanup

* Fix for update chrome error

* ESLint fix

* :red_light: fix for RMDIR

* Update README.md

* Update README.md

* fix: getProfilePicUrl fix by victormga (#941)

* fix: MD presence available/unavailable (#942)

* delete session when appropriate & fix for SW

* ignore QR timeout errors

* Presence and ChatState updates working for MD+Non-MD

* shell uses new session storage

* lint fix

* support session.json-based auth for non-md

* md fix

* md fix

* fix shell clientId

* remove exclusive mocha test

* make linkPreview default to false

* remove ignored errors on getQuotedMessage

* fix: dont modify existing this.options.puppeteer object

* tests work with new dir auth

* remove exclusive test

* fixes and tests for group creation and participant functions

* remove unused function

* wip fix group settings functions

* isRegisteredUser && getNumberId hotFix (#955)

* isRegisteredUser && getNumberId hotFix

A fix for client.isRegisteredUser and client.getNumberId. Use for reference or if you are stuck with MD and NEEDS this function. Problably Whatsapp will break this in a couple weeks

* fix for non-md

Co-authored-by: Rajeh Taher <rajeh@reforward.dev>

* Fix WA 2.2146.9 MD +  victormga branch (#991)

* qrcode now uses observers instead of timeout

* automatic auth/qrcode detection

* Fix WA 2.2146.9 MD

Got from github:victormga/whatsapp-web.js#multidevice maybe it's behind pedro branch

Co-authored-by: victormga <victor_mga@hotmail.com>

* fix

* fix*

* getnumberid to multidevice (#1027)

* getNumberId to main

 isRegisteredUser && getNumberId hotFix #955 To main

* Update Client.js

Co-authored-by: tuyuribr <45042245+tuyuribr@users.noreply.github.com>

* Update Client.js

* Message.raw() (#1005)

* Message.raw()

* i just noticed

* Update index.d.ts

* Update index.d.ts

* Update Message.js

* Get rid of sharp now!!!!!!!! (#1045)

* commit 1

* finally, gotten rid of sharp

* pckg.json

* service worker fix & disableMessage option

* typings

* Update example.js

* clear session system

* Update Client.js

* Update Client.js

* Fix accepting group private invite (#1094)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* [MD] Add getCommonGroups with specific user. (#1097)

* Add getCommonGroups with specific user.

* Fix

* Fix

* Fix

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* Fix getCommonGroups. (#1122)

* Fix of Unexpected identifier async destroy() (#1123)

* Fix of Unexpected identifier async destroy()

* Fix made in #1107

* Temporary fix for "Sticker" module

* some really quick changes

* Update Injected.js

* Update Injected.js

* Update index.d.ts

* fix: getNumberId Solved (#1142)

* getNumberId Solved

* isRegisteredUser Solved

* formmated

* Apply suggestions from code review

* Update src/util/Injected.js

Co-authored-by: Rajeh Taher <rajeh@reforward.dev>

* Fix: "Chrome user data dir was not found ..."

fixes the error caused by puppeteer.

* Update Client.js (#1154)

* fix: getNumberId and isRegisteredUser (#1159)

* fix: getNumberId and isRegisteredUser

* Apply suggestions from code review

Co-authored-by: Rajeh Taher <rajeh@reforward.dev>

* Update client.js

* Update Injected.js

* Update Client.js

* Update index.d.ts

* Update Client.js

* Update Client.js

* fix lint indentation

* fix auth_failure event for non-md, tests

* fix setting group subject

* fix finding Label module

* set remember-me after clearing localStorage

* fix: send messages to groups correctly on MD, use new ID format

* fix setting / getting contact status

* fix msg.getInfo, add message tests

* fix group settings functions

* fix set group description, handle errors in setSubject

* fix group invite functions

* fix leaving group

* bring back phone info for non-md users

* remove unused option, update typings

* add back jsdoc for qr event

* fix setting sticker metadata, clean up sticker functions

* rawData is a get only property

* fix and simplify getNumberId/isRegisteredUser

* fix getInviteInfo

* setDisplayName returns bool, not yet implemented for md

* fix: stream module (#1241)

* linkPreview has no effect on MD, return default to true

* fix: del linkPreview option on md

* cleanup, types and docs updates

* update readmes / test notes

* remove DS_Store

* DS_Store in gitignore

* test stability (timeouts/sleeps)

Co-authored-by: Rajeh Taher <rajeh@reforward.tk>
Co-authored-by: Gustavo B <52040719+Gugabit@users.noreply.github.com>
Co-authored-by: Maikel Ortega Hernández <maikeloh@gmail.com>
Co-authored-by: victormga <victor_mga@hotmail.com>
Co-authored-by: Pedro Lopez <pedroslopez@me.com>
Co-authored-by: tuyuribr <45042245+tuyuribr@users.noreply.github.com>
Co-authored-by: gon <68490103+nekiak@users.noreply.github.com>
Co-authored-by: Alon Schwartzblat <63599777+Schwartzblat@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Šebestíček <44745014+SebestikCZ@users.noreply.github.com>
Co-authored-by: Emmanuel Anaya Luna <38712443+KeruMx@users.noreply.github.com>
Co-authored-by: L337C0D3R <51872799+L337C0D3R@users.noreply.github.com>
Co-authored-by: Reni Delonzek <renidelonzek@gmail.com>
2022-02-27 18:51:08 -04:00
Pedro Lopez
8ef37b68ae chore: mark version v1.15.8 2022-02-25 17:45:33 -04:00
github-actions[bot]
bd5cfdc936 Update supported WhatsApp Web version to v2.2206.5 (#1247)
Co-authored-by: pedroslopez <pedroslopez@users.noreply.github.com>
2022-02-25 17:43:30 -04:00
༺ LᴇG̸ᴇɴD ༻
f0e49efcf9 [Main Branch]: Fix Cannot read properties of undefined (reading 'Socket') (#1249)
Co-authored-by: Joaquin Touris <joaquin@192.168.1.5>
2022-02-25 17:11:28 -04:00
Pedro Lopez
5d83b45ed4 chore: mark version v1.15.7 2022-02-19 15:48:03 -04:00
github-actions[bot]
e29354fca3 Update supported WhatsApp Web version to v2.2204.13 (#1210)
Co-authored-by: pedroslopez <pedroslopez@users.noreply.github.com>
2022-02-19 15:45:21 -04:00
Shir Serlui
66283da903 Fix message.delete(true) (#1211)
* Fix message.delete(true)

* Fix for tests
2022-02-19 15:31:23 -04:00
Tomas Melone
d7f7889b0f fix: Remove duplicate identifier (#1205) 2022-02-19 15:18:34 -04:00
Pedro Lopez
11955e9f03 chore: mark version v1.15.6 2022-02-08 22:38:33 -04:00
Md. Fahim Bin Amin
444abc2c76 added the Code of Conduct, closing #1156 (#1176) 2022-02-08 22:34:33 -04:00
Pedro S. Lopez
20f3bc7a8b fix: dont cause redirect loop due to session restore (#1181)
* fix: dont cause redirect loop due to session restore

* back to `state` in docs

* use referer to determine first injection

* bring bzck disconnect on nav

* revert some changes
2022-02-08 22:33:20 -04:00
Pedro Lopez
93c8a2b05e chore: mark version v1.15.5 2022-02-06 22:20:08 -04:00
Pedro S. Lopez
70ca073f38 fix: send messages properly when disappearing mode is on (#1174)
* fix: send messages properly when dissappearing mode is on

* add `isEphemeral` to message model
2022-02-06 21:48:55 -04:00
Shir Serlui
7e36cceaf0 extra options can override other options when sending message (#1103)
* Fix the option to use special options

When we want to use some extra function we need to pass it into the options object, but because it inserted in the first line, the auto options reset some options (like 'type').
This is minor change that can help to add functionallity

* Update Injected.js

Put the special options in the end

* Update Injected.js

Fix , mistake

* only `extra` options can override everything else

Co-authored-by: Pedro Lopez <pedroslopez@me.com>
2022-02-06 21:00:10 -04:00
Noam Zaks
303ea3ab6b fix types and docs for Buttons class (#1070)
* fix: typing of buttons class

* fix remaining types

Co-authored-by: Pedro Lopez <pedroslopez@me.com>
2022-02-07 00:56:57 +00:00
Pedro Lopez
4aae8b0f32 fix: sort before splicing when fetching messages 2022-02-06 20:03:59 -04:00
Pedro Lopez
64803c2ba6 update typings for fetchMessages changes 2022-02-06 19:30:13 -04:00
Azeem Haider
aa9e19a19e fetchMessages gets currently available messages by default (#1015)
* get chat default messages fix #1014

* fixing format

* Update src/structures/Chat.js

Co-authored-by: Pedro S. Lopez <pedroslopez@me.com>

Co-authored-by: Pedro S. Lopez <pedroslopez@me.com>
2022-02-06 19:27:38 -04:00
Pedro S. Lopez
7631400de1 add back the pull_request trigger on lint 2022-02-06 19:16:57 -04:00
Pedro Lopez
d7478de68a fix: emit message events after ciphertext is decrypted
fixes #924
fixes #1041
2022-02-06 18:54:10 -04:00
Pedro Lopez
a9b2a1aab8 remove duplicated message type 2022-02-06 16:30:44 -04:00
Pedro Lopez
3b4632201d fix: add missing message types 2022-02-06 16:26:25 -04:00
Pedro Lopez
2200390d4c disable eslint warning on intentionally skipped test 2022-02-05 23:36:05 -04:00
dependabot[bot]
b1f7ff01bc chore(deps-dev): bump sinon from 12.0.1 to 13.0.1 (#1160)
Bumps [sinon](https://github.com/sinonjs/sinon) from 12.0.1 to 13.0.1.
- [Release notes](https://github.com/sinonjs/sinon/releases)
- [Changelog](https://github.com/sinonjs/sinon/blob/master/docs/changelog.md)
- [Commits](https://github.com/sinonjs/sinon/compare/v12.0.1...v13.0.1)

---
updated-dependencies:
- dependency-name: sinon
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-02-05 23:35:04 -04:00
dependabot[bot]
21d565154a chore(deps-dev): bump dotenv from 10.0.0 to 16.0.0 (#1171)
Bumps [dotenv](https://github.com/motdotla/dotenv) from 10.0.0 to 16.0.0.
- [Release notes](https://github.com/motdotla/dotenv/releases)
- [Changelog](https://github.com/motdotla/dotenv/blob/master/CHANGELOG.md)
- [Commits](https://github.com/motdotla/dotenv/compare/v10.0.0...v16.0.0)

---
updated-dependencies:
- dependency-name: dotenv
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-02-05 23:32:53 -04:00
dependabot[bot]
09cbee0e65 chore(deps-dev): bump eslint-plugin-mocha from 9.0.0 to 10.0.3 (#1087)
Bumps [eslint-plugin-mocha](https://github.com/lo1tuma/eslint-plugin-mocha) from 9.0.0 to 10.0.3.
- [Release notes](https://github.com/lo1tuma/eslint-plugin-mocha/releases)
- [Changelog](https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/CHANGELOG.md)
- [Commits](https://github.com/lo1tuma/eslint-plugin-mocha/compare/9.0.0...10.0.3)

---
updated-dependencies:
- dependency-name: eslint-plugin-mocha
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-02-05 23:32:30 -04:00
github-actions[bot]
fa9f5aba38 Update supported WhatsApp Web version to v2.2202.12 (#1152)
Co-authored-by: pedroslopez <pedroslopez@users.noreply.github.com>
2022-02-05 23:17:11 -04:00
Pedro S. Lopez
c859ac39ce fix: dont crash when calling .destroy() while waiting for qr scan (#1172)
fixes #739
fixes #951
2022-02-05 23:05:01 -04:00
Pedro S. Lopez
221d29736a remove unnecessary pull_request trigger for lint 2022-02-05 23:04:47 -04:00
Igor Nunes
078933f061 fix(typings): add MessageTypes BUTTONS_RESPONSE (#1032)
fixes #1104
2022-02-05 22:11:53 -04:00
Pedro S. Lopez
f149516d0d chore(tests): add Chat model tests (#784)
* add search and status tests

* reset to previous status in test

* move version to its own test

* add tests for Chat model

* keep hooks at the top

* run tests recursively in default script
2022-02-05 22:05:42 -04:00
Pedro S. Lopez
2f1c894a34 add tests for takeoverOnConflict (#1170)
* add tests

* fix module test, remove unused CryptoLib
2022-02-05 20:04:00 -04:00
Pedro S. Lopez
32e47d818a fix: only emit disconnected event on navigation when state is PAIRING (#1169) 2022-02-05 18:19:02 -04:00
Zulfikar
20aee44c3b fix getLabels error (#1049)
Co-authored-by: Rajeh Taher <rajeh@reforward.dev>
2022-02-05 16:41:27 -04:00
Shir Serlui
bb2ef88e0a fix: message.delete() can revoke for everyone (#1107)
Change msg.canRevoke to msg._canRevoke according to WhatsApp code change
2022-02-05 15:52:04 -04:00
tuyuribr
6878598a5d fix: await promise when setting user agent (#1113)
Some of my devices were bugging out because the setUserAgent didn't had an await, after this everything was working fine (try loading the wwebjs in a broken microSd ahhaha).

We need some testing but on my limited testing everything is working

Co-authored-by: Rajeh Taher <rajeh@reforward.dev>
2022-02-05 15:42:25 -04:00
Pedro Lopez
4e6a00dffe chore: mark version v1.15.4 2022-01-25 20:49:07 -04:00
Pedro Lopez
b93c7b4b76 fix invalid jsdoc 2022-01-25 20:48:44 -04:00
Pedro Lopez
a37ff69692 fix: restore node 12 support 2022-01-25 20:40:50 -04:00
github-actions[bot]
3705d1fea9 Update supported WhatsApp Web version to v2.2202.8 (#1084)
Co-authored-by: pedroslopez <pedroslopez@users.noreply.github.com>
Co-authored-by: Pedro S. Lopez <pedroslopez@me.com>
2022-01-25 20:16:08 -04:00
Pedro S. Lopez
7950aae5d1 fix: find Store in v2.2202.8 (#1130)
Co-authored-by: Rajeh Taher <rajeh@reforward.dev>
2022-01-25 20:15:19 -04:00
Pedro Lopez
bdff59fb44 fix: remove problematic import 2022-01-25 19:45:57 -04:00
Wictor Nogueira
d05803074a update MessageMedia.fromUrl (#811)
* fix MessageMedia.fromUrl docs

* use content-type as fallback

* set filename based on url

* fix empty filename

* wrap expression in parentheses

* hotfix

* JSDoc fix

* fix for jsdog

* eslint gets retirement home

Co-authored-by: Rajeh Taher <rajeh@reforward.dev>
Co-authored-by: Aliyss Snow <33941859+Aliyss@users.noreply.github.com>
2022-01-21 23:57:15 +01:00
Rajeh Taher
d86c39de3c fix: Fix inactivity issue (#946)
* Fixed Remember me issue

* Update Client.js
2021-12-16 15:25:35 +00:00
shirser121
46ba9c5e9a Add isGif to message._patch (#963)
* Update Message.js

Add isGif to the message data

* add typings

Co-authored-by: Rajeh Taher <rajeh@reforward.dev>
Co-authored-by: Pedro Lopez <pedroslopez@me.com>
2021-12-12 21:57:11 -04:00
Pedro Lopez
d7a493e68a fix: use correct @types/node-fetch ver, use working node-fetch ver from puppeteer, add test 2021-12-12 21:28:38 -04:00
dependabot[bot]
da95d927b9 chore(deps): bump puppeteer from 10.4.0 to 13.0.0 (#1057)
Bumps [puppeteer](https://github.com/puppeteer/puppeteer) from 10.4.0 to 13.0.0.
- [Release notes](https://github.com/puppeteer/puppeteer/releases)
- [Changelog](https://github.com/puppeteer/puppeteer/blob/main/CHANGELOG.md)
- [Commits](https://github.com/puppeteer/puppeteer/compare/v10.4.0...v13.0.0)

---
updated-dependencies:
- dependency-name: puppeteer
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-12-12 21:09:56 -04:00
dependabot[bot]
92bc5e62ab chore(deps-dev): bump eslint from 7.32.0 to 8.4.1 (#1038)
Bumps [eslint](https://github.com/eslint/eslint) from 7.32.0 to 8.4.1.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v7.32.0...v8.4.1)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-12-12 19:47:11 -04:00
dependabot[bot]
73a3e28a4b chore(deps-dev): bump @types/node-fetch from 2.5.12 to 3.0.3 (#911)
Bumps [@types/node-fetch](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node-fetch) from 2.5.12 to 3.0.3.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node-fetch)

---
updated-dependencies:
- dependency-name: "@types/node-fetch"
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-12-12 19:46:30 -04:00
dependabot[bot]
4f376fc2fa chore(deps-dev): bump sinon from 11.1.2 to 12.0.1 (#1024)
Bumps [sinon](https://github.com/sinonjs/sinon) from 11.1.2 to 12.0.1.
- [Release notes](https://github.com/sinonjs/sinon/releases)
- [Changelog](https://github.com/sinonjs/sinon/blob/master/docs/changelog.md)
- [Commits](https://github.com/sinonjs/sinon/compare/v11.1.2...v12.0.1)

---
updated-dependencies:
- dependency-name: sinon
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-12-12 19:41:08 -04:00
dependabot[bot]
a20c8ef8f8 chore(deps): bump mime from 2.6.0 to 3.0.0 (#1023)
Bumps [mime](https://github.com/broofa/mime) from 2.6.0 to 3.0.0.
- [Release notes](https://github.com/broofa/mime/releases)
- [Changelog](https://github.com/broofa/mime/blob/master/CHANGELOG.md)
- [Commits](https://github.com/broofa/mime/compare/v2.6.0...v3.0.0)

---
updated-dependencies:
- dependency-name: mime
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-12-12 19:38:33 -04:00
tuyuribr
2052e0479d Fix: multiple list sections (#1004)
* Fix multiple list sections

* singleQuotes

* Update src/structures/List.js

Co-authored-by: Rajeh Taher <rajeh@reforward.dev>
2021-12-10 20:47:07 +01:00
Pedro Lopez
c55db82f73 mark version v1.15.3 2021-12-07 23:06:53 -04:00
github-actions[bot]
4e837b00f9 Update supported WhatsApp Web version to v2.2147.14 (#1033)
Co-authored-by: pedroslopez <pedroslopez@users.noreply.github.com>
2021-12-07 23:05:54 -04:00
tuyuribr
89a06b15a8 Hot Fix WA 2.2147.14 (#1035)
* Hot Fix WA 2.2147.14

* Update Injected.js

* Update Client.js

* sendPresence1

* Update Client.js

* queryLinkPreview

* openChatDrawer

* revert back to using Wap

Co-authored-by: Pedro Lopez <pedroslopez@me.com>
2021-12-07 23:04:44 -04:00
Pedro Lopez
55247576da add script to get change log 2021-11-24 10:07:27 -04:00
Pedro Lopez
8a1f6f0648 chore: mark version v1.15.2 2021-11-24 09:49:16 -04:00
github-actions[bot]
254ca884aa Update supported WhatsApp Web version to v2.2146.9 (#969)
Co-authored-by: pedroslopez <pedroslopez@users.noreply.github.com>
Co-authored-by: Pedro S. Lopez <pslamoros@hotmail.com>
2021-11-24 09:43:59 -04:00
tuyuribr
3958105926 Fix WA 2.2146.9 (#990)
* Fix WA 2.2146.9

WA is serving two versions to me,  so we need to check window.mR.findModule('Conn').lengh for a while

* to singleQuotes

* Update Injected.js

* simplify getting `Conn` module, use different object for `Store`

Co-authored-by: Pedro Lopez <pedroslopez@me.com>
2021-11-24 09:40:01 -04:00
Pedro Lopez
818bf48e5d fix: convert button ids to string 2021-11-01 21:30:34 -04:00
Pedro S. Lopez
d71544566c move links section in readme 2021-10-30 21:29:39 -04:00
Pedro S. Lopez
187aa50131 Url updates for wwebjs.dev (#944)
* Update package.json

* update links in readme
2021-10-30 21:27:08 -04:00
Pedro Lopez
e11e00d938 chore: update docs for v1.15.1 2021-10-30 00:46:37 -04:00
Pedro Lopez
d9dd89ccaf chore: mark version v1.15.1 2021-10-30 00:46:09 -04:00
Pedro Lopez
3aa0e4f7b3 fix: dont modify id reference when serializing message 2021-10-30 00:45:04 -04:00
Pedro Lopez
d82cf448d9 chore: mark version v1.15.0 2021-10-30 00:15:24 -04:00
github-actions[bot]
3f576c990c Update supported WhatsApp Web version to v2.2142.12 (#827)
Co-authored-by: pedroslopez <pedroslopez@users.noreply.github.com>
Co-authored-by: Pedro S. Lopez <pslamoros@hotmail.com>
2021-10-30 00:14:07 -04:00
Pedro Lopez
d44a525b02 fix: serialize message id remote when fetching messages
close #825
2021-10-30 00:12:06 -04:00
Pedro Lopez
d8217029ba add test for maxQrRetries 2021-10-30 00:03:19 -04:00
victormga
2a7337b142 max qr refresh before giving up (#852)
* max qr refresh before giving up

* Update src/Client.js

Co-authored-by: Rajeh Taher <rajeh@reforward.dev>

Co-authored-by: Rajeh Taher <rajeh@reforward.dev>
2021-10-29 23:45:04 -04:00
Pedro S. Lopez
1fcfaa0362 Update README.md (#907) 2021-10-29 23:43:27 -04:00
Pedro Lopez
c434e04e41 fix countrycode and formatted number functions, add tests 2021-10-29 23:41:49 -04:00
Rajeh Taher
97a1d399ee Format phone numbers (#650)
* 📦 Declared NumberInfo in store

* 📝 Add client.js functionality

* 🚨 eslint just admires singlequote strings

* 📝 Add shortcuts to using client method

*  Adding parity between the ids

*  Same method name parity

* 🚨 ESLint indentation error.

* 🚨 ESLint doublequote string error.

* 🎨 Proposed changes

* 🎨 Fixed badly done code :v and applied proposed changes.

*  fixed calling the wrong function (sigh)

*  Fixed missing try-catch code.

* 🚨 Fixes ESLint indentation errors.

*  fix the documentation issues.

* 🏷️ typescript

* 🏷️ Typo in function name

Co-authored-by: Rajeh Taher <rajeh@reforward.tk>
2021-10-29 23:33:38 -04:00
Rajeh Taher
dbf9bf2158 Type file improvements (#855)
* Updated Types

* Updated types to include (#868)

* Update index.d.ts

* fix list type

Co-authored-by: Pedro Lopez <pedroslopez@me.com>
Co-authored-by: Pedro S. Lopez <pslamoros@hotmail.com>
2021-10-29 23:32:13 -04:00
Pedro Lopez
353af130d0 remove unnecessary default 2021-10-29 23:25:06 -04:00
Rajeh Taher
06107af67d Allow a chat to be muted indefinitely (#849)
* muteChat fixed

* Update src/Client.js

Co-authored-by: Pedro S. Lopez <pedroslopez@me.com>

* Update src/Client.js

Co-authored-by: Pedro S. Lopez <pedroslopez@me.com>

* date fix

Co-authored-by: Pedro S. Lopez <pedroslopez@me.com>
2021-10-29 23:24:36 -04:00
Muhamad Ristiyanto
4338664590 Add getBlockedContacts method (#770)
* add simple method to get blocked ids

* Change getBlockedList to getBlockedIds

* getBlockedIds to getBlockedContacts

* typo

* ESLint & other changes

* 🏷️ types

* fix: no `this.client`

* add tests

Co-authored-by: Rajeh Taher <rajeh@reforward.dev>
Co-authored-by: Pedro Lopez <pedroslopez@me.com>
Co-authored-by: Pedro S. Lopez <pslamoros@hotmail.com>
2021-10-30 03:18:26 +00:00
Rajeh Taher
95facee885 Fixes GroupNotification.getChat() returning client's chat. (#699)
* 🥅 getChat returns expected, instead of the client's chat.

* 🥅 Fixed .reply method too

* revert + fix
2021-10-29 23:00:10 -04:00
Pedro Lopez
1f38b762ed add warning for multidevice, keep working for forced upgrade 2021-10-29 22:58:57 -04:00
tuyuribr
b60029ed09 feat: Send buttons and Lists (#756) 2021-09-14 00:06:05 +03:00
tuyuribr
ab415ff9be feat: Include payment info (#684) 2021-09-13 23:58:39 +03:00
Pedro Lopez
7beeff4901 chore: mark version 1.14.1 2021-09-01 09:19:28 -04:00
Pedro Lopez
022c87f3c7 optionally patch _find function if it's not found 2021-09-01 09:18:34 -04:00
Pedro Lopez
e527fe74fd fix: patch find function to get chats 2021-09-01 09:16:12 -04:00
Pedro S. Lopez
7597608f9d Update README.md 2021-08-02 00:49:03 -04:00
Pedro Lopez
be018e651d update .npmignore 2021-08-02 00:07:52 -04:00
Pedro Lopez
64189d2d67 chore: mark version v1.14.0 2021-08-01 23:59:56 -04:00
Pedro Lopez
38e31a07cf Update package.json and readme for node 12 support 2021-08-01 23:57:21 -04:00
Pedro Lopez
40cec51956 fix: node v12 support 2021-08-01 23:56:27 -04:00
Pedro S. Lopez
d9ccb6f276 fix: correctly resolve media that hasn't been downloaded (#763)
* fix: correctly abort if media does not exist

* catch 404s

* dont throw for media that cant be fetched
2021-08-01 23:29:06 -04:00
github-actions[bot]
628b6e4d49 Update supported WhatsApp Web version to v2.2126.14 (#806)
Co-authored-by: pedroslopez <pedroslopez@users.noreply.github.com>
2021-08-01 23:13:07 -04:00
Pedro S. Lopez
8e56aef3ce fix: more stable latest version check (#805) 2021-08-01 23:04:02 -04:00
Wictor Nogueira
cd774bef17 feat: Add MessageMedia.fromUrl method (#769) 2021-07-31 16:36:11 +03:00
Pedro S. Lopez
9c2592e164 chore: temporarily stop update action from auto running 2021-07-20 14:51:58 -04:00
Pedro S. Lopez
ae6d61bda9 fix: correctly serialize messages with replyButtons 2021-07-19 22:23:06 -04:00
Pedro S. Lopez
98acd2312d delete gh branch automatically when closing update PR 2021-07-19 19:46:24 -04:00
Pedro Lopez
62c7c15f44 chore: update links 2021-07-19 00:19:40 -04:00
Pedro Lopez
e12c53f6ce chore: specify minimum required node version 2021-07-19 00:11:57 -04:00
Pedro S. Lopez
811008da4b Delete CNAME 2021-07-18 23:37:45 -04:00
Pedro S. Lopez
863284c9d1 Create CNAME 2021-07-18 23:37:21 -04:00
Pedro S. Lopez
ec95483518 Create CNAME 2021-07-18 23:36:02 -04:00
Pedro S. Lopez
ff2eb95751 Change WA Web update PR branch name 2021-07-18 22:57:18 -04:00
dependabot[bot]
1b5e9d2392 chore(deps-dev): bump mocha from 8.4.0 to 9.0.2 (#776)
Bumps [mocha](https://github.com/mochajs/mocha) from 8.4.0 to 9.0.2.
- [Release notes](https://github.com/mochajs/mocha/releases)
- [Changelog](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mochajs/mocha/compare/v8.4.0...v9.0.2)

---
updated-dependencies:
- dependency-name: mocha
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-07-18 22:55:06 -04:00
Pedro Lopez
340e9764fe Publish gh-pages site (branch name change) 2021-07-18 22:43:07 -04:00
Rajeh Taher
084525ddfa Add Operating System information for bug reports. (#725)
* 📄 Add Operating System information for bug reports.

* 🐛 Forgot Line Break
2021-07-17 22:04:44 -04:00
github-actions[bot]
3398501ee6 Update supported WhatsApp Web version to v2.2126.11 (#766)
Co-authored-by: pedroslopez <pedroslopez@users.noreply.github.com>
Co-authored-by: Pedro S. Lopez <pslamoros@hotmail.com>
2021-07-17 00:07:38 -04:00
tuyuribr
cdede835af Include Calls (#720)
* Get Call module

* The call event

* Update onCall index.d.ts
2021-07-17 00:05:53 -04:00
Pedro S. Lopez
449d0f01d8 Trim current version string 2021-07-16 03:19:58 -04:00
Pedro S. Lopez
4ed9312eb7 Update update.yml 2021-07-16 03:09:54 -04:00
Pedro S. Lopez
76deaad2fd Update update.yml 2021-07-16 03:05:18 -04:00
Pedro S. Lopez
284903dce4 Update README.md 2021-07-16 02:53:39 -04:00
Pedro S. Lopez
a03cc41d22 Add tests and detect WhatsApp Web updates (#686)
* test setup, add initializer tests

* test sending messages

* add script to check latest version

* add github action

* use env vars

* configure environment with .env file

* add test for sticker name and author

* add DownloadManager model

* test chats and contacts

* test for number utility functions

* throw error if no remote id has been set

* Update .version
2021-07-16 02:50:05 -04:00
ApeironTsuka
04d2308bbc Update node-webpmux 2.x syntax to 3.x (support upstream breaking change) (#762)
Co-authored-by: Apeiron <apeiron@none>
2021-07-15 22:50:54 -04:00
Pedro S. Lopez
dc9b7e5f3d Update minimum moduleRaid version to 5.0.2
close #741
2021-07-14 22:42:21 -04:00
dependabot[bot]
cc7a729223 chore(deps): bump puppeteer from 5.5.0 to 10.1.0 (#750)
Bumps [puppeteer](https://github.com/puppeteer/puppeteer) from 5.5.0 to 10.1.0.
- [Release notes](https://github.com/puppeteer/puppeteer/releases)
- [Changelog](https://github.com/puppeteer/puppeteer/blob/main/CHANGELOG.md)
- [Commits](https://github.com/puppeteer/puppeteer/compare/v5.5.0...v10.1.0)

---
updated-dependencies:
- dependency-name: puppeteer
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-07-14 18:39:24 -04:00
dependabot[bot]
2ec46f674a chore(deps): bump sharp from 0.26.3 to 0.28.3 (#751)
Bumps [sharp](https://github.com/lovell/sharp) from 0.26.3 to 0.28.3.
- [Release notes](https://github.com/lovell/sharp/releases)
- [Changelog](https://github.com/lovell/sharp/blob/master/docs/changelog.md)
- [Commits](https://github.com/lovell/sharp/compare/v0.26.3...v0.28.3)

---
updated-dependencies:
- dependency-name: sharp
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-07-14 18:35:59 -04:00
dependabot[bot]
22993fc23d chore(deps): bump node-webpmux from 2.0.3 to 3.0.0 (#749)
Bumps [node-webpmux](https://github.com/ApeironTsuka/node-webpmux) from 2.0.3 to 3.0.0.
- [Release notes](https://github.com/ApeironTsuka/node-webpmux/releases)
- [Commits](https://github.com/ApeironTsuka/node-webpmux/commits)

---
updated-dependencies:
- dependency-name: node-webpmux
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-07-14 18:33:36 -04:00
Edson Tégila
cd52075447 Add the option to use "browserWSEndpoint" (#727)
* Update Client.js

* Update package.json

* Update package.json

* 🚨🔥 Fixed ESLint and removed old code.

* Update README.md

* Update README.md

* Update Client.js

* chore(deps): bump sharp from 0.26.3 to 0.28.3

Bumps [sharp](https://github.com/lovell/sharp) from 0.26.3 to 0.28.3.
- [Release notes](https://github.com/lovell/sharp/releases)
- [Changelog](https://github.com/lovell/sharp/blob/master/docs/changelog.md)
- [Commits](https://github.com/lovell/sharp/compare/v0.26.3...v0.28.3)

---
updated-dependencies:
- dependency-name: sharp
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update package.json

* Update README.md

* Update example.js

* Update README.md

Co-authored-by: Rajeh Taher <52720753+PurpShell@users.noreply.github.com>
Co-authored-by: Rajeh Taher <rajeh@reforward.tk>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Aliyss Snow <33941859+Aliyss@users.noreply.github.com>
2021-07-13 10:27:00 -07:00
Rajeh Taher
54a07fa22f feat: Add support to suspicious links (#642) 2021-07-12 11:03:11 -07:00
Pedro S. Lopez
1d49f74ab4 Update dependabot.yml 2021-07-11 21:29:58 -04:00
Pedro S. Lopez
ea4dfb17f3 Create dependabot.yml 2021-07-11 21:28:39 -04:00
stefanfuchs
efa6cf98d2 fix: location class type (#718) 2021-07-12 00:54:32 +00:00
Giancarlo Rocha
9d715735ed feat: message forwarding score (#716) 2021-07-11 20:52:54 -04:00
104 changed files with 7983 additions and 1313 deletions

3
.env.example Normal file
View File

@@ -0,0 +1,3 @@
WWEBJS_TEST_REMOTE_ID=XXXXXXXXXX@c.us
WWEBJS_TEST_CLIENT_ID=authenticated
WWEBJS_TEST_MD=1

View File

@@ -5,7 +5,7 @@
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"extends": ["eslint:recommended", "plugin:mocha/recommended"],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
@@ -13,6 +13,7 @@
"parserOptions": {
"ecmaVersion": 2020
},
"plugins": ["mocha"],
"ignorePatterns": ["docs"],
"rules": {
"indent": [

View File

@@ -1,38 +0,0 @@
---
name: Bug report
about: Is something not working as intended? Report it here.
title: ''
assignees: ''
---
### Bug description
A clear and concise description of what the bug is.
### Reproduction steps
Steps to reproduce the behavior:
1.
2.
3.
...
### Expected behavior
A clear and concise description of what you expected to happen.
### Relevant code
If applicable, add code snippets to help explain your problem.
### Environment (please complete the following information):
**WhatsApp**
- Account type [Standard / Business]:
- Device OS [iOS / Android]:
- WhatsApp Web version [run `await client.getWWebVersion()`]:
**Library**
- Browser [Chrome / Chromium]:
- NodeJS version (`node -v`):
- npm or yarn version (`npm -v`):
- whatsapp-web.js version:
### Additional context
Add any other context about the problem here.

105
.github/ISSUE_TEMPLATE/bug_report.yml vendored Normal file
View File

@@ -0,0 +1,105 @@
name: '🐛 Bug report'
description: Create a report to help us improve
labels: bug
body:
- type: markdown
attributes:
value: |
Thank you for reporting an issue :pray:.
This issue tracker is for reporting bugs found in [`whatsapp-web.js`](https://github.com/pedroslopez/whatsapp-web.js).
If you have a question about how to achieve something and are struggling, please post a question in our [Discord server](https://discord.gg/wyKybbF) instead.
Before submitting a new bug/issue, please check the links below to see if there is a solution or question posted there already:
- `whatsapp-web.js` [Issues tab](https://github.com/pedroslopez/whatsapp-web.js/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc)
- `whatsapp-web.js` [closed Issues tab](https://github.com/pedroslopez/whatsapp-web.js/issues?q=is%3Aissue+sort%3Aupdated-desc+is%3Aclosed)
The more information you fill in, the better the community can help you.
- type: checkboxes
attributes:
label: Is there an existing issue for this?
description: Please search to see if an issue already exists for the bug you encountered.
options:
- label: I have searched the existing issues
required: true
- type: textarea
id: description
attributes:
label: Describe the bug
description: Provide a clear and concise description of the challenge you are running into.
validations:
required: true
- type: textarea
id: expected
attributes:
label: Expected behavior
description: Provide a clear and concise description of what you expected to happen.
placeholder: |
As a user, I expected ___ behavior but I am seeing ___
validations:
required: true
- type: textarea
id: steps
attributes:
label: Steps to Reproduce the Bug or Issue
description: Describe the steps we have to take to reproduce the behavior.
placeholder: |
1. Do X
2. Do Y
3. Do Z
4. See error
validations:
required: true
- type: textarea
id: relevant_code
attributes:
label: Relevant Code
description: If applicable, add code snippets to help explain your problem.
validations:
required: false
- type: dropdown
id: browser_type
attributes:
label: Browser Type
description: What web browser are you using?
options:
- Chromium
- Google Chrome
- Other (please write in Additional Context)
validations:
required: true
- type: dropdown
id: whatsapp_type
attributes:
label: WhatsApp Account Type
options:
- Standard
- WhatsApp Business
validations:
required: true
- type: dropdown
id: multidevice
attributes:
label: Does your WhatsApp account have multidevice enabled?
options:
- Yes, I am using Multi Device
- No, I am not using Multi Device
validations:
required: true
- type: textarea
attributes:
label: Environment
description: |
- OS: [e.g. Mac, Windows, Linux, Docker + Ubuntu 18, etc]
- Phone OS: [e.g. Android, iOS]
- whatsapp-web.js version [e.g. 1.2.3]
- WhatsApp Web version [run `await client.getWWebVersion()`]:
- Node.js Version [e.g. 1.2.3]
validations:
required: true
- type: textarea
id: additional
attributes:
label: Additional context
description: Add any other context about the problem here.

View File

@@ -1,20 +0,0 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: ''
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.

View File

@@ -0,0 +1,42 @@
name: 🚀 Feature request
description: Suggest an idea for this project
labels: enhancement
body:
- type: checkboxes
attributes:
label: Is there an existing issue for this?
description: Please search to see if an issue related to this feature request already exists.
options:
- label: I have searched the existing issues
required: true
- type: textarea
attributes:
label: Is your feature request related to a problem? Please describe.
description: A concise description of the problem you are facing or the motivetion behind this feature request.
placeholder: I faced a problem due to ...
validations:
required: false
- type: textarea
attributes:
label: Describe the solution you'd like.
description: A concise description of the solution for the issue.
validations:
required: true
- type: textarea
attributes:
label: Describe an alternate solution.
description: Is there any other approach to solve the problem?
validations:
required: false
- type: textarea
attributes:
label: Additional context
description: |
Links? Screenshots? References? Anything that will give us more context about what you would like to see!
validations:
required: false

7
.github/dependabot.yml vendored Normal file
View File

@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
open-pull-requests-limit: 10
schedule:
interval: "monthly"

39
.github/workflows/update.yml vendored Normal file
View File

@@ -0,0 +1,39 @@
name: Update
on:
schedule:
- cron: "0/15 * * * *"
workflow_dispatch:
jobs:
update:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./tools/version-checker
steps:
- uses: actions/checkout@v2
- name: Install node v16
uses: actions/setup-node@v2
with:
node-version: '16'
- name: Install dependencies
run: npm install
- name: Run Updater
run: ./update-version
- name: Store WA Version
run: echo WA_VERSION=`cat ./.version` >> $GITHUB_ENV
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
with:
branch: auto-wa-web-update/patch
delete-branch: true
commit-message: Update supported WhatsApp Web version to v${{ env.WA_VERSION }}
title: Update WhatsApp Web Version (${{ env.WA_VERSION }})
body: |
A new version of WhatsApp Web has been detected!
Tests should be run against this new version before merging.
labels: WhatsApp Change
reviewers: pedroslopez

6
.gitignore vendored
View File

@@ -64,8 +64,10 @@ typings/
# next.js build output
.next
# macOS Thumbnails
# macOS
._*
.DS_Store
# Test sessions
*session.json
*session.json
.wwebjs_auth/

View File

@@ -12,3 +12,8 @@ yarn-debug.log*
yarn-error.log*
*session.json
.wwebjs_auth/
.env
tools/
tests/

133
CODE_OF_CONDUCT.md Normal file
View File

@@ -0,0 +1,133 @@
# Contributor Covenant Code of Conduct
## Our Pledge
We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, religion, or sexual identity
and orientation.
We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.
## Our Standards
Examples of behavior that contributes to a positive environment for our
community include:
* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the
overall community
Examples of unacceptable behavior include:
* The use of sexualized language or imagery, and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Enforcement Responsibilities
Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.
Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.
## Scope
This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
[pedroslopez@me.com](mailto:pedroslopez@me.com).
All complaints will be reviewed and investigated promptly and fairly.
All community leaders are obligated to respect the privacy and security of the
reporter of any incident.
## Enforcement Guidelines
Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:
### 1. Correction
**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.
**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.
### 2. Warning
**Community Impact**: A violation through a single incident or series
of actions.
**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or
permanent ban.
### 3. Temporary Ban
**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.
**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.
### 4. Permanent Ban
**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.
**Consequence**: A permanent ban from any sort of public interaction within
the community.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.0, available at
[https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0].
Community Impact Guidelines were inspired by
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
For answers to common questions about this code of conduct, see the FAQ at
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available
at [https://www.contributor-covenant.org/translations][translations].
[homepage]: https://www.contributor-covenant.org
[v2.0]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html
[Mozilla CoC]: https://github.com/mozilla/diversity
[FAQ]: https://www.contributor-covenant.org/faq
[translations]: https://www.contributor-covenant.org/translations

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 2.2126.10](https://img.shields.io/badge/WhatsApp_Web-2.2126.10-brightgreen.svg) [![Discord Chat](https://img.shields.io/discord/698610475432411196.svg?logo=discord)](https://discord.gg/H7DqQs4)
[![npm](https://img.shields.io/npm/v/whatsapp-web.js.svg)](https://www.npmjs.com/package/whatsapp-web.js) [![Depfu](https://badges.depfu.com/badges/4a65a0de96ece65fdf39e294e0c8dcba/overview.svg)](https://depfu.com/github/pedroslopez/whatsapp-web.js?project_id=9765) ![WhatsApp_Web 2.2206.5](https://img.shields.io/badge/WhatsApp_Web-2.2206.5-brightgreen.svg) [![Discord Chat](https://img.shields.io/discord/698610475432411196.svg?logo=discord)](https://discord.gg/H7DqQs4)
# whatsapp-web.js
A WhatsApp API client that connects through the WhatsApp Web browser app
@@ -7,16 +7,24 @@ It uses Puppeteer to run a real instance of Whatsapp Web to avoid getting blocke
**NOTE:** I can't guarantee you will not be blocked by using this method, although it has worked for me. WhatsApp does not allow bots or unofficial clients on their platform, so this shouldn't be considered totally safe.
## Quick Links
* [Guide / Getting Started](https://wwebjs.dev/guide) _(work in progress)_
* [Reference documentation](https://docs.wwebjs.dev/)
* [GitHub](https://github.com/pedroslopez/whatsapp-web.js)
* [npm](https://npmjs.org/package/whatsapp-web.js)
## Installation
The module is now available on npm! `npm i whatsapp-web.js`
Please note that Node v14+ is required.
Please note that Node v12+ is required.
## Example usage
```js
const { Client } = require('whatsapp-web.js');
const client = new Client();
client.on('qr', (qr) => {
@@ -39,18 +47,24 @@ client.initialize();
Take a look at [example.js](https://github.com/pedroslopez/whatsapp-web.js/blob/master/example.js) for another example with more use cases.
For more information on saving and restoring sessions, check out the available [Authentication Strategies](https://wwebjs.dev/guide/authentication.html).
## Supported features
| Feature | Status |
| ------------- | ------------- |
| Multi Device | ✅ |
| Send messages | ✅ |
| Receive messages | ✅ |
| Send media (images/audio/documents) | ✅ |
| Send media (video) | ✅ [(requires google chrome)](https://waguide.pedroslopez.me/features/handling-attachments#caveat-for-sending-videos-and-gifs) |
| Send media (video) | ✅ [(requires google chrome)](https://wwebjs.dev/guide/handling-attachments.html#caveat-for-sending-videos-and-gifs) |
| Send stickers | ✅ |
| Receive media (images/audio/video/documents) | ✅ |
| Send contact cards | ✅ |
| Send location | ✅ |
| Send buttons | ✅ |
| Send lists | ✅ (business accounts not supported) |
| Receive location | ✅ |
| Message replies | ✅ |
| Join groups by invite | ✅ |
@@ -69,21 +83,17 @@ Take a look at [example.js](https://github.com/pedroslopez/whatsapp-web.js/blob/
Something missing? Make an issue and let us know!
## Links
* [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
## Supporting the project
You can support the maintainer of this project through the link below
You can support the maintainer of this project through the links below
[![Support via PayPal](https://cdn.rawgit.com/twolfson/paypal-github-button/1.0.0/dist/button.svg)](https://www.paypal.me/psla/)
- [Support via GitHub Sponsors](https://github.com/sponsors/pedroslopez)
- [Support via PayPal](https://www.paypal.me/psla/)
- [Sign up for DigitalOcean](https://m.do.co/c/73f906a36ed4) and get $100 in credit when you sign up (Referral)
## Disclaimer

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Class: Base</title>
<title>whatsapp-web.js 1.16.4 &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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -0,0 +1,65 @@
<!doctype html>
<html>
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.16.4 &raquo; Class: BaseAuthStrategy</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">
<link href="css/baseline.css" rel="stylesheet">
</head>
<body onload="prettyPrint()">
<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>16.<wbr>4</a>
</div>
</div>
</nav>
<div id="jsdoc-body-container">
<div id="jsdoc-content">
<div id="jsdoc-content-container">
<div id="jsdoc-main" role="main">
<header class="page-header">
<div class="symbol-detail-labels"><span class="label label-kind">class</span></div>
<h1><small></small><span class="symbol-name">BaseAuthStrategy</span></h1>
<p class="source-link">Source: <a href="authStrategies_BaseAuthStrategy.js.html#source-line-6">authStrategies/<wbr>BaseAuthStrategy.<wbr>js:6</a></p>
<div class="symbol-classdesc">
<p>Base class which all authentication strategies extend</p>
</div>
<dl class="dl-compact">
</dl>
</header>
<section id="summary">
</section>
<section>
<h2 id="BaseAuthStrategy">new&nbsp;<span class="symbol-name">BaseAuthStrategy</span><span class="signature"><span class="signature-params">()</span></span></h2>
<dl class="dl-compact">
</dl>
</section>
<section>
</section>
</div>
</div>
<nav id="jsdoc-toc-nav" role="navigation"></nav>
</div>
</div>
<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.7 on March 9, 2022.
</p>
</div>
</footer>
<script src="scripts/jquery.min.js"></script>
<script src="scripts/tree.jquery.js"></script>
<script src="scripts/prettify.js"></script>
<script src="scripts/jsdoc-toc.js"></script>
<script src="scripts/linenumber.js"></script>
<script src="scripts/scrollanchor.js"></script>
</body>
</html>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Class: BusinessContact</title>
<title>whatsapp-web.js 1.16.4 &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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</a>
</div>
</div>
</nav>
@@ -104,20 +104,29 @@
<dt><a href="BusinessContact.html#getAbout">getAbout()</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="BusinessContact.html#getChat">getChat()</a></dt>
<dd>
</dd>
<dt><a href="BusinessContact.html#getProfilePicUrl">getProfilePicUrl()</a></dt>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="BusinessContact.html#getCommonGroups">getCommonGroups()</a></dt>
<dd>
</dd>
<dt><a href="BusinessContact.html#getCountryCode">getCountryCode()</a></dt>
<dd>
</dd>
<dt><a href="BusinessContact.html#getFormattedNumber">getFormattedNumber()</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="BusinessContact.html#getProfilePicUrl">getProfilePicUrl()</a></dt>
<dd>
</dd>
<dt><a href="BusinessContact.html#unblock">unblock()</a></dt>
<dd>
</dd>
@@ -263,6 +272,33 @@
<dd></dd>
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="getCommonGroups"><span class="symbol-name">getCommonGroups</span><span class="signature"><span class="signature-params">()</span>&nbsp;&rarr; <span class="signature-returns"> Promise containing Array of WAWebJS.ChatId</span></span></h3>
<p>Gets the Contact's common groups with you. Returns empty array if you don't have any common group.</p>
<dl class="dl-compact">
<dt>Inherited from</dt>
<dd><a href="Contact.html#getCommonGroups">Contact#getCommonGroups</a></dd>
<dt>Returns</dt>
<dd></dd>
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="getCountryCode"><span class="symbol-name">getCountryCode</span><span class="signature"><span class="signature-params">()</span>&nbsp;&rarr; <span class="signature-returns"> Promise containing string</span></span></h3>
<p>Returns the contact's countrycode, (1541859685@c.us) =&gt; (1)</p>
<dl class="dl-compact">
<dt>Inherited from</dt>
<dd><a href="Contact.html#getCountryCode">Contact#getCountryCode</a></dd>
<dt>Returns</dt>
<dd></dd>
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="getFormattedNumber"><span class="symbol-name">getFormattedNumber</span><span class="signature"><span class="signature-params">()</span>&nbsp;&rarr; <span class="signature-returns"> Promise containing string</span></span></h3>
<p>Returns the contact's formatted phone number, (12345678901@c.us) =&gt; (+1 (234) 5678-901)</p>
<dl class="dl-compact">
<dt>Inherited from</dt>
<dd><a href="Contact.html#getFormattedNumber">Contact#getFormattedNumber</a></dd>
<dt>Returns</dt>
<dd></dd>
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="getProfilePicUrl"><span class="symbol-name">getProfilePicUrl</span><span class="signature"><span class="signature-params">()</span>&nbsp;&rarr; <span class="signature-returns"> Promise containing string</span></span></h3>
<p>Returns the contact's profile picture URL, if privacy settings allow it</p>
<dl class="dl-compact">
@@ -290,7 +326,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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

249
docs/Buttons.html Normal file
View File

@@ -0,0 +1,249 @@
<!doctype html>
<html>
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.16.4 &raquo; Class: Buttons</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">
<link href="css/baseline.css" rel="stylesheet">
</head>
<body onload="prettyPrint()">
<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>16.<wbr>4</a>
</div>
</div>
</nav>
<div id="jsdoc-body-container">
<div id="jsdoc-content">
<div id="jsdoc-content-container">
<div id="jsdoc-main" role="main">
<header class="page-header">
<div class="symbol-detail-labels"><span class="label label-kind">class</span></div>
<h1><small></small><span class="symbol-name">Buttons</span></h1>
<p class="source-link">Source: <a href="structures_Buttons.js.html#source-line-23">structures/<wbr>Buttons.<wbr>js:23</a></p>
<div class="symbol-classdesc">
<p>Message type buttons</p>
</div>
<dl class="dl-compact">
</dl>
</header>
<section id="summary">
<div class="summary-callout">
<h2 class="summary-callout-heading">Properties</h2>
<div class="summary-content">
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="Buttons.html#body">body</a></dt>
<dd>
</dd>
<dt><a href="Buttons.html#buttons">buttons</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="Buttons.html#footer">footer</a></dt>
<dd>
</dd>
<dt><a href="Buttons.html#title">title</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
</div>
</div>
</div>
<div class="summary-callout">
<h2 class="summary-callout-heading">Method</h2>
<div class="summary-content">
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="Buttons.html#_format">_format(buttons)</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
</div>
<div class="summary-column">
</div>
</div>
</div>
</section>
<section>
<h2 id="Buttons">new&nbsp;<span class="symbol-name">Buttons</span><span class="signature"><span class="signature-params">(body, buttons, title, footer)</span></span></h2>
<section>
<h3>Parameters</h3>
<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>body</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>buttons</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>See <a href="global.html#ButtonSpec"><code>ButtonSpec</code></a></p>
</td>
</tr>
<tr>
<td>
<p>title</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>Value can be null.</p>
</td>
</tr>
<tr>
<td>
<p>footer</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>Value can be null.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
</dl>
</section>
<section>
<h2>Properties</h2>
<section>
<h3 id="body"><span class="symbol-name">body</span><small class="property-type">
&nbsp;(string or <a href="MessageMedia.html">MessageMedia</a>)</small></h3>
<p>Message body</p>
<dl class="dl-compact">
</dl>
<h3 id="buttons"><span class="symbol-name">buttons</span><small class="property-type">
&nbsp;Array of <a href="global.html#FormattedButtonSpec">FormattedButtonSpec</a></small></h3>
<p>buttons of message</p>
<dl class="dl-compact">
</dl>
<h3 id="footer"><span class="symbol-name">footer</span><small class="property-type">
&nbsp;string</small></h3>
<p>footer of message</p>
<dl class="dl-compact">
</dl>
<h3 id="title"><span class="symbol-name">title</span><small class="property-type">
&nbsp;string</small></h3>
<p>title of message</p>
<dl class="dl-compact">
</dl>
</section>
<h2>Method</h2>
<section>
<h3 id="_format"><span class="symbol-name">_format</span><span class="signature"><span class="signature-params">(buttons)</span>&nbsp;&rarr; <span class="signature-returns"> Array of <a href="global.html#FormattedButtonSpec">FormattedButtonSpec</a></span></span></h3>
<p>Creates button array from simple array</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>Input: [{id:&#x27;customId&#x27;,body:&#x27;button1&#x27;},{body:&#x27;button2&#x27;},{body:&#x27;button3&#x27;},{body:&#x27;button4&#x27;}]
Returns: [{ buttonId:&#x27;customId&#x27;,buttonText:{&#x27;displayText&#x27;:&#x27;button1&#x27;},type: 1 },{buttonId:&#x27;n3XKsL&#x27;,buttonText:{&#x27;displayText&#x27;:&#x27;button2&#x27;},type:1},{buttonId:&#x27;NDJk0a&#x27;,buttonText:{&#x27;displayText&#x27;:&#x27;button3&#x27;},type:1}]</code></pre>
</div>
</section>
<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>buttons</p>
</td>
<td>
<p>Array of <a href="global.html#ButtonSpec">ButtonSpec</a></p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Array of <a href="global.html#FormattedButtonSpec">FormattedButtonSpec</a></code> </p>
</dd>
</dl>
</section>
</section>
</div>
</div>
<nav id="jsdoc-toc-nav" role="navigation"></nav>
</div>
</div>
<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.7 on March 9, 2022.
</p>
</div>
</footer>
<script src="scripts/jquery.min.js"></script>
<script src="scripts/tree.jquery.js"></script>
<script src="scripts/prettify.js"></script>
<script src="scripts/jsdoc-toc.js"></script>
<script src="scripts/linenumber.js"></script>
<script src="scripts/scrollanchor.js"></script>
</body>
</html>

1
docs/CNAME Normal file
View File

@@ -0,0 +1 @@
docs.wwebjs.dev

159
docs/Call.html Normal file
View File

@@ -0,0 +1,159 @@
<!doctype html>
<html>
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.16.4 &raquo; Class: Call</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">
<link href="css/baseline.css" rel="stylesheet">
</head>
<body onload="prettyPrint()">
<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>16.<wbr>4</a>
</div>
</div>
</nav>
<div id="jsdoc-body-container">
<div id="jsdoc-content">
<div id="jsdoc-content-container">
<div id="jsdoc-main" role="main">
<header class="page-header">
<div class="symbol-detail-labels"><span class="label label-kind">class</span></div>
<h1><small></small><span class="symbol-name">Call</span></h1>
<p class="source-link">Source: <a href="structures_Call.js.html#source-line-9">structures/<wbr>Call.<wbr>js:9</a></p>
<div class="symbol-classdesc">
<p>Represents a Call on WhatsApp</p>
</div>
<dl class="dl-compact">
</dl>
</header>
<section id="summary">
<div class="summary-callout">
<h2 class="summary-callout-heading">Properties</h2>
<div class="summary-content">
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="Call.html#canHandleLocally">canHandleLocally</a></dt>
<dd>
</dd>
<dt><a href="Call.html#from">from</a></dt>
<dd>
</dd>
<dt><a href="Call.html#fromMe">fromMe</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="Call.html#id">id</a></dt>
<dd>
</dd>
<dt><a href="Call.html#isGroup">isGroup</a></dt>
<dd>
</dd>
<dt><a href="Call.html#isVideo">isVideo</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="Call.html#participants">participants</a></dt>
<dd>
</dd>
<dt><a href="Call.html#timestamp">timestamp</a></dt>
<dd>
</dd>
<dt><a href="Call.html#webClientShouldHandle">webClientShouldHandle</a></dt>
<dd>
</dd>
</dl>
</div>
</div>
</div>
</section>
<section>
<h2 id="Call">new&nbsp;<span class="symbol-name">Call</span><span class="signature"><span class="signature-params">()</span></span></h2>
<dl class="dl-compact">
<dt>Extends</dt>
<dd><a href="Base.html">Base</a></dd>
</dl>
</section>
<section>
<h2>Properties</h2>
<section>
<h3 id="canHandleLocally"><span class="symbol-name">canHandleLocally</span><small class="property-type">
&nbsp;boolean</small></h3>
<p>Indicates if the call can be handled in waweb</p>
<dl class="dl-compact">
</dl>
<h3 id="from"><span class="symbol-name">from</span><small class="property-type">
&nbsp;string</small></h3>
<p>From</p>
<dl class="dl-compact">
</dl>
<h3 id="fromMe"><span class="symbol-name">fromMe</span><small class="property-type">
&nbsp;boolean</small></h3>
<p>Indicates if the call was sent by the current user</p>
<dl class="dl-compact">
</dl>
<h3 id="id"><span class="symbol-name">id</span><small class="property-type">
&nbsp;string</small></h3>
<p>Call ID</p>
<dl class="dl-compact">
</dl>
<h3 id="isGroup"><span class="symbol-name">isGroup</span><small class="property-type">
&nbsp;boolean</small></h3>
<p>Is Group</p>
<dl class="dl-compact">
</dl>
<h3 id="isVideo"><span class="symbol-name">isVideo</span><small class="property-type">
&nbsp;boolean</small></h3>
<p>Is video</p>
<dl class="dl-compact">
</dl>
<h3 id="participants"><span class="symbol-name">participants</span><small class="property-type">
&nbsp;object</small></h3>
<p>Object with participants</p>
<dl class="dl-compact">
</dl>
<h3 id="timestamp"><span class="symbol-name">timestamp</span><small class="property-type">
&nbsp;number</small></h3>
<p>Unix timestamp for when the call was created</p>
<dl class="dl-compact">
</dl>
<h3 id="webClientShouldHandle"><span class="symbol-name">webClientShouldHandle</span><small class="property-type">
&nbsp;boolean</small></h3>
<p>Indicates if the call Should be handled in waweb</p>
<dl class="dl-compact">
</dl>
</section>
</section>
</div>
</div>
<nav id="jsdoc-toc-nav" role="navigation"></nav>
</div>
</div>
<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.7 on March 9, 2022.
</p>
</div>
</footer>
<script src="scripts/jquery.min.js"></script>
<script src="scripts/tree.jquery.js"></script>
<script src="scripts/prettify.js"></script>
<script src="scripts/jsdoc-toc.js"></script>
<script src="scripts/linenumber.js"></script>
<script src="scripts/scrollanchor.js"></script>
</body>
</html>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Class: Chat</title>
<title>whatsapp-web.js 1.16.4 &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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</a>
</div>
</div>
</nav>
@@ -176,7 +176,7 @@
<dl class="dl-compact">
</dl>
<h3 id="isMuted"><span class="symbol-name">isMuted</span><small class="property-type">
&nbsp;number</small></h3>
&nbsp;boolean</small></h3>
<p>Indicates if the chat is muted or not</p>
<dl class="dl-compact">
</dl>
@@ -224,7 +224,8 @@
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Promise containing Boolean</code> <p>result</p>
<p><code>Promise containing Boolean</code> 
<p>result</p>
</p>
</dd>
</dl>
@@ -239,7 +240,8 @@
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Promise containing Boolean</code> <p>result</p>
<p><code>Promise containing Boolean</code> 
<p>result</p>
</p>
</dd>
</dl>
@@ -292,8 +294,7 @@
<p>Yes</p>
</td>
<td>
<p>The amount of messages to return. Note that the actual number of returned messages may be smaller if there aren't enough messages in the conversation. Set this to Infinity to load all messages.</p>
<p>Defaults to <code>50</code>.</p>
<p>The amount of messages to return. If no limit is specified, the available messages will be returned. Note that the actual number of returned messages may be smaller if there aren't enough messages in the conversation. Set this to Infinity to load all messages.</p>
</td>
</tr>
</tbody>
@@ -334,7 +335,7 @@
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="mute"><span class="symbol-name">mute</span><span class="signature"><span class="signature-params">(unmuteDate)</span></span></h3>
<p>Mutes this chat until a specified date</p>
<p>Mutes this chat forever, unless a date is specified</p>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
@@ -358,7 +359,8 @@
<p>&nbsp;</p>
</td>
<td>
<p>Date at which the Chat will be unmuted</p>
<p>Date at which the Chat will be unmuted, leave as is to mute forever</p>
<p>Value can be null.</p>
</td>
</tr>
</tbody>
@@ -372,7 +374,8 @@
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Promise containing boolean</code> <p>New pin state. Could be false if the max number of pinned chats was reached.</p>
<p><code>Promise containing boolean</code> 
<p>New pin state. Could be false if the max number of pinned chats was reached.</p>
</p>
</dd>
</dl>
@@ -423,7 +426,8 @@
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Promise containing <a href="Message.html">Message</a></code> <p>Message that was just sent</p>
<p><code>Promise containing <a href="Message.html">Message</a></code> 
<p>Message that was just sent</p>
</p>
</dd>
</dl>
@@ -433,7 +437,8 @@
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Promise containing Boolean</code> <p>result</p>
<p><code>Promise containing Boolean</code> 
<p>result</p>
</p>
</dd>
</dl>
@@ -463,7 +468,8 @@
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Promise containing boolean</code> <p>New pin state</p>
<p><code>Promise containing boolean</code> 
<p>New pin state</p>
</p>
</dd>
</dl>
@@ -477,7 +483,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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Class: Client</title>
<title>whatsapp-web.js 1.16.4 &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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</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-52">Client.<wbr>js:52</a></p>
<p class="source-link">Source: <a href="Client.js.html#source-line-49">Client.<wbr>js:49</a></p>
<div class="symbol-classdesc">
<p>Starting point for interacting with the WhatsApp Web API</p>
</div>
@@ -55,7 +55,7 @@
<div class="summary-content">
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="Client.html#acceptGroupV4Invite">acceptGroupV4Invite(inviteV4)</a></dt>
<dt><a href="Client.html#acceptGroupV4Invite">acceptGroupV4Invite(inviteInfo)</a></dt>
<dd>
</dd>
<dt><a href="Client.html#acceptInvite">acceptInvite(inviteCode)</a></dt>
@@ -70,6 +70,9 @@
<dt><a href="Client.html#destroy">destroy()</a></dt>
<dd>
</dd>
<dt><a href="Client.html#getBlockedContacts">getBlockedContacts()</a></dt>
<dd>
</dd>
<dt><a href="Client.html#getChatById">getChatById(chatId)</a></dt>
<dd>
</dd>
@@ -82,19 +85,28 @@
<dt><a href="Client.html#getChatsByLabelId">getChatsByLabelId(labelId)</a></dt>
<dd>
</dd>
<dt><a href="Client.html#getCommonGroups">getCommonGroups(contactId)</a></dt>
<dd>
</dd>
<dt><a href="Client.html#getContactById">getContactById(contactId)</a></dt>
<dd>
</dd>
<dt><a href="Client.html#getContacts">getContacts()</a></dt>
<dd>
</dd>
<dt><a href="Client.html#getInviteInfo">getInviteInfo(inviteCode)</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="Client.html#getCountryCode">getCountryCode(number)</a></dt>
<dd>
</dd>
<dt><a href="Client.html#getFormattedNumber">getFormattedNumber(number)</a></dt>
<dd>
</dd>
<dt><a href="Client.html#getInviteInfo">getInviteInfo(inviteCode)</a></dt>
<dd>
</dd>
<dt><a href="Client.html#getLabelById">getLabelById(labelId)</a></dt>
<dd>
</dd>
@@ -125,16 +137,16 @@
<dt><a href="Client.html#markChatUnread">markChatUnread(chatId)</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="Client.html#muteChat">muteChat(chatId, unmuteDate)</a></dt>
<dd>
</dd>
<dt><a href="Client.html#pinChat">pinChat()</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="Client.html#resetState">resetState()</a></dt>
<dd>
</dd>
@@ -147,6 +159,9 @@
<dt><a href="Client.html#sendPresenceAvailable">sendPresenceAvailable()</a></dt>
<dd>
</dd>
<dt><a href="Client.html#sendPresenceUnavailable">sendPresenceUnavailable()</a></dt>
<dd>
</dd>
<dt><a href="Client.html#sendSeen">sendSeen(chatId)</a></dt>
<dd>
</dd>
@@ -202,6 +217,9 @@
<dt><a href="Client.html#event:group_update">group_update</a></dt>
<dd>
</dd>
<dt><a href="Client.html#event:incoming_call">incoming_call</a></dt>
<dd>
</dd>
<dt><a href="Client.html#event:media_uploaded">media_uploaded</a></dt>
<dd>
</dd>
@@ -211,13 +229,13 @@
<dt><a href="Client.html#event:message_ack">message_ack</a></dt>
<dd>
</dd>
<dt><a href="Client.html#event:message_create">message_create</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="Client.html#event:message_create">message_create</a></dt>
<dd>
</dd>
<dt><a href="Client.html#event:message_revoke_everyone">message_revoke_everyone</a></dt>
<dd>
</dd>
@@ -272,6 +290,20 @@
</tr>
</thead>
<tbody>
<tr>
<td>
<p>authStrategy</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>Determines how to save and restore sessions. Will use LegacySessionAuth if options.session is set. Otherwise, NoAuth will be used.</p>
</td>
</tr>
<tr>
<td>
<p>authTimeoutMs</p>
@@ -302,7 +334,7 @@
</tr>
<tr>
<td>
<p>qrRefreshIntervalMs</p>
<p>qrMaxRetries</p>
</td>
<td>
<p>&nbsp;</p>
@@ -311,21 +343,7 @@
<p>&nbsp;</p>
</td>
<td>
<p>Refresh interval for qr code (how much time to wait before checking if the qr code has changed)</p>
</td>
</tr>
<tr>
<td>
<p>qrTimeoutMs</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>Timeout for qr code selector in puppeteer</p>
<p>How many times should the qrcode be refreshed before giving up</p>
</td>
</tr>
<tr>
@@ -339,7 +357,7 @@
<p>&nbsp;</p>
</td>
<td>
<p>Restart client with a new session (i.e. use null 'session' var) if authentication fails</p>
<p>@deprecated This option should be set directly on the LegacySessionAuth.</p>
</td>
</tr>
<tr>
@@ -353,59 +371,7 @@
<p>&nbsp;</p>
</td>
<td>
<p>Whatsapp session to restore. If not set, will start a new session</p>
</td>
</tr>
<tr>
<td>
<p>session.WABrowserId</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>session.WASecretBundle</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>session.WAToken1</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>session.WAToken2</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>@deprecated Only here for backwards-compatibility. You should move to using LocalAuth, or set the authStrategy to LegacySessionAuth explicitly.</p>
</td>
</tr>
<tr>
@@ -504,7 +470,6 @@
<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>
@@ -519,7 +484,7 @@
<h2>Methods</h2>
<section>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="acceptGroupV4Invite"><span class="symbol-name">acceptGroupV4Invite</span><span class="signature"><span class="signature-params">(inviteV4)</span>&nbsp;&rarr; <span class="signature-returns"> Promise containing Object</span></span></h3>
<h3 id="acceptGroupV4Invite"><span class="symbol-name">acceptGroupV4Invite</span><span class="signature"><span class="signature-params">(inviteInfo)</span>&nbsp;&rarr; <span class="signature-returns"> Promise containing Object</span></span></h3>
<p>Accepts a private invitation to join a group</p>
<section>
<h4>Parameter</h4>
@@ -535,7 +500,7 @@
<tbody>
<tr>
<td>
<p>inviteV4</p>
<p>inviteInfo</p>
</td>
<td>
<p>object</p>
@@ -591,7 +556,8 @@
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Promise containing string</code> <p>Id of the joined Chat</p>
<p><code>Promise containing string</code> 
<p>Id of the joined Chat</p>
</p>
</dd>
</dl>
@@ -653,15 +619,18 @@
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Object</code> <p>createRes</p>
<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><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><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>
@@ -671,6 +640,15 @@
<dl class="dl-compact">
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="getBlockedContacts"><span class="symbol-name">getBlockedContacts</span><span class="signature"><span class="signature-params">()</span>&nbsp;&rarr; <span class="signature-returns"> Promise containing Array of <a href="Contact.html">Contact</a></span></span></h3>
<p>Gets all blocked contacts by host account</p>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Promise containing Array of <a href="Contact.html">Contact</a></code> </p>
</dd>
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="getChatById"><span class="symbol-name">getChatById</span><span class="signature"><span class="signature-params">(chatId)</span>&nbsp;&rarr; <span class="signature-returns"> Promise containing <a href="Chat.html">Chat</a></span></span></h3>
<p>Get chat instance by ID</p>
<section>
@@ -791,6 +769,44 @@
</dd>
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="getCommonGroups"><span class="symbol-name">getCommonGroups</span><span class="signature"><span class="signature-params">(contactId)</span>&nbsp;&rarr; <span class="signature-returns"> Promise containing Array of WAWebJS.ChatId</span></span></h3>
<p>Gets the Contact's common groups with you. Returns empty array if you don't have any common group.</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>contactId</p>
</td>
<td>
<p>string</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>the whatsapp user's ID (_serialized format)</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Promise containing Array of WAWebJS.ChatId</code> </p>
</dd>
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="getContactById"><span class="symbol-name">getContactById</span><span class="signature"><span class="signature-params">(contactId)</span>&nbsp;&rarr; <span class="signature-returns"> Promise containing <a href="Contact.html">Contact</a></span></span></h3>
<p>Get contact instance by ID</p>
<section>
@@ -837,6 +853,82 @@
</dd>
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="getCountryCode"><span class="symbol-name">getCountryCode</span><span class="signature"><span class="signature-params">(number)</span>&nbsp;&rarr; <span class="signature-returns"> Promise containing string</span></span></h3>
<p>Get the country code of a WhatsApp ID.</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>number</p>
</td>
<td>
<p>string</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>Number or ID</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Promise containing string</code> </p>
</dd>
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="getFormattedNumber"><span class="symbol-name">getFormattedNumber</span><span class="signature"><span class="signature-params">(number)</span>&nbsp;&rarr; <span class="signature-returns"> Promise containing string</span></span></h3>
<p>Get the formatted number of a WhatsApp ID.</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>number</p>
</td>
<td>
<p>string</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>Number or ID</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Promise containing string</code> </p>
</dd>
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="getInviteInfo"><span class="symbol-name">getInviteInfo</span><span class="signature"><span class="signature-params">(inviteCode)</span>&nbsp;&rarr; <span class="signature-returns"> Promise containing object</span></span></h3>
<p>Returns an object with information about the invite code's group</p>
<section>
@@ -870,7 +962,8 @@
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Promise containing object</code> <p>Invite information</p>
<p><code>Promise containing object</code> 
<p>Invite information</p>
</p>
</dd>
</dl>
@@ -1099,7 +1192,7 @@
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="muteChat"><span class="symbol-name">muteChat</span><span class="signature"><span class="signature-params">(chatId, unmuteDate)</span></span></h3>
<p>Mutes the Chat until a specified date</p>
<p>Mutes this chat forever, unless a date is specified</p>
<section>
<h4>Parameters</h4>
<table class="jsdoc-details-table">
@@ -1137,7 +1230,8 @@
<p>&nbsp;</p>
</td>
<td>
<p>Date when the chat will be unmuted</p>
<p>Date when the chat will be unmuted, leave as is to mute forever</p>
<p>Value can be null.</p>
</td>
</tr>
</tbody>
@@ -1151,7 +1245,8 @@
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Promise containing boolean</code> <p>New pin state. Could be false if the max number of pinned chats was reached.</p>
<p><code>Promise containing boolean</code> 
<p>New pin state. Could be false if the max number of pinned chats was reached.</p>
</p>
</dd>
</dl>
@@ -1295,7 +1390,7 @@
<p>content</p>
</td>
<td>
<p>(string, <a href="MessageMedia.html">MessageMedia</a>, <a href="Location.html">Location</a>, <a href="Contact.html">Contact</a>, or Array of <a href="Contact.html">Contact</a>)</p>
<p>(string, <a href="MessageMedia.html">MessageMedia</a>, <a href="Location.html">Location</a>, <a href="Contact.html">Contact</a>, Array of <a href="Contact.html">Contact</a>, <a href="Buttons.html">Buttons</a>, or <a href="List.html">List</a>)</p>
</td>
<td>
<p>&nbsp;</p>
@@ -1323,7 +1418,8 @@
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Promise containing <a href="Message.html">Message</a></code> <p>Message that was just sent</p>
<p><code>Promise containing <a href="Message.html">Message</a></code> 
<p>Message that was just sent</p>
</p>
</dd>
</dl>
@@ -1333,6 +1429,11 @@
<dl class="dl-compact">
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="sendPresenceUnavailable"><span class="symbol-name">sendPresenceUnavailable</span><span class="signature"><span class="signature-params">()</span></span></h3>
<p>Marks the client as unavailable</p>
<dl class="dl-compact">
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="sendSeen"><span class="symbol-name">sendSeen</span><span class="signature"><span class="signature-params">(chatId)</span>&nbsp;&rarr; <span class="signature-returns"> Promise containing boolean</span></span></h3>
<p>Mark as seen for the Chat</p>
<section>
@@ -1366,12 +1467,13 @@
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Promise containing boolean</code> <p>result</p>
<p><code>Promise containing boolean</code> 
<p>result</p>
</p>
</dd>
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="setDisplayName"><span class="symbol-name">setDisplayName</span><span class="signature"><span class="signature-params">(displayName)</span></span></h3>
<h3 id="setDisplayName"><span class="symbol-name">setDisplayName</span><span class="signature"><span class="signature-params">(displayName)</span>&nbsp;&rarr; <span class="signature-returns"> Promise containing Boolean</span></span></h3>
<p>Sets the current user's display name.
This is the name shown to WhatsApp users that have not added you as a contact beside your number in groups and in your profile.</p>
<section>
@@ -1404,6 +1506,10 @@
</table>
</section>
<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="setStatus"><span class="symbol-name">setStatus</span><span class="signature"><span class="signature-params">(status)</span></span></h3>
@@ -1488,7 +1594,8 @@
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Promise containing boolean</code> <p>New pin state</p>
<p><code>Promise containing boolean</code> 
<p>New pin state</p>
</p>
</dd>
</dl>
@@ -1529,104 +1636,10 @@
</dl>
<h3 id="event:authenticated"><span class="symbol-name">authenticated</span></h3>
<p>Emitted when authentication is successful</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>session</p>
</td>
<td>
<p>object</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>Object containing session information. Can be used to restore the session.</p>
<p>Values in <code>session</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>WABrowserId</p>
</td>
<td>
<p>string</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>WASecretBundle</p>
</td>
<td>
<p>string</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>WAToken1</p>
</td>
<td>
<p>string</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>WAToken2</p>
</td>
<td>
<p>string</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</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>
<p>Emitted when the battery percentage for the attached device changes. Will not be sent if using multi-device.</p>
<section>
<h4>Parameters</h4>
<table class="jsdoc-details-table">
@@ -1697,6 +1710,8 @@
</table>
</section>
<dl class="dl-compact">
<dt>Deprecated</dt>
<dd></dd>
</dl>
<h3 id="event:change_state"><span class="symbol-name">change_state</span></h3>
<p>Emitted when the connection state changes</p>
@@ -1863,6 +1878,163 @@
</section>
<dl class="dl-compact">
</dl>
<h3 id="event:incoming_call"><span class="symbol-name">incoming_call</span></h3>
<p>Emitted when a call is received</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>call</p>
</td>
<td>
<p>object</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>Values in <code>call</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>id</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>Call id</p>
</td>
</tr>
<tr>
<td>
<p>peerJid</p>
</td>
<td>
<p>string</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>Who called</p>
</td>
</tr>
<tr>
<td>
<p>isVideo</p>
</td>
<td>
<p>boolean</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>if is video</p>
</td>
</tr>
<tr>
<td>
<p>isGroup</p>
</td>
<td>
<p>boolean</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>if is group</p>
</td>
</tr>
<tr>
<td>
<p>canHandleLocally</p>
</td>
<td>
<p>boolean</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>if we can handle in waweb</p>
</td>
</tr>
<tr>
<td>
<p>outgoing</p>
</td>
<td>
<p>boolean</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>if is outgoing</p>
</td>
</tr>
<tr>
<td>
<p>webClientShouldHandle</p>
</td>
<td>
<p>boolean</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>If Waweb should handle</p>
</td>
</tr>
<tr>
<td>
<p>participants</p>
</td>
<td>
<p>object</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>Participants</p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</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>
@@ -2092,7 +2264,7 @@
<dl class="dl-compact">
</dl>
<h3 id="event:qr"><span class="symbol-name">qr</span></h3>
<p>Emitted when the QR code is received</p>
<p>Emitted when a QR code is received</p>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
@@ -2138,7 +2310,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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Source: Client.js</title>
<title>whatsapp-web.js 1.16.4 &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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</a>
</div>
</div>
</nav>
@@ -34,7 +34,6 @@
const EventEmitter &#x3D; require(&#x27;events&#x27;);
const puppeteer &#x3D; require(&#x27;puppeteer&#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;);
const InterfaceController &#x3D; require(&#x27;./util/InterfaceController&#x27;);
@@ -42,21 +41,20 @@ const { WhatsWebURL, DefaultOptions, Events, WAState } &#x3D; require(&#x27;./ut
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, Contact, Location, GroupNotification , Label } &#x3D; require(&#x27;./structures&#x27;);
const { ClientInfo, Message, MessageMedia, Contact, Location, GroupNotification, Label, Call, Buttons, List } &#x3D; require(&#x27;./structures&#x27;);
const LegacySessionAuth &#x3D; require(&#x27;./authStrategies/LegacySessionAuth&#x27;);
const NoAuth &#x3D; require(&#x27;./authStrategies/NoAuth&#x27;);
/**
* Starting point for interacting with the WhatsApp Web API
* @extends {EventEmitter}
* @param {object} options - Client options
* @param {AuthStrategy} options.authStrategy - Determines how to save and restore sessions. Will use LegacySessionAuth if options.session is set. Otherwise, NoAuth will be used.
* @param {number} options.authTimeoutMs - Timeout for authentication selector in puppeteer
* @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 {string} options.restartOnAuthFail - Restart client with a new session (i.e. use null &#x27;session&#x27; 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
* @param {string} options.session.WASecretBundle
* @param {string} options.session.WAToken1
* @param {string} options.session.WAToken2
* @param {number} options.qrMaxRetries - How many times should the qrcode be refreshed before giving up
* @param {string} options.restartOnAuthFail - @deprecated This option should be set directly on the LegacySessionAuth.
* @param {object} options.session - @deprecated Only here for backwards-compatibility. You should move to using LocalAuth, or set the authStrategy to LegacySessionAuth explicitly.
* @param {number} options.takeoverOnConflict - If another whatsapp web session is detected (another browser), take over the session in the current browser
* @param {number} options.takeoverTimeoutMs - How much time to wait before taking over the session
* @param {string} options.userAgent - User agent to use in puppeteer
@@ -78,13 +76,33 @@ const { ClientInfo, Message, MessageMedia, Contact, Location, GroupNotification
* @fires Client#group_update
* @fires Client#disconnected
* @fires Client#change_state
* @fires Client#change_battery
*/
class Client extends EventEmitter {
constructor(options &#x3D; {}) {
super();
this.options &#x3D; Util.mergeDefault(DefaultOptions, options);
if(!this.options.authStrategy) {
if(Object.prototype.hasOwnProperty.call(this.options, &#x27;session&#x27;)) {
process.emitWarning(
&#x27;options.session is deprecated and will be removed in a future release due to incompatibility with multi-device. &#x27; +
&#x27;Use the LocalAuth authStrategy, don\&#x27;t pass in a session as an option, or suppress this warning by using the LegacySessionAuth strategy explicitly (see https://wwebjs.dev/guide/authentication.html#legacysessionauth-strategy).&#x27;,
&#x27;DeprecationWarning&#x27;
);
this.authStrategy &#x3D; new LegacySessionAuth({
session: this.options.session,
restartOnAuthFail: this.options.restartOnAuthFail
});
} else {
this.authStrategy &#x3D; new NoAuth();
}
} else {
this.authStrategy &#x3D; this.options.authStrategy;
}
this.authStrategy.setup(this);
this.pupBrowser &#x3D; null;
this.pupPage &#x3D; null;
@@ -96,119 +114,156 @@ class Client extends EventEmitter {
* Sets up events and requirements, kicks off authentication request
*/
async initialize() {
const browser &#x3D; await puppeteer.launch(this.options.puppeteer);
const page &#x3D; (await browser.pages())[0];
page.setUserAgent(this.options.userAgent);
let [browser, page] &#x3D; [null, null];
await this.authStrategy.beforeBrowserInitialized();
const puppeteerOpts &#x3D; this.options.puppeteer;
if (puppeteerOpts &amp;amp;&amp;amp; puppeteerOpts.browserWSEndpoint) {
browser &#x3D; await puppeteer.connect(puppeteerOpts);
page &#x3D; await browser.newPage();
} else {
browser &#x3D; await puppeteer.launch(puppeteerOpts);
page &#x3D; (await browser.pages())[0];
}
await page.setUserAgent(this.options.userAgent);
if (this.options.bypassCSP) await page.setBypassCSP(true);
this.pupBrowser &#x3D; browser;
this.pupPage &#x3D; page;
if (this.options.session) {
await page.evaluateOnNewDocument(
session &#x3D;&gt; {
localStorage.clear();
localStorage.setItem(&#x27;WABrowserId&#x27;, session.WABrowserId);
localStorage.setItem(&#x27;WASecretBundle&#x27;, session.WASecretBundle);
localStorage.setItem(&#x27;WAToken1&#x27;, session.WAToken1);
localStorage.setItem(&#x27;WAToken2&#x27;, session.WAToken2);
}, this.options.session);
}
if(this.options.bypassCSP) {
await page.setBypassCSP(true);
}
await this.authStrategy.afterBrowserInitialized();
await page.goto(WhatsWebURL, {
waitUntil: &#x27;load&#x27;,
timeout: 0,
referer: &#x27;https://whatsapp.com/&#x27;
});
const KEEP_PHONE_CONNECTED_IMG_SELECTOR &#x3D; &#x27;[data-asset-intro-image-light&#x3D;&quot;true&quot;], [data-asset-intro-image-dark&#x3D;&quot;true&quot;]&#x27;;
const INTRO_IMG_SELECTOR &#x3D; &#x27;[data-testid&#x3D;&quot;intro-md-beta-logo-dark&quot;], [data-testid&#x3D;&quot;intro-md-beta-logo-light&quot;], [data-asset-intro-image-light&#x3D;&quot;true&quot;], [data-asset-intro-image-dark&#x3D;&quot;true&quot;]&#x27;;
const INTRO_QRCODE_SELECTOR &#x3D; &#x27;div[data-ref] canvas&#x27;;
if (this.options.session) {
// Check if session restore was successfull
try {
await page.waitForSelector(KEEP_PHONE_CONNECTED_IMG_SELECTOR, { timeout: this.options.authTimeoutMs });
} catch (err) {
if (err.name &#x3D;&#x3D;&#x3D; &#x27;TimeoutError&#x27;) {
/**
* Emitted when there has been an error while trying to restore an existing session
* @event Client#auth_failure
* @param {string} message
*/
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;
// Checks which selector appears first
const needAuthentication &#x3D; await Promise.race([
new Promise(resolve &#x3D;&gt; {
page.waitForSelector(INTRO_IMG_SELECTOR, { timeout: this.options.authTimeoutMs })
.then(() &#x3D;&gt; resolve(false))
.catch((err) &#x3D;&gt; resolve(err));
}),
new Promise(resolve &#x3D;&gt; {
page.waitForSelector(INTRO_QRCODE_SELECTOR, { timeout: this.options.authTimeoutMs })
.then(() &#x3D;&gt; resolve(true))
.catch((err) &#x3D;&gt; resolve(err));
})
]);
// Checks if an error ocurred on the first found selector. The second will be discarded and ignored by .race;
if (needAuthentication instanceof Error) throw needAuthentication;
// Scan-qrcode selector was found. Needs authentication
if (needAuthentication) {
const { failed, failureEventPayload, restart } &#x3D; await this.authStrategy.onAuthenticationNeeded();
if(failed) {
/**
* Emitted when there has been an error while trying to restore an existing session
* @event Client#auth_failure
* @param {string} message
*/
this.emit(Events.AUTHENTICATION_FAILURE, failureEventPayload);
await this.destroy();
if (restart) {
// session restore failed so try again but without session to force new authentication
return this.initialize();
}
throw err;
return;
}
} else {
const getQrCode &#x3D; async () &#x3D;&gt; {
// Check if retry button is present
var QR_RETRY_SELECTOR &#x3D; &#x27;div[data-ref] &gt; span &gt; button&#x27;;
var qrRetry &#x3D; await page.$(QR_RETRY_SELECTOR);
if (qrRetry) {
await qrRetry.click();
}
// Wait for QR Code
const QR_CANVAS_SELECTOR &#x3D; &#x27;canvas&#x27;;
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;
const QR_CONTAINER &#x3D; &#x27;div[data-ref]&#x27;;
const QR_RETRY_BUTTON &#x3D; &#x27;div[data-ref] &gt; span &gt; button&#x27;;
let qrRetries &#x3D; 0;
await page.exposeFunction(&#x27;qrChanged&#x27;, async (qr) &#x3D;&gt; {
/**
* Emitted when the QR code is received
* Emitted when a QR code is received
* @event Client#qr
* @param {string} qr QR Code
*/
this.emit(Events.QR_RECEIVED, qr);
};
getQrCode();
this._qrRefreshInterval &#x3D; setInterval(getQrCode, this.options.qrRefreshIntervalMs);
if (this.options.qrMaxRetries &gt; 0) {
qrRetries++;
if (qrRetries &gt; this.options.qrMaxRetries) {
this.emit(Events.DISCONNECTED, &#x27;Max qrcode retries reached&#x27;);
await this.destroy();
}
}
});
await page.evaluate(function (selectors) {
const qr_container &#x3D; document.querySelector(selectors.QR_CONTAINER);
window.qrChanged(qr_container.dataset.ref);
const obs &#x3D; new MutationObserver((muts) &#x3D;&gt; {
muts.forEach(mut &#x3D;&gt; {
// Listens to qr token change
if (mut.type &#x3D;&#x3D;&#x3D; &#x27;attributes&#x27; &amp;amp;&amp;amp; mut.attributeName &#x3D;&#x3D;&#x3D; &#x27;data-ref&#x27;) {
window.qrChanged(mut.target.dataset.ref);
} else
// Listens to retry button, when found, click it
if (mut.type &#x3D;&#x3D;&#x3D; &#x27;childList&#x27;) {
const retry_button &#x3D; document.querySelector(selectors.QR_RETRY_BUTTON);
if (retry_button) retry_button.click();
}
});
});
obs.observe(qr_container.parentElement, {
subtree: true,
childList: true,
attributes: true,
attributeFilter: [&#x27;data-ref&#x27;],
});
}, {
QR_CONTAINER,
QR_RETRY_BUTTON
});
// Wait for code scan
await page.waitForSelector(KEEP_PHONE_CONNECTED_IMG_SELECTOR, { timeout: 0 });
clearInterval(this._qrRefreshInterval);
this._qrRefreshInterval &#x3D; undefined;
try {
await page.waitForSelector(INTRO_IMG_SELECTOR, { timeout: 0 });
} catch(error) {
if (
error.name &#x3D;&#x3D;&#x3D; &#x27;ProtocolError&#x27; &amp;amp;&amp;amp;
error.message &amp;amp;&amp;amp;
error.message.match(/Target closed/)
) {
// something has called .destroy() while waiting
return;
}
throw error;
}
}
await page.evaluate(ExposeStore, moduleRaid.toString());
// Get session tokens
const localStorage &#x3D; JSON.parse(await page.evaluate(() &#x3D;&gt; {
return JSON.stringify(window.localStorage);
}));
const session &#x3D; {
WABrowserId: localStorage.WABrowserId,
WASecretBundle: localStorage.WASecretBundle,
WAToken1: localStorage.WAToken1,
WAToken2: localStorage.WAToken2
};
const authEventPayload &#x3D; await this.authStrategy.getAuthEventPayload();
/**
* Emitted when authentication is successful
* @event Client#authenticated
* @param {object} session Object containing session information. Can be used to restore the session.
* @param {string} session.WABrowserId
* @param {string} session.WASecretBundle
* @param {string} session.WAToken1
* @param {string} session.WAToken2
*/
this.emit(Events.AUTHENTICATED, session);
this.emit(Events.AUTHENTICATED, authEventPayload);
// Check window.Store Injection
await page.waitForFunction(&#x27;window.Store !&#x3D; undefined&#x27;);
await page.evaluate(async () &#x3D;&gt; {
// safely unregister service workers
const registrations &#x3D; await navigator.serviceWorker.getRegistrations();
for (let registration of registrations) {
registration.unregister();
}
});
//Load util functions (serializers, helper functions)
await page.evaluate(LoadUtils);
@@ -218,7 +273,7 @@ class Client extends EventEmitter {
* @type {ClientInfo}
*/
this.info &#x3D; new ClientInfo(this, await page.evaluate(() &#x3D;&gt; {
return window.Store.Conn.serialize();
return { ...window.Store.Conn.serialize(), wid: window.Store.User.getMeUser() };
}));
// Add InterfaceController
@@ -226,8 +281,6 @@ class Client extends EventEmitter {
// Register events
await page.exposeFunction(&#x27;onAddMessageEvent&#x27;, msg &#x3D;&gt; {
if (!msg.isNewMsg) return;
if (msg.type &#x3D;&#x3D;&#x3D; &#x27;gp2&#x27;) {
const notification &#x3D; new GroupNotification(this, msg);
if (msg.subtype &#x3D;&#x3D;&#x3D; &#x27;add&#x27; || msg.subtype &#x3D;&#x3D;&#x3D; &#x27;invite&#x27;) {
@@ -384,24 +437,53 @@ class Client extends EventEmitter {
if (battery &#x3D;&#x3D;&#x3D; undefined) return;
/**
* Emitted when the battery percentage for the attached device changes
* Emitted when the battery percentage for the attached device changes. Will not be sent if using multi-device.
* @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)
* @deprecated
*/
this.emit(Events.BATTERY_CHANGED, { battery, plugged });
});
await page.exposeFunction(&#x27;onIncomingCall&#x27;, (call) &#x3D;&gt; {
/**
* Emitted when a call is received
* @event Client#incoming_call
* @param {object} call
* @param {number} call.id - Call id
* @param {string} call.peerJid - Who called
* @param {boolean} call.isVideo - if is video
* @param {boolean} call.isGroup - if is group
* @param {boolean} call.canHandleLocally - if we can handle in waweb
* @param {boolean} call.outgoing - if is outgoing
* @param {boolean} call.webClientShouldHandle - If Waweb should handle
* @param {object} call.participants - Participants
*/
const cll &#x3D; new Call(this, call);
this.emit(Events.INCOMING_CALL, cll);
});
await page.evaluate(() &#x3D;&gt; {
window.Store.Msg.on(&#x27;add&#x27;, (msg) &#x3D;&gt; { if (msg.isNewMsg) window.onAddMessageEvent(window.WWebJS.getMessageModel(msg)); });
window.Store.Msg.on(&#x27;change&#x27;, (msg) &#x3D;&gt; { window.onChangeMessageEvent(window.WWebJS.getMessageModel(msg)); });
window.Store.Msg.on(&#x27;change:type&#x27;, (msg) &#x3D;&gt; { window.onChangeMessageTypeEvent(window.WWebJS.getMessageModel(msg)); });
window.Store.Msg.on(&#x27;change:ack&#x27;, (msg,ack) &#x3D;&gt; { window.onMessageAckEvent(window.WWebJS.getMessageModel(msg), ack); });
window.Store.Msg.on(&#x27;change:ack&#x27;, (msg, ack) &#x3D;&gt; { window.onMessageAckEvent(window.WWebJS.getMessageModel(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(window.WWebJS.getMessageModel(msg)); });
window.Store.Msg.on(&#x27;remove&#x27;, (msg) &#x3D;&gt; { if (msg.isNewMsg) window.onRemoveMessageEvent(window.WWebJS.getMessageModel(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); });
window.Store.Call.on(&#x27;add&#x27;, (call) &#x3D;&gt; { window.onIncomingCall(call); });
window.Store.Msg.on(&#x27;add&#x27;, (msg) &#x3D;&gt; {
if (msg.isNewMsg) {
if(msg.type &#x3D;&#x3D;&#x3D; &#x27;ciphertext&#x27;) {
// defer message event until ciphertext is resolved (type changed)
msg.once(&#x27;change:type&#x27;, (_msg) &#x3D;&gt; window.onAddMessageEvent(window.WWebJS.getMessageModel(_msg)));
} else {
window.onAddMessageEvent(window.WWebJS.getMessageModel(msg));
}
}
});
});
/**
@@ -410,11 +492,13 @@ class Client extends EventEmitter {
*/
this.emit(Events.READY);
// Disconnect when navigating away
// Because WhatsApp Web now reloads when logging out from the device, this also covers that case
// Disconnect when navigating away when in PAIRING state (detect logout)
this.pupPage.on(&#x27;framenavigated&#x27;, async () &#x3D;&gt; {
this.emit(Events.DISCONNECTED, &#x27;NAVIGATION&#x27;);
await this.destroy();
const appState &#x3D; await this.getState();
if(!appState || appState &#x3D;&#x3D;&#x3D; WAState.PAIRING) {
this.emit(Events.DISCONNECTED, &#x27;NAVIGATION&#x27;);
await this.destroy();
}
});
}
@@ -422,9 +506,6 @@ class Client extends EventEmitter {
* Closes the client
*/
async destroy() {
if (this._qrRefreshInterval) {
clearInterval(this._qrRefreshInterval);
}
await this.pupBrowser.close();
}
@@ -432,9 +513,11 @@ class Client extends EventEmitter {
* Logs out the client, closing the current session
*/
async logout() {
return await this.pupPage.evaluate(() &#x3D;&gt; {
await this.pupPage.evaluate(() &#x3D;&gt; {
return window.Store.AppState.logout();
});
await this.authStrategy.logout();
}
/**
@@ -464,7 +547,7 @@ class Client extends EventEmitter {
/**
* Message options.
* @typedef {Object} MessageSendOptions
* @property {boolean} [linkPreview&#x3D;true] - Show links preview
* @property {boolean} [linkPreview&#x3D;true] - Show links preview. Has no effect on multi-device accounts.
* @property {boolean} [sendAudioAsVoice&#x3D;false] - Send audio as voice message
* @property {boolean} [sendVideoAsGif&#x3D;false] - Send video as gif
* @property {boolean} [sendMediaAsSticker&#x3D;false] - Send media as a sticker
@@ -483,7 +566,7 @@ class Client extends EventEmitter {
/**
* Send a message to a specific chatId
* @param {string} chatId
* @param {string|MessageMedia|Location|Contact|Array&amp;lt;Contact&gt;} content
* @param {string|MessageMedia|Location|Contact|Array&amp;lt;Contact&gt;|Buttons|List} content
* @param {MessageSendOptions} [options] - Options used when sending the message
*
* @returns {Promise&amp;lt;Message&gt;} Message that was just sent
@@ -499,7 +582,7 @@ class Client extends EventEmitter {
quotedMessageId: options.quotedMessageId,
parseVCards: options.parseVCards &#x3D;&#x3D;&#x3D; false ? false : true,
mentionedJidList: Array.isArray(options.mentions) ? options.mentions.map(contact &#x3D;&gt; contact.id._serialized) : [],
...options.extra
extraOptions: options.extra
};
const sendSeen &#x3D; typeof options.sendSeen &#x3D;&#x3D;&#x3D; &#x27;undefined&#x27; ? true : options.sendSeen;
@@ -514,27 +597,36 @@ class Client extends EventEmitter {
} else if (content instanceof Location) {
internalOptions.location &#x3D; content;
content &#x3D; &#x27;&#x27;;
} else if(content instanceof Contact) {
} else if (content instanceof Contact) {
internalOptions.contactCard &#x3D; content.id._serialized;
content &#x3D; &#x27;&#x27;;
} else if(Array.isArray(content) &amp;amp;&amp;amp; content.length &gt; 0 &amp;amp;&amp;amp; content[0] instanceof Contact) {
} else if (Array.isArray(content) &amp;amp;&amp;amp; content.length &gt; 0 &amp;amp;&amp;amp; content[0] instanceof Contact) {
internalOptions.contactCardList &#x3D; content.map(contact &#x3D;&gt; contact.id._serialized);
content &#x3D; &#x27;&#x27;;
} else if (content instanceof Buttons) {
if (content.type !&#x3D;&#x3D; &#x27;chat&#x27;) { internalOptions.attachment &#x3D; content.body; }
internalOptions.buttons &#x3D; content;
content &#x3D; &#x27;&#x27;;
} else if (content instanceof List) {
internalOptions.list &#x3D; content;
content &#x3D; &#x27;&#x27;;
}
if (internalOptions.sendMediaAsSticker &amp;amp;&amp;amp; internalOptions.attachment) {
internalOptions.attachment &#x3D;
await Util.formatToWebpSticker(internalOptions.attachment, {
internalOptions.attachment &#x3D; await Util.formatToWebpSticker(
internalOptions.attachment, {
name: options.stickerName,
author: options.stickerAuthor,
categories: options.stickerCategories
});
}, this.pupPage
);
}
const newMessage &#x3D; await this.pupPage.evaluate(async (chatId, message, options, sendSeen) &#x3D;&gt; {
const chatWid &#x3D; window.Store.WidFactory.createWid(chatId);
const chat &#x3D; await window.Store.Chat.find(chatWid);
if (sendSeen) {
window.WWebJS.sendSeen(chatId);
}
@@ -621,7 +713,7 @@ class Client extends EventEmitter {
*/
async getInviteInfo(inviteCode) {
return await this.pupPage.evaluate(inviteCode &#x3D;&gt; {
return window.Store.Wap.groupInviteInfo(inviteCode);
return window.Store.InviteInfo.sendQueryGroupInvite(inviteCode);
}, inviteCode);
}
@@ -640,25 +732,25 @@ class Client extends EventEmitter {
/**
* Accepts a private invitation to join a group
* @param {object} inviteV4 Invite V4 Info
* @param {object} inviteInfo Invite V4 Info
* @returns {Promise&amp;lt;Object&gt;}
*/
async acceptGroupV4Invite(inviteInfo) {
if(!inviteInfo.inviteCode) throw &#x27;Invalid invite code, try passing the message.inviteV4 object&#x27;;
if (!inviteInfo.inviteCode) throw &#x27;Invalid invite code, try passing the message.inviteV4 object&#x27;;
if (inviteInfo.inviteCodeExp &#x3D;&#x3D; 0) throw &#x27;Expired invite code&#x27;;
return await this.pupPage.evaluate(async inviteInfo &#x3D;&gt; {
let { groupId, fromId, inviteCode, inviteCodeExp, toId } &#x3D; inviteInfo;
return await window.Store.Wap.acceptGroupV4Invite(groupId, fromId, inviteCode, String(inviteCodeExp), toId);
return this.pupPage.evaluate(async inviteInfo &#x3D;&gt; {
let { groupId, fromId, inviteCode, inviteCodeExp } &#x3D; inviteInfo;
return await window.Store.JoinInviteV4.sendJoinGroupViaInviteV4(inviteCode, String(inviteCodeExp), groupId, fromId);
}, inviteInfo);
}
/**
* Sets the current user&#x27;s status message
* @param {string} status New status message
*/
async setStatus(status) {
await this.pupPage.evaluate(async status &#x3D;&gt; {
return await window.Store.Wap.sendSetStatus(status);
return await window.Store.StatusUtils.setMyStatus(status);
}, status);
}
@@ -666,11 +758,22 @@ class Client extends EventEmitter {
* Sets the current user&#x27;s display name.
* This is the name shown to WhatsApp users that have not added you as a contact beside your number in groups and in your profile.
* @param {string} displayName New display name
* @returns {Promise&amp;lt;Boolean&gt;}
*/
async setDisplayName(displayName) {
await this.pupPage.evaluate(async displayName &#x3D;&gt; {
return await window.Store.Wap.setPushname(displayName);
const couldSet &#x3D; await this.pupPage.evaluate(async displayName &#x3D;&gt; {
if(!window.Store.Conn.canSetMyPushname()) return false;
if(window.Store.Features.features.MD_BACKEND) {
// TODO
return false;
} else {
const res &#x3D; await window.Store.Wap.setPushname(displayName);
return !res.status || res.status &#x3D;&#x3D;&#x3D; 200;
}
}, displayName);
return couldSet;
}
/**
@@ -679,6 +782,7 @@ class Client extends EventEmitter {
*/
async getState() {
return await this.pupPage.evaluate(() &#x3D;&gt; {
if(!window.Store) return null;
return window.Store.AppState.state;
});
}
@@ -688,7 +792,16 @@ class Client extends EventEmitter {
*/
async sendPresenceAvailable() {
return await this.pupPage.evaluate(() &#x3D;&gt; {
return window.Store.Wap.sendPresenceAvailable();
return window.Store.PresenceUtils.sendPresenceAvailable();
});
}
/**
* Marks the client as unavailable
*/
async sendPresenceUnavailable() {
return await this.pupPage.evaluate(() &#x3D;&gt; {
return window.Store.PresenceUtils.sendPresenceUnavailable();
});
}
@@ -700,7 +813,7 @@ class Client extends EventEmitter {
return await this.pupPage.evaluate(async chatId &#x3D;&gt; {
let chat &#x3D; await window.Store.Chat.get(chatId);
await window.Store.Cmd.archiveChat(chat, true);
return chat.archive;
return true;
}, chatId);
}
@@ -712,7 +825,7 @@ class Client extends EventEmitter {
return await this.pupPage.evaluate(async chatId &#x3D;&gt; {
let chat &#x3D; await window.Store.Chat.get(chatId);
await window.Store.Cmd.archiveChat(chat, false);
return chat.archive;
return false;
}, chatId);
}
@@ -754,15 +867,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 &#x3D; unmuteDate ? unmuteDate.getTime() / 1000 : -1;
await this.pupPage.evaluate(async (chatId, timestamp) &#x3D;&gt; {
let chat &#x3D; await window.Store.Chat.get(chatId);
await chat.mute.mute(timestamp, !0);
}, chatId, unmuteDate.getTime() / 1000);
}, chatId, unmuteDate || -1);
}
/**
@@ -793,13 +907,47 @@ class Client extends EventEmitter {
* @returns {Promise&amp;lt;string&gt;}
*/
async getProfilePicUrl(contactId) {
const profilePic &#x3D; await this.pupPage.evaluate((contactId) &#x3D;&gt; {
return window.Store.Wap.profilePicFind(contactId);
const profilePic &#x3D; await this.pupPage.evaluate(async contactId &#x3D;&gt; {
let asyncPic;
if (window.Store.Features.features.MD_BACKEND) {
const chatWid &#x3D; window.Store.WidFactory.createWid(contactId);
asyncPic &#x3D; await window.Store.getProfilePicFull(chatWid).catch(() &#x3D;&gt; {
return undefined;
});
} else {
asyncPic &#x3D; await window.Store.Wap.profilePicFind(contactId).catch(() &#x3D;&gt; {
return undefined;
});
}
return asyncPic;
}, contactId);
return profilePic ? profilePic.eurl : undefined;
}
/**
* Gets the Contact&#x27;s common groups with you. Returns empty array if you don&#x27;t have any common group.
* @param {string} contactId the whatsapp user&#x27;s ID (_serialized format)
* @returns {Promise&amp;lt;WAWebJS.ChatId[]&gt;}
*/
async getCommonGroups(contactId) {
const commonGroups &#x3D; await this.pupPage.evaluate(async (contactId) &#x3D;&gt; {
const contact &#x3D; window.Store.Contact.get(contactId);
if (contact.commonGroups) {
return contact.commonGroups.serialize();
}
const status &#x3D; await window.Store.findCommonGroups(contact);
if (status) {
return contact.commonGroups.serialize();
}
return [];
}, contactId);
const chats &#x3D; [];
for (const group of commonGroups) {
chats.push(group.id);
}
return chats;
}
/**
* Force reset of connection state for the client
*/
@@ -815,10 +963,7 @@ class Client extends EventEmitter {
* @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);
return Boolean(await this.getNumberId(id));
}
/**
@@ -828,17 +973,42 @@ class Client extends EventEmitter {
* @returns {Promise&amp;lt;Object|null&gt;}
*/
async getNumberId(number) {
if(!number.endsWith(&#x27;@c.us&#x27;)) {
if (!number.endsWith(&#x27;@c.us&#x27;)) {
number +&#x3D; &#x27;@c.us&#x27;;
}
try {
return await this.pupPage.evaluate(async numberId &#x3D;&gt; {
return window.WWebJS.getNumberId(numberId);
}, number);
} catch(_) {
return null;
}
return await this.pupPage.evaluate(async number &#x3D;&gt; {
const result &#x3D; await window.Store.QueryExist(number);
if (!result || result.wid &#x3D;&#x3D;&#x3D; undefined) return null;
return result.wid;
}, number);
}
/**
* Get the formatted number of a WhatsApp ID.
* @param {string} number Number or ID
* @returns {Promise&amp;lt;string&gt;}
*/
async getFormattedNumber(number) {
if (!number.endsWith(&#x27;@s.whatsapp.net&#x27;)) number &#x3D; number.replace(&#x27;c.us&#x27;, &#x27;s.whatsapp.net&#x27;);
if (!number.includes(&#x27;@s.whatsapp.net&#x27;)) number &#x3D; &#x60;${number}@s.whatsapp.net&#x60;;
return await this.pupPage.evaluate(async numberId &#x3D;&gt; {
return window.Store.NumberInfo.formattedPhoneNumber(numberId);
}, number);
}
/**
* Get the country code of a WhatsApp ID.
* @param {string} number Number or ID
* @returns {Promise&amp;lt;string&gt;}
*/
async getCountryCode(number) {
number &#x3D; number.replace(&#x27; &#x27;, &#x27;&#x27;).replace(&#x27;+&#x27;, &#x27;&#x27;).replace(&#x27;@c.us&#x27;, &#x27;&#x27;);
return await this.pupPage.evaluate(async numberId &#x3D;&gt; {
return window.Store.NumberInfo.findCC(numberId);
}, number);
}
/**
@@ -859,12 +1029,9 @@ class Client extends EventEmitter {
}
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;;
}
const participantWIDs &#x3D; participantIds.map(p &#x3D;&gt; window.Store.WidFactory.createWid(p));
const id &#x3D; window.Store.genId();
const res &#x3D; await window.Store.GroupUtils.sendCreateGroup(name, participantWIDs, undefined, id);
return res;
}, name, participants);
@@ -885,9 +1052,9 @@ class Client extends EventEmitter {
async getLabels() {
const labels &#x3D; await this.pupPage.evaluate(async () &#x3D;&gt; {
return window.WWebJS.getLabels();
});
});
return labels.map(data &#x3D;&gt; new Label(this , data));
return labels.map(data &#x3D;&gt; new Label(this, data));
}
/**
@@ -898,7 +1065,7 @@ class Client extends EventEmitter {
async getLabelById(labelId) {
const label &#x3D; await this.pupPage.evaluate(async (labelId) &#x3D;&gt; {
return window.WWebJS.getLabel(labelId);
}, labelId);
}, labelId);
return new Label(this, label);
}
@@ -908,12 +1075,12 @@ class Client extends EventEmitter {
* @param {string} chatId
* @returns {Promise&amp;lt;Array&amp;lt;Label&gt;&gt;}
*/
async getChatLabels(chatId){
async getChatLabels(chatId) {
const labels &#x3D; await this.pupPage.evaluate(async (chatId) &#x3D;&gt; {
return window.WWebJS.getChatLabels(chatId);
}, chatId);
return labels.map(data &#x3D;&gt; new Label(this, data));
return labels.map(data &#x3D;&gt; new Label(this, data));
}
/**
@@ -921,20 +1088,33 @@ class Client extends EventEmitter {
* @param {string} labelId
* @returns {Promise&amp;lt;Array&amp;lt;Chat&gt;&gt;}
*/
async getChatsByLabelId(labelId){
async getChatsByLabelId(labelId) {
const chatIds &#x3D; await this.pupPage.evaluate(async (labelId) &#x3D;&gt; {
const label &#x3D; window.Store.Label.get(labelId);
const labelItems &#x3D; label.labelItemCollection.models;
return labelItems.reduce((result, item) &#x3D;&gt; {
if(item.parentType &#x3D;&#x3D;&#x3D; &#x27;Chat&#x27;){
if (item.parentType &#x3D;&#x3D;&#x3D; &#x27;Chat&#x27;) {
result.push(item.parentId);
}
return result;
},[]);
}, []);
}, labelId);
return Promise.all(chatIds.map(id &#x3D;&gt; this.getChatById(id)));
}
/**
* Gets all blocked contacts by host account
* @returns {Promise&amp;lt;Array&amp;lt;Contact&gt;&gt;}
*/
async getBlockedContacts() {
const blockedContacts &#x3D; await this.pupPage.evaluate(() &#x3D;&gt; {
let chatIds &#x3D; window.Store.Blocklist.models.map(a &#x3D;&gt; a.id._serialized);
return Promise.all(chatIds.map(id &#x3D;&gt; window.WWebJS.getContact(id)));
});
return blockedContacts.map(contact &#x3D;&gt; ContactFactory.create(this.client, contact));
}
}
module.exports &#x3D; Client;
@@ -948,7 +1128,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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Class: ClientInfo</title>
<title>whatsapp-web.js 1.16.4 &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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</a>
</div>
</div>
</nav>
@@ -101,7 +101,7 @@
</dl>
<h3 id="phone"><span class="symbol-name">phone</span><small class="property-type">
&nbsp;object</small></h3>
<p>Information about the phone this client is connected to</p>
<p>Information about the phone this client is connected to. Not available in multi-device.</p>
<section>
<h4>Properties</h4>
<table class="jsdoc-details-table">
@@ -188,10 +188,12 @@
</table>
</section>
<dl class="dl-compact">
<dt>Deprecated</dt>
<dd></dd>
</dl>
<h3 id="platform"><span class="symbol-name">platform</span><small class="property-type">
&nbsp;string</small></h3>
<p>Platform the phone is running on</p>
<p>Platform WhatsApp is running on</p>
<dl class="dl-compact">
</dl>
<h3 id="pushname"><span class="symbol-name">pushname</span><small class="property-type">
@@ -211,17 +213,22 @@
<h3 id="getBatteryStatus"><span class="symbol-name">getBatteryStatus</span><span class="signature"><span class="signature-params">()</span>&nbsp;&rarr; <span class="signature-returns"> (object, number, or boolean)</span></span></h3>
<p>Get current battery percentage and charging status for the attached device</p>
<dl class="dl-compact">
<dt>Deprecated</dt>
<dd></dd>
<dt>Returns</dt>
<dd>
<p><code>object</code> <p>batteryStatus</p>
<p><code>object</code> 
<p>batteryStatus</p>
</p>
</dd>
<dd>
<p><code>number</code> <p>batteryStatus.battery - The current battery percentage</p>
<p><code>number</code> 
<p>batteryStatus.battery - The current battery percentage</p>
</p>
</dd>
<dd>
<p><code>boolean</code> <p>batteryStatus.plugged - Indicates if the phone is plugged in (true) or not (false)</p>
<p><code>boolean</code> 
<p>batteryStatus.plugged - Indicates if the phone is plugged in (true) or not (false)</p>
</p>
</dd>
</dl>
@@ -235,7 +242,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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Class: Contact</title>
<title>whatsapp-web.js 1.16.4 &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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</a>
</div>
</div>
</nav>
@@ -101,20 +101,29 @@
<dt><a href="Contact.html#getAbout">getAbout()</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="Contact.html#getChat">getChat()</a></dt>
<dd>
</dd>
<dt><a href="Contact.html#getProfilePicUrl">getProfilePicUrl()</a></dt>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="Contact.html#getCommonGroups">getCommonGroups()</a></dt>
<dd>
</dd>
<dt><a href="Contact.html#getCountryCode">getCountryCode()</a></dt>
<dd>
</dd>
<dt><a href="Contact.html#getFormattedNumber">getFormattedNumber()</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="Contact.html#getProfilePicUrl">getProfilePicUrl()</a></dt>
<dd>
</dd>
<dt><a href="Contact.html#unblock">unblock()</a></dt>
<dd>
</dd>
@@ -230,6 +239,33 @@
</dd>
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="getCommonGroups"><span class="symbol-name">getCommonGroups</span><span class="signature"><span class="signature-params">()</span>&nbsp;&rarr; <span class="signature-returns"> Promise containing Array of WAWebJS.ChatId</span></span></h3>
<p>Gets the Contact's common groups with you. Returns empty array if you don't have any common group.</p>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Promise containing Array of WAWebJS.ChatId</code> </p>
</dd>
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="getCountryCode"><span class="symbol-name">getCountryCode</span><span class="signature"><span class="signature-params">()</span>&nbsp;&rarr; <span class="signature-returns"> Promise containing string</span></span></h3>
<p>Returns the contact's countrycode, (1541859685@c.us) =&gt; (1)</p>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Promise containing string</code> </p>
</dd>
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="getFormattedNumber"><span class="symbol-name">getFormattedNumber</span><span class="signature"><span class="signature-params">()</span>&nbsp;&rarr; <span class="signature-returns"> Promise containing string</span></span></h3>
<p>Returns the contact's formatted phone number, (12345678901@c.us) =&gt; (+1 (234) 5678-901)</p>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Promise containing string</code> </p>
</dd>
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="getProfilePicUrl"><span class="symbol-name">getProfilePicUrl</span><span class="signature"><span class="signature-params">()</span>&nbsp;&rarr; <span class="signature-returns"> Promise containing string</span></span></h3>
<p>Returns the contact's profile picture URL, if privacy settings allow it</p>
<dl class="dl-compact">
@@ -257,7 +293,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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Class: GroupChat</title>
<title>whatsapp-web.js 1.16.4 &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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</a>
</div>
</div>
</nav>
@@ -405,7 +405,8 @@
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Promise containing {status: number}</code> <p>Object with status code indicating if the operation was successful</p>
<p><code>Promise containing {status: number}</code> 
<p>Object with status code indicating if the operation was successful</p>
</p>
</dd>
</dl>
@@ -458,8 +459,7 @@
<p>Yes</p>
</td>
<td>
<p>The amount of messages to return. Note that the actual number of returned messages may be smaller if there aren't enough messages in the conversation. Set this to Infinity to load all messages.</p>
<p>Defaults to <code>50</code>.</p>
<p>The amount of messages to return. If no limit is specified, the available messages will be returned. Note that the actual number of returned messages may be smaller if there aren't enough messages in the conversation. Set this to Infinity to load all messages.</p>
</td>
</tr>
</tbody>
@@ -490,7 +490,8 @@
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Promise containing string</code> <p>Group's invite code</p>
<p><code>Promise containing string</code> 
<p>Group's invite code</p>
</p>
</dd>
</dl>
@@ -521,7 +522,7 @@
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="mute"><span class="symbol-name">mute</span><span class="signature"><span class="signature-params">(unmuteDate)</span></span></h3>
<p>Mutes this chat until a specified date</p>
<p>Mutes this chat forever, unless a date is specified</p>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
@@ -545,7 +546,8 @@
<p>&nbsp;</p>
</td>
<td>
<p>Date at which the Chat will be unmuted</p>
<p>Date at which the Chat will be unmuted, leave as is to mute forever</p>
<p>Value can be null.</p>
</td>
</tr>
</tbody>
@@ -600,7 +602,8 @@
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Promise containing {status: number}</code> <p>Object with status code indicating if the operation was successful</p>
<p><code>Promise containing {status: number}</code> 
<p>Object with status code indicating if the operation was successful</p>
</p>
</dd>
</dl>
@@ -642,12 +645,14 @@
</dd>
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="revokeInvite"><span class="symbol-name">revokeInvite</span><span class="signature"><span class="signature-params">()</span>&nbsp;&rarr; <span class="signature-returns"> Promise</span></span></h3>
<h3 id="revokeInvite"><span class="symbol-name">revokeInvite</span><span class="signature"><span class="signature-params">()</span>&nbsp;&rarr; <span class="signature-returns"> Promise containing string</span></span></h3>
<p>Invalidates the current group invite code and generates a new one</p>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Promise</code> </p>
<p><code>Promise containing string</code> 
<p>New invite code</p>
</p>
</dd>
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
@@ -728,7 +733,7 @@
<dd><a href="Chat.html#sendStateTyping">Chat#sendStateTyping</a></dd>
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="setDescription"><span class="symbol-name">setDescription</span><span class="signature"><span class="signature-params">(description)</span>&nbsp;&rarr; <span class="signature-returns"> Promise</span></span></h3>
<h3 id="setDescription"><span class="symbol-name">setDescription</span><span class="signature"><span class="signature-params">(description)</span>&nbsp;&rarr; <span class="signature-returns"> Promise containing boolean</span></span></h3>
<p>Updates the group description</p>
<section>
<h4>Parameter</h4>
@@ -761,7 +766,9 @@
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Promise</code> </p>
<p><code>Promise containing boolean</code> 
<p>Returns true if the description was properly updated. This can return false if the user does not have the necessary permissions.</p>
</p>
</dd>
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
@@ -800,7 +807,8 @@
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Promise containing boolean</code> <p>Returns true if the setting was properly updated. This can return false if the user does not have the necessary permissions.</p>
<p><code>Promise containing boolean</code> 
<p>Returns true if the setting was properly updated. This can return false if the user does not have the necessary permissions.</p>
</p>
</dd>
</dl>
@@ -840,12 +848,13 @@
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Promise containing boolean</code> <p>Returns true if the setting was properly updated. This can return false if the user does not have the necessary permissions.</p>
<p><code>Promise containing boolean</code> 
<p>Returns true if the setting was properly updated. This can return false if the user does not have the necessary permissions.</p>
</p>
</dd>
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="setSubject"><span class="symbol-name">setSubject</span><span class="signature"><span class="signature-params">(subject)</span>&nbsp;&rarr; <span class="signature-returns"> Promise</span></span></h3>
<h3 id="setSubject"><span class="symbol-name">setSubject</span><span class="signature"><span class="signature-params">(subject)</span>&nbsp;&rarr; <span class="signature-returns"> Promise containing boolean</span></span></h3>
<p>Updates the group subject</p>
<section>
<h4>Parameter</h4>
@@ -878,7 +887,9 @@
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Promise</code> </p>
<p><code>Promise containing boolean</code> 
<p>Returns true if the subject was properly updated. This can return false if the user does not have the necessary permissions.</p>
</p>
</dd>
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
@@ -916,7 +927,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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Class: GroupNotification</title>
<title>whatsapp-web.js 1.16.4 &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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Class: InterfaceController</title>
<title>whatsapp-web.js 1.16.4 &raquo; Class: InterfaceController</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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</a>
</div>
</div>
</nav>
@@ -382,7 +382,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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Class: Label</title>
<title>whatsapp-web.js 1.16.4 &raquo; Class: Label</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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</a>
</div>
</div>
</nav>
@@ -163,7 +163,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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

188
docs/LegacySessionAuth.html Normal file
View File

@@ -0,0 +1,188 @@
<!doctype html>
<html>
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.16.4 &raquo; Class: LegacySessionAuth</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">
<link href="css/baseline.css" rel="stylesheet">
</head>
<body onload="prettyPrint()">
<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>16.<wbr>4</a>
</div>
</div>
</nav>
<div id="jsdoc-body-container">
<div id="jsdoc-content">
<div id="jsdoc-content-container">
<div id="jsdoc-main" role="main">
<header class="page-header">
<div class="symbol-detail-labels"><span class="label label-kind">class</span></div>
<h1><small></small><span class="symbol-name">LegacySessionAuth</span></h1>
<p class="source-link">Source: <a href="authStrategies_LegacySessionAuth.js.html#source-line-16">authStrategies/<wbr>LegacySessionAuth.<wbr>js:16</a></p>
<div class="symbol-classdesc">
<p>Legacy session auth strategy
Not compatible with multi-device accounts.</p>
</div>
<dl class="dl-compact">
</dl>
</header>
<section id="summary">
</section>
<section>
<h2 id="LegacySessionAuth">new&nbsp;<span class="symbol-name">LegacySessionAuth</span><span class="signature"><span class="signature-params">(options)</span></span></h2>
<section>
<h3>Parameters</h3>
<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>options</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>options</p>
<p>Values in <code>options</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>restartOnAuthFail</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>Restart client with a new session (i.e. use null 'session' var) if authentication fails</p>
</td>
</tr>
<tr>
<td>
<p>session</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>Whatsapp session to restore. If not set, will start a new session</p>
</td>
</tr>
<tr>
<td>
<p>session.WABrowserId</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>session.WASecretBundle</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>session.WAToken1</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>session.WAToken2</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
</dl>
</section>
<section>
</section>
</div>
</div>
<nav id="jsdoc-toc-nav" role="navigation"></nav>
</div>
</div>
<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.7 on March 9, 2022.
</p>
</div>
</footer>
<script src="scripts/jquery.min.js"></script>
<script src="scripts/tree.jquery.js"></script>
<script src="scripts/prettify.js"></script>
<script src="scripts/jsdoc-toc.js"></script>
<script src="scripts/linenumber.js"></script>
<script src="scripts/scrollanchor.js"></script>
</body>
</html>

271
docs/List.html Normal file
View File

@@ -0,0 +1,271 @@
<!doctype html>
<html>
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.16.4 &raquo; Class: List</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">
<link href="css/baseline.css" rel="stylesheet">
</head>
<body onload="prettyPrint()">
<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>16.<wbr>4</a>
</div>
</div>
</nav>
<div id="jsdoc-body-container">
<div id="jsdoc-content">
<div id="jsdoc-content-container">
<div id="jsdoc-main" role="main">
<header class="page-header">
<div class="symbol-detail-labels"><span class="label label-kind">class</span></div>
<h1><small></small><span class="symbol-name">List</span></h1>
<p class="source-link">Source: <a href="structures_List.js.html#source-line-8">structures/<wbr>List.<wbr>js:8</a></p>
<div class="symbol-classdesc">
<p>Message type List</p>
</div>
<dl class="dl-compact">
</dl>
</header>
<section id="summary">
<div class="summary-callout">
<h2 class="summary-callout-heading">Properties</h2>
<div class="summary-content">
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="List.html#buttonText">buttonText</a></dt>
<dd>
</dd>
<dt><a href="List.html#description">description</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="List.html#footer">footer</a></dt>
<dd>
</dd>
<dt><a href="List.html#sections">sections</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="List.html#title">title</a></dt>
<dd>
</dd>
</dl>
</div>
</div>
</div>
<div class="summary-callout">
<h2 class="summary-callout-heading">Method</h2>
<div class="summary-content">
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="List.html#_format">_format(sections)</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
</div>
<div class="summary-column">
</div>
</div>
</div>
</section>
<section>
<h2 id="List">new&nbsp;<span class="symbol-name">List</span><span class="signature"><span class="signature-params">(body, buttonText, sections, title, footer)</span></span></h2>
<section>
<h3>Parameters</h3>
<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>body</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>buttonText</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>sections</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>title</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>Value can be null.</p>
</td>
</tr>
<tr>
<td>
<p>footer</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>Value can be null.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
</dl>
</section>
<section>
<h2>Properties</h2>
<section>
<h3 id="buttonText"><span class="symbol-name">buttonText</span><small class="property-type">
&nbsp;string</small></h3>
<p>List button text</p>
<dl class="dl-compact">
</dl>
<h3 id="description"><span class="symbol-name">description</span><small class="property-type">
&nbsp;string</small></h3>
<p>Message body</p>
<dl class="dl-compact">
</dl>
<h3 id="footer"><span class="symbol-name">footer</span><small class="property-type">
&nbsp;string</small></h3>
<p>footer of message</p>
<dl class="dl-compact">
</dl>
<h3 id="sections"><span class="symbol-name">sections</span><small class="property-type">
&nbsp;Array of any</small></h3>
<p>sections of message</p>
<dl class="dl-compact">
</dl>
<h3 id="title"><span class="symbol-name">title</span><small class="property-type">
&nbsp;string</small></h3>
<p>title of message</p>
<dl class="dl-compact">
</dl>
</section>
<h2>Method</h2>
<section>
<h3 id="_format"><span class="symbol-name">_format</span><span class="signature"><span class="signature-params">(sections)</span>&nbsp;&rarr; <span class="signature-returns"> Array of any</span></span></h3>
<p>Creates section array from simple array</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>Input: [{title:&#x27;sectionTitle&#x27;,rows:[{id:&#x27;customId&#x27;, title:&#x27;ListItem2&#x27;, description: &#x27;desc&#x27;},{title:&#x27;ListItem2&#x27;}]}}]
Returns: [{&#x27;title&#x27;:&#x27;sectionTitle&#x27;,&#x27;rows&#x27;:[{&#x27;rowId&#x27;:&#x27;customId&#x27;,&#x27;title&#x27;:&#x27;ListItem1&#x27;,&#x27;description&#x27;:&#x27;desc&#x27;},{&#x27;rowId&#x27;:&#x27;oGSRoD&#x27;,&#x27;title&#x27;:&#x27;ListItem2&#x27;,&#x27;description&#x27;:&#x27;&#x27;}]}]</code></pre>
</div>
</section>
<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>sections</p>
</td>
<td>
<p>Array of any</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Array of any</code> </p>
</dd>
</dl>
</section>
</section>
</div>
</div>
<nav id="jsdoc-toc-nav" role="navigation"></nav>
</div>
</div>
<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.7 on March 9, 2022.
</p>
</div>
</footer>
<script src="scripts/jquery.min.js"></script>
<script src="scripts/tree.jquery.js"></script>
<script src="scripts/prettify.js"></script>
<script src="scripts/jsdoc-toc.js"></script>
<script src="scripts/linenumber.js"></script>
<script src="scripts/scrollanchor.js"></script>
</body>
</html>

135
docs/LocalAuth.html Normal file
View File

@@ -0,0 +1,135 @@
<!doctype html>
<html>
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.16.4 &raquo; Class: LocalAuth</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">
<link href="css/baseline.css" rel="stylesheet">
</head>
<body onload="prettyPrint()">
<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>16.<wbr>4</a>
</div>
</div>
</nav>
<div id="jsdoc-body-container">
<div id="jsdoc-content">
<div id="jsdoc-content-container">
<div id="jsdoc-main" role="main">
<header class="page-header">
<div class="symbol-detail-labels"><span class="label label-kind">class</span></div>
<h1><small></small><span class="symbol-name">LocalAuth</span></h1>
<p class="source-link">Source: <a href="authStrategies_LocalAuth.js.html#source-line-13">authStrategies/<wbr>LocalAuth.<wbr>js:13</a></p>
<div class="symbol-classdesc">
<p>Local directory-based authentication</p>
</div>
<dl class="dl-compact">
</dl>
</header>
<section id="summary">
</section>
<section>
<h2 id="LocalAuth">new&nbsp;<span class="symbol-name">LocalAuth</span><span class="signature"><span class="signature-params">(options)</span></span></h2>
<section>
<h3>Parameters</h3>
<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>options</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>options</p>
<p>Values in <code>options</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>clientId</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>Client id to distinguish instances if you are using multiple, otherwise keep null if you are using only one instance</p>
</td>
</tr>
<tr>
<td>
<p>dataPath</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>Change the default path for saving session files, default is: &quot;./.wwebjs_auth/&quot;</p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
</dl>
</section>
<section>
</section>
</div>
</div>
<nav id="jsdoc-toc-nav" role="navigation"></nav>
</div>
</div>
<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.7 on March 9, 2022.
</p>
</div>
</footer>
<script src="scripts/jquery.min.js"></script>
<script src="scripts/tree.jquery.js"></script>
<script src="scripts/prettify.js"></script>
<script src="scripts/jsdoc-toc.js"></script>
<script src="scripts/linenumber.js"></script>
<script src="scripts/scrollanchor.js"></script>
</body>
</html>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Class: Location</title>
<title>whatsapp-web.js 1.16.4 &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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Class: Message</title>
<title>whatsapp-web.js 1.16.4 &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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</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">Message</span></h1>
<p class="source-link">Source: <a href="structures_Message.js.html#source-line-13">structures/<wbr>Message.<wbr>js:13</a></p>
<p class="source-link">Source: <a href="structures_Message.js.html#source-line-14">structures/<wbr>Message.<wbr>js:14</a></p>
<div class="symbol-classdesc">
<p>Represents a Message on WhatsApp</p>
</div>
@@ -54,6 +54,12 @@
<dt><a href="Message.html#deviceType">deviceType</a></dt>
<dd>
</dd>
<dt><a href="Message.html#duration">duration</a></dt>
<dd>
</dd>
<dt><a href="Message.html#forwardingScore">forwardingScore</a></dt>
<dd>
</dd>
<dt><a href="Message.html#from">from</a></dt>
<dd>
</dd>
@@ -76,9 +82,15 @@
<dt><a href="Message.html#inviteV4">inviteV4</a></dt>
<dd>
</dd>
<dt><a href="Message.html#isEphemeral">isEphemeral</a></dt>
<dd>
</dd>
<dt><a href="Message.html#isForwarded">isForwarded</a></dt>
<dd>
</dd>
<dt><a href="Message.html#isGif">isGif</a></dt>
<dd>
</dd>
<dt><a href="Message.html#isStarred">isStarred</a></dt>
<dd>
</dd>
@@ -104,6 +116,9 @@
<dt><a href="Message.html#orderId">orderId</a></dt>
<dd>
</dd>
<dt><a href="Message.html#rawData">rawData</a></dt>
<dd>
</dd>
<dt><a href="Message.html#timestamp">timestamp</a></dt>
<dd>
</dd>
@@ -159,13 +174,19 @@
<dt><a href="Message.html#getOrder">getOrder()</a></dt>
<dd>
</dd>
<dt><a href="Message.html#getQuotedMessage">getQuotedMessage()</a></dt>
<dt><a href="Message.html#getPayment">getPayment()</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="Message.html#getQuotedMessage">getQuotedMessage()</a></dt>
<dd>
</dd>
<dt><a href="Message.html#reload">reload()</a></dt>
<dd>
</dd>
<dt><a href="Message.html#reply">reply(content[, chatId][, options])</a></dt>
<dd>
</dd>
@@ -215,6 +236,17 @@
<p>String that represents from which device type the message was sent</p>
<dl class="dl-compact">
</dl>
<h3 id="duration"><span class="symbol-name">duration</span><small class="property-type">
&nbsp;string</small></h3>
<p>Indicates the duration of the message in seconds</p>
<dl class="dl-compact">
</dl>
<h3 id="forwardingScore"><span class="symbol-name">forwardingScore</span><small class="property-type">
&nbsp;number</small></h3>
<p>Indicates how many times the message was forwarded.</p>
<p>The maximum value is 127.</p>
<dl class="dl-compact">
</dl>
<h3 id="from"><span class="symbol-name">from</span><small class="property-type">
&nbsp;string</small></h3>
<p>ID for the Chat that this message was sent to, except if the message was sent by the current user.</p>
@@ -245,11 +277,21 @@
<p>Group Invite Data</p>
<dl class="dl-compact">
</dl>
<h3 id="isEphemeral"><span class="symbol-name">isEphemeral</span><small class="property-type">
&nbsp;boolean</small></h3>
<p>Indicates if the message will disappear after it expires</p>
<dl class="dl-compact">
</dl>
<h3 id="isForwarded"><span class="symbol-name">isForwarded</span><small class="property-type">
&nbsp;boolean</small></h3>
<p>Indicates if the message was forwarded</p>
<dl class="dl-compact">
</dl>
<h3 id="isGif"><span class="symbol-name">isGif</span><small class="property-type">
&nbsp;boolean</small></h3>
<p>Indicates whether the message is a Gif</p>
<dl class="dl-compact">
</dl>
<h3 id="isStarred"><span class="symbol-name">isStarred</span><small class="property-type">
&nbsp;boolean</small></h3>
<p>Indicates if the message was starred</p>
@@ -261,7 +303,7 @@
<dl class="dl-compact">
</dl>
<h3 id="links"><span class="symbol-name">links</span><small class="property-type">
&nbsp;Array of string</small></h3>
&nbsp;Array of {link: string, isSuspicious: boolean}</small></h3>
<p>Links included in the message.</p>
<dl class="dl-compact">
</dl>
@@ -285,6 +327,11 @@
<p>Order ID for message type ORDER</p>
<dl class="dl-compact">
</dl>
<h3 id="rawData"><span class="symbol-name">rawData</span><small class="property-type">
&nbsp;Object</small></h3>
<p>Returns message in a raw format</p>
<dl class="dl-compact">
</dl>
<h3 id="timestamp"><span class="symbol-name">timestamp</span><small class="property-type">
&nbsp;number</small></h3>
<p>Unix timestamp for when the message was created</p>
@@ -450,6 +497,15 @@
</dd>
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="getPayment"><span class="symbol-name">getPayment</span><span class="signature"><span class="signature-params">()</span>&nbsp;&rarr; <span class="signature-returns"> Promise containing <a href="Payment.html">Payment</a></span></span></h3>
<p>Gets the payment details associated with a given message</p>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Promise containing <a href="Payment.html">Payment</a></code> </p>
</dd>
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="getQuotedMessage"><span class="symbol-name">getQuotedMessage</span><span class="signature"><span class="signature-params">()</span>&nbsp;&rarr; <span class="signature-returns"> Promise containing <a href="Message.html">Message</a></span></span></h3>
<p>Returns the quoted message, if any</p>
<dl class="dl-compact">
@@ -459,6 +515,16 @@
</dd>
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="reload"><span class="symbol-name">reload</span><span class="signature"><span class="signature-params">()</span>&nbsp;&rarr; <span class="signature-returns"> Promise containing <a href="Message.html">Message</a></span></span></h3>
<p>Reloads this Message object's data in-place with the latest values from WhatsApp Web.
Note that the Message must still be in the web app cache for this to work, otherwise will return null.</p>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Promise containing <a href="Message.html">Message</a></code> </p>
</dd>
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="reply"><span class="symbol-name">reply</span><span class="signature"><span class="signature-params">(content[, chatId][, options])</span>&nbsp;&rarr; <span class="signature-returns"> Promise containing <a href="Message.html">Message</a></span></span></h3>
<p>Sends a message as a reply to this message. If chatId is specified, it will be sent
through the specified Chat. If not, it will send the message
@@ -543,7 +609,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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Class: MessageMedia</title>
<title>whatsapp-web.js 1.16.4 &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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</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">MessageMedia</span></h1>
<p class="source-link">Source: <a href="structures_MessageMedia.js.html#source-line-13">structures/<wbr>MessageMedia.<wbr>js:13</a></p>
<p class="source-link">Source: <a href="structures_MessageMedia.js.html#source-line-15">structures/<wbr>MessageMedia.<wbr>js:15</a></p>
<div class="symbol-classdesc">
<p>Media attached to a message</p>
</div>
@@ -61,7 +61,7 @@
</div>
</div>
<div class="summary-callout">
<h2 class="summary-callout-heading">Method</h2>
<h2 class="summary-callout-heading">Methods</h2>
<div class="summary-content">
<div class="summary-column">
<dl class="dl-summary-callout">
@@ -71,6 +71,11 @@
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="MessageMedia.html#.fromUrl">fromUrl(url[, options])</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
</div>
@@ -159,7 +164,7 @@
<dl class="dl-compact">
</dl>
</section>
<h2>Method</h2>
<h2>Methods</h2>
<section>
<div class="symbol-detail-labels"><span class="label label-static">static</span></div>
<h3 id=".fromFilePath"><span class="symbol-name">fromFilePath</span><span class="signature"><span class="signature-params">(filePath)</span>&nbsp;&rarr; <span class="signature-returns"> <a href="MessageMedia.html">MessageMedia</a></span></span></h3>
@@ -198,6 +203,136 @@
<p><code><a href="MessageMedia.html">MessageMedia</a></code> </p>
</dd>
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span>&nbsp;<span class="label label-static">static</span></div>
<h3 id=".fromUrl"><span class="symbol-name">fromUrl</span><span class="signature"><span class="signature-params">(url[, options])</span>&nbsp;&rarr; <span class="signature-returns"> Promise containing <a href="MessageMedia.html">MessageMedia</a></span></span></h3>
<p>Creates a MessageMedia instance from a URL</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>url</p>
</td>
<td>
<p>string</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>options</p>
</td>
<td>
<p>Object</p>
</td>
<td>
<p>Yes</p>
</td>
<td>
<p>Values in <code>options</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>unsafeMime</p>
</td>
<td>
<p>boolean</p>
</td>
<td>
<p>Yes</p>
</td>
<td>
<p>Defaults to <code>false</code>.</p>
</td>
</tr>
<tr>
<td>
<p>filename</p>
</td>
<td>
<p>string</p>
</td>
<td>
<p>Yes</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>client</p>
</td>
<td>
<p>object</p>
</td>
<td>
<p>Yes</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>reqOptions</p>
</td>
<td>
<p>object</p>
</td>
<td>
<p>Yes</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>reqOptions.size</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p>Yes</p>
</td>
<td>
<p>Defaults to <code>0</code>.</p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Promise containing <a href="MessageMedia.html">MessageMedia</a></code> </p>
</dd>
</dl>
</section>
</section>
</div>
@@ -208,7 +343,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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

66
docs/NoAuth.html Normal file
View File

@@ -0,0 +1,66 @@
<!doctype html>
<html>
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.16.4 &raquo; Class: NoAuth</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">
<link href="css/baseline.css" rel="stylesheet">
</head>
<body onload="prettyPrint()">
<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>16.<wbr>4</a>
</div>
</div>
</nav>
<div id="jsdoc-body-container">
<div id="jsdoc-content">
<div id="jsdoc-content-container">
<div id="jsdoc-main" role="main">
<header class="page-header">
<div class="symbol-detail-labels"><span class="label label-kind">class</span></div>
<h1><small></small><span class="symbol-name">NoAuth</span></h1>
<p class="source-link">Source: <a href="authStrategies_NoAuth.js.html#source-line-9">authStrategies/<wbr>NoAuth.<wbr>js:9</a></p>
<div class="symbol-classdesc">
<p>No session restoring functionality
Will need to authenticate via QR code every time</p>
</div>
<dl class="dl-compact">
</dl>
</header>
<section id="summary">
</section>
<section>
<h2 id="NoAuth">new&nbsp;<span class="symbol-name">NoAuth</span><span class="signature"><span class="signature-params">()</span></span></h2>
<dl class="dl-compact">
</dl>
</section>
<section>
</section>
</div>
</div>
<nav id="jsdoc-toc-nav" role="navigation"></nav>
</div>
</div>
<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.7 on March 9, 2022.
</p>
</div>
</footer>
<script src="scripts/jquery.min.js"></script>
<script src="scripts/tree.jquery.js"></script>
<script src="scripts/prettify.js"></script>
<script src="scripts/jsdoc-toc.js"></script>
<script src="scripts/linenumber.js"></script>
<script src="scripts/scrollanchor.js"></script>
</body>
</html>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Class: Order</title>
<title>whatsapp-web.js 1.16.4 &raquo; Class: Order</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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</a>
</div>
</div>
</nav>
@@ -102,7 +102,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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Class: PrivateChat</title>
<title>whatsapp-web.js 1.16.4 &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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</a>
</div>
</div>
</nav>
@@ -318,8 +318,7 @@
<p>Yes</p>
</td>
<td>
<p>The amount of messages to return. Note that the actual number of returned messages may be smaller if there aren't enough messages in the conversation. Set this to Infinity to load all messages.</p>
<p>Defaults to <code>50</code>.</p>
<p>The amount of messages to return. If no limit is specified, the available messages will be returned. Note that the actual number of returned messages may be smaller if there aren't enough messages in the conversation. Set this to Infinity to load all messages.</p>
</td>
</tr>
</tbody>
@@ -362,7 +361,7 @@
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="mute"><span class="symbol-name">mute</span><span class="signature"><span class="signature-params">(unmuteDate)</span></span></h3>
<p>Mutes this chat until a specified date</p>
<p>Mutes this chat forever, unless a date is specified</p>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
@@ -386,7 +385,8 @@
<p>&nbsp;</p>
</td>
<td>
<p>Date at which the Chat will be unmuted</p>
<p>Date at which the Chat will be unmuted, leave as is to mute forever</p>
<p>Value can be null.</p>
</td>
</tr>
</tbody>
@@ -519,7 +519,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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Class: PrivateContact</title>
<title>whatsapp-web.js 1.16.4 &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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</a>
</div>
</div>
</nav>
@@ -101,20 +101,29 @@
<dt><a href="PrivateContact.html#getAbout">getAbout()</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="PrivateContact.html#getChat">getChat()</a></dt>
<dd>
</dd>
<dt><a href="PrivateContact.html#getProfilePicUrl">getProfilePicUrl()</a></dt>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="PrivateContact.html#getCommonGroups">getCommonGroups()</a></dt>
<dd>
</dd>
<dt><a href="PrivateContact.html#getCountryCode">getCountryCode()</a></dt>
<dd>
</dd>
<dt><a href="PrivateContact.html#getFormattedNumber">getFormattedNumber()</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="PrivateContact.html#getProfilePicUrl">getProfilePicUrl()</a></dt>
<dd>
</dd>
<dt><a href="PrivateContact.html#unblock">unblock()</a></dt>
<dd>
</dd>
@@ -256,6 +265,33 @@
<dd></dd>
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="getCommonGroups"><span class="symbol-name">getCommonGroups</span><span class="signature"><span class="signature-params">()</span>&nbsp;&rarr; <span class="signature-returns"> Promise containing Array of WAWebJS.ChatId</span></span></h3>
<p>Gets the Contact's common groups with you. Returns empty array if you don't have any common group.</p>
<dl class="dl-compact">
<dt>Inherited from</dt>
<dd><a href="Contact.html#getCommonGroups">Contact#getCommonGroups</a></dd>
<dt>Returns</dt>
<dd></dd>
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="getCountryCode"><span class="symbol-name">getCountryCode</span><span class="signature"><span class="signature-params">()</span>&nbsp;&rarr; <span class="signature-returns"> Promise containing string</span></span></h3>
<p>Returns the contact's countrycode, (1541859685@c.us) =&gt; (1)</p>
<dl class="dl-compact">
<dt>Inherited from</dt>
<dd><a href="Contact.html#getCountryCode">Contact#getCountryCode</a></dd>
<dt>Returns</dt>
<dd></dd>
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="getFormattedNumber"><span class="symbol-name">getFormattedNumber</span><span class="signature"><span class="signature-params">()</span>&nbsp;&rarr; <span class="signature-returns"> Promise containing string</span></span></h3>
<p>Returns the contact's formatted phone number, (12345678901@c.us) =&gt; (+1 (234) 5678-901)</p>
<dl class="dl-compact">
<dt>Inherited from</dt>
<dd><a href="Contact.html#getFormattedNumber">Contact#getFormattedNumber</a></dd>
<dt>Returns</dt>
<dd></dd>
</dl>
<div class="symbol-detail-labels"><span class="label label-async">async</span></div>
<h3 id="getProfilePicUrl"><span class="symbol-name">getProfilePicUrl</span><span class="signature"><span class="signature-params">()</span>&nbsp;&rarr; <span class="signature-returns"> Promise containing string</span></span></h3>
<p>Returns the contact's profile picture URL, if privacy settings allow it</p>
<dl class="dl-compact">
@@ -283,7 +319,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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Class: Product</title>
<title>whatsapp-web.js 1.16.4 &raquo; Class: Product</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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</a>
</div>
</div>
</nav>
@@ -127,7 +127,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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Class: Util</title>
<title>whatsapp-web.js 1.16.4 &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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</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">Util</span></h1>
<p class="source-link">Source: <a href="util_Util.js.html#source-line-16">util/<wbr>Util.<wbr>js:16</a></p>
<p class="source-link">Source: <a href="util_Util.js.html#source-line-15">util/<wbr>Util.<wbr>js:15</a></p>
<div class="symbol-classdesc">
<p>Utility methods</p>
</div>
@@ -104,7 +104,8 @@
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Promise containing <a href="MessageMedia.html">MessageMedia</a></code> <p>media in webp format</p>
<p><code>Promise containing <a href="MessageMedia.html">MessageMedia</a></code> 
<p>media in webp format</p>
</p>
</dd>
</dl>
@@ -155,7 +156,8 @@
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Promise containing <a href="MessageMedia.html">MessageMedia</a></code> <p>media in webp format</p>
<p><code>Promise containing <a href="MessageMedia.html">MessageMedia</a></code> 
<p>media in webp format</p>
</p>
</dd>
</dl>
@@ -193,7 +195,8 @@
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Promise containing <a href="MessageMedia.html">MessageMedia</a></code> <p>media in webp format</p>
<p><code>Promise containing <a href="MessageMedia.html">MessageMedia</a></code> 
<p>media in webp format</p>
</p>
</dd>
</dl>
@@ -240,7 +243,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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -0,0 +1,77 @@
<!doctype html>
<html>
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.16.4 &raquo; Source: authStrategies/BaseAuthStrategy.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">
<link href="css/baseline.css" rel="stylesheet">
</head>
<body onload="prettyPrint()">
<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>16.<wbr>4</a>
</div>
</div>
</nav>
<div id="jsdoc-body-container">
<div id="jsdoc-content">
<div id="jsdoc-content-container">
<div id="jsdoc-banner" role="banner">
</div>
<div id="jsdoc-main" role="main">
<header class="page-header">
<h1>Source: authStrategies/BaseAuthStrategy.js</h1>
</header>
<article>
<pre class="prettyprint linenums"><code>&#x27;use strict&#x27;;
/**
* Base class which all authentication strategies extend
*/
class BaseAuthStrategy {
constructor() {}
setup(client) {
this.client &#x3D; client;
}
async beforeBrowserInitialized() {}
async afterBrowserInitialized() {}
async onAuthenticationNeeded() {
return {
failed: false,
restart: false,
failureEventPayload: undefined
};
}
async getAuthEventPayload() {}
async logout() {}
}
module.exports &#x3D; BaseAuthStrategy;</code></pre>
</article>
</div>
</div>
<nav id="jsdoc-toc-nav" role="navigation"></nav>
</div>
</div>
<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.7 on March 9, 2022.
</p>
</div>
</footer>
<script src="scripts/jquery.min.js"></script>
<script src="scripts/tree.jquery.js"></script>
<script src="scripts/prettify.js"></script>
<script src="scripts/jsdoc-toc.js"></script>
<script src="scripts/linenumber.js"></script>
<script src="scripts/scrollanchor.js"></script>
</body>
</html>

View File

@@ -0,0 +1,125 @@
<!doctype html>
<html>
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.16.4 &raquo; Source: authStrategies/LegacySessionAuth.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">
<link href="css/baseline.css" rel="stylesheet">
</head>
<body onload="prettyPrint()">
<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>16.<wbr>4</a>
</div>
</div>
</nav>
<div id="jsdoc-body-container">
<div id="jsdoc-content">
<div id="jsdoc-content-container">
<div id="jsdoc-banner" role="banner">
</div>
<div id="jsdoc-main" role="main">
<header class="page-header">
<h1>Source: authStrategies/LegacySessionAuth.js</h1>
</header>
<article>
<pre class="prettyprint linenums"><code>&#x27;use strict&#x27;;
const BaseAuthStrategy &#x3D; require(&#x27;./BaseAuthStrategy&#x27;);
/**
* Legacy session auth strategy
* Not compatible with multi-device accounts.
* @param {object} options - options
* @param {string} options.restartOnAuthFail - Restart client with a new session (i.e. use null &#x27;session&#x27; 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
* @param {string} options.session.WASecretBundle
* @param {string} options.session.WAToken1
* @param {string} options.session.WAToken2
*/
class LegacySessionAuth extends BaseAuthStrategy {
constructor({ session, restartOnAuthFail }&#x3D;{}) {
super();
this.session &#x3D; session;
this.restartOnAuthFail &#x3D; restartOnAuthFail;
}
async afterBrowserInitialized() {
if(this.session) {
await this.client.pupPage.evaluateOnNewDocument(session &#x3D;&gt; {
if (document.referrer &#x3D;&#x3D;&#x3D; &#x27;https://whatsapp.com/&#x27;) {
localStorage.clear();
localStorage.setItem(&#x27;WABrowserId&#x27;, session.WABrowserId);
localStorage.setItem(&#x27;WASecretBundle&#x27;, session.WASecretBundle);
localStorage.setItem(&#x27;WAToken1&#x27;, session.WAToken1);
localStorage.setItem(&#x27;WAToken2&#x27;, session.WAToken2);
}
localStorage.setItem(&#x27;remember-me&#x27;, &#x27;true&#x27;);
}, this.session);
}
}
async onAuthenticationNeeded() {
if(this.session) {
this.session &#x3D; null;
return {
failed: true,
restart: this.restartOnAuthFail,
failureEventPayload: &#x27;Unable to log in. Are the session details valid?&#x27;
};
}
return { failed: false };
}
async getAuthEventPayload() {
const isMD &#x3D; await this.client.pupPage.evaluate(() &#x3D;&gt; {
return window.Store.Features.features.MD_BACKEND;
});
if(isMD) throw new Error(&#x27;Authenticating via JSON session is not supported for MultiDevice-enabled WhatsApp accounts.&#x27;);
const localStorage &#x3D; JSON.parse(await this.client.pupPage.evaluate(() &#x3D;&gt; {
return JSON.stringify(window.localStorage);
}));
return {
WABrowserId: localStorage.WABrowserId,
WASecretBundle: localStorage.WASecretBundle,
WAToken1: localStorage.WAToken1,
WAToken2: localStorage.WAToken2
};
}
}
module.exports &#x3D; LegacySessionAuth;</code></pre>
</article>
</div>
</div>
<nav id="jsdoc-toc-nav" role="navigation"></nav>
</div>
</div>
<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.7 on March 9, 2022.
</p>
</div>
</footer>
<script src="scripts/jquery.min.js"></script>
<script src="scripts/tree.jquery.js"></script>
<script src="scripts/prettify.js"></script>
<script src="scripts/jsdoc-toc.js"></script>
<script src="scripts/linenumber.js"></script>
<script src="scripts/scrollanchor.js"></script>
</body>
</html>

View File

@@ -0,0 +1,106 @@
<!doctype html>
<html>
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.16.4 &raquo; Source: authStrategies/LocalAuth.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">
<link href="css/baseline.css" rel="stylesheet">
</head>
<body onload="prettyPrint()">
<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>16.<wbr>4</a>
</div>
</div>
</nav>
<div id="jsdoc-body-container">
<div id="jsdoc-content">
<div id="jsdoc-content-container">
<div id="jsdoc-banner" role="banner">
</div>
<div id="jsdoc-main" role="main">
<header class="page-header">
<h1>Source: authStrategies/LocalAuth.js</h1>
</header>
<article>
<pre class="prettyprint linenums"><code>&#x27;use strict&#x27;;
const path &#x3D; require(&#x27;path&#x27;);
const fs &#x3D; require(&#x27;fs&#x27;);
const BaseAuthStrategy &#x3D; require(&#x27;./BaseAuthStrategy&#x27;);
/**
* Local directory-based authentication
* @param {object} options - options
* @param {string} options.clientId - Client id to distinguish instances if you are using multiple, otherwise keep null if you are using only one instance
* @param {string} options.dataPath - Change the default path for saving session files, default is: &quot;./.wwebjs_auth/&quot;
*/
class LocalAuth extends BaseAuthStrategy {
constructor({ clientId, dataPath }&#x3D;{}) {
super();
const idRegex &#x3D; /^[-_\w]+$/i;
if(clientId &amp;amp;&amp;amp; !idRegex.test(clientId)) {
throw new Error(&#x27;Invalid clientId. Only alphanumeric characters, underscores and hyphens are allowed.&#x27;);
}
this.dataPath &#x3D; path.resolve(dataPath || &#x27;./.wwebjs_auth/&#x27;);
this.clientId &#x3D; clientId;
}
async beforeBrowserInitialized() {
const puppeteerOpts &#x3D; this.client.options.puppeteer;
const sessionDirName &#x3D; this.clientId ? &#x60;session-${this.clientId}&#x60; : &#x27;session&#x27;;
const dirPath &#x3D; path.join(this.dataPath, sessionDirName);
if(puppeteerOpts.userDataDir &amp;amp;&amp;amp; puppeteerOpts.userDataDir !&#x3D;&#x3D; dirPath) {
throw new Error(&#x27;LocalAuth is not compatible with a user-supplied userDataDir.&#x27;);
}
fs.mkdirSync(dirPath, { recursive: true });
this.client.options.puppeteer &#x3D; {
...puppeteerOpts,
userDataDir: dirPath
};
this.userDataDir &#x3D; dirPath;
}
async logout() {
if (this.userDataDir) {
return (fs.rmSync ? fs.rmSync : fs.rmdirSync).call(this, this.userDataDir, { recursive: true });
}
}
}
module.exports &#x3D; LocalAuth;</code></pre>
</article>
</div>
</div>
<nav id="jsdoc-toc-nav" role="navigation"></nav>
</div>
</div>
<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.7 on March 9, 2022.
</p>
</div>
</footer>
<script src="scripts/jquery.min.js"></script>
<script src="scripts/tree.jquery.js"></script>
<script src="scripts/prettify.js"></script>
<script src="scripts/jsdoc-toc.js"></script>
<script src="scripts/linenumber.js"></script>
<script src="scripts/scrollanchor.js"></script>
</body>
</html>

View File

@@ -0,0 +1,65 @@
<!doctype html>
<html>
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.16.4 &raquo; Source: authStrategies/NoAuth.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">
<link href="css/baseline.css" rel="stylesheet">
</head>
<body onload="prettyPrint()">
<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>16.<wbr>4</a>
</div>
</div>
</nav>
<div id="jsdoc-body-container">
<div id="jsdoc-content">
<div id="jsdoc-content-container">
<div id="jsdoc-banner" role="banner">
</div>
<div id="jsdoc-main" role="main">
<header class="page-header">
<h1>Source: authStrategies/NoAuth.js</h1>
</header>
<article>
<pre class="prettyprint linenums"><code>&#x27;use strict&#x27;;
const BaseAuthStrategy &#x3D; require(&#x27;./BaseAuthStrategy&#x27;);
/**
* No session restoring functionality
* Will need to authenticate via QR code every time
*/
class NoAuth extends BaseAuthStrategy { }
module.exports &#x3D; NoAuth;</code></pre>
</article>
</div>
</div>
<nav id="jsdoc-toc-nav" role="navigation"></nav>
</div>
</div>
<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.7 on March 9, 2022.
</p>
</div>
</footer>
<script src="scripts/jquery.min.js"></script>
<script src="scripts/tree.jquery.js"></script>
<script src="scripts/prettify.js"></script>
<script src="scripts/jsdoc-toc.js"></script>
<script src="scripts/linenumber.js"></script>
<script src="scripts/scrollanchor.js"></script>
</body>
</html>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Globals</title>
<title>whatsapp-web.js 1.16.4 &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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</a>
</div>
</div>
</nav>
@@ -68,16 +68,22 @@
<div class="summary-content">
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="global.html#ButtonSpec">ButtonSpec</a></dt>
<dd>
</dd>
<dt><a href="global.html#ContactId">ContactId</a></dt>
<dd>
</dd>
<dt><a href="global.html#GroupParticipant">GroupParticipant</a></dt>
<dt><a href="global.html#FormattedButtonSpec">FormattedButtonSpec</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="global.html#GroupParticipant">GroupParticipant</a></dt>
<dd>
</dd>
<dt><a href="global.html#MessageInfo">MessageInfo</a></dt>
<dd>
</dd>
@@ -383,6 +389,19 @@
<td>
</td>
</tr>
<tr>
<td>
<p>INCOMING_CALL</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
</tbody>
</table>
</section>
@@ -836,6 +855,266 @@
<td>
</td>
</tr>
<tr>
<td>
<p>LIST</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>LIST_RESPONSE</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>BUTTONS_RESPONSE</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>PAYMENT</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>BROADCAST_NOTIFICATION</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>CALL_LOG</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>CIPHERTEXT</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>DEBUG</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>E2E_NOTIFICATION</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>GP2</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>GROUP_NOTIFICATION</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>HSM</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>INTERACTIVE</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>NATIVE_FLOW</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>NOTIFICATION</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>NOTIFICATION_TEMPLATE</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>OVERSIZED</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>PROTOCOL</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>REACTION</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>TEMPLATE_BUTTON_REPLY</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
</tbody>
</table>
</section>
@@ -1081,6 +1360,54 @@
</section>
<h2>Abstract types</h2>
<section>
<h3 id="ButtonSpec"><span class="symbol-name">ButtonSpec</span><small class="property-type">
&nbsp;Object</small></h3>
<p>Button spec used in Buttons constructor</p>
<section>
<h4>Properties</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>id</p>
</td>
<td>
<p>string</p>
</td>
<td>
<p>Yes</p>
</td>
<td>
<p>Custom ID to set on the button. A random one will be generated if one is not passed.</p>
</td>
</tr>
<tr>
<td>
<p>body</p>
</td>
<td>
<p>string</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
<p>The text to show on the button.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
</dl>
<h3 id="ContactId"><span class="symbol-name">ContactId</span><small class="property-type">
&nbsp;Object</small></h3>
<p>ID that represents a contact</p>
@@ -1140,6 +1467,64 @@
</section>
<dl class="dl-compact">
</dl>
<h3 id="FormattedButtonSpec"><span class="symbol-name">FormattedButtonSpec</span><small class="property-type">
&nbsp;Object</small></h3>
<section>
<h4>Properties</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>buttonId</p>
</td>
<td>
<p>string</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>type</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p>buttonText</p>
</td>
<td>
<p>Object</p>
</td>
<td>
<p>&nbsp;</p>
</td>
<td>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
</dl>
<h3 id="GroupParticipant"><span class="symbol-name">GroupParticipant</span><small class="property-type">
&nbsp;Object</small></h3>
<p>Group participant information</p>
@@ -1329,7 +1714,7 @@
<p>Yes</p>
</td>
<td>
<p>Show links preview</p>
<p>Show links preview. Has no effect on multi-device accounts.</p>
<p>Defaults to <code>true</code>.</p>
</td>
</tr>
@@ -1595,7 +1980,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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

File diff suppressed because it is too large Load Diff

View File

@@ -6,7 +6,7 @@
treeNode.tree({
autoEscape: false,
closedIcon: '&#x21e2;',
data: [{"label":"<a href=\"global.html\">Globals</a>","id":"global","children":[]},{"label":"<a href=\"Base.html\">Base</a>","id":"Base","children":[]},{"label":"<a href=\"BusinessContact.html\">BusinessContact</a>","id":"BusinessContact","children":[]},{"label":"<a href=\"Chat.html\">Chat</a>","id":"Chat","children":[]},{"label":"<a href=\"Client.html\">Client</a>","id":"Client","children":[]},{"label":"<a href=\"ClientInfo.html\">ClientInfo</a>","id":"ClientInfo","children":[]},{"label":"<a href=\"Contact.html\">Contact</a>","id":"Contact","children":[]},{"label":"<a href=\"GroupChat.html\">GroupChat</a>","id":"GroupChat","children":[]},{"label":"<a href=\"GroupNotification.html\">GroupNotification</a>","id":"GroupNotification","children":[]},{"label":"<a href=\"InterfaceController.html\">InterfaceController</a>","id":"InterfaceController","children":[]},{"label":"<a href=\"Label.html\">Label</a>","id":"Label","children":[]},{"label":"<a href=\"Location.html\">Location</a>","id":"Location","children":[]},{"label":"<a href=\"Message.html\">Message</a>","id":"Message","children":[]},{"label":"<a href=\"MessageMedia.html\">MessageMedia</a>","id":"MessageMedia","children":[]},{"label":"<a href=\"Order.html\">Order</a>","id":"Order","children":[]},{"label":"<a href=\"PrivateChat.html\">PrivateChat</a>","id":"PrivateChat","children":[]},{"label":"<a href=\"PrivateContact.html\">PrivateContact</a>","id":"PrivateContact","children":[]},{"label":"<a href=\"Product.html\">Product</a>","id":"Product","children":[]},{"label":"<a href=\"Util.html\">Util</a>","id":"Util","children":[]}],
data: [{"label":"<a href=\"global.html\">Globals</a>","id":"global","children":[]},{"label":"<a href=\"Base.html\">Base</a>","id":"Base","children":[]},{"label":"<a href=\"BaseAuthStrategy.html\">BaseAuthStrategy</a>","id":"BaseAuthStrategy","children":[]},{"label":"<a href=\"BusinessContact.html\">BusinessContact</a>","id":"BusinessContact","children":[]},{"label":"<a href=\"Buttons.html\">Buttons</a>","id":"Buttons","children":[]},{"label":"<a href=\"Call.html\">Call</a>","id":"Call","children":[]},{"label":"<a href=\"Chat.html\">Chat</a>","id":"Chat","children":[]},{"label":"<a href=\"Client.html\">Client</a>","id":"Client","children":[]},{"label":"<a href=\"ClientInfo.html\">ClientInfo</a>","id":"ClientInfo","children":[]},{"label":"<a href=\"Contact.html\">Contact</a>","id":"Contact","children":[]},{"label":"<a href=\"GroupChat.html\">GroupChat</a>","id":"GroupChat","children":[]},{"label":"<a href=\"GroupNotification.html\">GroupNotification</a>","id":"GroupNotification","children":[]},{"label":"<a href=\"InterfaceController.html\">InterfaceController</a>","id":"InterfaceController","children":[]},{"label":"<a href=\"Label.html\">Label</a>","id":"Label","children":[]},{"label":"<a href=\"LegacySessionAuth.html\">LegacySessionAuth</a>","id":"LegacySessionAuth","children":[]},{"label":"<a href=\"List.html\">List</a>","id":"List","children":[]},{"label":"<a href=\"LocalAuth.html\">LocalAuth</a>","id":"LocalAuth","children":[]},{"label":"<a href=\"Location.html\">Location</a>","id":"Location","children":[]},{"label":"<a href=\"Message.html\">Message</a>","id":"Message","children":[]},{"label":"<a href=\"MessageMedia.html\">MessageMedia</a>","id":"MessageMedia","children":[]},{"label":"<a href=\"NoAuth.html\">NoAuth</a>","id":"NoAuth","children":[]},{"label":"<a href=\"Order.html\">Order</a>","id":"Order","children":[]},{"label":"<a href=\"PrivateChat.html\">PrivateChat</a>","id":"PrivateChat","children":[]},{"label":"<a href=\"PrivateContact.html\">PrivateContact</a>","id":"PrivateContact","children":[]},{"label":"<a href=\"Product.html\">Product</a>","id":"Product","children":[]},{"label":"<a href=\"Util.html\">Util</a>","id":"Util","children":[]}],
openedIcon: ' &#x21e3;',
saveState: false,
useContextMenu: false

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Source: structures/Base.js</title>
<title>whatsapp-web.js 1.16.4 &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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Source: structures/BusinessContact.js</title>
<title>whatsapp-web.js 1.16.4 &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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -0,0 +1,135 @@
<!doctype html>
<html>
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.16.4 &raquo; Source: structures/Buttons.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">
<link href="css/baseline.css" rel="stylesheet">
</head>
<body onload="prettyPrint()">
<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>16.<wbr>4</a>
</div>
</div>
</nav>
<div id="jsdoc-body-container">
<div id="jsdoc-content">
<div id="jsdoc-content-container">
<div id="jsdoc-banner" role="banner">
</div>
<div id="jsdoc-main" role="main">
<header class="page-header">
<h1>Source: structures/Buttons.js</h1>
</header>
<article>
<pre class="prettyprint linenums"><code>&#x27;use strict&#x27;;
const MessageMedia &#x3D; require(&#x27;./MessageMedia&#x27;);
const Util &#x3D; require(&#x27;../util/Util&#x27;);
/**
* Button spec used in Buttons constructor
* @typedef {Object} ButtonSpec
* @property {string&#x3D;} id - Custom ID to set on the button. A random one will be generated if one is not passed.
* @property {string} body - The text to show on the button.
*/
/**
* @typedef {Object} FormattedButtonSpec
* @property {string} buttonId
* @property {number} type
* @property {Object} buttonText
*/
/**
* Message type buttons
*/
class Buttons {
/**
* @param {string|MessageMedia} body
* @param {ButtonSpec[]} buttons - See {@link ButtonSpec}
* @param {string?} title
* @param {string?} footer
*/
constructor(body, buttons, title, footer) {
/**
* Message body
* @type {string|MessageMedia}
*/
this.body &#x3D; body;
/**
* title of message
* @type {string}
*/
this.title &#x3D; title;
/**
* footer of message
* @type {string}
*/
this.footer &#x3D; footer;
if (body instanceof MessageMedia) {
this.type &#x3D; &#x27;media&#x27;;
this.title &#x3D; &#x27;&#x27;;
}else{
this.type &#x3D; &#x27;chat&#x27;;
}
/**
* buttons of message
* @type {FormattedButtonSpec[]}
*/
this.buttons &#x3D; this._format(buttons);
if(!this.buttons.length){ throw &#x27;[BT01] No buttons&#x27;;}
}
/**
* Creates button array from simple array
* @param {ButtonSpec[]} buttons
* @returns {FormattedButtonSpec[]}
* @example
* Input: [{id:&#x27;customId&#x27;,body:&#x27;button1&#x27;},{body:&#x27;button2&#x27;},{body:&#x27;button3&#x27;},{body:&#x27;button4&#x27;}]
* Returns: [{ buttonId:&#x27;customId&#x27;,buttonText:{&#x27;displayText&#x27;:&#x27;button1&#x27;},type: 1 },{buttonId:&#x27;n3XKsL&#x27;,buttonText:{&#x27;displayText&#x27;:&#x27;button2&#x27;},type:1},{buttonId:&#x27;NDJk0a&#x27;,buttonText:{&#x27;displayText&#x27;:&#x27;button3&#x27;},type:1}]
*/
_format(buttons){
buttons &#x3D; buttons.slice(0,3); // phone users can only see 3 buttons, so lets limit this
return buttons.map((btn) &#x3D;&gt; {
return {&#x27;buttonId&#x27;:btn.id ? String(btn.id) : Util.generateHash(6),&#x27;buttonText&#x27;:{&#x27;displayText&#x27;:btn.body},&#x27;type&#x27;:1};
});
}
}
module.exports &#x3D; Buttons;</code></pre>
</article>
</div>
</div>
<nav id="jsdoc-toc-nav" role="navigation"></nav>
</div>
</div>
<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.7 on March 9, 2022.
</p>
</div>
</footer>
<script src="scripts/jquery.min.js"></script>
<script src="scripts/tree.jquery.js"></script>
<script src="scripts/prettify.js"></script>
<script src="scripts/jsdoc-toc.js"></script>
<script src="scripts/linenumber.js"></script>
<script src="scripts/scrollanchor.js"></script>
</body>
</html>

View File

@@ -0,0 +1,121 @@
<!doctype html>
<html>
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.16.4 &raquo; Source: structures/Call.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">
<link href="css/baseline.css" rel="stylesheet">
</head>
<body onload="prettyPrint()">
<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>16.<wbr>4</a>
</div>
</div>
</nav>
<div id="jsdoc-body-container">
<div id="jsdoc-content">
<div id="jsdoc-content-container">
<div id="jsdoc-banner" role="banner">
</div>
<div id="jsdoc-main" role="main">
<header class="page-header">
<h1>Source: structures/Call.js</h1>
</header>
<article>
<pre class="prettyprint linenums"><code>&#x27;use strict&#x27;;
const Base &#x3D; require(&#x27;./Base&#x27;);
/**
* Represents a Call on WhatsApp
* @extends {Base}
*/
class Call extends Base {
constructor(client, data) {
super(client);
if (data) this._patch(data);
}
_patch(data) {
/**
* Call ID
* @type {string}
*/
this.id &#x3D; data.id;
/**
* From
* @type {string}
*/
this.from &#x3D; data.peerJid;
/**
* Unix timestamp for when the call was created
* @type {number}
*/
this.timestamp &#x3D; data.offerTime;
/**
* Is video
* @type {boolean}
*/
this.isVideo &#x3D; data.isVideo;
/**
* Is Group
* @type {boolean}
*/
this.isGroup &#x3D; data.isGroup;
/**
* Indicates if the call was sent by the current user
* @type {boolean}
*/
this.fromMe &#x3D; data.outgoing;
/**
* Indicates if the call can be handled in waweb
* @type {boolean}
*/
this.canHandleLocally &#x3D; data.canHandleLocally;
/**
* Indicates if the call Should be handled in waweb
* @type {boolean}
*/
this.webClientShouldHandle &#x3D; data.webClientShouldHandle;
/**
* Object with participants
* @type {object}
*/
this.participants &#x3D; data.participants;
return super._patch(data);
}
}
module.exports &#x3D; Call;</code></pre>
</article>
</div>
</div>
<nav id="jsdoc-toc-nav" role="navigation"></nav>
</div>
</div>
<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.7 on March 9, 2022.
</p>
</div>
</footer>
<script src="scripts/jquery.min.js"></script>
<script src="scripts/tree.jquery.js"></script>
<script src="scripts/prettify.js"></script>
<script src="scripts/jsdoc-toc.js"></script>
<script src="scripts/linenumber.js"></script>
<script src="scripts/scrollanchor.js"></script>
</body>
</html>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Source: structures/Chat.js</title>
<title>whatsapp-web.js 1.16.4 &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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</a>
</div>
</div>
</nav>
@@ -96,7 +96,7 @@ class Chat extends Base {
/**
* Indicates if the chat is muted or not
* @type {number}
* @type {boolean}
*/
this.isMuted &#x3D; data.isMuted;
@@ -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);
@@ -202,30 +202,32 @@ class Chat extends Base {
/**
* Loads chat messages, sorted from earliest to latest.
* @param {Object} searchOptions Options for searching messages. Right now only limit is supported.
* @param {Number} [searchOptions.limit&#x3D;50] The amount of messages to return. Note that the actual number of returned messages may be smaller if there aren&#x27;t enough messages in the conversation. Set this to Infinity to load all messages.
* @param {Number} [searchOptions.limit] The amount of messages to return. If no limit is specified, the available messages will be returned. Note that the actual number of returned messages may be smaller if there aren&#x27;t enough messages in the conversation. Set this to Infinity to load all messages.
* @returns {Promise&amp;lt;Array&amp;lt;Message&gt;&gt;}
*/
async fetchMessages(searchOptions) {
if (!searchOptions || !searchOptions.limit) {
searchOptions &#x3D; { limit: 50 };
}
let messages &#x3D; await this.client.pupPage.evaluate(async (chatId, limit) &#x3D;&gt; {
let messages &#x3D; await this.client.pupPage.evaluate(async (chatId, searchOptions) &#x3D;&gt; {
const msgFilter &#x3D; m &#x3D;&gt; !m.isNotification; // dont include notification messages
const chat &#x3D; window.Store.Chat.get(chatId);
let msgs &#x3D; chat.msgs.models.filter(msgFilter);
while (msgs.length &amp;lt; limit) {
const loadedMessages &#x3D; await chat.loadEarlierMsgs();
if (!loadedMessages) break;
msgs &#x3D; [...loadedMessages.filter(msgFilter), ...msgs];
if (searchOptions &amp;amp;&amp;amp; searchOptions.limit &gt; 0) {
while (msgs.length &amp;lt; searchOptions.limit) {
const loadedMessages &#x3D; await chat.loadEarlierMsgs();
if (!loadedMessages) break;
msgs &#x3D; [...loadedMessages.filter(msgFilter), ...msgs];
}
if (msgs.length &gt; searchOptions.limit) {
msgs.sort((a, b) &#x3D;&gt; (a.t &gt; b.t) ? 1 : -1);
msgs &#x3D; msgs.splice(msgs.length - searchOptions.limit);
}
}
msgs.sort((a, b) &#x3D;&gt; (a.t &gt; b.t) ? 1 : -1);
if (msgs.length &gt; limit) msgs &#x3D; msgs.splice(msgs.length - limit);
return msgs.map(m &#x3D;&gt; window.WWebJS.getMessageModel(m));
}, this.id._serialized, searchOptions.limit);
}, this.id._serialized, searchOptions);
return messages.map(m &#x3D;&gt; new Message(this.client, m));
}
@@ -288,7 +290,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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Source: structures/ClientInfo.js</title>
<title>whatsapp-web.js 1.16.4 &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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</a>
</div>
</div>
</nav>
@@ -51,12 +51,6 @@ class ClientInfo extends Base {
*/
this.pushname &#x3D; data.pushname;
/**
* @type {object}
* @deprecated Use .wid instead
*/
this.me &#x3D; data.wid;
/**
* Current user ID
* @type {object}
@@ -64,18 +58,25 @@ class ClientInfo extends Base {
this.wid &#x3D; data.wid;
/**
* Information about the phone this client is connected to
* @type {object}
* @deprecated Use .wid instead
*/
this.me &#x3D; data.wid;
/**
* Information about the phone this client is connected to. Not available in multi-device.
* @type {object}
* @property {string} wa_version WhatsApp Version running on the phone
* @property {string} os_version OS Version running on the phone (iOS or Android version)
* @property {string} device_manufacturer Device manufacturer
* @property {string} device_model Device model
* @property {string} os_build_number OS build number
* @deprecated
*/
this.phone &#x3D; data.phone;
/**
* Platform the phone is running on
* Platform WhatsApp is running on
* @type {string}
*/
this.platform &#x3D; data.platform;
@@ -88,6 +89,7 @@ class ClientInfo extends Base {
* @returns {object} batteryStatus
* @returns {number} batteryStatus.battery - The current battery percentage
* @returns {boolean} batteryStatus.plugged - Indicates if the phone is plugged in (true) or not (false)
* @deprecated
*/
async getBatteryStatus() {
return await this.client.pupPage.evaluate(() &#x3D;&gt; {
@@ -95,7 +97,6 @@ class ClientInfo extends Base {
return { battery, plugged };
});
}
}
module.exports &#x3D; ClientInfo;</code></pre>
@@ -108,7 +109,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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Source: structures/Contact.js</title>
<title>whatsapp-web.js 1.16.4 &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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</a>
</div>
</div>
</nav>
@@ -139,7 +139,7 @@ class Contact extends Base {
* @type {boolean}
*/
this.isBlocked &#x3D; 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&#x27;s formatted phone number, (12345678901@c.us) &#x3D;&gt; (+1 (234) 5678-901)
* @returns {Promise&amp;lt;string&gt;}
*/
async getFormattedNumber() {
return await this.client.getFormattedNumber(this.id._serialized);
}
/**
* Returns the contact&#x27;s countrycode, (1541859685@c.us) &#x3D;&gt; (1)
* @returns {Promise&amp;lt;string&gt;}
*/
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.
@@ -198,7 +214,8 @@ class Contact extends Base {
*/
async getAbout() {
const about &#x3D; await this.client.pupPage.evaluate(async (contactId) &#x3D;&gt; {
return window.Store.Wap.statusFind(contactId);
const wid &#x3D; window.Store.WidFactory.createWid(contactId);
return window.Store.StatusUtils.getStatus(wid);
}, this.id._serialized);
if (typeof about.status !&#x3D;&#x3D; &#x27;string&#x27;)
@@ -206,10 +223,19 @@ class Contact extends Base {
return about.status;
}
/**
* Gets the Contact&#x27;s common groups with you. Returns empty array if you don&#x27;t have any common group.
* @returns {Promise&amp;lt;WAWebJS.ChatId[]&gt;}
*/
async getCommonGroups() {
return await this.client.getCommonGroups(this.id._serialized);
}
}
module.exports &#x3D; Contact;</code></pre>
module.exports &#x3D; Contact;
</code></pre>
</article>
</div>
</div>
@@ -219,7 +245,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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Source: structures/GroupChat.js</title>
<title>whatsapp-web.js 1.16.4 &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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</a>
</div>
</div>
</nav>
@@ -91,7 +91,9 @@ class GroupChat extends Chat {
*/
async addParticipants(participantIds) {
return await this.client.pupPage.evaluate((chatId, participantIds) &#x3D;&gt; {
return window.Store.Wap.addParticipants(chatId, participantIds);
const chatWid &#x3D; window.Store.WidFactory.createWid(chatId);
const participantWids &#x3D; participantIds.map(p &#x3D;&gt; window.Store.WidFactory.createWid(p));
return window.Store.GroupParticipants.sendAddParticipants(chatWid, participantWids);
}, this.id._serialized, participantIds);
}
@@ -102,7 +104,9 @@ class GroupChat extends Chat {
*/
async removeParticipants(participantIds) {
return await this.client.pupPage.evaluate((chatId, participantIds) &#x3D;&gt; {
return window.Store.Wap.removeParticipants(chatId, participantIds);
const chatWid &#x3D; window.Store.WidFactory.createWid(chatId);
const participantWids &#x3D; participantIds.map(p &#x3D;&gt; window.Store.WidFactory.createWid(p));
return window.Store.GroupParticipants.sendRemoveParticipants(chatWid, participantWids);
}, this.id._serialized, participantIds);
}
@@ -113,7 +117,9 @@ class GroupChat extends Chat {
*/
async promoteParticipants(participantIds) {
return await this.client.pupPage.evaluate((chatId, participantIds) &#x3D;&gt; {
return window.Store.Wap.promoteParticipants(chatId, participantIds);
const chatWid &#x3D; window.Store.WidFactory.createWid(chatId);
const participantWids &#x3D; participantIds.map(p &#x3D;&gt; window.Store.WidFactory.createWid(p));
return window.Store.GroupParticipants.sendPromoteParticipants(chatWid, participantWids);
}, this.id._serialized, participantIds);
}
@@ -124,39 +130,53 @@ class GroupChat extends Chat {
*/
async demoteParticipants(participantIds) {
return await this.client.pupPage.evaluate((chatId, participantIds) &#x3D;&gt; {
return window.Store.Wap.demoteParticipants(chatId, participantIds);
const chatWid &#x3D; window.Store.WidFactory.createWid(chatId);
const participantWids &#x3D; participantIds.map(p &#x3D;&gt; window.Store.WidFactory.createWid(p));
return window.Store.GroupParticipants.sendDemoteParticipants(chatWid, participantWids);
}, this.id._serialized, participantIds);
}
/**
* Updates the group subject
* @param {string} subject
* @returns {Promise}
* @returns {Promise&amp;lt;boolean&gt;} Returns true if the subject was properly updated. This can return false if the user does not have the necessary permissions.
*/
async setSubject(subject) {
let res &#x3D; await this.client.pupPage.evaluate((chatId, subject) &#x3D;&gt; {
return window.Store.Wap.changeSubject(chatId, subject);
const success &#x3D; await this.client.pupPage.evaluate(async (chatId, subject) &#x3D;&gt; {
const chatWid &#x3D; window.Store.WidFactory.createWid(chatId);
try {
return await window.Store.GroupUtils.sendSetGroupSubject(chatWid, subject);
} catch (err) {
if(err.name &#x3D;&#x3D;&#x3D; &#x27;ServerStatusCodeError&#x27;) return false;
throw err;
}
}, this.id._serialized, subject);
if(res.status &#x3D;&#x3D; 200) {
this.name &#x3D; subject;
}
if(!success) return false;
this.name &#x3D; subject;
return true;
}
/**
* Updates the group description
* @param {string} description
* @returns {Promise}
* @returns {Promise&amp;lt;boolean&gt;} Returns true if the description was properly updated. This can return false if the user does not have the necessary permissions.
*/
async setDescription(description) {
let res &#x3D; await this.client.pupPage.evaluate((chatId, description) &#x3D;&gt; {
let descId &#x3D; window.Store.GroupMetadata.get(chatId).descId;
return window.Store.Wap.setGroupDescription(chatId, description, window.Store.genId(), descId);
const success &#x3D; await this.client.pupPage.evaluate(async (chatId, description) &#x3D;&gt; {
const chatWid &#x3D; window.Store.WidFactory.createWid(chatId);
let descId &#x3D; window.Store.GroupMetadata.get(chatWid).descId;
try {
return await window.Store.GroupUtils.sendSetGroupDescription(chatWid, description, window.Store.MsgKey.newId(), descId);
} catch (err) {
if(err.name &#x3D;&#x3D;&#x3D; &#x27;ServerStatusCodeError&#x27;) return false;
throw err;
}
}, this.id._serialized, description);
if (res.status &#x3D;&#x3D; 200) {
this.groupMetadata.desc &#x3D; description;
}
if(!success) return false;
this.groupMetadata.desc &#x3D; description;
return true;
}
/**
@@ -165,12 +185,18 @@ class GroupChat extends Chat {
* @returns {Promise&amp;lt;boolean&gt;} Returns true if the setting was properly updated. This can return false if the user does not have the necessary permissions.
*/
async setMessagesAdminsOnly(adminsOnly&#x3D;true) {
let res &#x3D; await this.client.pupPage.evaluate((chatId, value) &#x3D;&gt; {
return window.Store.Wap.setGroupProperty(chatId, &#x27;announcement&#x27;, value);
const success &#x3D; await this.client.pupPage.evaluate(async (chatId, adminsOnly) &#x3D;&gt; {
const chatWid &#x3D; window.Store.WidFactory.createWid(chatId);
try {
return await window.Store.GroupUtils.sendSetGroupProperty(chatWid, &#x27;announcement&#x27;, adminsOnly ? 1 : 0);
} catch (err) {
if(err.name &#x3D;&#x3D;&#x3D; &#x27;ServerStatusCodeError&#x27;) return false;
throw err;
}
}, this.id._serialized, adminsOnly);
if (res.status !&#x3D;&#x3D; 200) return false;
if(!success) return false;
this.groupMetadata.announce &#x3D; adminsOnly;
return true;
}
@@ -181,11 +207,17 @@ class GroupChat extends Chat {
* @returns {Promise&amp;lt;boolean&gt;} Returns true if the setting was properly updated. This can return false if the user does not have the necessary permissions.
*/
async setInfoAdminsOnly(adminsOnly&#x3D;true) {
let res &#x3D; await this.client.pupPage.evaluate((chatId, value) &#x3D;&gt; {
return window.Store.Wap.setGroupProperty(chatId, &#x27;restrict&#x27;, value);
const success &#x3D; await this.client.pupPage.evaluate(async (chatId, adminsOnly) &#x3D;&gt; {
const chatWid &#x3D; window.Store.WidFactory.createWid(chatId);
try {
return await window.Store.GroupUtils.sendSetGroupProperty(chatWid, &#x27;restrict&#x27;, adminsOnly ? 1 : 0);
} catch (err) {
if(err.name &#x3D;&#x3D;&#x3D; &#x27;ServerStatusCodeError&#x27;) return false;
throw err;
}
}, this.id._serialized, adminsOnly);
if (res.status !&#x3D;&#x3D; 200) return false;
if(!success) return false;
this.groupMetadata.restrict &#x3D; adminsOnly;
return true;
@@ -196,25 +228,25 @@ class GroupChat extends Chat {
* @returns {Promise&amp;lt;string&gt;} Group&#x27;s invite code
*/
async getInviteCode() {
let res &#x3D; await this.client.pupPage.evaluate(chatId &#x3D;&gt; {
return window.Store.Wap.groupInviteCode(chatId);
const code &#x3D; await this.client.pupPage.evaluate(async chatId &#x3D;&gt; {
const chatWid &#x3D; window.Store.WidFactory.createWid(chatId);
return window.Store.Invite.sendQueryGroupInviteCode(chatWid);
}, this.id._serialized);
if (res.status &#x3D;&#x3D; 200) {
return res.code;
}
throw new Error(&#x27;Not authorized&#x27;);
return code;
}
/**
* Invalidates the current group invite code and generates a new one
* @returns {Promise}
* @returns {Promise&amp;lt;string&gt;} New invite code
*/
async revokeInvite() {
return await this.client.pupPage.evaluate(chatId &#x3D;&gt; {
return window.Store.Wap.revokeGroupInvite(chatId);
const code &#x3D; await this.client.pupPage.evaluate(chatId &#x3D;&gt; {
const chatWid &#x3D; window.Store.WidFactory.createWid(chatId);
return window.Store.Invite.sendRevokeGroupInviteCode(chatWid);
}, this.id._serialized);
return code;
}
/**
@@ -222,8 +254,9 @@ class GroupChat extends Chat {
* @returns {Promise}
*/
async leave() {
return await this.client.pupPage.evaluate(chatId &#x3D;&gt; {
return window.Store.Wap.leaveGroup(chatId);
await this.client.pupPage.evaluate(chatId &#x3D;&gt; {
const chatWid &#x3D; window.Store.WidFactory.createWid(chatId);
return window.Store.GroupUtils.sendExitGroup(chatWid);
}, this.id._serialized);
}
@@ -239,7 +272,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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Source: structures/GroupNotification.js</title>
<title>whatsapp-web.js 1.16.4 &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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</a>
</div>
</div>
</nav>
@@ -74,7 +74,7 @@ class GroupNotification extends Base {
*
* @type {string}
*/
this.chatId &#x3D; typeof (data.from) &#x3D;&#x3D;&#x3D; &#x27;object&#x27; ? data.from._serialized : data.from;
this.chatId &#x3D; typeof (data.to) &#x3D;&#x3D;&#x3D; &#x27;object&#x27; ? data.to._serialized : data.to;
/**
* 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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Source: structures/Label.js</title>
<title>whatsapp-web.js 1.16.4 &raquo; Source: structures/Label.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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</a>
</div>
</div>
</nav>
@@ -88,7 +88,7 @@ module.exports &#x3D; Label;</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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -0,0 +1,133 @@
<!doctype html>
<html>
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.16.4 &raquo; Source: structures/List.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">
<link href="css/baseline.css" rel="stylesheet">
</head>
<body onload="prettyPrint()">
<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>16.<wbr>4</a>
</div>
</div>
</nav>
<div id="jsdoc-body-container">
<div id="jsdoc-content">
<div id="jsdoc-content-container">
<div id="jsdoc-banner" role="banner">
</div>
<div id="jsdoc-main" role="main">
<header class="page-header">
<h1>Source: structures/List.js</h1>
</header>
<article>
<pre class="prettyprint linenums"><code>&#x27;use strict&#x27;;
const Util &#x3D; require(&#x27;../util/Util&#x27;);
/**
* Message type List
*/
class List {
/**
* @param {string} body
* @param {string} buttonText
* @param {Array&amp;lt;any&gt;} sections
* @param {string?} title
* @param {string?} footer
*/
constructor(body, buttonText, sections, title, footer) {
/**
* Message body
* @type {string}
*/
this.description &#x3D; body;
/**
* List button text
* @type {string}
*/
this.buttonText &#x3D; buttonText;
/**
* title of message
* @type {string}
*/
this.title &#x3D; title;
/**
* footer of message
* @type {string}
*/
this.footer &#x3D; footer;
/**
* sections of message
* @type {Array&amp;lt;any&gt;}
*/
this.sections &#x3D; this._format(sections);
}
/**
* Creates section array from simple array
* @param {Array&amp;lt;any&gt;} sections
* @returns {Array&amp;lt;any&gt;}
* @example
* Input: [{title:&#x27;sectionTitle&#x27;,rows:[{id:&#x27;customId&#x27;, title:&#x27;ListItem2&#x27;, description: &#x27;desc&#x27;},{title:&#x27;ListItem2&#x27;}]}}]
* Returns: [{&#x27;title&#x27;:&#x27;sectionTitle&#x27;,&#x27;rows&#x27;:[{&#x27;rowId&#x27;:&#x27;customId&#x27;,&#x27;title&#x27;:&#x27;ListItem1&#x27;,&#x27;description&#x27;:&#x27;desc&#x27;},{&#x27;rowId&#x27;:&#x27;oGSRoD&#x27;,&#x27;title&#x27;:&#x27;ListItem2&#x27;,&#x27;description&#x27;:&#x27;&#x27;}]}]
*/
_format(sections){
if(!sections.length){throw &#x27;[LT02] List without sections&#x27;;}
if(sections.length &gt; 1 &amp;amp;&amp;amp; sections.filter(s &#x3D;&gt; typeof s.title &#x3D;&#x3D; &#x27;undefined&#x27;).length &gt; 1){throw &#x27;[LT05] You can\&#x27;t have more than one empty title.&#x27;;}
return sections.map( (section) &#x3D;&gt;{
if(!section.rows.length){throw &#x27;[LT03] Section without rows&#x27;;}
return {
title: section.title ? section.title : undefined,
rows: section.rows.map( (row) &#x3D;&gt; {
if(!row.title){throw &#x27;[LT04] Row without title&#x27;;}
return {
rowId: row.id ? row.id : Util.generateHash(6),
title: row.title,
description: row.description ? row.description : &#x27;&#x27;
};
})
};
});
}
}
module.exports &#x3D; List;
</code></pre>
</article>
</div>
</div>
<nav id="jsdoc-toc-nav" role="navigation"></nav>
</div>
</div>
<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.7 on March 9, 2022.
</p>
</div>
</footer>
<script src="scripts/jquery.min.js"></script>
<script src="scripts/tree.jquery.js"></script>
<script src="scripts/prettify.js"></script>
<script src="scripts/jsdoc-toc.js"></script>
<script src="scripts/linenumber.js"></script>
<script src="scripts/scrollanchor.js"></script>
</body>
</html>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Source: structures/Location.js</title>
<title>whatsapp-web.js 1.16.4 &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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Source: structures/Message.js</title>
<title>whatsapp-web.js 1.16.4 &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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</a>
</div>
</div>
</nav>
@@ -35,6 +35,7 @@ const Base &#x3D; require(&#x27;./Base&#x27;);
const MessageMedia &#x3D; require(&#x27;./MessageMedia&#x27;);
const Location &#x3D; require(&#x27;./Location&#x27;);
const Order &#x3D; require(&#x27;./Order&#x27;);
const Payment &#x3D; require(&#x27;./Payment&#x27;);
const { MessageTypes } &#x3D; require(&#x27;../util/Constants&#x27;);
/**
@@ -49,13 +50,14 @@ class Message extends Base {
}
_patch(data) {
this._data &#x3D; data;
/**
* MediaKey that represents the sticker &#x27;ID&#x27;
* @type {string}
*/
this.mediaKey &#x3D; data.mediaKey;
/**
* ID that represents the message
* @type {object}
@@ -80,7 +82,7 @@ class Message extends Base {
*/
this.body &#x3D; this.hasMedia ? data.caption || &#x27;&#x27; : data.body || &#x27;&#x27;;
/**
/**
* Message type
* @type {MessageTypes}
*/
@@ -100,9 +102,9 @@ class Message extends Base {
/**
* ID for who this message is for.
*
*
* If the message is sent by the current user, it will be the Chat to which the message is being sent.
* If the message is sent by another user, it will be the ID for the current user.
* If the message is sent by another user, it will be the ID for the current user.
* @type {string}
*/
this.to &#x3D; (typeof (data.to) &#x3D;&#x3D;&#x3D; &#x27;object&#x27; &amp;amp;&amp;amp; data.to !&#x3D;&#x3D; null) ? data.to._serialized : data.to;
@@ -117,14 +119,22 @@ class Message extends Base {
* String that represents from which device type the message was sent
* @type {string}
*/
this.deviceType &#x3D; data.id.id.length &gt; 21 ? &#x27;android&#x27; : data.id.id.substring(0,2) &#x3D;&#x3D;&#x27;3A&#x27; ? &#x27;ios&#x27; : &#x27;web&#x27;;
this.deviceType &#x3D; data.id.id.length &gt; 21 ? &#x27;android&#x27; : data.id.id.substring(0, 2) &#x3D;&#x3D; &#x27;3A&#x27; ? &#x27;ios&#x27; : &#x27;web&#x27;;
/**
* Indicates if the message was forwarded
* @type {boolean}
*/
this.isForwarded &#x3D; data.isForwarded;
/**
* Indicates how many times the message was forwarded.
*
* The maximum value is 127.
* @type {number}
*/
this.forwardingScore &#x3D; data.forwardingScore || 0;
/**
* Indicates if the message is a status update
* @type {boolean}
@@ -136,14 +146,14 @@ class Message extends Base {
* @type {boolean}
*/
this.isStarred &#x3D; data.star;
/**
* Indicates if the message was a broadcast
* @type {boolean}
*/
this.broadcast &#x3D; data.broadcast;
/**
/**
* Indicates if the message was sent by the current user
* @type {boolean}
*/
@@ -155,6 +165,12 @@ class Message extends Base {
*/
this.hasQuotedMsg &#x3D; data.quotedMsg ? true : false;
/**
* Indicates the duration of the message in seconds
* @type {string}
*/
this.duration &#x3D; data.duration ? data.duration : undefined;
/**
* Location information contained in the message, if the message is type &quot;location&quot;
* @type {Location}
@@ -179,7 +195,7 @@ class Message extends Base {
fromId: data.from._serialized,
toId: data.to._serialized
} : undefined;
/**
* Indicates the mentions in the message body.
* @type {Array&amp;lt;string&gt;}
@@ -201,6 +217,18 @@ class Message extends Base {
*/
this.token &#x3D; data.token ? data.token : undefined;
/**
* Indicates whether the message is a Gif
* @type {boolean}
*/
this.isGif &#x3D; Boolean(data.isGif);
/**
* Indicates if the message will disappear after it expires
* @type {boolean}
*/
this.isEphemeral &#x3D; data.isEphemeral;
/** Title */
if (data.title) {
this.title &#x3D; data.title;
@@ -223,10 +251,26 @@ class Message extends Base {
/**
* Links included in the message.
* @type {Array&amp;lt;string&gt;}
* @type {Array&amp;lt;{link: string, isSuspicious: boolean}&gt;}
*
*/
this.links &#x3D; data.links;
/** Buttons */
if (data.dynamicReplyButtons) {
this.dynamicReplyButtons &#x3D; data.dynamicReplyButtons;
}
/** Selected Button Id **/
if (data.selectedButtonId) {
this.selectedButtonId &#x3D; data.selectedButtonId;
}
/** Selected List row Id **/
if (data.listResponse &amp;amp;&amp;amp; data.listResponse.singleSelectReply.selectedRowId) {
this.selectedRowId &#x3D; data.listResponse.singleSelectReply.selectedRowId;
}
return super._patch(data);
}
@@ -234,6 +278,32 @@ class Message extends Base {
return this.fromMe ? this.to : this.from;
}
/**
* Reloads this Message object&#x27;s data in-place with the latest values from WhatsApp Web.
* Note that the Message must still be in the web app cache for this to work, otherwise will return null.
* @returns {Promise&amp;lt;Message&gt;}
*/
async reload() {
const newData &#x3D; await this.client.pupPage.evaluate((msgId) &#x3D;&gt; {
const msg &#x3D; window.Store.Msg.get(msgId);
if(!msg) return null;
return window.WWebJS.getMessageModel(msg);
}, this.id._serialized);
if(!newData) return null;
this._patch(newData);
return this;
}
/**
* Returns message in a raw format
* @type {Object}
*/
get rawData() {
return this._data;
}
/**
* Returns the Chat this message was sent in
* @returns {Promise&amp;lt;Chat&gt;}
@@ -274,12 +344,12 @@ class Message extends Base {
}
/**
* Sends a message as a reply to this message. If chatId is specified, it will be sent
* through the specified Chat. If not, it will send the message
* Sends a message as a reply to this message. If chatId is specified, it will be sent
* through the specified Chat. If not, it will send the message
* in the same Chat as the original message was sent.
*
* @param {string|MessageMedia|Location} content
* @param {string} [chatId]
*
* @param {string|MessageMedia|Location} content
* @param {string} [chatId]
* @param {MessageSendOptions} [options]
* @returns {Promise&amp;lt;Message&gt;}
*/
@@ -303,10 +373,10 @@ class Message extends Base {
async acceptGroupV4Invite() {
return await this.client.acceptGroupV4Invite(this.inviteV4);
}
/**
* Forwards this message to another chat
*
*
* @param {string|Chat} chat Chat model or chat ID to which the message will be forwarded
* @returns {Promise}
*/
@@ -335,32 +405,39 @@ class Message extends Base {
if (msg.mediaData.mediaStage !&#x3D; &#x27;RESOLVED&#x27;) {
// try to resolve media
await msg.downloadMedia(true, 1);
await msg.downloadMedia({
downloadEvenIfExpensive: true,
rmrReason: 1
});
}
if (msg.mediaData.mediaStage.includes(&#x27;ERROR&#x27;)) {
if (msg.mediaData.mediaStage.includes(&#x27;ERROR&#x27;) || msg.mediaData.mediaStage &#x3D;&#x3D;&#x3D; &#x27;FETCHING&#x27;) {
// media could not be downloaded
return undefined;
}
const decryptedMedia &#x3D; await window.Store.DownloadManager.downloadAndDecrypt({
directPath: msg.directPath,
encFilehash: msg.encFilehash,
filehash: msg.filehash,
mediaKey: msg.mediaKey,
mediaKeyTimestamp: msg.mediaKeyTimestamp,
type: msg.type,
signal: (new AbortController).signal
});
try {
const decryptedMedia &#x3D; await window.Store.DownloadManager.downloadAndDecrypt({
directPath: msg.directPath,
encFilehash: msg.encFilehash,
filehash: msg.filehash,
mediaKey: msg.mediaKey,
mediaKeyTimestamp: msg.mediaKeyTimestamp,
type: msg.type,
signal: (new AbortController).signal
});
const data &#x3D; window.WWebJS.arrayBufferToBase64(decryptedMedia);
return {
data,
mimetype: msg.mimetype,
filename: msg.filename
};
const data &#x3D; window.WWebJS.arrayBufferToBase64(decryptedMedia);
return {
data,
mimetype: msg.mimetype,
filename: msg.filename
};
} catch (e) {
if(e.status &amp;amp;&amp;amp; e.status &#x3D;&#x3D;&#x3D; 404) return undefined;
throw e;
}
}, this.id._serialized);
if (!result) return undefined;
@@ -375,8 +452,8 @@ class Message extends Base {
await this.client.pupPage.evaluate((msgId, everyone) &#x3D;&gt; {
let msg &#x3D; window.Store.Msg.get(msgId);
if (everyone &amp;amp;&amp;amp; msg.id.fromMe &amp;amp;&amp;amp; msg.canRevoke()) {
return window.Store.Cmd.sendRevokeMsgs(msg.chat, [msg], true);
if (everyone &amp;amp;&amp;amp; msg.id.fromMe &amp;amp;&amp;amp; msg._canRevoke()) {
return window.Store.Cmd.sendRevokeMsgs(msg.chat, [msg], {type: &#x27;Sender&#x27;});
}
return window.Store.Cmd.sendDeleteMsgs(msg.chat, [msg], true);
@@ -427,14 +504,10 @@ class Message extends Base {
async getInfo() {
const info &#x3D; await this.client.pupPage.evaluate(async (msgId) &#x3D;&gt; {
const msg &#x3D; window.Store.Msg.get(msgId);
if(!msg) return null;
return await window.Store.Wap.queryMsgInfo(msg.id);
}, this.id._serialized);
if (!msg) return null;
if(info.status) {
return null;
}
return await window.Store.MessageInfo.sendQueryMsgInfo(msg);
}, this.id._serialized);
return info;
}
@@ -445,14 +518,29 @@ class Message extends Base {
*/
async getOrder() {
if (this.type &#x3D;&#x3D;&#x3D; MessageTypes.ORDER) {
const result &#x3D; await this.client.pupPage.evaluate((orderId, token) &#x3D;&gt; {
return window.WWebJS.getOrderDetail(orderId, token);
}, this.orderId, this.token);
const result &#x3D; await this.client.pupPage.evaluate((orderId, token, chatId) &#x3D;&gt; {
return window.WWebJS.getOrderDetail(orderId, token, chatId);
}, this.orderId, this.token, this._getChatId());
if (!result) return undefined;
return new Order(this.client, result);
}
return undefined;
}
/**
* Gets the payment details associated with a given message
* @return {Promise&amp;lt;Payment&gt;}
*/
async getPayment() {
if (this.type &#x3D;&#x3D;&#x3D; MessageTypes.PAYMENT) {
const msg &#x3D; await this.client.pupPage.evaluate(async (msgId) &#x3D;&gt; {
const msg &#x3D; 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 &#x3D; Message;
@@ -466,7 +554,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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Source: structures/MessageMedia.js</title>
<title>whatsapp-web.js 1.16.4 &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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</a>
</div>
</div>
</nav>
@@ -34,6 +34,8 @@
const fs &#x3D; require(&#x27;fs&#x27;);
const path &#x3D; require(&#x27;path&#x27;);
const mime &#x3D; require(&#x27;mime&#x27;);
const fetch &#x3D; require(&#x27;node-fetch&#x27;);
const { URL } &#x3D; require(&#x27;url&#x27;);
/**
* Media attached to a message
@@ -74,9 +76,63 @@ class MessageMedia {
return new MessageMedia(mimetype, b64data, filename);
}
/**
* Creates a MessageMedia instance from a URL
* @param {string} url
* @param {Object} [options]
* @param {boolean} [options.unsafeMime&#x3D;false]
* @param {string} [options.filename]
* @param {object} [options.client]
* @param {object} [options.reqOptions]
* @param {number} [options.reqOptions.size&#x3D;0]
* @returns {Promise&amp;lt;MessageMedia&gt;}
*/
static async fromUrl(url, options &#x3D; {}) {
const pUrl &#x3D; new URL(url);
let mimetype &#x3D; mime.getType(pUrl.pathname);
if (!mimetype &amp;amp;&amp;amp; !options.unsafeMime)
throw new Error(&#x27;Unable to determine MIME type using URL. Set unsafeMime to true to download it anyway.&#x27;);
async function fetchData (url, options) {
const reqOptions &#x3D; Object.assign({ headers: { accept: &#x27;image/* video/* text/* audio/*&#x27; } }, options);
const response &#x3D; await fetch(url, reqOptions);
const mime &#x3D; response.headers.get(&#x27;Content-Type&#x27;);
const contentDisposition &#x3D; response.headers.get(&#x27;Content-Disposition&#x27;);
const name &#x3D; contentDisposition ? contentDisposition.match(/((?&amp;lt;&#x3D;filename&#x3D;&quot;)(.*)(?&#x3D;&quot;))/) : null;
let data &#x3D; &#x27;&#x27;;
if (response.buffer) {
data &#x3D; (await response.buffer()).toString(&#x27;base64&#x27;);
} else {
const bArray &#x3D; new Uint8Array(await response.arrayBuffer());
bArray.forEach((b) &#x3D;&gt; {
data +&#x3D; String.fromCharCode(b);
});
data &#x3D; btoa(data);
}
return { data, mime, name };
}
const res &#x3D; options.client
? (await options.client.pupPage.evaluate(fetchData, url, options.reqOptions))
: (await fetchData(url, options.reqOptions));
const filename &#x3D; options.filename ||
(res.name ? res.name[0] : (pUrl.pathname.split(&#x27;/&#x27;).pop() || &#x27;file&#x27;));
if (!mimetype)
mimetype &#x3D; res.mime;
return new MessageMedia(mimetype, res.data, filename);
}
}
module.exports &#x3D; MessageMedia;</code></pre>
module.exports &#x3D; MessageMedia;
</code></pre>
</article>
</div>
</div>
@@ -86,7 +142,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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Source: structures/Order.js</title>
<title>whatsapp-web.js 1.16.4 &raquo; Source: structures/Order.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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</a>
</div>
</div>
</nav>
@@ -90,7 +90,7 @@ module.exports &#x3D; Order;</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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -0,0 +1,133 @@
<!doctype html>
<html>
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.16.4 &raquo; Source: structures/Payment.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">
<link href="css/baseline.css" rel="stylesheet">
</head>
<body onload="prettyPrint()">
<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>16.<wbr>4</a>
</div>
</div>
</nav>
<div id="jsdoc-body-container">
<div id="jsdoc-content">
<div id="jsdoc-content-container">
<div id="jsdoc-banner" role="banner">
</div>
<div id="jsdoc-main" role="main">
<header class="page-header">
<h1>Source: structures/Payment.js</h1>
</header>
<article>
<pre class="prettyprint linenums"><code>const Base &#x3D; require(&#x27;./Base&#x27;);
class Payment extends Base {
constructor(client, data) {
super(client);
if (data) this._patch(data);
}
_patch(data) {
/**
* The payment Id
* @type {object}
*/
this.id &#x3D; data.id;
/**
* The payment currency
* @type {string}
*/
this.paymentCurrency &#x3D; data.paymentCurrency;
/**
* The payment ammount ( R$ 1.00 &#x3D; 1000 )
* @type {number}
*/
this.paymentAmount1000 &#x3D; data.paymentAmount1000;
/**
* The payment receiver
* @type {object}
*/
this.paymentMessageReceiverJid &#x3D; data.paymentMessageReceiverJid;
/**
* The payment transaction timestamp
* @type {number}
*/
this.paymentTransactionTimestamp &#x3D; data.paymentTransactionTimestamp;
/**
* The paymentStatus
*
* 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
*
* @type {number}
*/
this.paymentStatus &#x3D; data.paymentStatus;
/**
* Integer that represents the payment Text
* @type {number}
*/
this.paymentTxnStatus &#x3D; data.paymentTxnStatus;
/**
* The note sent with the payment
* @type {string}
*/
this.paymentNote &#x3D; !data.paymentNoteMsg ? undefined : data.paymentNoteMsg.body ? data.paymentNoteMsg.body : undefined ;
return super._patch(data);
}
}
module.exports &#x3D; Payment;
</code></pre>
</article>
</div>
</div>
<nav id="jsdoc-toc-nav" role="navigation"></nav>
</div>
</div>
<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.7 on March 9, 2022.
</p>
</div>
</footer>
<script src="scripts/jquery.min.js"></script>
<script src="scripts/tree.jquery.js"></script>
<script src="scripts/prettify.js"></script>
<script src="scripts/jsdoc-toc.js"></script>
<script src="scripts/linenumber.js"></script>
<script src="scripts/scrollanchor.js"></script>
</body>
</html>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Source: structures/PrivateChat.js</title>
<title>whatsapp-web.js 1.16.4 &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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Source: structures/PrivateContact.js</title>
<title>whatsapp-web.js 1.16.4 &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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Source: structures/Product.js</title>
<title>whatsapp-web.js 1.16.4 &raquo; Source: structures/Product.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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</a>
</div>
</div>
</nav>
@@ -106,7 +106,7 @@ module.exports &#x3D; Product;</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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Source: structures/ProductMetadata.js</title>
<title>whatsapp-web.js 1.16.4 &raquo; Source: structures/ProductMetadata.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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</a>
</div>
</div>
</nav>
@@ -63,7 +63,7 @@ module.exports &#x3D; ProductMetadata;</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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Source: util/Constants.js</title>
<title>whatsapp-web.js 1.16.4 &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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</a>
</div>
</div>
</nav>
@@ -38,10 +38,8 @@ exports.DefaultOptions &#x3D; {
headless: true,
defaultViewport: null
},
session: false,
qrTimeoutMs: 45000,
qrRefreshIntervalMs: 20000,
authTimeoutMs: 45000,
authTimeoutMs: 0,
qrMaxRetries: 0,
takeoverOnConflict: false,
takeoverTimeoutMs: 0,
userAgent: &#x27;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&#x27;,
@@ -81,7 +79,8 @@ exports.Events &#x3D; {
QR_RECEIVED: &#x27;qr&#x27;,
DISCONNECTED: &#x27;disconnected&#x27;,
STATE_CHANGED: &#x27;change_state&#x27;,
BATTERY_CHANGED: &#x27;change_battery&#x27;
BATTERY_CHANGED: &#x27;change_battery&#x27;,
INCOMING_CALL: &#x27;incoming_call&#x27;
};
/**
@@ -104,7 +103,27 @@ exports.MessageTypes &#x3D; {
REVOKED: &#x27;revoked&#x27;,
PRODUCT: &#x27;product&#x27;,
UNKNOWN: &#x27;unknown&#x27;,
GROUP_INVITE: &#x27;groups_v4_invite&#x27;
GROUP_INVITE: &#x27;groups_v4_invite&#x27;,
LIST: &#x27;list&#x27;,
LIST_RESPONSE: &#x27;list_response&#x27;,
BUTTONS_RESPONSE: &#x27;buttons_response&#x27;,
PAYMENT: &#x27;payment&#x27;,
BROADCAST_NOTIFICATION: &#x27;broadcast_notification&#x27;,
CALL_LOG: &#x27;call_log&#x27;,
CIPHERTEXT: &#x27;ciphertext&#x27;,
DEBUG: &#x27;debug&#x27;,
E2E_NOTIFICATION: &#x27;e2e_notification&#x27;,
GP2: &#x27;gp2&#x27;,
GROUP_NOTIFICATION: &#x27;group_notification&#x27;,
HSM: &#x27;hsm&#x27;,
INTERACTIVE: &#x27;interactive&#x27;,
NATIVE_FLOW: &#x27;native_flow&#x27;,
NOTIFICATION: &#x27;notification&#x27;,
NOTIFICATION_TEMPLATE: &#x27;notification_template&#x27;,
OVERSIZED: &#x27;oversized&#x27;,
PROTOCOL: &#x27;protocol&#x27;,
REACTION: &#x27;reaction&#x27;,
TEMPLATE_BUTTON_REPLY: &#x27;template_button_reply&#x27;,
};
/**
@@ -178,7 +197,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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Source: util/InterfaceController.js</title>
<title>whatsapp-web.js 1.16.4 &raquo; Source: util/InterfaceController.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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</a>
</div>
</div>
</nav>
@@ -59,7 +59,7 @@ class InterfaceController {
async openChatDrawer(chatId) {
await this.pupPage.evaluate(async chatId &#x3D;&gt; {
let chat &#x3D; await window.Store.Chat.get(chatId);
await window.Store.Cmd.chatInfoDrawer(chat);
await window.Store.Cmd.openDrawerMid(chat);
}, chatId);
}
@@ -160,7 +160,7 @@ module.exports &#x3D; InterfaceController;
<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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.13.2 &raquo; Source: util/Util.js</title>
<title>whatsapp-web.js 1.16.4 &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>13.<wbr>2</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>16.<wbr>4</a>
</div>
</div>
</nav>
@@ -31,7 +31,6 @@
<article>
<pre class="prettyprint linenums"><code>&#x27;use strict&#x27;;
const sharp &#x3D; require(&#x27;sharp&#x27;);
const path &#x3D; require(&#x27;path&#x27;);
const Crypto &#x3D; require(&#x27;crypto&#x27;);
const { tmpdir } &#x3D; require(&#x27;os&#x27;);
@@ -45,7 +44,6 @@ const has &#x3D; (o, k) &#x3D;&gt; Object.prototype.hasOwnProperty.call(o, k);
* Utility methods
*/
class Util {
constructor() {
throw new Error(&#x60;The ${this.constructor.name} class may not be instantiated.&#x60;);
}
@@ -54,7 +52,7 @@ class Util {
var result &#x3D; &#x27;&#x27;;
var characters &#x3D; &#x27;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789&#x27;;
var charactersLength &#x3D; characters.length;
for ( var i &#x3D; 0; i &amp;lt; length; i++ ) {
for (var i &#x3D; 0; i &amp;lt; length; i++) {
result +&#x3D; characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
@@ -86,33 +84,19 @@ class Util {
*
* @returns {Promise&amp;lt;MessageMedia&gt;} media in webp format
*/
static async formatImageToWebpSticker(media) {
static async formatImageToWebpSticker(media, pupPage) {
if (!media.mimetype.includes(&#x27;image&#x27;))
throw new Error(&#x27;media is not a image&#x27;);
if (media.mimetype.includes(&#x27;webp&#x27;)) {
return media;
}
const buff &#x3D; Buffer.from(media.data, &#x27;base64&#x27;);
let sharpImg &#x3D; sharp(buff);
sharpImg &#x3D; sharpImg.webp();
sharpImg &#x3D; sharpImg.resize(512, 512, {
fit: &#x27;contain&#x27;,
background: { r: 0, g: 0, b: 0, alpha: 0 },
});
let webpBase64 &#x3D; (await sharpImg.toBuffer()).toString(&#x27;base64&#x27;);
return {
mimetype: &#x27;image/webp&#x27;,
data: webpBase64,
filename: media.filename,
};
return pupPage.evaluate((media) &#x3D;&gt; {
return window.WWebJS.toStickerData(media);
}, media);
}
/**
* Formats a video to webp
* @param {MessageMedia} media
@@ -122,14 +106,14 @@ class Util {
static async formatVideoToWebpSticker(media) {
if (!media.mimetype.includes(&#x27;video&#x27;))
throw new Error(&#x27;media is not a video&#x27;);
const videoType &#x3D; media.mimetype.split(&#x27;/&#x27;)[1];
const tempFile &#x3D; path.join(
tmpdir(),
&#x60;${Crypto.randomBytes(6).readUIntLE(0, 6).toString(36)}.webp&#x60;
);
const stream &#x3D; new (require(&#x27;stream&#x27;).Readable)();
const buffer &#x3D; Buffer.from(
media.data.replace(&#x60;data:${media.mimetype};base64,&#x60;, &#x27;&#x27;),
@@ -166,17 +150,17 @@ class Util {
.toFormat(&#x27;webp&#x27;)
.save(tempFile);
});
const data &#x3D; await fs.readFile(tempFile, &#x27;base64&#x27;);
await fs.unlink(tempFile);
return {
return {
mimetype: &#x27;image/webp&#x27;,
data: data,
filename: media.filename,
};
}
/**
* Sticker metadata.
* @typedef {Object} StickerMetadata
@@ -192,14 +176,14 @@ class Util {
*
* @returns {Promise&amp;lt;MessageMedia&gt;} media in webp format
*/
static async formatToWebpSticker(media, metadata) {
static async formatToWebpSticker(media, metadata, pupPage) {
let webpMedia;
if (media.mimetype.includes(&#x27;image&#x27;))
webpMedia &#x3D; await this.formatImageToWebpSticker(media);
else if (media.mimetype.includes(&#x27;video&#x27;))
if (media.mimetype.includes(&#x27;image&#x27;))
webpMedia &#x3D; await this.formatImageToWebpSticker(media, pupPage);
else if (media.mimetype.includes(&#x27;video&#x27;))
webpMedia &#x3D; await this.formatVideoToWebpSticker(media);
else
else
throw new Error(&#x27;Invalid media format&#x27;);
if (metadata.name || metadata.author) {
@@ -214,9 +198,9 @@ class Util {
let jsonBuffer &#x3D; Buffer.from(JSON.stringify(json), &#x27;utf8&#x27;);
let exif &#x3D; Buffer.concat([exifAttr, jsonBuffer]);
exif.writeUIntLE(jsonBuffer.length, 14, 4);
await img.loadBuffer(Buffer.from(webpMedia.data, &#x27;base64&#x27;));
await img.load(Buffer.from(webpMedia.data, &#x27;base64&#x27;));
img.exif &#x3D; exif;
webpMedia.data &#x3D; (await img.saveBuffer()).toString(&#x27;base64&#x27;);
webpMedia.data &#x3D; (await img.save(null)).toString(&#x27;base64&#x27;);
}
return webpMedia;
@@ -242,7 +226,7 @@ module.exports &#x3D; Util;
<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.7 on July 9, 2021.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.7 on March 9, 2022.
</p>
</div>
</footer>

View File

@@ -1,15 +1,9 @@
const fs = require('fs');
const { Client, Location } = require('./index');
const { Client, Location, List, Buttons, LocalAuth } = require('./index');
const SESSION_FILE_PATH = './session.json';
let sessionCfg;
if (fs.existsSync(SESSION_FILE_PATH)) {
sessionCfg = require(SESSION_FILE_PATH);
}
const client = new Client({ puppeteer: { headless: false }, session: sessionCfg });
// You can use an existing session and avoid scanning a QR code by adding a "session" object to the client options.
// This object must include WABrowserId, WASecretBundle, WAToken1 and WAToken2.
const client = new Client({
authStrategy: new LocalAuth(),
puppeteer: { headless: false }
});
client.initialize();
@@ -18,18 +12,12 @@ client.on('qr', (qr) => {
console.log('QR RECEIVED', qr);
});
client.on('authenticated', (session) => {
console.log('AUTHENTICATED', session);
sessionCfg=session;
fs.writeFile(SESSION_FILE_PATH, JSON.stringify(session), function (err) {
if (err) {
console.error(err);
}
});
client.on('authenticated', () => {
console.log('AUTHENTICATED');
});
client.on('auth_failure', msg => {
// Fired if session restore was unsuccessfull
// Fired if session restore was unsuccessful
console.error('AUTHENTICATION FAILURE', msg);
});
@@ -117,9 +105,8 @@ client.on('message', async msg => {
client.sendMessage(msg.from, `
*Connection info*
User name: ${info.pushname}
My number: ${info.me.user}
My number: ${info.wid.user}
Platform: ${info.platform}
WhatsApp version: ${info.phone.wa_version}
`);
} else if (msg.body === '!mediainfo' && msg.hasMedia) {
const attachmentData = await msg.downloadMedia();
@@ -197,6 +184,13 @@ client.on('message', async msg => {
const quotedMsg = await msg.getQuotedMessage();
client.interface.openChatWindowAt(quotedMsg.id._serialized);
}
} else if (msg.body === '!buttons') {
let button = new Buttons('Button body',[{body:'bt1'},{body:'bt2'},{body:'bt3'}],'title','footer');
client.sendMessage(msg.from, button);
} else if (msg.body === '!list') {
let sections = [{title:'sectionTitle',rows:[{title:'ListItem1', description: 'desc'},{title:'ListItem2'}]}];
let list = new List('List body','btnText',sections,'Title','footer');
client.sendMessage(msg.from, list);
}
});
@@ -253,12 +247,6 @@ 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('change_state', state => {
console.log('CHANGE STATE', state );
});

347
index.d.ts vendored
View File

@@ -1,6 +1,7 @@
import { EventEmitter } from 'events'
import puppeteer = require('puppeteer')
import { RequestInit } from 'node-fetch'
import puppeteer from 'puppeteer'
declare namespace WAWebJS {
@@ -47,6 +48,9 @@ declare namespace WAWebJS {
/** Logs out the client, closing the current session */
logout(): Promise<void>
/** Get all blocked contacts by host account */
getBlockedContacts(): Promise<Contact[]>
/** Get chat instance by ID */
getChatById(chatId: string): Promise<Chat>
@@ -58,6 +62,12 @@ declare namespace WAWebJS {
/** Get all current contact instances */
getContacts(): Promise<Contact[]>
/** Get the country code of a WhatsApp ID. (154185968@c.us) => (1) */
getCountryCode(number: string): Promise<string>
/** Get the formatted number of a WhatsApp ID. (12345678901@c.us) => (+1 (234) 5678-901) */
getFormattedNumber(number: string): Promise<string>
/** Get all current Labels */
getLabels(): Promise<Label[]>
@@ -74,6 +84,9 @@ declare namespace WAWebJS {
/** Returns the contact ID's profile picture URL, if privacy settings allow it */
getProfilePicUrl(contactId: string): Promise<string>
/** Gets the Contact's common groups with you. Returns empty array if you don't have any common group. */
getCommonGroups(contactId: string): Promise<ChatId[]>
/** Gets the current connection state for the client */
getState(): Promise<WAState>
@@ -90,11 +103,11 @@ declare namespace WAWebJS {
getNumberId(number: string): Promise<ContactId | null>
/**
* Mutes the Chat until a specified date
* Mutes this chat forever, unless a date is specified
* @param chatId ID of the chat that will be muted
* @param unmuteDate Date when the chat will be unmuted
* @param unmuteDate Date when the chat will be unmuted, leave as is to mute forever
*/
muteChat(chatId: string, unmuteDate: Date): Promise<void>
muteChat(chatId: string, unmuteDate?: Date): Promise<void>
/** Force reset of connection state for the client */
resetState(): Promise<void>
@@ -108,6 +121,9 @@ declare namespace WAWebJS {
/** Marks the client as online */
sendPresenceAvailable(): Promise<void>
/** Marks the client as offline */
sendPresenceUnavailable(): Promise<void>
/** Mark as seen for the Chat */
sendSeen(chatId: string): Promise<boolean>
@@ -124,7 +140,7 @@ declare namespace WAWebJS {
* Sets the current user's display name
* @param displayName New display name
*/
setDisplayName(displayName: string): Promise<void>
setDisplayName(displayName: string): Promise<boolean>
/** Changes and returns the archive state of the Chat */
unarchiveChat(chatId: string): Promise<boolean>
@@ -140,11 +156,16 @@ declare namespace WAWebJS {
/** Emitted when authentication is successful */
on(event: 'authenticated', listener: (
/** Object containing session information. Can be used to restore the session */
session: ClientSession
/**
* Object containing session information, when using LegacySessionAuth. Can be used to restore the session
*/
session?: ClientSession
) => void): this
/** Emitted when the battery percentage for the attached device changes */
/**
* Emitted when the battery percentage for the attached device changes
* @deprecated
*/
on(event: 'change_battery', listener: (batteryInfo: BatteryInfo) => void): this
/** Emitted when the connection state changes */
@@ -156,7 +177,7 @@ declare namespace WAWebJS {
/** Emitted when the client has been disconnected */
on(event: 'disconnected', listener: (
/** reason that caused the disconnect */
reason: WAState | "NAVIGATED"
reason: WAState | "NAVIGATION"
) => void): this
/** Emitted when a user joins the chat via invite link or is added by an admin */
@@ -227,6 +248,12 @@ declare namespace WAWebJS {
qr: string
) => void): this
/** Emitted when a call is received */
on(event: 'call', listener: (
/** The call that started */
call: Call
) => void): this
/** Emitted when the client has initialized and is ready to receive messages */
on(event: 'ready', listener: () => void): this
}
@@ -240,7 +267,10 @@ declare namespace WAWebJS {
me: ContactId
/** Current user ID */
wid: ContactId
/** Information about the phone this client is connected to */
/**
* Information about the phone this client is connected to. Not available in multi-device.
* @deprecated
*/
phone: ClientInfoPhone
/** Platform the phone is running on */
platform: string
@@ -251,7 +281,10 @@ declare namespace WAWebJS {
getBatteryStatus: () => Promise<BatteryInfo>
}
/** Information about the phone this client is connected to */
/**
* Information about the phone this client is connected to
* @deprecated
*/
export interface ClientInfoPhone {
/** WhatsApp Version running on the phone */
wa_version: string
@@ -268,20 +301,22 @@ declare namespace WAWebJS {
/** Options for initializing the whatsapp client */
export interface ClientOptions {
/** Timeout for authentication selector in puppeteer
* @default 45000 */
* @default 0 */
authTimeoutMs?: number,
/** Puppeteer launch options. View docs here: https://github.com/puppeteer/puppeteer/ */
puppeteer?: puppeteer.LaunchOptions
/** Refresh interval for qr code (how much time to wait before checking if the qr code has changed)
* @default 20000 */
qrRefreshIntervalMs?: number
/** Timeout for qr code selector in puppeteer
* @default 45000 */
qrTimeoutMs?: number,
/** Restart client with a new session (i.e. use null 'session' var) if authentication fails
* @default false */
puppeteer?: puppeteer.LaunchOptions & puppeteer.BrowserLaunchArgumentOptions & puppeteer.BrowserConnectOptions
/** Determines how to save and restore sessions. Will use LegacySessionAuth if options.session is set. Otherwise, NoAuth will be used. */
authStrategy?: AuthStrategy,
/** How many times should the qrcode be refreshed before giving up
* @default 0 (disabled) */
qrMaxRetries?: number,
/**
* @deprecated This option should be set directly on the LegacySessionAuth
*/
restartOnAuthFail?: boolean
/** Whatsapp session to restore. If not set, will start a new session */
/**
* @deprecated Only here for backwards-compatibility. You should move to using LocalAuth, or set the authStrategy to LegacySessionAuth explicitly.
*/
session?: ClientSession
/** If another whatsapp web session is detected (another browser), take over the session in the current browser
* @default false */
@@ -297,7 +332,54 @@ declare namespace WAWebJS {
ffmpegPath?: string
}
/** Represents a Whatsapp client session */
/**
* Base class which all authentication strategies extend
*/
export abstract class AuthStrategy {
setup: (client: Client) => void;
beforeBrowserInitialized: () => Promise<void>;
afterBrowserInitialized: () => Promise<void>;
onAuthenticationNeeded: () => Promise<{
failed?: boolean;
restart?: boolean;
failureEventPayload?: any
}>;
getAuthEventPayload: () => Promise<any>;
logout: () => Promise<void>;
}
/**
* No session restoring functionality
* Will need to authenticate via QR code every time
*/
export class NoAuth extends AuthStrategy {}
/**
* Local directory-based authentication
*/
export class LocalAuth extends AuthStrategy {
public clientId?: string;
public dataPath?: string;
constructor(options?: {
clientId?: string,
dataPath?: string
})
}
/**
* Legacy session auth strategy
* Not compatible with multi-device accounts.
*/
export class LegacySessionAuth extends AuthStrategy {
constructor(options?: {
session?: ClientSession,
restartOnAuthFail?: boolean,
})
}
/**
* Represents a WhatsApp client session
*/
export interface ClientSession {
WABrowserId: string,
WASecretBundle: string,
@@ -305,6 +387,9 @@ declare namespace WAWebJS {
WAToken2: string,
}
/**
* @deprecated
*/
export interface BatteryInfo {
/** The current battery percentage */
battery: number,
@@ -349,7 +434,7 @@ declare namespace WAWebJS {
reply: (content: MessageContent, options?: MessageSendOptions) => Promise<Message>,
}
/** whatsapp web url */
export const WhatsWebURL: string
@@ -421,8 +506,28 @@ declare namespace WAWebJS {
REVOKED = 'revoked',
ORDER = 'order',
PRODUCT = 'product',
PAYMENT = 'payment',
UNKNOWN = 'unknown',
GROUP_INVITE = 'groups_v4_invite',
LIST = 'list',
LIST_RESPONSE = 'list_response',
BUTTONS_RESPONSE = 'buttons_response',
BROADCAST_NOTIFICATION = 'broadcast_notification',
CALL_LOG = 'call_log',
CIPHERTEXT = 'ciphertext',
DEBUG = 'debug',
E2E_NOTIFICATION = 'e2e_notification',
GP2 = 'gp2',
GROUP_NOTIFICATION = 'group_notification',
HSM = 'hsm',
INTERACTIVE = 'interactive',
NATIVE_FLOW = 'native_flow',
NOTIFICATION = 'notification',
NOTIFICATION_TEMPLATE = 'notification_template',
OVERSIZED = 'oversized',
PROTOCOL = 'protocol',
REACTION = 'reaction',
TEMPLATE_BUTTON_REPLY = 'template_button_reply',
}
/** Client status */
@@ -505,6 +610,10 @@ declare namespace WAWebJS {
broadcast: boolean,
/** Indicates if the message was a status update */
isStatus: boolean,
/** Indicates if the message is a Gif */
isGif: boolean,
/** Indicates if the message will disappear after it expires */
isEphemeral: boolean,
/** ID for the Chat that this message was sent to, except if the message was sent by the current user */
from: string,
/** Indicates if the message was sent by the current user */
@@ -513,10 +622,17 @@ declare namespace WAWebJS {
hasMedia: boolean,
/** Indicates if the message was sent as a reply to another message */
hasQuotedMsg: boolean,
/** Indicates the duration of the message in seconds */
duration: string,
/** ID that represents the message */
id: MessageId,
/** Indicates if the message was forwarded */
isForwarded: boolean,
/**
* Indicates how many times the message was forwarded.
* The maximum value is 127.
*/
forwardingScore: number,
/** Indicates if the message was starred */
isStarred: boolean,
/** Location information contained in the message, if the message is type "location" */
@@ -540,7 +656,10 @@ declare namespace WAWebJS {
/** Message type */
type: MessageTypes,
/** Links included in the message. */
links: string[],
links: Array<{
link: string,
isSuspicious: boolean
}>,
/** Order ID */
orderId: string,
/** title */
@@ -551,6 +670,19 @@ declare namespace WAWebJS {
businessOwnerJid?: string,
/** Product JID */
productId?: string,
/** Message buttons */
dynamicReplyButtons?: object,
/** Selected button ID */
selectedButtonId?: string,
/** Selected list row ID */
selectedRowId?: string,
/** Returns message in a raw format */
rawData: object,
/*
* Reloads this Message object's data in-place with the latest values from WhatsApp Web.
* Note that the Message must still be in the web app cache for this to work, otherwise will return null.
*/
reload: () => Promise<Message>,
/** Accept the Group V4 Invite in message */
acceptGroupV4Invite: () => Promise<{status: number}>,
/** Deletes the message from the chat */
@@ -584,7 +716,11 @@ declare namespace WAWebJS {
/**
* Gets the order associated with a given message
*/
getOrder: () => Order,
getOrder: () => Promise<Order>,
/**
* Gets the payment details associated with a given message
*/
getPayment: () => Promise<Payment>,
}
/** ID that represents a message */
@@ -595,10 +731,13 @@ declare namespace WAWebJS {
_serialized: string,
}
export interface Location {
description?: string | null,
latitude: string,
longitude: string,
/** Location information */
export class Location {
description?: string | null
latitude: string
longitude: string
constructor(latitude: number, longitude: number, description?: string)
}
export interface Label {
@@ -615,7 +754,7 @@ declare namespace WAWebJS {
/** Options for sending a message */
export interface MessageSendOptions {
/** Show links preview */
/** Show links preview. Has no effect on multi-device accounts. */
linkPreview?: boolean
/** Send audio as voice message */
sendAudioAsVoice?: boolean
@@ -647,6 +786,13 @@ declare namespace WAWebJS {
stickerCategories?: string[]
}
export interface MediaFromURLOptions {
client?: Client
filename?: string
unsafeMime?: boolean
reqOptions?: RequestInit
}
/** Media attached to a message */
export class MessageMedia {
/** MIME type of the attachment */
@@ -665,9 +811,12 @@ declare namespace WAWebJS {
/** Creates a MessageMedia instance from a local file path */
static fromFilePath: (filePath: string) => MessageMedia
/** Creates a MessageMedia instance from a URL */
static fromUrl: (url: string, options?: MediaFromURLOptions) => Promise<MessageMedia>
}
export type MessageContent = string | MessageMedia | Location | Contact | Contact[]
export type MessageContent = string | MessageMedia | Location | Contact | Contact[] | List | Buttons
/**
* Represents a Contact on WhatsApp
@@ -745,14 +894,24 @@ declare namespace WAWebJS {
* Will return null when getting chat for currently logged in user.
*/
getChat: () => Promise<Chat>,
/** Returns the contact's countrycode, (1541859685@c.us) => (1) */
getCountryCode(): Promise<string>,
/** Returns the contact's formatted phone number, (12345678901@c.us) => (+1 (234) 5678-901) */
getFormattedNumber(): Promise<string>,
/** Blocks this contact from WhatsApp */
block: () => Promise<boolean>,
/** Unlocks this contact from WhatsApp */
unblock: () => Promise<boolean>,
/** Gets the Contact's current "about" info. Returns null if you don't have permission to read their status. */
getAbout: () => Promise<string | null>,
/** Gets the Contact's common groups with you. Returns empty array if you don't have any common group. */
getCommonGroups: () => Promise<ChatId[]>
}
@@ -826,8 +985,8 @@ declare namespace WAWebJS {
delete: () => Promise<boolean>,
/** Loads chat messages, sorted from earliest to latest. */
fetchMessages: (searchOptions: MessageSearchOptions) => Promise<Message[]>,
/** Mutes this chat until a specified date */
mute: (unmuteDate: Date) => Promise<void>,
/** Mutes this chat forever, unless a date is specified */
mute: (unmuteDate?: Date) => Promise<void>,
/** Send a message to this chat */
sendMessage: (content: MessageContent, options?: MessageSendOptions) => Promise<Message>,
/** Set the message as seen */
@@ -850,10 +1009,9 @@ declare namespace WAWebJS {
export interface MessageSearchOptions {
/**
* The amount of messages to return.
* The amount of messages to return. If no limit is specified, the available messages will be returned.
* Note that the actual number of returned messages may be smaller if there aren't enough messages in the conversation.
* Set this to Infinity to load all messages.
* @default 50
*/
limit?: number
}
@@ -897,7 +1055,7 @@ declare namespace WAWebJS {
}
/** Promotes or demotes participants by IDs to regular users or admins */
export type ChangeParticipantsPermisions =
export type ChangeParticipantsPermissions =
(participantIds: Array<string>) => Promise<{ status: number }>
/** Adds or removes a list of participants by ID to the group */
@@ -927,13 +1085,13 @@ declare namespace WAWebJS {
/** Removes a list of participants by ID to the group */
removeParticipants: ChangeGroupParticipants;
/** Promotes participants by IDs to admins */
promoteParticipants: ChangeParticipantsPermisions;
promoteParticipants: ChangeParticipantsPermissions;
/** Demotes participants by IDs to regular users */
demoteParticipants: ChangeParticipantsPermisions;
demoteParticipants: ChangeParticipantsPermissions;
/** Updates the group subject */
setSubject: (subject: string) => Promise<void>;
setSubject: (subject: string) => Promise<boolean>;
/** Updates the group description */
setDescription: (description: string) => Promise<void>;
setDescription: (description: string) => Promise<boolean>;
/** Updates the group settings to only allow admins to send messages
* @param {boolean} [adminsOnly=true] Enable or disable this option
* @returns {Promise<boolean>} Returns true if the setting was properly updated. This can return false if the user does not have the necessary permissions.
@@ -1033,6 +1191,111 @@ declare namespace WAWebJS {
/** Order Created At*/
createdAt: number;
}
/**
* Represents a Payment on WhatsApp
*
* @example
* {
* id: {
* fromMe: true,
* remote: {
* server: 'c.us',
* user: '5511999999999',
* _serialized: '5511999999999@c.us'
* },
* id: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
* _serialized: 'true_5511999999999@c.us_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
* },
* paymentCurrency: 'BRL',
* paymentAmount1000: 1000,
* paymentMessageReceiverJid: {
* server: 'c.us',
* user: '5511999999999',
* _serialized: '5511999999999@c.us'
* },
* paymentTransactionTimestamp: 1623463058,
* paymentStatus: 4,
* paymentTxnStatus: 4,
* paymentNote: 'note'
* }
*/
export interface Payment {
/** Payment Id*/
id: object,
/** Payment currency */
paymentCurrency: string,
/** Payment ammount */
paymentAmount1000 : number,
/** Payment receiver */
paymentMessageReceiverJid : object,
/** Payment transaction timestamp */
paymentTransactionTimestamp : number,
/** Payment paymentStatus */
paymentStatus : number,
/** Integer that represents the payment Text */
paymentTxnStatus : number,
/** The note sent with the payment */
paymentNote : string;
}
/**
* Represents a Call on WhatsApp
*
* @example
* Call {
* id: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
* from: '5511999999@c.us',
* timestamp: 1625003709,
* isVideo: false,
* isGroup: false,
* fromMe: false,
* canHandleLocally: false,
* webClientShouldHandle: false,
* participants: []
* }
*/
export interface Call {
/** Call Id */
id: string,
/** from */
from?: string,
/** Unix timestamp for when the call was created*/
timestamp: number,
/** Is video */
isVideo: boolean,
/** Is Group */
isGroup: boolean,
/** Indicates if the call was sent by the current user */
fromMe: boolean,
/** indicates if the call can be handled in waweb */
canHandleLocally: boolean,
/** indicates if the call should be handled in waweb */
webClientShouldHandle: boolean,
/** Object with participants */
participants: object
}
/** Message type List */
export class List {
body: string
buttonText: string
sections: Array<any>
title?: string | null
footer?: string | null
constructor(body: string, buttonText: string, sections: Array<any>, title?: string | null, footer?: string | null)
}
/** Message type buttons */
export class Buttons {
body: string | MessageMedia
buttons: Array<{ buttonId: string; buttonText: {displayText: string}; type: number }>
title?: string | null
footer?: string | null
constructor(body: string, buttons: Array<{ id?: string; body: string }>, title?: string | null, footer?: string | null)
}
}
export = WAWebJS

View File

@@ -19,5 +19,13 @@ module.exports = {
ClientInfo: require('./src/structures/ClientInfo'),
Location: require('./src/structures/Location'),
ProductMetadata: require('./src/structures/ProductMetadata'),
List: require('./src/structures/List'),
Buttons: require('./src/structures/Buttons'),
// Auth Strategies
NoAuth: require('./src/authStrategies/NoAuth'),
LocalAuth: require('./src/authStrategies/LocalAuth'),
LegacySessionAuth: require('./src/authStrategies/LegacySessionAuth'),
...Constants
};

View File

@@ -1,11 +1,12 @@
{
"name": "whatsapp-web.js",
"version": "1.13.2",
"version": "1.16.4",
"description": "Library for interacting with the WhatsApp Web API ",
"main": "./index.js",
"typings": "./index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "mocha tests --recursive --timeout 5000",
"test-single": "mocha",
"shell": "node --experimental-repl-await ./shell.js",
"generate-docs": "node_modules/.bin/jsdoc --configure .jsdoc.json --verbose"
},
@@ -26,19 +27,29 @@
"bugs": {
"url": "https://github.com/pedroslopez/whatsapp-web.js/issues"
},
"homepage": "https://waguide.pedroslopez.me/",
"homepage": "https://wwebjs.dev/",
"dependencies": {
"@pedroslopez/moduleraid": "^5.0.1",
"@pedroslopez/moduleraid": "^5.0.2",
"fluent-ffmpeg": "^2.1.2",
"jsqr": "^1.3.1",
"mime": "^2.4.5",
"node-webpmux": "^2.0.0",
"puppeteer": "^5.2.1",
"sharp": "^0.26.3"
"mime": "^3.0.0",
"node-fetch": "^2.6.5",
"node-webpmux": "^3.1.0",
"puppeteer": "^13.0.0"
},
"devDependencies": {
"eslint": "^7.27.0",
"@types/node-fetch": "^2.5.12",
"chai": "^4.3.4",
"chai-as-promised": "^7.1.1",
"dotenv": "^16.0.0",
"eslint": "^8.4.1",
"eslint-plugin-mocha": "^10.0.3",
"jsdoc": "^3.6.4",
"jsdoc-baseline": "^0.1.5"
"jsdoc-baseline": "^0.1.5",
"mocha": "^9.0.2",
"sinon": "^13.0.1"
},
"engines": {
"node": ">=12.0.0"
}
}

View File

@@ -2,24 +2,17 @@
* ==== wwebjs-shell ====
* Used for quickly testing library features
*
* Running `npm run shell` will start WhatsApp Web in headless mode
* Running `npm run shell` will start WhatsApp Web with headless=false
* and then drop you into Node REPL with `client` in its context.
*/
const repl = require('repl');
const fs = require('fs');
const { Client } = require('./index');
const SESSION_FILE_PATH = './session.json';
let sessionCfg;
if (fs.existsSync(SESSION_FILE_PATH)) {
sessionCfg = require(SESSION_FILE_PATH);
}
const { Client, LocalAuth } = require('./index');
const client = new Client({
puppeteer: { headless: false },
session: sessionCfg
authStrategy: new LocalAuth()
});
console.log('Initializing...');
@@ -30,6 +23,10 @@ client.on('qr', () => {
console.log('Please scan the QR code on the browser.');
});
client.on('authenticated', (session) => {
console.log(JSON.stringify(session));
});
client.on('ready', () => {
const shell = repl.start('wwebjs> ');
shell.context.client = client;

View File

@@ -3,7 +3,6 @@
const EventEmitter = require('events');
const puppeteer = require('puppeteer');
const moduleRaid = require('@pedroslopez/moduleraid/moduleraid');
const jsQR = require('jsqr');
const Util = require('./util/Util');
const InterfaceController = require('./util/InterfaceController');
@@ -11,21 +10,20 @@ const { WhatsWebURL, DefaultOptions, Events, WAState } = require('./util/Constan
const { ExposeStore, LoadUtils } = require('./util/Injected');
const ChatFactory = require('./factories/ChatFactory');
const ContactFactory = require('./factories/ContactFactory');
const { ClientInfo, Message, MessageMedia, Contact, Location, GroupNotification , Label } = require('./structures');
const { ClientInfo, Message, MessageMedia, Contact, Location, GroupNotification, Label, Call, Buttons, List } = require('./structures');
const LegacySessionAuth = require('./authStrategies/LegacySessionAuth');
const NoAuth = require('./authStrategies/NoAuth');
/**
* Starting point for interacting with the WhatsApp Web API
* @extends {EventEmitter}
* @param {object} options - Client options
* @param {AuthStrategy} options.authStrategy - Determines how to save and restore sessions. Will use LegacySessionAuth if options.session is set. Otherwise, NoAuth will be used.
* @param {number} options.authTimeoutMs - Timeout for authentication selector in puppeteer
* @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 {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
* @param {string} options.session.WASecretBundle
* @param {string} options.session.WAToken1
* @param {string} options.session.WAToken2
* @param {number} options.qrMaxRetries - How many times should the qrcode be refreshed before giving up
* @param {string} options.restartOnAuthFail - @deprecated This option should be set directly on the LegacySessionAuth.
* @param {object} options.session - @deprecated Only here for backwards-compatibility. You should move to using LocalAuth, or set the authStrategy to LegacySessionAuth explicitly.
* @param {number} options.takeoverOnConflict - If another whatsapp web session is detected (another browser), take over the session in the current browser
* @param {number} options.takeoverTimeoutMs - How much time to wait before taking over the session
* @param {string} options.userAgent - User agent to use in puppeteer
@@ -47,13 +45,33 @@ const { ClientInfo, Message, MessageMedia, Contact, Location, GroupNotification
* @fires Client#group_update
* @fires Client#disconnected
* @fires Client#change_state
* @fires Client#change_battery
*/
class Client extends EventEmitter {
constructor(options = {}) {
super();
this.options = Util.mergeDefault(DefaultOptions, options);
if(!this.options.authStrategy) {
if(Object.prototype.hasOwnProperty.call(this.options, 'session')) {
process.emitWarning(
'options.session is deprecated and will be removed in a future release due to incompatibility with multi-device. ' +
'Use the LocalAuth authStrategy, don\'t pass in a session as an option, or suppress this warning by using the LegacySessionAuth strategy explicitly (see https://wwebjs.dev/guide/authentication.html#legacysessionauth-strategy).',
'DeprecationWarning'
);
this.authStrategy = new LegacySessionAuth({
session: this.options.session,
restartOnAuthFail: this.options.restartOnAuthFail
});
} else {
this.authStrategy = new NoAuth();
}
} else {
this.authStrategy = this.options.authStrategy;
}
this.authStrategy.setup(this);
this.pupBrowser = null;
this.pupPage = null;
@@ -65,119 +83,156 @@ class Client extends EventEmitter {
* Sets up events and requirements, kicks off authentication request
*/
async initialize() {
const browser = await puppeteer.launch(this.options.puppeteer);
const page = (await browser.pages())[0];
page.setUserAgent(this.options.userAgent);
let [browser, page] = [null, null];
await this.authStrategy.beforeBrowserInitialized();
const puppeteerOpts = this.options.puppeteer;
if (puppeteerOpts && puppeteerOpts.browserWSEndpoint) {
browser = await puppeteer.connect(puppeteerOpts);
page = await browser.newPage();
} else {
browser = await puppeteer.launch(puppeteerOpts);
page = (await browser.pages())[0];
}
await page.setUserAgent(this.options.userAgent);
if (this.options.bypassCSP) await page.setBypassCSP(true);
this.pupBrowser = browser;
this.pupPage = page;
if (this.options.session) {
await page.evaluateOnNewDocument(
session => {
localStorage.clear();
localStorage.setItem('WABrowserId', session.WABrowserId);
localStorage.setItem('WASecretBundle', session.WASecretBundle);
localStorage.setItem('WAToken1', session.WAToken1);
localStorage.setItem('WAToken2', session.WAToken2);
}, this.options.session);
}
if(this.options.bypassCSP) {
await page.setBypassCSP(true);
}
await this.authStrategy.afterBrowserInitialized();
await page.goto(WhatsWebURL, {
waitUntil: 'load',
timeout: 0,
referer: 'https://whatsapp.com/'
});
const KEEP_PHONE_CONNECTED_IMG_SELECTOR = '[data-asset-intro-image-light="true"], [data-asset-intro-image-dark="true"]';
const INTRO_IMG_SELECTOR = '[data-testid="intro-md-beta-logo-dark"], [data-testid="intro-md-beta-logo-light"], [data-asset-intro-image-light="true"], [data-asset-intro-image-dark="true"]';
const INTRO_QRCODE_SELECTOR = 'div[data-ref] canvas';
if (this.options.session) {
// Check if session restore was successfull
try {
await page.waitForSelector(KEEP_PHONE_CONNECTED_IMG_SELECTOR, { timeout: this.options.authTimeoutMs });
} catch (err) {
if (err.name === 'TimeoutError') {
/**
* Emitted when there has been an error while trying to restore an existing session
* @event Client#auth_failure
* @param {string} message
*/
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;
// Checks which selector appears first
const needAuthentication = await Promise.race([
new Promise(resolve => {
page.waitForSelector(INTRO_IMG_SELECTOR, { timeout: this.options.authTimeoutMs })
.then(() => resolve(false))
.catch((err) => resolve(err));
}),
new Promise(resolve => {
page.waitForSelector(INTRO_QRCODE_SELECTOR, { timeout: this.options.authTimeoutMs })
.then(() => resolve(true))
.catch((err) => resolve(err));
})
]);
// Checks if an error ocurred on the first found selector. The second will be discarded and ignored by .race;
if (needAuthentication instanceof Error) throw needAuthentication;
// Scan-qrcode selector was found. Needs authentication
if (needAuthentication) {
const { failed, failureEventPayload, restart } = await this.authStrategy.onAuthenticationNeeded();
if(failed) {
/**
* Emitted when there has been an error while trying to restore an existing session
* @event Client#auth_failure
* @param {string} message
*/
this.emit(Events.AUTHENTICATION_FAILURE, failureEventPayload);
await this.destroy();
if (restart) {
// session restore failed so try again but without session to force new authentication
return this.initialize();
}
throw err;
return;
}
} else {
const getQrCode = async () => {
// Check if retry button is present
var QR_RETRY_SELECTOR = 'div[data-ref] > span > button';
var qrRetry = await page.$(QR_RETRY_SELECTOR);
if (qrRetry) {
await qrRetry.click();
}
// Wait for QR Code
const QR_CANVAS_SELECTOR = 'canvas';
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;
const QR_CONTAINER = 'div[data-ref]';
const QR_RETRY_BUTTON = 'div[data-ref] > span > button';
let qrRetries = 0;
await page.exposeFunction('qrChanged', async (qr) => {
/**
* Emitted when the QR code is received
* Emitted when a QR code is received
* @event Client#qr
* @param {string} qr QR Code
*/
this.emit(Events.QR_RECEIVED, qr);
};
getQrCode();
this._qrRefreshInterval = setInterval(getQrCode, this.options.qrRefreshIntervalMs);
if (this.options.qrMaxRetries > 0) {
qrRetries++;
if (qrRetries > this.options.qrMaxRetries) {
this.emit(Events.DISCONNECTED, 'Max qrcode retries reached');
await this.destroy();
}
}
});
await page.evaluate(function (selectors) {
const qr_container = document.querySelector(selectors.QR_CONTAINER);
window.qrChanged(qr_container.dataset.ref);
const obs = new MutationObserver((muts) => {
muts.forEach(mut => {
// Listens to qr token change
if (mut.type === 'attributes' && mut.attributeName === 'data-ref') {
window.qrChanged(mut.target.dataset.ref);
} else
// Listens to retry button, when found, click it
if (mut.type === 'childList') {
const retry_button = document.querySelector(selectors.QR_RETRY_BUTTON);
if (retry_button) retry_button.click();
}
});
});
obs.observe(qr_container.parentElement, {
subtree: true,
childList: true,
attributes: true,
attributeFilter: ['data-ref'],
});
}, {
QR_CONTAINER,
QR_RETRY_BUTTON
});
// Wait for code scan
await page.waitForSelector(KEEP_PHONE_CONNECTED_IMG_SELECTOR, { timeout: 0 });
clearInterval(this._qrRefreshInterval);
this._qrRefreshInterval = undefined;
try {
await page.waitForSelector(INTRO_IMG_SELECTOR, { timeout: 0 });
} catch(error) {
if (
error.name === 'ProtocolError' &&
error.message &&
error.message.match(/Target closed/)
) {
// something has called .destroy() while waiting
return;
}
throw error;
}
}
await page.evaluate(ExposeStore, moduleRaid.toString());
// Get session tokens
const localStorage = JSON.parse(await page.evaluate(() => {
return JSON.stringify(window.localStorage);
}));
const session = {
WABrowserId: localStorage.WABrowserId,
WASecretBundle: localStorage.WASecretBundle,
WAToken1: localStorage.WAToken1,
WAToken2: localStorage.WAToken2
};
const authEventPayload = await this.authStrategy.getAuthEventPayload();
/**
* Emitted when authentication is successful
* @event Client#authenticated
* @param {object} session Object containing session information. Can be used to restore the session.
* @param {string} session.WABrowserId
* @param {string} session.WASecretBundle
* @param {string} session.WAToken1
* @param {string} session.WAToken2
*/
this.emit(Events.AUTHENTICATED, session);
this.emit(Events.AUTHENTICATED, authEventPayload);
// Check window.Store Injection
await page.waitForFunction('window.Store != undefined');
await page.evaluate(async () => {
// safely unregister service workers
const registrations = await navigator.serviceWorker.getRegistrations();
for (let registration of registrations) {
registration.unregister();
}
});
//Load util functions (serializers, helper functions)
await page.evaluate(LoadUtils);
@@ -187,7 +242,7 @@ class Client extends EventEmitter {
* @type {ClientInfo}
*/
this.info = new ClientInfo(this, await page.evaluate(() => {
return window.Store.Conn.serialize();
return { ...window.Store.Conn.serialize(), wid: window.Store.User.getMeUser() };
}));
// Add InterfaceController
@@ -195,8 +250,6 @@ class Client extends EventEmitter {
// Register events
await page.exposeFunction('onAddMessageEvent', msg => {
if (!msg.isNewMsg) return;
if (msg.type === 'gp2') {
const notification = new GroupNotification(this, msg);
if (msg.subtype === 'add' || msg.subtype === 'invite') {
@@ -353,24 +406,53 @@ class Client extends EventEmitter {
if (battery === undefined) return;
/**
* Emitted when the battery percentage for the attached device changes
* Emitted when the battery percentage for the attached device changes. Will not be sent if using multi-device.
* @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)
* @deprecated
*/
this.emit(Events.BATTERY_CHANGED, { battery, plugged });
});
await page.exposeFunction('onIncomingCall', (call) => {
/**
* Emitted when a call is received
* @event Client#incoming_call
* @param {object} call
* @param {number} call.id - Call id
* @param {string} call.peerJid - Who called
* @param {boolean} call.isVideo - if is video
* @param {boolean} call.isGroup - if is group
* @param {boolean} call.canHandleLocally - if we can handle in waweb
* @param {boolean} call.outgoing - if is outgoing
* @param {boolean} call.webClientShouldHandle - If Waweb should handle
* @param {object} call.participants - Participants
*/
const cll = new Call(this, call);
this.emit(Events.INCOMING_CALL, cll);
});
await page.evaluate(() => {
window.Store.Msg.on('add', (msg) => { if (msg.isNewMsg) window.onAddMessageEvent(window.WWebJS.getMessageModel(msg)); });
window.Store.Msg.on('change', (msg) => { window.onChangeMessageEvent(window.WWebJS.getMessageModel(msg)); });
window.Store.Msg.on('change:type', (msg) => { window.onChangeMessageTypeEvent(window.WWebJS.getMessageModel(msg)); });
window.Store.Msg.on('change:ack', (msg,ack) => { window.onMessageAckEvent(window.WWebJS.getMessageModel(msg), ack); });
window.Store.Msg.on('change:ack', (msg, ack) => { window.onMessageAckEvent(window.WWebJS.getMessageModel(msg), ack); });
window.Store.Msg.on('change:isUnsentMedia', (msg, unsent) => { if (msg.id.fromMe && !unsent) window.onMessageMediaUploadedEvent(window.WWebJS.getMessageModel(msg)); });
window.Store.Msg.on('remove', (msg) => { if (msg.isNewMsg) window.onRemoveMessageEvent(window.WWebJS.getMessageModel(msg)); });
window.Store.AppState.on('change:state', (_AppState, state) => { window.onAppStateChangedEvent(state); });
window.Store.Conn.on('change:battery', (state) => { window.onBatteryStateChangedEvent(state); });
window.Store.Call.on('add', (call) => { window.onIncomingCall(call); });
window.Store.Msg.on('add', (msg) => {
if (msg.isNewMsg) {
if(msg.type === 'ciphertext') {
// defer message event until ciphertext is resolved (type changed)
msg.once('change:type', (_msg) => window.onAddMessageEvent(window.WWebJS.getMessageModel(_msg)));
} else {
window.onAddMessageEvent(window.WWebJS.getMessageModel(msg));
}
}
});
});
/**
@@ -379,11 +461,13 @@ class Client extends EventEmitter {
*/
this.emit(Events.READY);
// Disconnect when navigating away
// Because WhatsApp Web now reloads when logging out from the device, this also covers that case
// Disconnect when navigating away when in PAIRING state (detect logout)
this.pupPage.on('framenavigated', async () => {
this.emit(Events.DISCONNECTED, 'NAVIGATION');
await this.destroy();
const appState = await this.getState();
if(!appState || appState === WAState.PAIRING) {
this.emit(Events.DISCONNECTED, 'NAVIGATION');
await this.destroy();
}
});
}
@@ -391,9 +475,6 @@ class Client extends EventEmitter {
* Closes the client
*/
async destroy() {
if (this._qrRefreshInterval) {
clearInterval(this._qrRefreshInterval);
}
await this.pupBrowser.close();
}
@@ -401,9 +482,11 @@ class Client extends EventEmitter {
* Logs out the client, closing the current session
*/
async logout() {
return await this.pupPage.evaluate(() => {
await this.pupPage.evaluate(() => {
return window.Store.AppState.logout();
});
await this.authStrategy.logout();
}
/**
@@ -433,7 +516,7 @@ class Client extends EventEmitter {
/**
* Message options.
* @typedef {Object} MessageSendOptions
* @property {boolean} [linkPreview=true] - Show links preview
* @property {boolean} [linkPreview=true] - Show links preview. Has no effect on multi-device accounts.
* @property {boolean} [sendAudioAsVoice=false] - Send audio as voice message
* @property {boolean} [sendVideoAsGif=false] - Send video as gif
* @property {boolean} [sendMediaAsSticker=false] - Send media as a sticker
@@ -452,7 +535,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
@@ -468,7 +551,7 @@ class Client extends EventEmitter {
quotedMessageId: options.quotedMessageId,
parseVCards: options.parseVCards === false ? false : true,
mentionedJidList: Array.isArray(options.mentions) ? options.mentions.map(contact => contact.id._serialized) : [],
...options.extra
extraOptions: options.extra
};
const sendSeen = typeof options.sendSeen === 'undefined' ? true : options.sendSeen;
@@ -483,27 +566,36 @@ class Client extends EventEmitter {
} else if (content instanceof Location) {
internalOptions.location = content;
content = '';
} else if(content instanceof Contact) {
} else if (content instanceof Contact) {
internalOptions.contactCard = content.id._serialized;
content = '';
} else if(Array.isArray(content) && content.length > 0 && content[0] instanceof Contact) {
} 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) {
internalOptions.attachment =
await Util.formatToWebpSticker(internalOptions.attachment, {
internalOptions.attachment = await Util.formatToWebpSticker(
internalOptions.attachment, {
name: options.stickerName,
author: options.stickerAuthor,
categories: options.stickerCategories
});
}, this.pupPage
);
}
const newMessage = await this.pupPage.evaluate(async (chatId, message, options, sendSeen) => {
const chatWid = window.Store.WidFactory.createWid(chatId);
const chat = await window.Store.Chat.find(chatWid);
if (sendSeen) {
window.WWebJS.sendSeen(chatId);
}
@@ -590,7 +682,7 @@ class Client extends EventEmitter {
*/
async getInviteInfo(inviteCode) {
return await this.pupPage.evaluate(inviteCode => {
return window.Store.Wap.groupInviteInfo(inviteCode);
return window.Store.InviteInfo.sendQueryGroupInvite(inviteCode);
}, inviteCode);
}
@@ -609,25 +701,25 @@ class Client extends EventEmitter {
/**
* Accepts a private invitation to join a group
* @param {object} inviteV4 Invite V4 Info
* @param {object} inviteInfo Invite V4 Info
* @returns {Promise<Object>}
*/
async acceptGroupV4Invite(inviteInfo) {
if(!inviteInfo.inviteCode) throw 'Invalid invite code, try passing the message.inviteV4 object';
if (!inviteInfo.inviteCode) throw 'Invalid invite code, try passing the message.inviteV4 object';
if (inviteInfo.inviteCodeExp == 0) throw 'Expired invite code';
return await this.pupPage.evaluate(async inviteInfo => {
let { groupId, fromId, inviteCode, inviteCodeExp, toId } = inviteInfo;
return await window.Store.Wap.acceptGroupV4Invite(groupId, fromId, inviteCode, String(inviteCodeExp), toId);
return this.pupPage.evaluate(async inviteInfo => {
let { groupId, fromId, inviteCode, inviteCodeExp } = inviteInfo;
return await window.Store.JoinInviteV4.sendJoinGroupViaInviteV4(inviteCode, String(inviteCodeExp), groupId, fromId);
}, inviteInfo);
}
/**
* Sets the current user's status message
* @param {string} status New status message
*/
async setStatus(status) {
await this.pupPage.evaluate(async status => {
return await window.Store.Wap.sendSetStatus(status);
return await window.Store.StatusUtils.setMyStatus(status);
}, status);
}
@@ -635,11 +727,22 @@ class Client extends EventEmitter {
* Sets the current user's display name.
* This is the name shown to WhatsApp users that have not added you as a contact beside your number in groups and in your profile.
* @param {string} displayName New display name
* @returns {Promise<Boolean>}
*/
async setDisplayName(displayName) {
await this.pupPage.evaluate(async displayName => {
return await window.Store.Wap.setPushname(displayName);
const couldSet = await this.pupPage.evaluate(async displayName => {
if(!window.Store.Conn.canSetMyPushname()) return false;
if(window.Store.Features.features.MD_BACKEND) {
// TODO
return false;
} else {
const res = await window.Store.Wap.setPushname(displayName);
return !res.status || res.status === 200;
}
}, displayName);
return couldSet;
}
/**
@@ -648,6 +751,7 @@ class Client extends EventEmitter {
*/
async getState() {
return await this.pupPage.evaluate(() => {
if(!window.Store) return null;
return window.Store.AppState.state;
});
}
@@ -657,7 +761,16 @@ class Client extends EventEmitter {
*/
async sendPresenceAvailable() {
return await this.pupPage.evaluate(() => {
return window.Store.Wap.sendPresenceAvailable();
return window.Store.PresenceUtils.sendPresenceAvailable();
});
}
/**
* Marks the client as unavailable
*/
async sendPresenceUnavailable() {
return await this.pupPage.evaluate(() => {
return window.Store.PresenceUtils.sendPresenceUnavailable();
});
}
@@ -669,7 +782,7 @@ class Client extends EventEmitter {
return await this.pupPage.evaluate(async chatId => {
let chat = await window.Store.Chat.get(chatId);
await window.Store.Cmd.archiveChat(chat, true);
return chat.archive;
return true;
}, chatId);
}
@@ -681,7 +794,7 @@ class Client extends EventEmitter {
return await this.pupPage.evaluate(async chatId => {
let chat = await window.Store.Chat.get(chatId);
await window.Store.Cmd.archiveChat(chat, false);
return chat.archive;
return false;
}, chatId);
}
@@ -723,15 +836,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);
}
/**
@@ -762,13 +876,47 @@ class Client extends EventEmitter {
* @returns {Promise<string>}
*/
async getProfilePicUrl(contactId) {
const profilePic = await this.pupPage.evaluate((contactId) => {
return window.Store.Wap.profilePicFind(contactId);
const profilePic = await this.pupPage.evaluate(async contactId => {
let asyncPic;
if (window.Store.Features.features.MD_BACKEND) {
const chatWid = window.Store.WidFactory.createWid(contactId);
asyncPic = await window.Store.getProfilePicFull(chatWid).catch(() => {
return undefined;
});
} else {
asyncPic = await window.Store.Wap.profilePicFind(contactId).catch(() => {
return undefined;
});
}
return asyncPic;
}, contactId);
return profilePic ? profilePic.eurl : undefined;
}
/**
* Gets the Contact's common groups with you. Returns empty array if you don't have any common group.
* @param {string} contactId the whatsapp user's ID (_serialized format)
* @returns {Promise<WAWebJS.ChatId[]>}
*/
async getCommonGroups(contactId) {
const commonGroups = await this.pupPage.evaluate(async (contactId) => {
const contact = window.Store.Contact.get(contactId);
if (contact.commonGroups) {
return contact.commonGroups.serialize();
}
const status = await window.Store.findCommonGroups(contact);
if (status) {
return contact.commonGroups.serialize();
}
return [];
}, contactId);
const chats = [];
for (const group of commonGroups) {
chats.push(group.id);
}
return chats;
}
/**
* Force reset of connection state for the client
*/
@@ -784,10 +932,7 @@ class Client extends EventEmitter {
* @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);
return Boolean(await this.getNumberId(id));
}
/**
@@ -797,17 +942,42 @@ class Client extends EventEmitter {
* @returns {Promise<Object|null>}
*/
async getNumberId(number) {
if(!number.endsWith('@c.us')) {
if (!number.endsWith('@c.us')) {
number += '@c.us';
}
try {
return await this.pupPage.evaluate(async numberId => {
return window.WWebJS.getNumberId(numberId);
}, number);
} catch(_) {
return null;
}
return await this.pupPage.evaluate(async number => {
const result = await window.Store.QueryExist(number);
if (!result || result.wid === undefined) return null;
return result.wid;
}, number);
}
/**
* 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);
}
/**
@@ -828,12 +998,9 @@ class Client extends EventEmitter {
}
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!';
}
const participantWIDs = participantIds.map(p => window.Store.WidFactory.createWid(p));
const id = window.Store.genId();
const res = await window.Store.GroupUtils.sendCreateGroup(name, participantWIDs, undefined, id);
return res;
}, name, participants);
@@ -854,9 +1021,9 @@ class Client extends EventEmitter {
async getLabels() {
const labels = await this.pupPage.evaluate(async () => {
return window.WWebJS.getLabels();
});
});
return labels.map(data => new Label(this , data));
return labels.map(data => new Label(this, data));
}
/**
@@ -867,7 +1034,7 @@ class Client extends EventEmitter {
async getLabelById(labelId) {
const label = await this.pupPage.evaluate(async (labelId) => {
return window.WWebJS.getLabel(labelId);
}, labelId);
}, labelId);
return new Label(this, label);
}
@@ -877,12 +1044,12 @@ class Client extends EventEmitter {
* @param {string} chatId
* @returns {Promise<Array<Label>>}
*/
async getChatLabels(chatId){
async getChatLabels(chatId) {
const labels = await this.pupPage.evaluate(async (chatId) => {
return window.WWebJS.getChatLabels(chatId);
}, chatId);
return labels.map(data => new Label(this, data));
return labels.map(data => new Label(this, data));
}
/**
@@ -890,20 +1057,33 @@ class Client extends EventEmitter {
* @param {string} labelId
* @returns {Promise<Array<Chat>>}
*/
async getChatsByLabelId(labelId){
async getChatsByLabelId(labelId) {
const chatIds = await this.pupPage.evaluate(async (labelId) => {
const label = window.Store.Label.get(labelId);
const labelItems = label.labelItemCollection.models;
return labelItems.reduce((result, item) => {
if(item.parentType === 'Chat'){
if (item.parentType === 'Chat') {
result.push(item.parentId);
}
return result;
},[]);
}, []);
}, labelId);
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;

View File

@@ -0,0 +1,24 @@
'use strict';
/**
* Base class which all authentication strategies extend
*/
class BaseAuthStrategy {
constructor() {}
setup(client) {
this.client = client;
}
async beforeBrowserInitialized() {}
async afterBrowserInitialized() {}
async onAuthenticationNeeded() {
return {
failed: false,
restart: false,
failureEventPayload: undefined
};
}
async getAuthEventPayload() {}
async logout() {}
}
module.exports = BaseAuthStrategy;

View File

@@ -0,0 +1,72 @@
'use strict';
const BaseAuthStrategy = require('./BaseAuthStrategy');
/**
* Legacy session auth strategy
* Not compatible with multi-device accounts.
* @param {object} options - options
* @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
* @param {string} options.session.WASecretBundle
* @param {string} options.session.WAToken1
* @param {string} options.session.WAToken2
*/
class LegacySessionAuth extends BaseAuthStrategy {
constructor({ session, restartOnAuthFail }={}) {
super();
this.session = session;
this.restartOnAuthFail = restartOnAuthFail;
}
async afterBrowserInitialized() {
if(this.session) {
await this.client.pupPage.evaluateOnNewDocument(session => {
if (document.referrer === 'https://whatsapp.com/') {
localStorage.clear();
localStorage.setItem('WABrowserId', session.WABrowserId);
localStorage.setItem('WASecretBundle', session.WASecretBundle);
localStorage.setItem('WAToken1', session.WAToken1);
localStorage.setItem('WAToken2', session.WAToken2);
}
localStorage.setItem('remember-me', 'true');
}, this.session);
}
}
async onAuthenticationNeeded() {
if(this.session) {
this.session = null;
return {
failed: true,
restart: this.restartOnAuthFail,
failureEventPayload: 'Unable to log in. Are the session details valid?'
};
}
return { failed: false };
}
async getAuthEventPayload() {
const isMD = await this.client.pupPage.evaluate(() => {
return window.Store.Features.features.MD_BACKEND;
});
if(isMD) throw new Error('Authenticating via JSON session is not supported for MultiDevice-enabled WhatsApp accounts.');
const localStorage = JSON.parse(await this.client.pupPage.evaluate(() => {
return JSON.stringify(window.localStorage);
}));
return {
WABrowserId: localStorage.WABrowserId,
WASecretBundle: localStorage.WASecretBundle,
WAToken1: localStorage.WAToken1,
WAToken2: localStorage.WAToken2
};
}
}
module.exports = LegacySessionAuth;

View File

@@ -0,0 +1,53 @@
'use strict';
const path = require('path');
const fs = require('fs');
const BaseAuthStrategy = require('./BaseAuthStrategy');
/**
* Local directory-based authentication
* @param {object} options - options
* @param {string} options.clientId - Client id to distinguish instances if you are using multiple, otherwise keep null if you are using only one instance
* @param {string} options.dataPath - Change the default path for saving session files, default is: "./.wwebjs_auth/"
*/
class LocalAuth extends BaseAuthStrategy {
constructor({ clientId, dataPath }={}) {
super();
const idRegex = /^[-_\w]+$/i;
if(clientId && !idRegex.test(clientId)) {
throw new Error('Invalid clientId. Only alphanumeric characters, underscores and hyphens are allowed.');
}
this.dataPath = path.resolve(dataPath || './.wwebjs_auth/');
this.clientId = clientId;
}
async beforeBrowserInitialized() {
const puppeteerOpts = this.client.options.puppeteer;
const sessionDirName = this.clientId ? `session-${this.clientId}` : 'session';
const dirPath = path.join(this.dataPath, sessionDirName);
if(puppeteerOpts.userDataDir && puppeteerOpts.userDataDir !== dirPath) {
throw new Error('LocalAuth is not compatible with a user-supplied userDataDir.');
}
fs.mkdirSync(dirPath, { recursive: true });
this.client.options.puppeteer = {
...puppeteerOpts,
userDataDir: dirPath
};
this.userDataDir = dirPath;
}
async logout() {
if (this.userDataDir) {
return (fs.rmSync ? fs.rmSync : fs.rmdirSync).call(this, this.userDataDir, { recursive: true });
}
}
}
module.exports = LocalAuth;

View File

@@ -0,0 +1,12 @@
'use strict';
const BaseAuthStrategy = require('./BaseAuthStrategy');
/**
* No session restoring functionality
* Will need to authenticate via QR code every time
*/
class NoAuth extends BaseAuthStrategy { }
module.exports = NoAuth;

82
src/structures/Buttons.js Normal file
View File

@@ -0,0 +1,82 @@
'use strict';
const MessageMedia = require('./MessageMedia');
const Util = require('../util/Util');
/**
* Button spec used in Buttons constructor
* @typedef {Object} ButtonSpec
* @property {string=} id - Custom ID to set on the button. A random one will be generated if one is not passed.
* @property {string} body - The text to show on the button.
*/
/**
* @typedef {Object} FormattedButtonSpec
* @property {string} buttonId
* @property {number} type
* @property {Object} buttonText
*/
/**
* Message type buttons
*/
class Buttons {
/**
* @param {string|MessageMedia} body
* @param {ButtonSpec[]} buttons - See {@link ButtonSpec}
* @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 {FormattedButtonSpec[]}
*/
this.buttons = this._format(buttons);
if(!this.buttons.length){ throw '[BT01] No buttons';}
}
/**
* Creates button array from simple array
* @param {ButtonSpec[]} buttons
* @returns {FormattedButtonSpec[]}
* @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 ? String(btn.id) : Util.generateHash(6),'buttonText':{'displayText':btn.body},'type':1};
});
}
}
module.exports = Buttons;

68
src/structures/Call.js Normal file
View File

@@ -0,0 +1,68 @@
'use strict';
const Base = require('./Base');
/**
* Represents a Call on WhatsApp
* @extends {Base}
*/
class Call extends Base {
constructor(client, data) {
super(client);
if (data) this._patch(data);
}
_patch(data) {
/**
* Call ID
* @type {string}
*/
this.id = data.id;
/**
* From
* @type {string}
*/
this.from = data.peerJid;
/**
* Unix timestamp for when the call was created
* @type {number}
*/
this.timestamp = data.offerTime;
/**
* Is video
* @type {boolean}
*/
this.isVideo = data.isVideo;
/**
* Is Group
* @type {boolean}
*/
this.isGroup = data.isGroup;
/**
* Indicates if the call was sent by the current user
* @type {boolean}
*/
this.fromMe = data.outgoing;
/**
* Indicates if the call can be handled in waweb
* @type {boolean}
*/
this.canHandleLocally = data.canHandleLocally;
/**
* Indicates if the call Should be handled in waweb
* @type {boolean}
*/
this.webClientShouldHandle = data.webClientShouldHandle;
/**
* Object with participants
* @type {object}
*/
this.participants = data.participants;
return super._patch(data);
}
}
module.exports = Call;

View File

@@ -65,7 +65,7 @@ class Chat extends Base {
/**
* Indicates if the chat is muted or not
* @type {number}
* @type {boolean}
*/
this.isMuted = data.isMuted;
@@ -147,8 +147,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);
@@ -171,30 +171,32 @@ class Chat extends Base {
/**
* Loads chat messages, sorted from earliest to latest.
* @param {Object} searchOptions Options for searching messages. Right now only limit is supported.
* @param {Number} [searchOptions.limit=50] The amount of messages to return. Note that the actual number of returned messages may be smaller if there aren't enough messages in the conversation. Set this to Infinity to load all messages.
* @param {Number} [searchOptions.limit] The amount of messages to return. If no limit is specified, the available messages will be returned. Note that the actual number of returned messages may be smaller if there aren't enough messages in the conversation. Set this to Infinity to load all messages.
* @returns {Promise<Array<Message>>}
*/
async fetchMessages(searchOptions) {
if (!searchOptions || !searchOptions.limit) {
searchOptions = { limit: 50 };
}
let messages = await this.client.pupPage.evaluate(async (chatId, limit) => {
let messages = await this.client.pupPage.evaluate(async (chatId, searchOptions) => {
const msgFilter = m => !m.isNotification; // dont include notification messages
const chat = window.Store.Chat.get(chatId);
let msgs = chat.msgs.models.filter(msgFilter);
while (msgs.length < limit) {
const loadedMessages = await chat.loadEarlierMsgs();
if (!loadedMessages) break;
msgs = [...loadedMessages.filter(msgFilter), ...msgs];
if (searchOptions && searchOptions.limit > 0) {
while (msgs.length < searchOptions.limit) {
const loadedMessages = await chat.loadEarlierMsgs();
if (!loadedMessages) break;
msgs = [...loadedMessages.filter(msgFilter), ...msgs];
}
if (msgs.length > searchOptions.limit) {
msgs.sort((a, b) => (a.t > b.t) ? 1 : -1);
msgs = msgs.splice(msgs.length - searchOptions.limit);
}
}
msgs.sort((a, b) => (a.t > b.t) ? 1 : -1);
if (msgs.length > limit) msgs = msgs.splice(msgs.length - limit);
return msgs.map(m => window.WWebJS.getMessageModel(m));
}, this.id._serialized, searchOptions.limit);
}, this.id._serialized, searchOptions);
return messages.map(m => new Message(this.client, m));
}

View File

@@ -20,12 +20,6 @@ class ClientInfo extends Base {
*/
this.pushname = data.pushname;
/**
* @type {object}
* @deprecated Use .wid instead
*/
this.me = data.wid;
/**
* Current user ID
* @type {object}
@@ -33,18 +27,25 @@ class ClientInfo extends Base {
this.wid = data.wid;
/**
* Information about the phone this client is connected to
* @type {object}
* @deprecated Use .wid instead
*/
this.me = data.wid;
/**
* Information about the phone this client is connected to. Not available in multi-device.
* @type {object}
* @property {string} wa_version WhatsApp Version running on the phone
* @property {string} os_version OS Version running on the phone (iOS or Android version)
* @property {string} device_manufacturer Device manufacturer
* @property {string} device_model Device model
* @property {string} os_build_number OS build number
* @deprecated
*/
this.phone = data.phone;
/**
* Platform the phone is running on
* Platform WhatsApp is running on
* @type {string}
*/
this.platform = data.platform;
@@ -57,6 +58,7 @@ class ClientInfo extends Base {
* @returns {object} batteryStatus
* @returns {number} batteryStatus.battery - The current battery percentage
* @returns {boolean} batteryStatus.plugged - Indicates if the phone is plugged in (true) or not (false)
* @deprecated
*/
async getBatteryStatus() {
return await this.client.pupPage.evaluate(() => {
@@ -64,7 +66,6 @@ class ClientInfo extends Base {
return { battery, plugged };
});
}
}
module.exports = ClientInfo;

View File

@@ -108,7 +108,7 @@ class Contact extends Base {
* @type {boolean}
*/
this.isBlocked = data.isBlocked;
return super._patch(data);
}
@@ -120,6 +120,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.
@@ -167,7 +183,8 @@ class Contact extends Base {
*/
async getAbout() {
const about = await this.client.pupPage.evaluate(async (contactId) => {
return window.Store.Wap.statusFind(contactId);
const wid = window.Store.WidFactory.createWid(contactId);
return window.Store.StatusUtils.getStatus(wid);
}, this.id._serialized);
if (typeof about.status !== 'string')
@@ -175,7 +192,15 @@ class Contact extends Base {
return about.status;
}
/**
* Gets the Contact's common groups with you. Returns empty array if you don't have any common group.
* @returns {Promise<WAWebJS.ChatId[]>}
*/
async getCommonGroups() {
return await this.client.getCommonGroups(this.id._serialized);
}
}
module.exports = Contact;
module.exports = Contact;

View File

@@ -60,7 +60,9 @@ class GroupChat extends Chat {
*/
async addParticipants(participantIds) {
return await this.client.pupPage.evaluate((chatId, participantIds) => {
return window.Store.Wap.addParticipants(chatId, participantIds);
const chatWid = window.Store.WidFactory.createWid(chatId);
const participantWids = participantIds.map(p => window.Store.WidFactory.createWid(p));
return window.Store.GroupParticipants.sendAddParticipants(chatWid, participantWids);
}, this.id._serialized, participantIds);
}
@@ -71,7 +73,9 @@ class GroupChat extends Chat {
*/
async removeParticipants(participantIds) {
return await this.client.pupPage.evaluate((chatId, participantIds) => {
return window.Store.Wap.removeParticipants(chatId, participantIds);
const chatWid = window.Store.WidFactory.createWid(chatId);
const participantWids = participantIds.map(p => window.Store.WidFactory.createWid(p));
return window.Store.GroupParticipants.sendRemoveParticipants(chatWid, participantWids);
}, this.id._serialized, participantIds);
}
@@ -82,7 +86,9 @@ class GroupChat extends Chat {
*/
async promoteParticipants(participantIds) {
return await this.client.pupPage.evaluate((chatId, participantIds) => {
return window.Store.Wap.promoteParticipants(chatId, participantIds);
const chatWid = window.Store.WidFactory.createWid(chatId);
const participantWids = participantIds.map(p => window.Store.WidFactory.createWid(p));
return window.Store.GroupParticipants.sendPromoteParticipants(chatWid, participantWids);
}, this.id._serialized, participantIds);
}
@@ -93,39 +99,53 @@ class GroupChat extends Chat {
*/
async demoteParticipants(participantIds) {
return await this.client.pupPage.evaluate((chatId, participantIds) => {
return window.Store.Wap.demoteParticipants(chatId, participantIds);
const chatWid = window.Store.WidFactory.createWid(chatId);
const participantWids = participantIds.map(p => window.Store.WidFactory.createWid(p));
return window.Store.GroupParticipants.sendDemoteParticipants(chatWid, participantWids);
}, this.id._serialized, participantIds);
}
/**
* Updates the group subject
* @param {string} subject
* @returns {Promise}
* @returns {Promise<boolean>} Returns true if the subject was properly updated. This can return false if the user does not have the necessary permissions.
*/
async setSubject(subject) {
let res = await this.client.pupPage.evaluate((chatId, subject) => {
return window.Store.Wap.changeSubject(chatId, subject);
const success = await this.client.pupPage.evaluate(async (chatId, subject) => {
const chatWid = window.Store.WidFactory.createWid(chatId);
try {
return await window.Store.GroupUtils.sendSetGroupSubject(chatWid, subject);
} catch (err) {
if(err.name === 'ServerStatusCodeError') return false;
throw err;
}
}, this.id._serialized, subject);
if(res.status == 200) {
this.name = subject;
}
if(!success) return false;
this.name = subject;
return true;
}
/**
* Updates the group description
* @param {string} description
* @returns {Promise}
* @returns {Promise<boolean>} Returns true if the description was properly updated. This can return false if the user does not have the necessary permissions.
*/
async setDescription(description) {
let res = await this.client.pupPage.evaluate((chatId, description) => {
let descId = window.Store.GroupMetadata.get(chatId).descId;
return window.Store.Wap.setGroupDescription(chatId, description, window.Store.genId(), descId);
const success = await this.client.pupPage.evaluate(async (chatId, description) => {
const chatWid = window.Store.WidFactory.createWid(chatId);
let descId = window.Store.GroupMetadata.get(chatWid).descId;
try {
return await window.Store.GroupUtils.sendSetGroupDescription(chatWid, description, window.Store.MsgKey.newId(), descId);
} catch (err) {
if(err.name === 'ServerStatusCodeError') return false;
throw err;
}
}, this.id._serialized, description);
if (res.status == 200) {
this.groupMetadata.desc = description;
}
if(!success) return false;
this.groupMetadata.desc = description;
return true;
}
/**
@@ -134,12 +154,18 @@ class GroupChat extends Chat {
* @returns {Promise<boolean>} Returns true if the setting was properly updated. This can return false if the user does not have the necessary permissions.
*/
async setMessagesAdminsOnly(adminsOnly=true) {
let res = await this.client.pupPage.evaluate((chatId, value) => {
return window.Store.Wap.setGroupProperty(chatId, 'announcement', value);
const success = await this.client.pupPage.evaluate(async (chatId, adminsOnly) => {
const chatWid = window.Store.WidFactory.createWid(chatId);
try {
return await window.Store.GroupUtils.sendSetGroupProperty(chatWid, 'announcement', adminsOnly ? 1 : 0);
} catch (err) {
if(err.name === 'ServerStatusCodeError') return false;
throw err;
}
}, this.id._serialized, adminsOnly);
if (res.status !== 200) return false;
if(!success) return false;
this.groupMetadata.announce = adminsOnly;
return true;
}
@@ -150,11 +176,17 @@ class GroupChat extends Chat {
* @returns {Promise<boolean>} Returns true if the setting was properly updated. This can return false if the user does not have the necessary permissions.
*/
async setInfoAdminsOnly(adminsOnly=true) {
let res = await this.client.pupPage.evaluate((chatId, value) => {
return window.Store.Wap.setGroupProperty(chatId, 'restrict', value);
const success = await this.client.pupPage.evaluate(async (chatId, adminsOnly) => {
const chatWid = window.Store.WidFactory.createWid(chatId);
try {
return await window.Store.GroupUtils.sendSetGroupProperty(chatWid, 'restrict', adminsOnly ? 1 : 0);
} catch (err) {
if(err.name === 'ServerStatusCodeError') return false;
throw err;
}
}, this.id._serialized, adminsOnly);
if (res.status !== 200) return false;
if(!success) return false;
this.groupMetadata.restrict = adminsOnly;
return true;
@@ -165,25 +197,25 @@ class GroupChat extends Chat {
* @returns {Promise<string>} Group's invite code
*/
async getInviteCode() {
let res = await this.client.pupPage.evaluate(chatId => {
return window.Store.Wap.groupInviteCode(chatId);
const code = await this.client.pupPage.evaluate(async chatId => {
const chatWid = window.Store.WidFactory.createWid(chatId);
return window.Store.Invite.sendQueryGroupInviteCode(chatWid);
}, this.id._serialized);
if (res.status == 200) {
return res.code;
}
throw new Error('Not authorized');
return code;
}
/**
* Invalidates the current group invite code and generates a new one
* @returns {Promise}
* @returns {Promise<string>} New invite code
*/
async revokeInvite() {
return await this.client.pupPage.evaluate(chatId => {
return window.Store.Wap.revokeGroupInvite(chatId);
const code = await this.client.pupPage.evaluate(chatId => {
const chatWid = window.Store.WidFactory.createWid(chatId);
return window.Store.Invite.sendRevokeGroupInviteCode(chatWid);
}, this.id._serialized);
return code;
}
/**
@@ -191,8 +223,9 @@ class GroupChat extends Chat {
* @returns {Promise}
*/
async leave() {
return await this.client.pupPage.evaluate(chatId => {
return window.Store.Wap.leaveGroup(chatId);
await this.client.pupPage.evaluate(chatId => {
const chatWid = window.Store.WidFactory.createWid(chatId);
return window.Store.GroupUtils.sendExitGroup(chatWid);
}, this.id._serialized);
}

View File

@@ -43,7 +43,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.

79
src/structures/List.js Normal file
View File

@@ -0,0 +1,79 @@
'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 && sections.filter(s => typeof s.title == 'undefined').length > 1){throw '[LT05] You can\'t have more than one empty title.';}
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;

View File

@@ -4,6 +4,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');
/**
@@ -18,13 +19,14 @@ class Message extends Base {
}
_patch(data) {
this._data = data;
/**
* MediaKey that represents the sticker 'ID'
* @type {string}
*/
this.mediaKey = data.mediaKey;
/**
* ID that represents the message
* @type {object}
@@ -49,7 +51,7 @@ class Message extends Base {
*/
this.body = this.hasMedia ? data.caption || '' : data.body || '';
/**
/**
* Message type
* @type {MessageTypes}
*/
@@ -69,9 +71,9 @@ class Message extends Base {
/**
* ID for who this message is for.
*
*
* If the message is sent by the current user, it will be the Chat to which the message is being sent.
* If the message is sent by another user, it will be the ID for the current user.
* If the message is sent by another user, it will be the ID for the current user.
* @type {string}
*/
this.to = (typeof (data.to) === 'object' && data.to !== null) ? data.to._serialized : data.to;
@@ -86,14 +88,22 @@ class Message extends Base {
* String that represents from which device type the message was sent
* @type {string}
*/
this.deviceType = data.id.id.length > 21 ? 'android' : data.id.id.substring(0,2) =='3A' ? 'ios' : 'web';
this.deviceType = data.id.id.length > 21 ? 'android' : data.id.id.substring(0, 2) == '3A' ? 'ios' : 'web';
/**
* Indicates if the message was forwarded
* @type {boolean}
*/
this.isForwarded = data.isForwarded;
/**
* Indicates how many times the message was forwarded.
*
* The maximum value is 127.
* @type {number}
*/
this.forwardingScore = data.forwardingScore || 0;
/**
* Indicates if the message is a status update
* @type {boolean}
@@ -105,14 +115,14 @@ class Message extends Base {
* @type {boolean}
*/
this.isStarred = data.star;
/**
* Indicates if the message was a broadcast
* @type {boolean}
*/
this.broadcast = data.broadcast;
/**
/**
* Indicates if the message was sent by the current user
* @type {boolean}
*/
@@ -124,6 +134,12 @@ class Message extends Base {
*/
this.hasQuotedMsg = data.quotedMsg ? true : false;
/**
* Indicates the duration of the message in seconds
* @type {string}
*/
this.duration = data.duration ? data.duration : undefined;
/**
* Location information contained in the message, if the message is type "location"
* @type {Location}
@@ -148,7 +164,7 @@ class Message extends Base {
fromId: data.from._serialized,
toId: data.to._serialized
} : undefined;
/**
* Indicates the mentions in the message body.
* @type {Array<string>}
@@ -170,6 +186,18 @@ class Message extends Base {
*/
this.token = data.token ? data.token : undefined;
/**
* Indicates whether the message is a Gif
* @type {boolean}
*/
this.isGif = Boolean(data.isGif);
/**
* Indicates if the message will disappear after it expires
* @type {boolean}
*/
this.isEphemeral = data.isEphemeral;
/** Title */
if (data.title) {
this.title = data.title;
@@ -192,10 +220,26 @@ class Message extends Base {
/**
* Links included in the message.
* @type {Array<string>}
* @type {Array<{link: string, isSuspicious: boolean}>}
*
*/
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);
}
@@ -203,6 +247,32 @@ class Message extends Base {
return this.fromMe ? this.to : this.from;
}
/**
* Reloads this Message object's data in-place with the latest values from WhatsApp Web.
* Note that the Message must still be in the web app cache for this to work, otherwise will return null.
* @returns {Promise<Message>}
*/
async reload() {
const newData = await this.client.pupPage.evaluate((msgId) => {
const msg = window.Store.Msg.get(msgId);
if(!msg) return null;
return window.WWebJS.getMessageModel(msg);
}, this.id._serialized);
if(!newData) return null;
this._patch(newData);
return this;
}
/**
* Returns message in a raw format
* @type {Object}
*/
get rawData() {
return this._data;
}
/**
* Returns the Chat this message was sent in
* @returns {Promise<Chat>}
@@ -243,12 +313,12 @@ class Message extends Base {
}
/**
* Sends a message as a reply to this message. If chatId is specified, it will be sent
* through the specified Chat. If not, it will send the message
* Sends a message as a reply to this message. If chatId is specified, it will be sent
* through the specified Chat. If not, it will send the message
* in the same Chat as the original message was sent.
*
* @param {string|MessageMedia|Location} content
* @param {string} [chatId]
*
* @param {string|MessageMedia|Location} content
* @param {string} [chatId]
* @param {MessageSendOptions} [options]
* @returns {Promise<Message>}
*/
@@ -272,10 +342,10 @@ class Message extends Base {
async acceptGroupV4Invite() {
return await this.client.acceptGroupV4Invite(this.inviteV4);
}
/**
* Forwards this message to another chat
*
*
* @param {string|Chat} chat Chat model or chat ID to which the message will be forwarded
* @returns {Promise}
*/
@@ -304,32 +374,39 @@ class Message extends Base {
if (msg.mediaData.mediaStage != 'RESOLVED') {
// try to resolve media
await msg.downloadMedia(true, 1);
await msg.downloadMedia({
downloadEvenIfExpensive: true,
rmrReason: 1
});
}
if (msg.mediaData.mediaStage.includes('ERROR')) {
if (msg.mediaData.mediaStage.includes('ERROR') || msg.mediaData.mediaStage === 'FETCHING') {
// media could not be downloaded
return undefined;
}
const decryptedMedia = await window.Store.DownloadManager.downloadAndDecrypt({
directPath: msg.directPath,
encFilehash: msg.encFilehash,
filehash: msg.filehash,
mediaKey: msg.mediaKey,
mediaKeyTimestamp: msg.mediaKeyTimestamp,
type: msg.type,
signal: (new AbortController).signal
});
try {
const decryptedMedia = await window.Store.DownloadManager.downloadAndDecrypt({
directPath: msg.directPath,
encFilehash: msg.encFilehash,
filehash: msg.filehash,
mediaKey: msg.mediaKey,
mediaKeyTimestamp: msg.mediaKeyTimestamp,
type: msg.type,
signal: (new AbortController).signal
});
const data = window.WWebJS.arrayBufferToBase64(decryptedMedia);
return {
data,
mimetype: msg.mimetype,
filename: msg.filename
};
const data = window.WWebJS.arrayBufferToBase64(decryptedMedia);
return {
data,
mimetype: msg.mimetype,
filename: msg.filename
};
} catch (e) {
if(e.status && e.status === 404) return undefined;
throw e;
}
}, this.id._serialized);
if (!result) return undefined;
@@ -344,8 +421,8 @@ class Message extends Base {
await this.client.pupPage.evaluate((msgId, everyone) => {
let msg = window.Store.Msg.get(msgId);
if (everyone && msg.id.fromMe && msg.canRevoke()) {
return window.Store.Cmd.sendRevokeMsgs(msg.chat, [msg], true);
if (everyone && msg.id.fromMe && msg._canRevoke()) {
return window.Store.Cmd.sendRevokeMsgs(msg.chat, [msg], {type: 'Sender'});
}
return window.Store.Cmd.sendDeleteMsgs(msg.chat, [msg], true);
@@ -396,14 +473,10 @@ class Message extends Base {
async getInfo() {
const info = await this.client.pupPage.evaluate(async (msgId) => {
const msg = window.Store.Msg.get(msgId);
if(!msg) return null;
return await window.Store.Wap.queryMsgInfo(msg.id);
}, this.id._serialized);
if (!msg) return null;
if(info.status) {
return null;
}
return await window.Store.MessageInfo.sendQueryMsgInfo(msg);
}, this.id._serialized);
return info;
}
@@ -414,14 +487,29 @@ class Message extends Base {
*/
async getOrder() {
if (this.type === MessageTypes.ORDER) {
const result = await this.client.pupPage.evaluate((orderId, token) => {
return window.WWebJS.getOrderDetail(orderId, token);
}, this.orderId, this.token);
const result = await this.client.pupPage.evaluate((orderId, token, chatId) => {
return window.WWebJS.getOrderDetail(orderId, token, chatId);
}, this.orderId, this.token, this._getChatId());
if (!result) return undefined;
return new Order(this.client, result);
}
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;

View File

@@ -3,6 +3,8 @@
const fs = require('fs');
const path = require('path');
const mime = require('mime');
const fetch = require('node-fetch');
const { URL } = require('url');
/**
* Media attached to a message
@@ -43,6 +45,59 @@ class MessageMedia {
return new MessageMedia(mimetype, b64data, filename);
}
/**
* Creates a MessageMedia instance from a URL
* @param {string} url
* @param {Object} [options]
* @param {boolean} [options.unsafeMime=false]
* @param {string} [options.filename]
* @param {object} [options.client]
* @param {object} [options.reqOptions]
* @param {number} [options.reqOptions.size=0]
* @returns {Promise<MessageMedia>}
*/
static async fromUrl(url, options = {}) {
const pUrl = new URL(url);
let mimetype = mime.getType(pUrl.pathname);
if (!mimetype && !options.unsafeMime)
throw new Error('Unable to determine MIME type using URL. Set unsafeMime to true to download it anyway.');
async function fetchData (url, options) {
const reqOptions = Object.assign({ headers: { accept: 'image/* video/* text/* audio/*' } }, options);
const response = await fetch(url, reqOptions);
const mime = response.headers.get('Content-Type');
const contentDisposition = response.headers.get('Content-Disposition');
const name = contentDisposition ? contentDisposition.match(/((?<=filename=")(.*)(?="))/) : null;
let data = '';
if (response.buffer) {
data = (await response.buffer()).toString('base64');
} else {
const bArray = new Uint8Array(await response.arrayBuffer());
bArray.forEach((b) => {
data += String.fromCharCode(b);
});
data = btoa(data);
}
return { data, mime, name };
}
const res = options.client
? (await options.client.pupPage.evaluate(fetchData, url, options.reqOptions))
: (await fetchData(url, options.reqOptions));
const filename = options.filename ||
(res.name ? res.name[0] : (pUrl.pathname.split('/').pop() || 'file'));
if (!mimetype)
mimetype = res.mime;
return new MessageMedia(mimetype, res.data, filename);
}
}
module.exports = MessageMedia;
module.exports = MessageMedia;

79
src/structures/Payment.js Normal file
View File

@@ -0,0 +1,79 @@
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
*
* 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
*
* @type {number}
*/
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;

View File

@@ -13,5 +13,9 @@ module.exports = {
GroupNotification: require('./GroupNotification'),
Label: require('./Label.js'),
Order: require('./Order'),
Product: require('./Product')
};
Product: require('./Product'),
Call: require('./Call'),
Buttons: require('./Buttons'),
List: require('./List'),
Payment: require('./Payment')
};

View File

@@ -7,10 +7,8 @@ exports.DefaultOptions = {
headless: true,
defaultViewport: null
},
session: false,
qrTimeoutMs: 45000,
qrRefreshIntervalMs: 20000,
authTimeoutMs: 45000,
authTimeoutMs: 0,
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',
@@ -50,7 +48,8 @@ exports.Events = {
QR_RECEIVED: 'qr',
DISCONNECTED: 'disconnected',
STATE_CHANGED: 'change_state',
BATTERY_CHANGED: 'change_battery'
BATTERY_CHANGED: 'change_battery',
INCOMING_CALL: 'incoming_call'
};
/**
@@ -73,7 +72,27 @@ exports.MessageTypes = {
REVOKED: 'revoked',
PRODUCT: 'product',
UNKNOWN: 'unknown',
GROUP_INVITE: 'groups_v4_invite'
GROUP_INVITE: 'groups_v4_invite',
LIST: 'list',
LIST_RESPONSE: 'list_response',
BUTTONS_RESPONSE: 'buttons_response',
PAYMENT: 'payment',
BROADCAST_NOTIFICATION: 'broadcast_notification',
CALL_LOG: 'call_log',
CIPHERTEXT: 'ciphertext',
DEBUG: 'debug',
E2E_NOTIFICATION: 'e2e_notification',
GP2: 'gp2',
GROUP_NOTIFICATION: 'group_notification',
HSM: 'hsm',
INTERACTIVE: 'interactive',
NATIVE_FLOW: 'native_flow',
NOTIFICATION: 'notification',
NOTIFICATION_TEMPLATE: 'notification_template',
OVERSIZED: 'oversized',
PROTOCOL: 'protocol',
REACTION: 'reaction',
TEMPLATE_BUTTON_REPLY: 'template_button_reply',
};
/**

View File

@@ -5,50 +5,72 @@ exports.ExposeStore = (moduleRaidStr) => {
eval('var moduleRaid = ' + moduleRaidStr);
// eslint-disable-next-line no-undef
window.mR = moduleRaid();
window.Store = window.mR.findModule('Chat')[0].default;
window.Store.AppState = window.mR.findModule('STREAM')[0].default;
window.Store.Conn = window.mR.findModule('Conn')[0].default;
window.Store = Object.assign({}, window.mR.findModule(m => m.default && m.default.Chat)[0].default);
window.Store.AppState = window.mR.findModule('Socket')[0].Socket;
window.Store.Conn = window.mR.findModule('Conn')[0].Conn;
window.Store.BlockContact = window.mR.findModule('blockContact')[0];
window.Store.Call = window.mR.findModule('CallCollection')[0].CallCollection;
window.Store.Cmd = window.mR.findModule('Cmd')[0].Cmd;
window.Store.CryptoLib = window.mR.findModule('decryptE2EMedia')[0];
window.Store.Wap = window.mR.findModule('Wap')[0].default;
window.Store.SendSeen = window.mR.findModule('sendSeen')[0];
window.Store.SendClear = window.mR.findModule('sendClear')[0];
window.Store.SendDelete = window.mR.findModule('sendDelete')[0];
window.Store.genId = window.mR.findModule('randomId')[0].default;
window.Store.SendMessage = window.mR.findModule('addAndSendMsgToChat')[0];
window.Store.MsgKey = window.mR.findModule((module) => module.default && module.default.fromString)[0].default;
window.Store.DownloadManager = window.mR.findModule('downloadManager')[0].downloadManager;
window.Store.Features = window.mR.findModule('FEATURE_CHANGE_EVENT')[0].GK;
window.Store.GroupMetadata = window.mR.findModule((module) => module.default && module.default.handlePendingInvite)[0].default;
window.Store.Invite = window.mR.findModule('sendJoinGroupViaInvite')[0];
window.Store.OpaqueData = window.mR.findModule(module => module.default && module.default.createFromData)[0].default;
window.Store.InviteInfo = window.mR.findModule('sendQueryGroupInvite')[0];
window.Store.Label = window.mR.findModule('LabelCollection')[0].LabelCollection;
window.Store.MediaPrep = window.mR.findModule('MediaPrep')[0];
window.Store.MediaObject = window.mR.findModule('getOrCreateMediaObject')[0];
window.Store.MediaUpload = window.mR.findModule('uploadMedia')[0];
window.Store.Cmd = window.mR.findModule('Cmd')[0].default;
window.Store.NumberInfo = window.mR.findModule('formattedPhoneNumber')[0];
window.Store.MediaTypes = window.mR.findModule('msgToMediaType')[0];
window.Store.VCard = window.mR.findModule('vcardFromContactModel')[0];
window.Store.MediaUpload = window.mR.findModule('uploadMedia')[0];
window.Store.MsgKey = window.mR.findModule((module) => module.default && module.default.fromString)[0].default;
window.Store.MessageInfo = window.mR.findModule('sendQueryMsgInfo')[0];
window.Store.OpaqueData = window.mR.findModule(module => module.default && module.default.createFromData)[0].default;
window.Store.QueryExist = window.mR.findModule('queryExists')[0].queryExists;
window.Store.QueryProduct = window.mR.findModule('queryProduct')[0];
window.Store.QueryOrder = window.mR.findModule('queryOrder')[0];
window.Store.SendClear = window.mR.findModule('sendClear')[0];
window.Store.SendDelete = window.mR.findModule('sendDelete')[0];
window.Store.SendMessage = window.mR.findModule('addAndSendMsgToChat')[0];
window.Store.SendSeen = window.mR.findModule('sendSeen')[0];
window.Store.User = window.mR.findModule('getMaybeMeUser')[0];
window.Store.UploadUtils = window.mR.findModule((module) => (module.default && module.default.encryptAndUpload) ? module.default : null)[0].default;
window.Store.UserConstructor = window.mR.findModule((module) => (module.default && module.default.prototype && module.default.prototype.isServer && module.default.prototype.isUser) ? module.default : null)[0].default;
window.Store.Validators = window.mR.findModule('findLinks')[0];
window.Store.VCard = window.mR.findModule('vcardFromContactModel')[0];
window.Store.Wap = window.mR.findModule('queryLinkPreview')[0].default;
window.Store.WidFactory = window.mR.findModule('createWid')[0];
window.Store.BlockContact = window.mR.findModule('blockContact')[0];
window.Store.GroupMetadata = window.mR.findModule((module) => module.default && module.default.handlePendingInvite)[0].default;
window.Store.Sticker = window.mR.findModule('Sticker')[0].default.Sticker;
window.Store.UploadUtils = window.mR.findModule((module) => (module.default && module.default.encryptAndUpload) ? module.default : null)[0].default;
window.Store.Label = window.mR.findModule('LabelCollection')[0].default;
window.Store.Features = window.mR.findModule('FEATURE_CHANGE_EVENT')[0].default;
window.Store.QueryOrder = window.mR.findModule('queryOrder')[0];
window.Store.QueryProduct = window.mR.findModule('queryProduct')[0];
window.Store.DownloadManager = window.mR.findModule('DownloadManager')[0].default;
window.Store.getProfilePicFull = window.mR.findModule('getProfilePicFull')[0].getProfilePicFull;
window.Store.PresenceUtils = window.mR.findModule('sendPresenceAvailable')[0];
window.Store.ChatState = window.mR.findModule('sendChatStateComposing')[0];
window.Store.GroupParticipants = window.mR.findModule('sendPromoteParticipants')[0];
window.Store.JoinInviteV4 = window.mR.findModule('sendJoinGroupViaInviteV4')[0];
window.Store.findCommonGroups = window.mR.findModule('findCommonGroups')[0].findCommonGroups;
window.Store.StatusUtils = window.mR.findModule('setMyStatus')[0];
window.Store.StickerTools = {
...window.mR.findModule('toWebpSticker')[0],
...window.mR.findModule('addWebpMetadata')[0]
};
window.Store.GroupUtils = {
...window.mR.findModule('sendCreateGroup')[0],
...window.mR.findModule('sendSetGroupSubject')[0],
...window.mR.findModule('markExited')[0]
};
if (!window.Store.Chat._find) {
window.Store.Chat._find = e => {
const target = window.Store.Chat.get(e);
return target ? Promise.resolve(target) : Promise.resolve({
id: e
});
};
}
};
exports.LoadUtils = () => {
window.WWebJS = {};
window.WWebJS.getNumberId = async (id) => {
let result = await window.Store.Wap.queryExist(id);
if (result.jid === undefined)
throw 'The number provided is not a registered whatsapp user';
return result.jid;
};
window.WWebJS.sendSeen = async (chatId) => {
let chat = window.Store.Chat.get(chatId);
if (chat !== undefined) {
@@ -58,14 +80,14 @@ exports.LoadUtils = () => {
return false;
};
window.WWebJS.sendMessage = async (chat, content, options = {}) => {
let attOptions = {};
if (options.attachment) {
attOptions = options.sendMediaAsSticker
attOptions = options.sendMediaAsSticker
? await window.WWebJS.processStickerData(options.attachment)
: await window.WWebJS.processMediaData(options.attachment, {
forceVoice: options.sendAudioAsVoice,
forceVoice: options.sendAudioAsVoice,
forceDocument: options.sendMediaAsDocument,
forceGif: options.sendVideoAsGif
});
@@ -135,48 +157,124 @@ exports.LoadUtils = () => {
if (options.linkPreview) {
delete options.linkPreview;
const link = window.Store.Validators.findLink(content);
if (link) {
const preview = await window.Store.Wap.queryLinkPreview(link.url);
preview.preview = true;
preview.subtype = 'url';
options = { ...options, ...preview };
// Not supported yet by WhatsApp Web on MD
if(!window.Store.Features.features.MD_BACKEND) {
const link = window.Store.Validators.findLink(content);
if (link) {
const preview = await window.Store.Wap.queryLinkPreview(link.url);
preview.preview = true;
preview.subtype = 'url';
options = { ...options, ...preview };
}
}
}
let buttonOptions = {};
if(options.buttons){
let caption;
if (options.buttons.type === 'chat') {
content = options.buttons.body;
caption = content;
} else {
caption = options.caption ? options.caption : ' '; //Caption can't be empty
}
buttonOptions = {
productHeaderImageRejected: false,
isFromTemplate: false,
isDynamicReplyButtonsMsg: true,
title: options.buttons.title ? options.buttons.title : undefined,
footer: options.buttons.footer ? options.buttons.footer : undefined,
dynamicReplyButtons: options.buttons.buttons,
replyButtons: options.buttons.buttons,
caption: caption
};
delete options.buttons;
}
let listOptions = {};
if(options.list){
if(window.Store.Conn.platform === 'smba' || window.Store.Conn.platform === 'smbi'){
throw '[LT01] Whatsapp business can\'t send this yet';
}
listOptions = {
type: 'list',
footer: options.list.footer,
list: {
...options.list,
listType: 1
},
body: options.list.description
};
delete options.list;
delete listOptions.list.footer;
}
const meUser = window.Store.User.getMaybeMeUser();
const isMD = window.Store.Features.features.MD_BACKEND;
const newMsgId = new window.Store.MsgKey({
fromMe: true,
remote: chat.id,
id: window.Store.genId(),
from: meUser,
to: chat.id,
id: window.Store.MsgKey.newId(),
participant: isMD && chat.id.isGroup() ? meUser : undefined,
selfDir: 'out',
});
const extraOptions = options.extraOptions || {};
delete options.extraOptions;
const ephemeralSettings = {
ephemeralDuration: chat.isEphemeralSettingOn() ? chat.getEphemeralSetting() : undefined,
ephemeralSettingTimestamp: chat.getEphemeralSettingTimestamp() || undefined,
disappearingModeInitiator: chat.getDisappearingModeInitiator() || undefined,
};
const message = {
...options,
id: newMsgId,
ack: 0,
body: content,
from: window.Store.Conn.wid,
from: meUser,
to: chat.id,
local: true,
self: 'out',
t: parseInt(new Date().getTime() / 1000),
isNewMsg: true,
type: 'chat',
...ephemeralSettings,
...locationOptions,
...attOptions,
...quotedMsgOptions,
...vcardOptions
...vcardOptions,
...buttonOptions,
...listOptions,
...extraOptions
};
await window.Store.SendMessage.addAndSendMsgToChat(chat, message);
return window.Store.Msg.get(newMsgId._serialized);
};
window.WWebJS.toStickerData = async (mediaInfo) => {
if (mediaInfo.mimetype == 'image/webp') return mediaInfo;
const file = window.WWebJS.mediaInfoToFile(mediaInfo);
const webpSticker = await window.Store.StickerTools.toWebpSticker(file);
const webpBuffer = await webpSticker.arrayBuffer();
const data = window.WWebJS.arrayBufferToBase64(webpBuffer);
return {
mimetype: 'image/webp',
data
};
};
window.WWebJS.processStickerData = async (mediaInfo) => {
if (mediaInfo.mimetype !== 'image/webp') throw new Error('Invalid media type');
const file = window.WWebJS.mediaInfoToFile(mediaInfo);
let filehash = await window.WWebJS.getFileHash(file);
let filehash = await window.WWebJS.getFileHash(file);
let mediaKey = await window.WWebJS.generateHash(32);
const controller = new AbortController();
@@ -262,27 +360,44 @@ exports.LoadUtils = () => {
window.WWebJS.getMessageModel = message => {
const msg = message.serialize();
msg.isEphemeral = message.isEphemeral;
msg.isStatusV3 = message.isStatusV3;
msg.links = (message.getLinks()).map(link => link.href);
msg.links = (message.getLinks()).map(link => ({
link: link.href,
isSuspicious: Boolean(link.suspiciousCharacters && link.suspiciousCharacters.size)
}));
if (msg.buttons) {
msg.buttons = msg.buttons.serialize();
}
if (msg.dynamicReplyButtons) {
msg.dynamicReplyButtons = JSON.parse(JSON.stringify(msg.dynamicReplyButtons));
}
if (msg.replyButtons) {
msg.replyButtons = JSON.parse(JSON.stringify(msg.replyButtons));
}
if (typeof msg.id.remote === 'object') {
msg.id = Object.assign({}, msg.id, { remote: msg.id.remote._serialized });
}
delete msg.pendingAckUpdate;
return msg;
};
window.WWebJS.getChatModel = async chat => {
let res = chat.serialize();
res.isGroup = chat.isGroup;
res.formattedTitle = chat.formattedTitle;
res.isMuted = chat.mute && chat.mute.isMuted;
if (chat.groupMetadata) {
await window.Store.GroupMetadata.update(chat.id._serialized);
const chatWid = window.Store.WidFactory.createWid((chat.id._serialized));
await window.Store.GroupMetadata.update(chatWid);
res.groupMetadata = chat.groupMetadata.serialize();
}
@@ -294,7 +409,8 @@ exports.LoadUtils = () => {
};
window.WWebJS.getChat = async chatId => {
const chat = window.Store.Chat.get(chatId);
const chatWid = window.Store.WidFactory.createWid(chatId);
const chat = await window.Store.Chat.find(chatWid);
return await window.WWebJS.getChatModel(chat);
};
@@ -324,8 +440,9 @@ exports.LoadUtils = () => {
return res;
};
window.WWebJS.getContact = contactId => {
const contact = window.Store.Contact.get(contactId);
window.WWebJS.getContact = async contactId => {
const wid = window.Store.WidFactory.createWid(contactId);
const contact = await window.Store.Contact.find(wid);
return window.WWebJS.getContactModel(contact);
};
@@ -335,7 +452,7 @@ exports.LoadUtils = () => {
};
window.WWebJS.mediaInfoToFile = ({ data, mimetype, filename }) => {
const binaryData = atob(data);
const binaryData = window.atob(data);
const buffer = new ArrayBuffer(binaryData.length);
const view = new Uint8Array(buffer);
@@ -352,15 +469,15 @@ exports.LoadUtils = () => {
window.WWebJS.arrayBufferToBase64 = (arrayBuffer) => {
let binary = '';
const bytes = new Uint8Array( arrayBuffer );
const bytes = new Uint8Array(arrayBuffer);
const len = bytes.byteLength;
for (let i = 0; i < len; i++) {
binary += String.fromCharCode( bytes[ i ] );
binary += String.fromCharCode(bytes[i]);
}
return window.btoa( binary );
return window.btoa(binary);
};
window.WWebJS.getFileHash = async (data) => {
window.WWebJS.getFileHash = async (data) => {
let buffer = await data.arrayBuffer();
const hashBuffer = await crypto.subtle.digest('SHA-256', buffer);
return btoa(String.fromCharCode(...new Uint8Array(hashBuffer)));
@@ -370,7 +487,7 @@ exports.LoadUtils = () => {
var result = '';
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var charactersLength = characters.length;
for ( var i = 0; i < length; i++ ) {
for (var i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
@@ -395,15 +512,18 @@ exports.LoadUtils = () => {
};
window.WWebJS.sendChatstate = async (state, chatId) => {
if (window.Store.Features.features.MD_BACKEND) {
chatId = window.Store.WidFactory.createWid(chatId);
}
switch (state) {
case 'typing':
await window.Store.Wap.sendChatstateComposing(chatId);
await window.Store.ChatState.sendChatStateComposing(chatId);
break;
case 'recording':
await window.Store.Wap.sendChatstateRecording(chatId);
await window.Store.ChatState.sendChatStateRecording(chatId);
break;
case 'stop':
await window.Store.Wap.sendChatstatePaused(chatId);
await window.Store.ChatState.sendChatStatePaused(chatId);
break;
default:
throw 'Invalid chatstate';
@@ -415,7 +535,7 @@ exports.LoadUtils = () => {
window.WWebJS.getLabelModel = label => {
let res = label.serialize();
res.hexColor = label.hexColor;
return res;
};
@@ -434,8 +554,9 @@ exports.LoadUtils = () => {
return (chat.labels || []).map(id => window.WWebJS.getLabel(id));
};
window.WWebJS.getOrderDetail = async (orderId, token) => {
return window.Store.QueryOrder.queryOrder(orderId, 80, 80, token);
window.WWebJS.getOrderDetail = async (orderId, token, chatId) => {
const chatWid = window.Store.WidFactory.createWid(chatId);
return window.Store.QueryOrder.queryOrder(chatWid, orderId, 80, 80, token);
};
window.WWebJS.getProductMetadata = async (productId) => {
@@ -448,20 +569,3 @@ exports.LoadUtils = () => {
return undefined;
};
};
exports.MarkAllRead = () => {
let Chats = window.Store.Chat.models;
for (let chatIndex in Chats) {
if (isNaN(chatIndex)) {
continue;
}
let chat = Chats[chatIndex];
if (chat.unreadCount > 0) {
chat.markSeen();
window.Store.Wap.sendConversationSeen(chat.id, chat.getLastMsgKeyForAction(), chat.unreadCount - chat.pendingSeenCount);
}
}
};

View File

@@ -28,7 +28,7 @@ class InterfaceController {
async openChatDrawer(chatId) {
await this.pupPage.evaluate(async chatId => {
let chat = await window.Store.Chat.get(chatId);
await window.Store.Cmd.chatInfoDrawer(chat);
await window.Store.Cmd.openDrawerMid(chat);
}, chatId);
}

View File

@@ -1,6 +1,5 @@
'use strict';
const sharp = require('sharp');
const path = require('path');
const Crypto = require('crypto');
const { tmpdir } = require('os');
@@ -14,7 +13,6 @@ const has = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
* Utility methods
*/
class Util {
constructor() {
throw new Error(`The ${this.constructor.name} class may not be instantiated.`);
}
@@ -23,7 +21,7 @@ class Util {
var result = '';
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var charactersLength = characters.length;
for ( var i = 0; i < length; i++ ) {
for (var i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
@@ -55,33 +53,19 @@ class Util {
*
* @returns {Promise<MessageMedia>} media in webp format
*/
static async formatImageToWebpSticker(media) {
static async formatImageToWebpSticker(media, pupPage) {
if (!media.mimetype.includes('image'))
throw new Error('media is not a image');
if (media.mimetype.includes('webp')) {
return media;
}
const buff = Buffer.from(media.data, 'base64');
let sharpImg = sharp(buff);
sharpImg = sharpImg.webp();
sharpImg = sharpImg.resize(512, 512, {
fit: 'contain',
background: { r: 0, g: 0, b: 0, alpha: 0 },
});
let webpBase64 = (await sharpImg.toBuffer()).toString('base64');
return {
mimetype: 'image/webp',
data: webpBase64,
filename: media.filename,
};
return pupPage.evaluate((media) => {
return window.WWebJS.toStickerData(media);
}, media);
}
/**
* Formats a video to webp
* @param {MessageMedia} media
@@ -91,14 +75,14 @@ class Util {
static async formatVideoToWebpSticker(media) {
if (!media.mimetype.includes('video'))
throw new Error('media is not a video');
const videoType = media.mimetype.split('/')[1];
const tempFile = path.join(
tmpdir(),
`${Crypto.randomBytes(6).readUIntLE(0, 6).toString(36)}.webp`
);
const stream = new (require('stream').Readable)();
const buffer = Buffer.from(
media.data.replace(`data:${media.mimetype};base64,`, ''),
@@ -135,17 +119,17 @@ class Util {
.toFormat('webp')
.save(tempFile);
});
const data = await fs.readFile(tempFile, 'base64');
await fs.unlink(tempFile);
return {
return {
mimetype: 'image/webp',
data: data,
filename: media.filename,
};
}
/**
* Sticker metadata.
* @typedef {Object} StickerMetadata
@@ -161,14 +145,14 @@ class Util {
*
* @returns {Promise<MessageMedia>} media in webp format
*/
static async formatToWebpSticker(media, metadata) {
static async formatToWebpSticker(media, metadata, pupPage) {
let webpMedia;
if (media.mimetype.includes('image'))
webpMedia = await this.formatImageToWebpSticker(media);
else if (media.mimetype.includes('video'))
if (media.mimetype.includes('image'))
webpMedia = await this.formatImageToWebpSticker(media, pupPage);
else if (media.mimetype.includes('video'))
webpMedia = await this.formatVideoToWebpSticker(media);
else
else
throw new Error('Invalid media format');
if (metadata.name || metadata.author) {
@@ -183,9 +167,9 @@ class Util {
let jsonBuffer = Buffer.from(JSON.stringify(json), 'utf8');
let exif = Buffer.concat([exifAttr, jsonBuffer]);
exif.writeUIntLE(jsonBuffer.length, 14, 4);
await img.loadBuffer(Buffer.from(webpMedia.data, 'base64'));
await img.load(Buffer.from(webpMedia.data, 'base64'));
img.exif = exif;
webpMedia.data = (await img.saveBuffer()).toString('base64');
webpMedia.data = (await img.save(null)).toString('base64');
}
return webpMedia;

14
tests/README.md Normal file
View File

@@ -0,0 +1,14 @@
## Running tests
These tests require an authenticated WhatsApp Web session, as well as an additional phone that you can send messages to.
This can be configured using the following environment variables:
- `WWEBJS_TEST_SESSION`: A JSON-formatted string with legacy auth session details. Must include `WABrowserId`, `WASecretBundle`, `WAToken1` and `WAToken2`.
- `WWEBJS_TEST_SESSION_PATH`: Path to a JSON file that contains the legacy auth session details. Must include `WABrowserId`, `WASecretBundle`, `WAToken1` and `WAToken2`.
- `WWEBJS_TEST_CLIENT_ID`: `clientId` to use for local file based authentication.
- `WWEBJS_TEST_REMOTE_ID`: A valid WhatsApp ID that you can send messages to, e.g. `123456789@c.us`. It should be different from the ID used by the provided session.
You *must* set `WWEBJS_TEST_REMOTE_ID` **and** either `WWEBJS_TEST_SESSION`, `WWEBJS_TEST_SESSION_PATH` or `WWEBJS_TEST_CLIENT_ID` for the tests to run properly.
### Multidevice
Some of the tested functionality depends on whether the account has multidevice enabled or not. If you are using multidevice, you should set `WWEBJS_TEST_MD=1`.

612
tests/client.js Normal file
View File

@@ -0,0 +1,612 @@
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
const sinon = require('sinon');
const helper = require('./helper');
const Chat = require('../src/structures/Chat');
const Contact = require('../src/structures/Contact');
const Message = require('../src/structures/Message');
const MessageMedia = require('../src/structures/MessageMedia');
const Location = require('../src/structures/Location');
const LegacySessionAuth = require('../src/authStrategies/LegacySessionAuth');
const { MessageTypes, WAState } = require('../src/util/Constants');
const expect = chai.expect;
chai.use(chaiAsPromised);
const remoteId = helper.remoteId;
const isMD = helper.isMD();
describe('Client', function() {
describe('Authentication', function() {
it('should emit QR code if not authenticated', async function() {
this.timeout(25000);
const callback = sinon.spy();
const client = helper.createClient();
client.on('qr', callback);
client.initialize();
await helper.sleep(20000);
expect(callback.called).to.equal(true);
expect(callback.args[0][0]).to.have.lengthOf(152);
await client.destroy();
});
it('should disconnect after reaching max qr retries', async function () {
this.timeout(50000);
const qrCallback = sinon.spy();
const disconnectedCallback = sinon.spy();
const client = helper.createClient({options: {qrMaxRetries: 2}});
client.on('qr', qrCallback);
client.on('disconnected', disconnectedCallback);
client.initialize();
await helper.sleep(45000);
expect(qrCallback.calledThrice).to.eql(true);
expect(disconnectedCallback.calledOnceWith('Max qrcode retries reached')).to.eql(true);
});
it('should authenticate with existing session', async function() {
this.timeout(40000);
const authenticatedCallback = sinon.spy();
const qrCallback = sinon.spy();
const readyCallback = sinon.spy();
const client = helper.createClient({
authenticated: true,
});
client.on('qr', qrCallback);
client.on('authenticated', authenticatedCallback);
client.on('ready', readyCallback);
await client.initialize();
expect(authenticatedCallback.called).to.equal(true);
if(helper.isUsingLegacySession()) {
const newSession = authenticatedCallback.args[0][0];
expect(newSession).to.have.key([
'WABrowserId',
'WASecretBundle',
'WAToken1',
'WAToken2'
]);
}
expect(readyCallback.called).to.equal(true);
expect(qrCallback.called).to.equal(false);
await client.destroy();
});
describe('LegacySessionAuth', function () {
it('should fail auth if session is invalid', async function() {
this.timeout(40000);
const authFailCallback = sinon.spy();
const qrCallback = sinon.spy();
const readyCallback = sinon.spy();
const client = helper.createClient({
options: {
authStrategy: new LegacySessionAuth({
session: {
WABrowserId: 'invalid',
WASecretBundle: 'invalid',
WAToken1: 'invalid',
WAToken2: 'invalid'
},
restartOnAuthFail: false,
}),
}
});
client.on('qr', qrCallback);
client.on('auth_failure', authFailCallback);
client.on('ready', readyCallback);
client.initialize();
await helper.sleep(25000);
expect(authFailCallback.called).to.equal(true);
expect(authFailCallback.args[0][0]).to.equal('Unable to log in. Are the session details valid?');
expect(readyCallback.called).to.equal(false);
expect(qrCallback.called).to.equal(false);
await client.destroy();
});
it('can restart without a session if session was invalid and restartOnAuthFail=true', async function() {
this.timeout(40000);
const authFailCallback = sinon.spy();
const qrCallback = sinon.spy();
const client = helper.createClient({
options: {
authStrategy: new LegacySessionAuth({
session: {
WABrowserId: 'invalid',
WASecretBundle: 'invalid',
WAToken1: 'invalid',
WAToken2: 'invalid'
},
restartOnAuthFail: true,
}),
}
});
client.on('auth_failure', authFailCallback);
client.on('qr', qrCallback);
client.initialize();
await helper.sleep(35000);
expect(authFailCallback.called).to.equal(true);
expect(qrCallback.called).to.equal(true);
expect(qrCallback.args[0][0]).to.have.lengthOf(152);
await client.destroy();
});
});
describe('Non-MD only', function () {
if(!isMD) {
it('can take over if client was logged in somewhere else with takeoverOnConflict=true', async function() {
this.timeout(40000);
const readyCallback1 = sinon.spy();
const readyCallback2 = sinon.spy();
const disconnectedCallback1 = sinon.spy();
const disconnectedCallback2 = sinon.spy();
const client1 = helper.createClient({
authenticated: true,
options: { takeoverOnConflict: true, takeoverTimeoutMs: 5000 }
});
const client2 = helper.createClient({authenticated: true});
client1.on('ready', readyCallback1);
client2.on('ready', readyCallback2);
client1.on('disconnected', disconnectedCallback1);
client2.on('disconnected', disconnectedCallback2);
await client1.initialize();
expect(readyCallback1.called).to.equal(true);
expect(readyCallback2.called).to.equal(false);
expect(disconnectedCallback1.called).to.equal(false);
expect(disconnectedCallback2.called).to.equal(false);
await client2.initialize();
expect(readyCallback2.called).to.equal(true);
expect(disconnectedCallback1.called).to.equal(false);
expect(disconnectedCallback2.called).to.equal(false);
// wait for takeoverTimeoutMs to kick in
await helper.sleep(5200);
expect(disconnectedCallback1.called).to.equal(false);
expect(disconnectedCallback2.called).to.equal(true);
expect(disconnectedCallback2.calledWith(WAState.CONFLICT)).to.equal(true);
await client1.destroy();
});
}
});
});
describe('Authenticated', function() {
let client;
before(async function() {
this.timeout(35000);
client = helper.createClient({authenticated: true});
await client.initialize();
});
after(async function () {
await client.destroy();
});
it('can get current WhatsApp Web version', async function () {
const version = await client.getWWebVersion();
expect(typeof version).to.equal('string');
console.log(`WA Version: ${version}`);
});
describe('Expose Store', function() {
it('exposes the store', async function() {
const exposed = await client.pupPage.evaluate(() => {
return Boolean(window.Store);
});
expect(exposed).to.equal(true);
});
it('exposes all required WhatsApp Web internal models', async function() {
const expectedModules = [
'AppState',
'BlockContact',
'Call',
'Chat',
'ChatState',
'Cmd',
'Conn',
'Contact',
'DownloadManager',
'Features',
'GroupMetadata',
'GroupParticipants',
'GroupUtils',
'Invite',
'InviteInfo',
'JoinInviteV4',
'Label',
'MediaObject',
'MediaPrep',
'MediaTypes',
'MediaUpload',
'MessageInfo',
'Msg',
'MsgKey',
'OpaqueData',
'QueryOrder',
'QueryProduct',
'PresenceUtils',
'QueryExist',
'QueryProduct',
'QueryOrder',
'SendClear',
'SendDelete',
'SendMessage',
'SendSeen',
'StatusUtils',
'UploadUtils',
'UserConstructor',
'VCard',
'Validators',
'Wap',
'WidFactory',
'findCommonGroups',
'getProfilePicFull',
];
const loadedModules = await client.pupPage.evaluate((expectedModules) => {
return expectedModules.filter(m => Boolean(window.Store[m]));
}, expectedModules);
expect(loadedModules).to.have.members(expectedModules);
});
});
describe('Send Messages', function () {
it('can send a message', async function() {
const msg = await client.sendMessage(remoteId, 'hello world');
expect(msg).to.be.instanceOf(Message);
expect(msg.type).to.equal(MessageTypes.TEXT);
expect(msg.fromMe).to.equal(true);
expect(msg.body).to.equal('hello world');
expect(msg.to).to.equal(remoteId);
});
it('can send a media message', async function() {
const media = new MessageMedia(
'image/png',
'iVBORw0KGgoAAAANSUhEUgAAAV4AAACWBAMAAABkyf1EAAAAG1BMVEXMzMyWlpacnJyqqqrFxcWxsbGjo6O3t7e+vr6He3KoAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAEcElEQVR4nO2aTW/bRhCGh18ij1zKknMkbbf2UXITIEeyMhIfRaF1exQLA/JRclslRykO+rs7s7s0VwytNmhJtsA8gHZEcox9PTs7uysQgGEYhmEYhmEYhmEYhmEYhmEYhmEYhmEYhmEYhmEYhmGYr2OWRK/ReIKI8Zt7Hb19wTcQ0uTkGh13bQupcw7gPOvdo12/5CzNtNR7xLUtNtT3CGBQ6g3InjY720pvofUec22LJPr8PhEp2OMPyI40PdwWUdronCu9yQpdPx53bQlfLKnfOVhlnDYRBXve4Ov+IZTeMgdedm0NR+xoXJeQvdJ3CvziykSukwil16W/Oe7aGjIjqc/9ib4jQlJy0uArtN4A0+cvXFvDkmUJ47sJ1Y1ATLDNVXZkNPIepQzxy1ki9fqiwbUj/I+64zxWNzyZnPuhvohJ9K70VvXBixpcu2SAHU+Xd9EKdEJDNpYP3AQr3bQSpPQ6Y6/4dl1z7ZDbArsszjA7L0g7ibB0CDcidUWVoErvIMKZh2Xs0LUzcLW6V5NfiUgNEbaYmAVL6bXl0nJRc+1S72ua/D/cTjGPlQj7eUqd7A096rYlRjdPYlhz7VIvxpVG3cemDKF+WAwLY/6XelOZKTXXzsC4xvDjjtSN6kHLhLke6PrwM8h1raf40qjrGO7H9aTEbduucjS04ZrYU/4iuS5Z2Hdt0rvCLFdmLEXcU30AGddST62o+sLcf5l6k7CP+ru4pLYqX/VFyxbm/utQbx/r22ZEbTb2f5I2kns1Y1OQR8ZyofX+TjJxj1Rz7QQVnf1QzR26Oth0ueJVYcRP6ZUPac/Rx/5M6ixO1dhSrT3Y1DpiYmx3tF4ZUdpz9LD/dSg9PXES0LB71BwcGjKROuV28lnvnv7HHJsezheBGH5+X2CfSfRbMKW+5aGs3JFjMrjGibJc0S7TJzqjHrh2hDybj9XRXNZa89Aro55XBdbW5wti2c/5WJ7jJ1RolVUn/HWpb0I58Tziup6Rx7Dm2hnbRP1GM9PW/NFmQ4PtVRVN63Wvxfmu5sowDMMwDMMwDMMwDMMwDMMwDMMwzL+CpT//F/6beoV8zb2Jmt4Qryx6lTUCsENQ75HOkhXAO3EPVgyQtKtUy3C/e+FJg17Zjnew1Xrdb9InbG4WqfUAftG+WhLwPVyfg536+MU7m4C1CMk4ZznpXZzDYI1PDL2nS1hpvc5cNd7E2sJg05Fe7/7d3Fln8Cvc3bwB616auxsKl4WPghjemHrDqyDWeu1UNW5s2btPnSQ75oOdunEwWazfwgVG0kqluYCM9OIjWOGnfA2b9G4Ha63XKpvQ8perTvTifJNhi6+WMWmi7smEZf6G8MmhlyGq+NqP8GV84TLuJr7UIQVx+bDEoEpRZIz42gs40OuN4Mv8hXzelV7KX1isH+ewTWckikyVv+CfHuqVF7I16gN0VKypX6wPsE+zFPzkinolU9UH8OMGvSpnZqKsv13p/RsMun6X5x/y2LeAr8O66lsBwzBMP/wJfyGq8pgBk6IAAAAASUVORK5CYII='
);
const msg = await client.sendMessage(remoteId, media, {caption: 'here\'s my media'});
expect(msg).to.be.instanceOf(Message);
expect(msg.type).to.equal(MessageTypes.IMAGE);
expect(msg.fromMe).to.equal(true);
expect(msg.hasMedia).to.equal(true);
expect(msg.body).to.equal('here\'s my media');
expect(msg.to).to.equal(remoteId);
});
it('can send a media message from URL', async function() {
const media = await MessageMedia.fromUrl('https://via.placeholder.com/350x150.png');
const msg = await client.sendMessage(remoteId, media);
expect(msg).to.be.instanceOf(Message);
expect(msg.type).to.equal(MessageTypes.IMAGE);
expect(msg.fromMe).to.equal(true);
expect(msg.hasMedia).to.equal(true);
expect(msg.to).to.equal(remoteId);
});
it('can send a media message as a document', async function() {
const media = new MessageMedia(
'image/png',
'iVBORw0KGgoAAAANSUhEUgAAAV4AAACWBAMAAABkyf1EAAAAG1BMVEXMzMyWlpacnJyqqqrFxcWxsbGjo6O3t7e+vr6He3KoAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAEcElEQVR4nO2aTW/bRhCGh18ij1zKknMkbbf2UXITIEeyMhIfRaF1exQLA/JRclslRykO+rs7s7s0VwytNmhJtsA8gHZEcox9PTs7uysQgGEYhmEYhmEYhmEYhmEYhmEYhmEYhmEYhmEYhmEYhmGYr2OWRK/ReIKI8Zt7Hb19wTcQ0uTkGh13bQupcw7gPOvdo12/5CzNtNR7xLUtNtT3CGBQ6g3InjY720pvofUec22LJPr8PhEp2OMPyI40PdwWUdronCu9yQpdPx53bQlfLKnfOVhlnDYRBXve4Ov+IZTeMgdedm0NR+xoXJeQvdJ3CvziykSukwil16W/Oe7aGjIjqc/9ib4jQlJy0uArtN4A0+cvXFvDkmUJ47sJ1Y1ATLDNVXZkNPIepQzxy1ki9fqiwbUj/I+64zxWNzyZnPuhvohJ9K70VvXBixpcu2SAHU+Xd9EKdEJDNpYP3AQr3bQSpPQ6Y6/4dl1z7ZDbArsszjA7L0g7ibB0CDcidUWVoErvIMKZh2Xs0LUzcLW6V5NfiUgNEbaYmAVL6bXl0nJRc+1S72ua/D/cTjGPlQj7eUqd7A096rYlRjdPYlhz7VIvxpVG3cemDKF+WAwLY/6XelOZKTXXzsC4xvDjjtSN6kHLhLke6PrwM8h1raf40qjrGO7H9aTEbduucjS04ZrYU/4iuS5Z2Hdt0rvCLFdmLEXcU30AGddST62o+sLcf5l6k7CP+ru4pLYqX/VFyxbm/utQbx/r22ZEbTb2f5I2kns1Y1OQR8ZyofX+TjJxj1Rz7QQVnf1QzR26Oth0ueJVYcRP6ZUPac/Rx/5M6ixO1dhSrT3Y1DpiYmx3tF4ZUdpz9LD/dSg9PXES0LB71BwcGjKROuV28lnvnv7HHJsezheBGH5+X2CfSfRbMKW+5aGs3JFjMrjGibJc0S7TJzqjHrh2hDybj9XRXNZa89Aro55XBdbW5wti2c/5WJ7jJ1RolVUn/HWpb0I58Tziup6Rx7Dm2hnbRP1GM9PW/NFmQ4PtVRVN63Wvxfmu5sowDMMwDMMwDMMwDMMwDMMwDMMwzL+CpT//F/6beoV8zb2Jmt4Qryx6lTUCsENQ75HOkhXAO3EPVgyQtKtUy3C/e+FJg17Zjnew1Xrdb9InbG4WqfUAftG+WhLwPVyfg536+MU7m4C1CMk4ZznpXZzDYI1PDL2nS1hpvc5cNd7E2sJg05Fe7/7d3Fln8Cvc3bwB616auxsKl4WPghjemHrDqyDWeu1UNW5s2btPnSQ75oOdunEwWazfwgVG0kqluYCM9OIjWOGnfA2b9G4Ha63XKpvQ8perTvTifJNhi6+WMWmi7smEZf6G8MmhlyGq+NqP8GV84TLuJr7UIQVx+bDEoEpRZIz42gs40OuN4Mv8hXzelV7KX1isH+ewTWckikyVv+CfHuqVF7I16gN0VKypX6wPsE+zFPzkinolU9UH8OMGvSpnZqKsv13p/RsMun6X5x/y2LeAr8O66lsBwzBMP/wJfyGq8pgBk6IAAAAASUVORK5CYII=',
'this is my filename.png'
);
const msg = await client.sendMessage(remoteId, media, { sendMediaAsDocument: true});
expect(msg).to.be.instanceOf(Message);
expect(msg.type).to.equal(MessageTypes.DOCUMENT);
expect(msg.fromMe).to.equal(true);
expect(msg.hasMedia).to.equal(true);
expect(msg.body).to.equal('this is my filename.png');
expect(msg.to).to.equal(remoteId);
});
it('can send a sticker message', async function() {
const media = new MessageMedia(
'image/png',
'iVBORw0KGgoAAAANSUhEUgAAAV4AAACWBAMAAABkyf1EAAAAG1BMVEXMzMyWlpacnJyqqqrFxcWxsbGjo6O3t7e+vr6He3KoAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAEcElEQVR4nO2aTW/bRhCGh18ij1zKknMkbbf2UXITIEeyMhIfRaF1exQLA/JRclslRykO+rs7s7s0VwytNmhJtsA8gHZEcox9PTs7uysQgGEYhmEYhmEYhmEYhmEYhmEYhmEYhmEYhmEYhmEYhmGYr2OWRK/ReIKI8Zt7Hb19wTcQ0uTkGh13bQupcw7gPOvdo12/5CzNtNR7xLUtNtT3CGBQ6g3InjY720pvofUec22LJPr8PhEp2OMPyI40PdwWUdronCu9yQpdPx53bQlfLKnfOVhlnDYRBXve4Ov+IZTeMgdedm0NR+xoXJeQvdJ3CvziykSukwil16W/Oe7aGjIjqc/9ib4jQlJy0uArtN4A0+cvXFvDkmUJ47sJ1Y1ATLDNVXZkNPIepQzxy1ki9fqiwbUj/I+64zxWNzyZnPuhvohJ9K70VvXBixpcu2SAHU+Xd9EKdEJDNpYP3AQr3bQSpPQ6Y6/4dl1z7ZDbArsszjA7L0g7ibB0CDcidUWVoErvIMKZh2Xs0LUzcLW6V5NfiUgNEbaYmAVL6bXl0nJRc+1S72ua/D/cTjGPlQj7eUqd7A096rYlRjdPYlhz7VIvxpVG3cemDKF+WAwLY/6XelOZKTXXzsC4xvDjjtSN6kHLhLke6PrwM8h1raf40qjrGO7H9aTEbduucjS04ZrYU/4iuS5Z2Hdt0rvCLFdmLEXcU30AGddST62o+sLcf5l6k7CP+ru4pLYqX/VFyxbm/utQbx/r22ZEbTb2f5I2kns1Y1OQR8ZyofX+TjJxj1Rz7QQVnf1QzR26Oth0ueJVYcRP6ZUPac/Rx/5M6ixO1dhSrT3Y1DpiYmx3tF4ZUdpz9LD/dSg9PXES0LB71BwcGjKROuV28lnvnv7HHJsezheBGH5+X2CfSfRbMKW+5aGs3JFjMrjGibJc0S7TJzqjHrh2hDybj9XRXNZa89Aro55XBdbW5wti2c/5WJ7jJ1RolVUn/HWpb0I58Tziup6Rx7Dm2hnbRP1GM9PW/NFmQ4PtVRVN63Wvxfmu5sowDMMwDMMwDMMwDMMwDMMwDMMwzL+CpT//F/6beoV8zb2Jmt4Qryx6lTUCsENQ75HOkhXAO3EPVgyQtKtUy3C/e+FJg17Zjnew1Xrdb9InbG4WqfUAftG+WhLwPVyfg536+MU7m4C1CMk4ZznpXZzDYI1PDL2nS1hpvc5cNd7E2sJg05Fe7/7d3Fln8Cvc3bwB616auxsKl4WPghjemHrDqyDWeu1UNW5s2btPnSQ75oOdunEwWazfwgVG0kqluYCM9OIjWOGnfA2b9G4Ha63XKpvQ8perTvTifJNhi6+WMWmi7smEZf6G8MmhlyGq+NqP8GV84TLuJr7UIQVx+bDEoEpRZIz42gs40OuN4Mv8hXzelV7KX1isH+ewTWckikyVv+CfHuqVF7I16gN0VKypX6wPsE+zFPzkinolU9UH8OMGvSpnZqKsv13p/RsMun6X5x/y2LeAr8O66lsBwzBMP/wJfyGq8pgBk6IAAAAASUVORK5CYII='
);
const msg = await client.sendMessage(remoteId, media, {sendMediaAsSticker: true});
expect(msg).to.be.instanceOf(Message);
expect(msg.type).to.equal(MessageTypes.STICKER);
expect(msg.fromMe).to.equal(true);
expect(msg.hasMedia).to.equal(true);
expect(msg.to).to.equal(remoteId);
});
it('can send a sticker message with custom author and name', async function() {
const media = new MessageMedia(
'image/png',
'iVBORw0KGgoAAAANSUhEUgAAAV4AAACWBAMAAABkyf1EAAAAG1BMVEXMzMyWlpacnJyqqqrFxcWxsbGjo6O3t7e+vr6He3KoAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAEcElEQVR4nO2aTW/bRhCGh18ij1zKknMkbbf2UXITIEeyMhIfRaF1exQLA/JRclslRykO+rs7s7s0VwytNmhJtsA8gHZEcox9PTs7uysQgGEYhmEYhmEYhmEYhmEYhmEYhmEYhmEYhmEYhmEYhmGYr2OWRK/ReIKI8Zt7Hb19wTcQ0uTkGh13bQupcw7gPOvdo12/5CzNtNR7xLUtNtT3CGBQ6g3InjY720pvofUec22LJPr8PhEp2OMPyI40PdwWUdronCu9yQpdPx53bQlfLKnfOVhlnDYRBXve4Ov+IZTeMgdedm0NR+xoXJeQvdJ3CvziykSukwil16W/Oe7aGjIjqc/9ib4jQlJy0uArtN4A0+cvXFvDkmUJ47sJ1Y1ATLDNVXZkNPIepQzxy1ki9fqiwbUj/I+64zxWNzyZnPuhvohJ9K70VvXBixpcu2SAHU+Xd9EKdEJDNpYP3AQr3bQSpPQ6Y6/4dl1z7ZDbArsszjA7L0g7ibB0CDcidUWVoErvIMKZh2Xs0LUzcLW6V5NfiUgNEbaYmAVL6bXl0nJRc+1S72ua/D/cTjGPlQj7eUqd7A096rYlRjdPYlhz7VIvxpVG3cemDKF+WAwLY/6XelOZKTXXzsC4xvDjjtSN6kHLhLke6PrwM8h1raf40qjrGO7H9aTEbduucjS04ZrYU/4iuS5Z2Hdt0rvCLFdmLEXcU30AGddST62o+sLcf5l6k7CP+ru4pLYqX/VFyxbm/utQbx/r22ZEbTb2f5I2kns1Y1OQR8ZyofX+TjJxj1Rz7QQVnf1QzR26Oth0ueJVYcRP6ZUPac/Rx/5M6ixO1dhSrT3Y1DpiYmx3tF4ZUdpz9LD/dSg9PXES0LB71BwcGjKROuV28lnvnv7HHJsezheBGH5+X2CfSfRbMKW+5aGs3JFjMrjGibJc0S7TJzqjHrh2hDybj9XRXNZa89Aro55XBdbW5wti2c/5WJ7jJ1RolVUn/HWpb0I58Tziup6Rx7Dm2hnbRP1GM9PW/NFmQ4PtVRVN63Wvxfmu5sowDMMwDMMwDMMwDMMwDMMwDMMwzL+CpT//F/6beoV8zb2Jmt4Qryx6lTUCsENQ75HOkhXAO3EPVgyQtKtUy3C/e+FJg17Zjnew1Xrdb9InbG4WqfUAftG+WhLwPVyfg536+MU7m4C1CMk4ZznpXZzDYI1PDL2nS1hpvc5cNd7E2sJg05Fe7/7d3Fln8Cvc3bwB616auxsKl4WPghjemHrDqyDWeu1UNW5s2btPnSQ75oOdunEwWazfwgVG0kqluYCM9OIjWOGnfA2b9G4Ha63XKpvQ8perTvTifJNhi6+WMWmi7smEZf6G8MmhlyGq+NqP8GV84TLuJr7UIQVx+bDEoEpRZIz42gs40OuN4Mv8hXzelV7KX1isH+ewTWckikyVv+CfHuqVF7I16gN0VKypX6wPsE+zFPzkinolU9UH8OMGvSpnZqKsv13p/RsMun6X5x/y2LeAr8O66lsBwzBMP/wJfyGq8pgBk6IAAAAASUVORK5CYII='
);
const msg = await client.sendMessage(remoteId, media, {
sendMediaAsSticker: true,
stickerAuthor: 'WWEBJS',
stickerName: 'My Sticker'
});
expect(msg).to.be.instanceOf(Message);
expect(msg.type).to.equal(MessageTypes.STICKER);
expect(msg.fromMe).to.equal(true);
expect(msg.hasMedia).to.equal(true);
expect(msg.to).to.equal(remoteId);
});
it('can send a location message', async function() {
const location = new Location(37.422, -122.084, 'Googleplex\nGoogle Headquarters');
const msg = await client.sendMessage(remoteId, location);
expect(msg).to.be.instanceOf(Message);
expect(msg.type).to.equal(MessageTypes.LOCATION);
expect(msg.fromMe).to.equal(true);
expect(msg.to).to.equal(remoteId);
expect(msg.location).to.be.instanceOf(Location);
expect(msg.location.latitude).to.equal(37.422);
expect(msg.location.longitude).to.equal(-122.084);
expect(msg.location.description).to.equal('Googleplex\nGoogle Headquarters');
});
it('can send a vCard as a contact card message', async function() {
const vCard = `BEGIN:VCARD
VERSION:3.0
FN;CHARSET=UTF-8:John Doe
N;CHARSET=UTF-8:Doe;John;;;
EMAIL;CHARSET=UTF-8;type=HOME,INTERNET:john@doe.com
TEL;TYPE=HOME,VOICE:1234567890
REV:2021-06-06T02:35:53.559Z
END:VCARD`;
const msg = await client.sendMessage(remoteId, vCard);
expect(msg).to.be.instanceOf(Message);
expect(msg.type).to.equal(MessageTypes.CONTACT_CARD);
expect(msg.fromMe).to.equal(true);
expect(msg.to).to.equal(remoteId);
expect(msg.body).to.equal(vCard);
expect(msg.vCards).to.have.lengthOf(1);
expect(msg.vCards[0]).to.equal(vCard);
});
it('can optionally turn off vCard parsing', async function() {
const vCard = `BEGIN:VCARD
VERSION:3.0
FN;CHARSET=UTF-8:John Doe
N;CHARSET=UTF-8:Doe;John;;;
EMAIL;CHARSET=UTF-8;type=HOME,INTERNET:john@doe.com
TEL;TYPE=HOME,VOICE:1234567890
REV:2021-06-06T02:35:53.559Z
END:VCARD`;
const msg = await client.sendMessage(remoteId, vCard, {parseVCards: false});
expect(msg).to.be.instanceOf(Message);
expect(msg.type).to.equal(MessageTypes.TEXT); // not a contact card
expect(msg.fromMe).to.equal(true);
expect(msg.to).to.equal(remoteId);
expect(msg.body).to.equal(vCard);
});
it('can send a Contact as a contact card message', async function() {
const contact = await client.getContactById(remoteId);
const msg = await client.sendMessage(remoteId, contact);
expect(msg).to.be.instanceOf(Message);
expect(msg.type).to.equal(MessageTypes.CONTACT_CARD);
expect(msg.fromMe).to.equal(true);
expect(msg.to).to.equal(remoteId);
expect(msg.body).to.match(/BEGIN:VCARD/);
expect(msg.vCards).to.have.lengthOf(1);
expect(msg.vCards[0]).to.match(/BEGIN:VCARD/);
});
it('can send multiple Contacts as a contact card message', async function () {
const contact1 = await client.getContactById(remoteId);
const contact2 = await client.getContactById('5511942167462@c.us'); //iFood
const msg = await client.sendMessage(remoteId, [contact1, contact2]);
expect(msg).to.be.instanceOf(Message);
expect(msg.type).to.equal(MessageTypes.CONTACT_CARD_MULTI);
expect(msg.fromMe).to.equal(true);
expect(msg.to).to.equal(remoteId);
expect(msg.vCards).to.have.lengthOf(2);
expect(msg.vCards[0]).to.match(/BEGIN:VCARD/);
expect(msg.vCards[1]).to.match(/BEGIN:VCARD/);
});
});
describe('Get Chats', function () {
it('can get a chat by its ID', async function () {
const chat = await client.getChatById(remoteId);
expect(chat).to.be.instanceOf(Chat);
expect(chat.id._serialized).to.eql(remoteId);
expect(chat.isGroup).to.eql(false);
});
it('can get all chats', async function () {
const chats = await client.getChats();
expect(chats.length).to.be.greaterThanOrEqual(1);
const chat = chats.find(c => c.id._serialized === remoteId);
expect(chat).to.exist;
expect(chat).to.be.instanceOf(Chat);
});
});
describe('Get Contacts', function () {
it('can get a contact by its ID', async function () {
const contact = await client.getContactById(remoteId);
expect(contact).to.be.instanceOf(Contact);
expect(contact.id._serialized).to.eql(remoteId);
expect(contact.number).to.eql(remoteId.split('@')[0]);
});
it('can get all contacts', async function () {
const contacts = await client.getContacts();
expect(contacts.length).to.be.greaterThanOrEqual(1);
const contact = contacts.find(c => c.id._serialized === remoteId);
expect(contact).to.exist;
expect(contact).to.be.instanceOf(Contact);
});
it('can block a contact', async function () {
const contact = await client.getContactById(remoteId);
await contact.block();
const refreshedContact = await client.getContactById(remoteId);
expect(refreshedContact.isBlocked).to.eql(true);
});
it('can get a list of blocked contacts', async function () {
const blockedContacts = await client.getBlockedContacts();
expect(blockedContacts.length).to.be.greaterThanOrEqual(1);
const contact = blockedContacts.find(c => c.id._serialized === remoteId);
expect(contact).to.exist;
expect(contact).to.be.instanceOf(Contact);
});
it('can unblock a contact', async function () {
const contact = await client.getContactById(remoteId);
await contact.unblock();
const refreshedContact = await client.getContactById(remoteId);
expect(refreshedContact.isBlocked).to.eql(false);
});
});
describe('Numbers and Users', function () {
it('can verify that a user is registered', async function () {
const isRegistered = await client.isRegisteredUser(remoteId);
expect(isRegistered).to.be.true;
});
it('can verify that a user is not registered', async function () {
const isRegistered = await client.isRegisteredUser('9999999999@c.us');
expect(isRegistered).to.be.false;
});
it('can get a number\'s whatsapp id', async function () {
const number = remoteId.split('@')[0];
const numberId = await client.getNumberId(number);
expect(numberId).to.eql({
server: 'c.us',
user: number,
_serialized: `${number}@c.us`
});
});
it('returns null when getting an unregistered number\'s whatsapp id', async function () {
const number = '9999999999';
const numberId = await client.getNumberId(number);
expect(numberId).to.eql(null);
});
it('can get a number\'s country code', async function () {
const number = '18092201111';
const countryCode = await client.getCountryCode(number);
expect(countryCode).to.eql('1');
});
it('can get a formatted number', async function () {
const number = '18092201111';
const formatted = await client.getFormattedNumber(number);
expect(formatted).to.eql('+1 (809) 220-1111');
});
it('can get a formatted number from a serialized ID', async function () {
const number = '18092201111@c.us';
const formatted = await client.getFormattedNumber(number);
expect(formatted).to.eql('+1 (809) 220-1111');
});
});
describe('Search messages', function () {
it('can search for messages', async function () {
const m1 = await client.sendMessage(remoteId, 'I\'m searching for Super Mario Brothers');
const m2 = await client.sendMessage(remoteId, 'This also contains Mario');
const m3 = await client.sendMessage(remoteId, 'Nothing of interest here, just Luigi');
// wait for search index to catch up
await helper.sleep(1000);
const msgs = await client.searchMessages('Mario', {chatId: remoteId});
expect(msgs.length).to.be.greaterThanOrEqual(2);
const msgIds = msgs.map(m => m.id._serialized);
expect(msgIds).to.include.members([
m1.id._serialized, m2.id._serialized
]);
expect(msgIds).to.not.include.members([m3.id._serialized]);
});
});
describe('Status/About', function () {
let me, previousStatus;
before(async function () {
me = await client.getContactById(client.info.wid._serialized);
previousStatus = await me.getAbout();
});
after(async function () {
await client.setStatus(previousStatus);
});
it('can set the status text', async function () {
await client.setStatus('My shiny new status');
const status = await me.getAbout();
expect(status).to.eql('My shiny new status');
});
it('can set the status text to something else', async function () {
await client.setStatus('Busy');
const status = await me.getAbout();
expect(status).to.eql('Busy');
});
});
});
});

64
tests/helper.js Normal file
View File

@@ -0,0 +1,64 @@
const path = require('path');
const { Client, LegacySessionAuth, LocalAuth } = require('..');
require('dotenv').config();
const remoteId = process.env.WWEBJS_TEST_REMOTE_ID;
if(!remoteId) throw new Error('The WWEBJS_TEST_REMOTE_ID environment variable has not been set.');
function isUsingLegacySession() {
return Boolean(process.env.WWEBJS_TEST_SESSION || process.env.WWEBJS_TEST_SESSION_PATH);
}
function isMD() {
return Boolean(process.env.WWEBJS_TEST_MD);
}
if(isUsingLegacySession() && isMD()) throw 'Cannot use legacy sessions with WWEBJS_TEST_MD=true';
function getSessionFromEnv() {
if (!isUsingLegacySession()) return null;
const envSession = process.env.WWEBJS_TEST_SESSION;
if(envSession) return JSON.parse(envSession);
const envSessionPath = process.env.WWEBJS_TEST_SESSION_PATH;
if(envSessionPath) {
const absPath = path.resolve(process.cwd(), envSessionPath);
return require(absPath);
}
}
function createClient({authenticated, options: additionalOpts}={}) {
const options = {};
if(authenticated) {
const legacySession = getSessionFromEnv();
if(legacySession) {
options.authStrategy = new LegacySessionAuth({
session: legacySession
});
} else {
const clientId = process.env.WWEBJS_TEST_CLIENT_ID;
if(!clientId) throw new Error('No session found in environment.');
options.authStrategy = new LocalAuth({
clientId
});
}
}
const allOpts = {...options, ...(additionalOpts || {})};
return new Client(allOpts);
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
module.exports = {
sleep,
createClient,
isUsingLegacySession,
isMD,
remoteId,
};

193
tests/structures/chat.js Normal file
View File

@@ -0,0 +1,193 @@
const { expect } = require('chai');
const helper = require('../helper');
const Message = require('../../src/structures/Message');
const { MessageTypes } = require('../../src/util/Constants');
const { Contact } = require('../../src/structures');
const remoteId = helper.remoteId;
describe('Chat', function () {
let client;
let chat;
before(async function() {
this.timeout(35000);
client = helper.createClient({ authenticated: true });
await client.initialize();
chat = await client.getChatById(remoteId);
});
after(async function () {
await client.destroy();
});
it('can send a message to a chat', async function () {
const msg = await chat.sendMessage('hello world');
expect(msg).to.be.instanceOf(Message);
expect(msg.type).to.equal(MessageTypes.TEXT);
expect(msg.fromMe).to.equal(true);
expect(msg.body).to.equal('hello world');
expect(msg.to).to.equal(remoteId);
});
it('can fetch messages sent in a chat', async function () {
await helper.sleep(1000);
const msg = await chat.sendMessage('another message');
await helper.sleep(500);
const messages = await chat.fetchMessages();
expect(messages.length).to.be.greaterThanOrEqual(2);
const fetchedMsg = messages[messages.length-1];
expect(fetchedMsg).to.be.instanceOf(Message);
expect(fetchedMsg.type).to.equal(MessageTypes.TEXT);
expect(fetchedMsg.id._serialized).to.equal(msg.id._serialized);
expect(fetchedMsg.body).to.equal(msg.body);
});
it('can use a limit when fetching messages sent in a chat', async function () {
await helper.sleep(1000);
const msg = await chat.sendMessage('yet another message');
await helper.sleep(500);
const messages = await chat.fetchMessages({limit: 1});
expect(messages).to.have.lengthOf(1);
const fetchedMsg = messages[0];
expect(fetchedMsg).to.be.instanceOf(Message);
expect(fetchedMsg.type).to.equal(MessageTypes.TEXT);
expect(fetchedMsg.id._serialized).to.equal(msg.id._serialized);
expect(fetchedMsg.body).to.equal(msg.body);
});
it('can get the related contact', async function () {
const contact = await chat.getContact();
expect(contact).to.be.instanceOf(Contact);
expect(contact.id._serialized).to.equal(chat.id._serialized);
});
describe('Seen', function () {
it('can mark a chat as unread', async function () {
await chat.markUnread();
await helper.sleep(500);
// refresh chat
chat = await client.getChatById(remoteId);
expect(chat.unreadCount).to.equal(-1);
});
it('can mark a chat as seen', async function () {
const res = await chat.sendSeen();
expect(res).to.equal(true);
await helper.sleep(1000);
// refresh chat
chat = await client.getChatById(remoteId);
expect(chat.unreadCount).to.equal(0);
});
});
describe('Archiving', function (){
it('can archive a chat', async function () {
const res = await chat.archive();
expect(res).to.equal(true);
await helper.sleep(1000);
// refresh chat
chat = await client.getChatById(remoteId);
expect(chat.archived).to.equal(true);
});
it('can unarchive a chat', async function () {
const res = await chat.unarchive();
expect(res).to.equal(false);
await helper.sleep(1000);
// refresh chat
chat = await client.getChatById(remoteId);
expect(chat.archived).to.equal(false);
});
});
describe('Pinning', function () {
it('can pin a chat', async function () {
const res = await chat.pin();
expect(res).to.equal(true);
await helper.sleep(1000);
// refresh chat
chat = await client.getChatById(remoteId);
expect(chat.pinned).to.equal(true);
});
it('can unpin a chat', async function () {
const res = await chat.unpin();
expect(res).to.equal(false);
await helper.sleep(1000);
// refresh chat
chat = await client.getChatById(remoteId);
expect(chat.pinned).to.equal(false);
});
});
describe('Muting', function () {
it('can mute a chat forever', async function() {
await chat.mute();
await helper.sleep(1000);
// refresh chat
chat = await client.getChatById(remoteId);
expect(chat.isMuted).to.equal(true);
expect(chat.muteExpiration).to.equal(-1);
});
it('can mute a chat until a specific date', async function() {
const unmuteDate = new Date(new Date().getTime() + (1000*60*60));
await chat.mute(unmuteDate);
await helper.sleep(1000);
// refresh chat
chat = await client.getChatById(remoteId);
expect(chat.isMuted).to.equal(true);
expect(chat.muteExpiration).to.equal(
Math.round(unmuteDate.getTime() / 1000)
);
});
it('can unmute a chat', async function () {
await chat.unmute();
await helper.sleep(500);
// refresh chat
chat = await client.getChatById(remoteId);
expect(chat.isMuted).to.equal(false);
expect(chat.muteExpiration).to.equal(0);
});
});
// eslint-disable-next-line mocha/no-skipped-tests
describe.skip('Destructive operations', function () {
it('can clear all messages from chat', async function () {
const res = await chat.clearMessages();
expect(res).to.equal(true);
await helper.sleep(3000);
const msgs = await chat.fetchMessages();
expect(msgs).to.have.lengthOf(0);
});
it('can delete a chat', async function () {
const res = await chat.delete();
expect(res).to.equal(true);
});
});
});

227
tests/structures/group.js Normal file
View File

@@ -0,0 +1,227 @@
const { expect } = require('chai');
const helper = require('../helper');
const remoteId = helper.remoteId;
describe('Group', function() {
let client;
let group;
before(async function() {
this.timeout(35000);
client = helper.createClient({
authenticated: true,
});
await client.initialize();
const createRes = await client.createGroup('My Awesome Group', [remoteId]);
expect(createRes.gid).to.exist;
await helper.sleep(500);
group = await client.getChatById(createRes.gid._serialized);
expect(group).to.exist;
});
beforeEach(async function () {
await helper.sleep(500);
});
describe('Settings', function () {
it('can change the group subject', async function () {
expect(group.name).to.equal('My Awesome Group');
const res = await group.setSubject('My Amazing Group');
expect(res).to.equal(true);
await helper.sleep(1000);
// reload
group = await client.getChatById(group.id._serialized);
expect(group.name).to.equal('My Amazing Group');
});
it('can change the group description', async function () {
expect(group.description).to.equal(undefined);
const res = await group.setDescription('some description');
expect(res).to.equal(true);
expect(group.description).to.equal('some description');
await helper.sleep(1000);
// reload
group = await client.getChatById(group.id._serialized);
expect(group.description).to.equal('some description');
});
it('can set only admins able to send messages', async function () {
expect(group.groupMetadata.announce).to.equal(false);
const res = await group.setMessagesAdminsOnly();
expect(res).to.equal(true);
expect(group.groupMetadata.announce).to.equal(true);
await helper.sleep(1000);
// reload
group = await client.getChatById(group.id._serialized);
expect(group.groupMetadata.announce).to.equal(true);
});
it('can set all participants able to send messages', async function () {
expect(group.groupMetadata.announce).to.equal(true);
const res = await group.setMessagesAdminsOnly(false);
expect(res).to.equal(true);
expect(group.groupMetadata.announce).to.equal(false);
await helper.sleep(1000);
// reload
group = await client.getChatById(group.id._serialized);
expect(group.groupMetadata.announce).to.equal(false);
});
it('can set only admins able to set group info', async function () {
expect(group.groupMetadata.restrict).to.equal(false);
const res = await group.setInfoAdminsOnly();
expect(res).to.equal(true);
expect(group.groupMetadata.restrict).to.equal(true);
await helper.sleep(1000);
// reload
group = await client.getChatById(group.id._serialized);
expect(group.groupMetadata.restrict).to.equal(true);
});
it('can set all participants able to set group info', async function () {
expect(group.groupMetadata.restrict).to.equal(true);
const res = await group.setInfoAdminsOnly(false);
expect(res).to.equal(true);
expect(group.groupMetadata.restrict).to.equal(false);
await helper.sleep(1000);
// reload
group = await client.getChatById(group.id._serialized);
expect(group.groupMetadata.restrict).to.equal(false);
});
});
describe('Invites', function () {
it('can get the invite code', async function () {
const code = await group.getInviteCode();
expect(typeof code).to.equal('string');
});
it('can get invite info', async function () {
const code = await group.getInviteCode();
const info = await client.getInviteInfo(code);
expect(info.id._serialized).to.equal(group.id._serialized);
expect(info.participants.length).to.equal(2);
});
it('can revoke the invite code', async function () {
const code = await group.getInviteCode();
const newCode = await group.revokeInvite();
expect(typeof newCode).to.equal('string');
expect(newCode).to.not.equal(code);
});
});
describe('Participants', function () {
it('can promote a user to admin', async function () {
let participant = group.participants.find(p => p.id._serialized === remoteId);
expect(participant).to.exist;
expect(participant.isAdmin).to.equal(false);
const res = await group.promoteParticipants([remoteId]);
expect(res.status).to.be.greaterThanOrEqual(200);
await helper.sleep(1000);
// reload and check
group = await client.getChatById(group.id._serialized);
participant = group.participants.find(p => p.id._serialized=== remoteId);
expect(participant).to.exist;
expect(participant.isAdmin).to.equal(true);
});
it('can demote a user', async function () {
let participant = group.participants.find(p => p.id._serialized=== remoteId);
expect(participant).to.exist;
expect(participant.isAdmin).to.equal(true);
const res = await group.demoteParticipants([remoteId]);
expect(res.status).to.be.greaterThanOrEqual(200);
await helper.sleep(1000);
// reload and check
group = await client.getChatById(group.id._serialized);
participant = group.participants.find(p => p.id._serialized=== remoteId);
expect(participant).to.exist;
expect(participant.isAdmin).to.equal(false);
});
it('can remove a user from the group', async function () {
let participant = group.participants.find(p => p.id._serialized=== remoteId);
expect(participant).to.exist;
const res = await group.removeParticipants([remoteId]);
expect(res.status).to.be.greaterThanOrEqual(200);
await helper.sleep(1000);
// reload and check
group = await client.getChatById(group.id._serialized);
participant = group.participants.find(p => p.id._serialized=== remoteId);
expect(participant).to.not.exist;
});
it('can add back a user to the group', async function () {
let participant = group.participants.find(p => p.id._serialized=== remoteId);
expect(participant).to.not.exist;
const res = await group.addParticipants([remoteId]);
expect(res.status).to.be.greaterThanOrEqual(200);
await helper.sleep(1000);
// reload and check
group = await client.getChatById(group.id._serialized);
participant = group.participants.find(p => p.id._serialized=== remoteId);
expect(participant).to.exist;
});
});
describe('Leave / re-join', function () {
let code;
before(async function () {
code = await group.getInviteCode();
});
it('can leave the group', async function () {
expect(group.isReadOnly).to.equal(false);
await group.leave();
await helper.sleep(1000);
// reload and check
group = await client.getChatById(group.id._serialized);
expect(group.isReadOnly).to.equal(true);
});
it('can join a group via invite code', async function () {
const chatId = await client.acceptInvite(code);
expect(chatId).to.equal(group.id._serialized);
await helper.sleep(1000);
// reload and check
group = await client.getChatById(group.id._serialized);
expect(group.isReadOnly).to.equal(false);
});
});
after(async function () {
await client.destroy();
});
});

Some files were not shown because too many files have changed in this diff Show More