@pney/whatsapp-web 1.34.6 → 1.34.7-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/.env.example +0 -1
  2. package/.gitattributes +4 -0
  3. package/.husky/commit-msg +4 -0
  4. package/.husky/pre-commit +1 -0
  5. package/.lintstagedrc.json +6 -0
  6. package/.prettierignore +8 -0
  7. package/.prettierrc.json +10 -0
  8. package/README.md +83 -80
  9. package/commitlint.config.js +29 -0
  10. package/eslint.config.mjs +67 -0
  11. package/example.js +151 -71
  12. package/index.d.ts +982 -734
  13. package/index.js +4 -4
  14. package/package.json +3 -3
  15. package/shell.js +4 -4
  16. package/src/Client.js +1860 -920
  17. package/src/authStrategies/BaseAuthStrategy.js +4 -2
  18. package/src/authStrategies/LocalAuth.js +25 -12
  19. package/src/authStrategies/NoAuth.js +3 -4
  20. package/src/authStrategies/RemoteAuth.js +92 -43
  21. package/src/factories/ChatFactory.js +1 -1
  22. package/src/factories/ContactFactory.js +2 -2
  23. package/src/structures/Base.js +5 -3
  24. package/src/structures/Broadcast.js +1 -2
  25. package/src/structures/BusinessContact.js +1 -2
  26. package/src/structures/Buttons.js +14 -10
  27. package/src/structures/Call.js +10 -6
  28. package/src/structures/Channel.js +171 -91
  29. package/src/structures/Chat.js +57 -41
  30. package/src/structures/ClientInfo.js +1 -1
  31. package/src/structures/Contact.js +37 -16
  32. package/src/structures/GroupChat.js +425 -228
  33. package/src/structures/GroupNotification.js +21 -12
  34. package/src/structures/Label.js +6 -6
  35. package/src/structures/List.js +22 -14
  36. package/src/structures/Location.js +5 -4
  37. package/src/structures/Message.js +412 -168
  38. package/src/structures/MessageMedia.js +31 -18
  39. package/src/structures/Order.js +4 -4
  40. package/src/structures/Payment.js +6 -3
  41. package/src/structures/Poll.js +2 -2
  42. package/src/structures/PollVote.js +9 -6
  43. package/src/structures/PrivateChat.js +2 -4
  44. package/src/structures/PrivateContact.js +2 -4
  45. package/src/structures/Product.js +1 -1
  46. package/src/structures/ProductMetadata.js +1 -2
  47. package/src/structures/Reaction.js +2 -4
  48. package/src/structures/ScheduledEvent.js +22 -10
  49. package/src/util/Constants.js +8 -6
  50. package/src/util/Injected/AuthStore/AuthStore.js +7 -3
  51. package/src/util/Injected/Utils.js +753 -345
  52. package/src/util/InterfaceController.js +72 -25
  53. package/src/util/Puppeteer.js +1 -1
  54. package/src/util/Util.js +28 -15
  55. package/src/webCache/LocalWebCache.js +7 -5
  56. package/src/webCache/RemoteWebCache.js +10 -4
  57. package/src/webCache/WebCache.js +8 -5
  58. package/src/webCache/WebCacheFactory.js +9 -9
  59. package/CODE_OF_CONDUCT.md +0 -133
package/.env.example CHANGED
@@ -1,3 +1,2 @@
1
1
  WWEBJS_TEST_REMOTE_ID=XXXXXXXXXX@c.us
2
2
  WWEBJS_TEST_CLIENT_ID=authenticated
3
- WWEBJS_TEST_MD=1
package/.gitattributes ADDED
@@ -0,0 +1,4 @@
1
+ * text=auto eol=lf
2
+
3
+ package-lock.json linguist-generated=true text=auto eol=lf
4
+ docs/* linguist-generated=true text=auto eol=lf
@@ -0,0 +1,4 @@
1
+ # Normalize commit type to lowercase
2
+ sed -E 's/^[A-Za-z]+/\L&/' "$1" > "$1.tmp" && mv "$1.tmp" "$1"
3
+
4
+ npx --no-install commitlint --edit "$1"
@@ -0,0 +1 @@
1
+ npx lint-staged
@@ -0,0 +1,6 @@
1
+ {
2
+ "*": "prettier --ignore-unknown --write",
3
+ "*.{js,ts}": "eslint --fix",
4
+ "src/**/*.{js,ts}": "eslint --fix",
5
+ "tests/**/*.{js,ts}": "eslint --fix"
6
+ }
@@ -0,0 +1,8 @@
1
+ node_modules
2
+ dist
3
+ coverage
4
+ *.min.js
5
+ .wa-version
6
+ .wwebjs_auth
7
+ .wwebjs_cache
8
+ docs
@@ -0,0 +1,10 @@
1
+ {
2
+ "semi": true,
3
+ "trailingComma": "all",
4
+ "singleQuote": true,
5
+ "printWidth": 80,
6
+ "tabWidth": 4,
7
+ "useTabs": false,
8
+ "arrowParens": "always",
9
+ "endOfLine": "lf"
10
+ }
package/README.md CHANGED
@@ -1,59 +1,65 @@
1
1
  <div align="center">
2
- <br />
3
2
  <p>
4
- <a href="https://wwebjs.dev"><img src="https://github.com/wwebjs/assets/blob/main/Collection/GitHub/wwebjs.png?raw=true" title="whatsapp-web.js" alt="WWebJS Website" width="500" /></a>
3
+ <a href="https://wwebjs.dev">
4
+ <img src="https://github.com/wwebjs/Assets/blob/main/Collection/GitHub/whatsapp-web.js.png?raw=true"
5
+ title="whatsapp-web.js" alt="WWebJS Website" />
6
+ </a>
5
7
  </p>
6
- <br />
7
8
  <p>
8
- <a href="https://www.npmjs.com/package/whatsapp-web.js"><img src="https://img.shields.io/npm/v/whatsapp-web.js.svg" alt="npm" /></a>
9
- <a href="https://depfu.com/github/pedroslopez/whatsapp-web.js?project_id=9765"><img src="https://badges.depfu.com/badges/4a65a0de96ece65fdf39e294e0c8dcba/overview.svg" alt="Depfu" /></a>
10
- <img src="https://img.shields.io/badge/WhatsApp_Web-2.3000.1017054665-brightgreen.svg" alt="WhatsApp_Web 2.2346.52" />
11
- <a href="https://discord.gg/H7DqQs4"><img src="https://img.shields.io/discord/698610475432411196.svg?logo=discord" alt="Discord server" /></a>
12
- </p>
13
- <br />
9
+ <a href="https://www.npmjs.com/package/whatsapp-web.js"><img
10
+ src="https://img.shields.io/npm/v/whatsapp-web.js.svg" alt="npm" /></a>
11
+ <a href="https://www.npmjs.com/package/whatsapp-web.js"><img alt="NPM Downloads"
12
+ src="https://img.shields.io/npm/d18m/whatsapp-web.js" /></a>
13
+ <a href="https://github.com/wwebjs/whatsapp-web.js/graphs/contributors"><img alt="GitHub contributors"
14
+ src="https://img.shields.io/github/contributors-anon/wwebjs/whatsapp-web.js" /></a>
15
+ <a href="https://depfu.com/github/wwebjs/whatsapp-web.js?project_id=9765"><img
16
+ src="https://badges.depfu.com/badges/4a65a0de96ece65fdf39e294e0c8dcba/overview.svg" alt="Depfu" /></a>
17
+ <a href="https://discord.wwebjs.dev"><img
18
+ src="https://img.shields.io/discord/698610475432411196.svg?logo=discord" alt="Discord server" /></a>
19
+ </p>
14
20
  </div>
15
21
 
16
22
  ## About
17
- **A WhatsApp API client that operates via the WhatsApp Web browser.**
18
-
19
- The library launches the WhatsApp Web browser app via Puppeteer, accessing its internal functions and creating a managed instance to reduce the risk of being blocked. This gives the API client nearly all WhatsApp Web features for dynamic use in a Node.js application.
20
23
 
21
- > [!IMPORTANT]
22
- > **It is not guaranteed you will not be blocked by using this method. WhatsApp does not allow bots or unofficial clients on their platform, so this shouldn't be considered totally safe.**
24
+ whatsapp‑web.js is a powerful [Node.js][nodejs] library that lets you interact with WhatsApp Web, making it easy to build a dynamic WhatsApp API with nearly all features of the web client. It uses [Puppeteer][puppeteer] to access WhatsApp Web’s internal functions and runs them in a managed browser instance to reduce the risk of being blocked.
23
25
 
24
26
  ## Links
25
27
 
26
- * [GitHub][gitHub]
27
- * [Guide][guide] ([source][guide-source])
28
- * [Documentation][documentation] ([source][documentation-source])
29
- * [Discord Server][discord]
30
- * [npm][npm]
28
+ - [GitHub][gitHub]
29
+ - [Guide][guide] ([source][guide-source])
30
+ - [Documentation][documentation] ([source][documentation-source])
31
+ - [Discord Server][discord]
32
+ - [npm][npm]
31
33
 
32
34
  ## Installation
33
35
 
34
- The module is available on [npm][npm] via `npm i whatsapp-web.js`!
36
+ **Node.js `v18.0.0` or higher, is required.**
37
+
38
+ ```sh
39
+ npm install whatsapp-web.js
40
+ yarn add whatsapp-web.js
41
+ pnpm add whatsapp-web.js
42
+ ```
35
43
 
36
- > [!NOTE]
37
- > **Node ``v18`` or higher, is required.**
38
- > See the [Guide][guide] for quick upgrade instructions.
44
+ Having trouble installing? Take a peak at the [Guide][guide] for more detailed instructions.
39
45
 
40
46
  ## Example usage
41
47
 
42
48
  ```js
43
49
  const { Client } = require('whatsapp-web.js');
50
+ const qrcode = require('qrcode-terminal');
44
51
 
45
52
  const client = new Client();
46
53
 
47
54
  client.on('qr', (qr) => {
48
- // Generate and scan this code with your phone
49
- console.log('QR RECEIVED', qr);
55
+ qrcode.generate(qr, { small: true });
50
56
  });
51
57
 
52
58
  client.on('ready', () => {
53
59
  console.log('Client is ready!');
54
60
  });
55
61
 
56
- client.on('message', msg => {
62
+ client.on('message', (msg) => {
57
63
  if (msg.body == '!ping') {
58
64
  msg.reply('pong');
59
65
  }
@@ -62,60 +68,58 @@ client.on('message', msg => {
62
68
  client.initialize();
63
69
  ```
64
70
 
65
- Take a look at [example.js][examples] for another examples with additional use cases.
66
- For further details on saving and restoring sessions, explore the provided [Authentication Strategies][auth-strategies].
67
-
71
+ Take a look at [example.js][examples] for additional examples and use cases.
72
+ For more details on saving and restoring sessions, check out the [Authentication Strategies][auth-strategies].
68
73
 
69
74
  ## Supported features
70
75
 
71
- | Feature | Status |
72
- | ------------- | ------------- |
73
- | Multi Device | ✅ |
74
- | Send messages | ✅ |
75
- | Receive messages | ✅ |
76
- | Send media (images/audio/documents) | ✅ |
77
- | Send media (video) | ✅ [(requires Google Chrome)][google-chrome] |
78
- | Send stickers | ✅ |
79
- | Receive media (images/audio/video/documents) | ✅ |
80
- | Send contact cards | ✅ |
81
- | Send location | ✅ |
82
- | Send buttons | ❌ [(DEPRECATED)][deprecated-video] |
83
- | Send lists | ❌ [(DEPRECATED)][deprecated-video] |
84
- | Receive location | ✅ |
85
- | Message replies | ✅ |
86
- | Join groups by invite | ✅ |
87
- | Get invite for group | ✅ |
88
- | Modify group info (subject, description) | ✅ |
89
- | Modify group settings (send messages, edit info) | ✅ |
90
- | Add group participants | ✅ |
91
- | Kick group participants | ✅ |
92
- | Promote/demote group participants | ✅ |
93
- | Mention users | ✅ |
94
- | Mention groups | ✅ |
95
- | Mute/unmute chats | ✅ |
96
- | Block/unblock contacts | ✅ |
97
- | Get contact info | ✅ |
98
- | Get profile pictures | ✅ |
99
- | Set user status message | ✅ |
100
- | React to messages | ✅ |
101
- | Create polls | ✅ |
102
- | Channels | ✅ |
103
- | Vote in polls | 🔜 |
104
- | Communities | 🔜 |
76
+ | Feature | Status |
77
+ | ------------------------------------------------ | -------------------------------------------- |
78
+ | Multi Device | ✅ |
79
+ | Send messages | ✅ |
80
+ | Receive messages | ✅ |
81
+ | Send media (images/audio/documents) | ✅ |
82
+ | Send media (video) | ✅ [(requires Google Chrome)][google-chrome] |
83
+ | Send stickers | ✅ |
84
+ | Receive media (images/audio/video/documents) | ✅ |
85
+ | Send contact cards | ✅ |
86
+ | Send location | ✅ |
87
+ | Send buttons | ❌ [(DEPRECATED)][deprecated-video] |
88
+ | Send lists | ❌ [(DEPRECATED)][deprecated-video] |
89
+ | Receive location | ✅ |
90
+ | Message replies | ✅ |
91
+ | Join groups by invite | ✅ |
92
+ | Get invite for group | ✅ |
93
+ | Modify group info (subject, description) | ✅ |
94
+ | Modify group settings (send messages, edit info) | ✅ |
95
+ | Add group participants | ✅ |
96
+ | Kick group participants | ✅ |
97
+ | Promote/demote group participants | ✅ |
98
+ | Mention users | ✅ |
99
+ | Mention groups | ✅ |
100
+ | Mute/unmute chats | ✅ |
101
+ | Block/unblock contacts | ✅ |
102
+ | Get contact info | ✅ |
103
+ | Get profile pictures | ✅ |
104
+ | Set user status message | ✅ |
105
+ | React to messages | ✅ |
106
+ | Create polls | ✅ |
107
+ | Channels | ✅ |
108
+ | Vote in polls | |
109
+ | Communities | 🔜 |
105
110
 
106
111
  Something missing? Make an issue and let us know!
107
112
 
108
- ## Contributing
109
-
110
- Feel free to open pull requests; we welcome contributions! However, for significant changes, it's best to open an issue beforehand. Make sure to review our [contribution guidelines][contributing] before creating a pull request. Before creating your own issue or pull request, always check to see if one already exists!
111
-
112
113
  ## Supporting the project
113
114
 
114
- You can support the maintainer of this project through the links below
115
+ You can support the maintainer of this project through the links below:
115
116
 
116
117
  - [Support via GitHub Sponsors][gitHub-sponsors]
117
118
  - [Support via PayPal][support-payPal]
118
- - [Sign up for DigitalOcean][digitalocean] and get $200 in credit when you sign up (Referral)
119
+
120
+ ## Contributing
121
+
122
+ Feel free to open pull requests; we welcome contributions! However, for significant changes, it's best to open an issue beforehand. Make sure to review our [contribution guidelines][contributing] before creating a pull request. Before creating your own issue or pull request, always check to see if one already exists!
119
123
 
120
124
  ## Disclaimer
121
125
 
@@ -123,33 +127,32 @@ This project is not affiliated, associated, authorized, endorsed by, or in any w
123
127
 
124
128
  ## License
125
129
 
126
- Copyright 2019 Pedro S Lopez
130
+ Copyright 2019 Pedro S Lopez
127
131
 
128
132
  Licensed under the Apache License, Version 2.0 (the "License");
129
133
  you may not use this project except in compliance with the License.
130
- You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
134
+ You may obtain a copy of the License at <https://www.apache.org/licenses/LICENSE-2.0>.
131
135
 
132
136
  Unless required by applicable law or agreed to in writing, software
133
137
  distributed under the License is distributed on an "AS IS" BASIS,
134
138
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
135
139
  See the License for the specific language governing permissions and
136
- limitations under the License.
137
-
140
+ limitations under the License.
138
141
 
139
142
  [guide]: https://guide.wwebjs.dev/guide
140
143
  [guide-source]: https://github.com/wwebjs/wwebjs.dev/tree/main
141
144
  [documentation]: https://docs.wwebjs.dev/
142
- [documentation-source]: https://github.com/pedroslopez/whatsapp-web.js/tree/main/docs
143
- [discord]: https://discord.gg/H7DqQs4
144
- [gitHub]: https://github.com/pedroslopez/whatsapp-web.js
145
+ [documentation-source]: https://github.com/wwebjs/whatsapp-web.js/tree/main/docs
146
+ [discord]: https://discord.wwebjs.dev
147
+ [gitHub]: https://github.com/wwebjs/whatsapp-web.js
145
148
  [npm]: https://npmjs.org/package/whatsapp-web.js
146
149
  [nodejs]: https://nodejs.org/en/download/
147
- [examples]: https://github.com/pedroslopez/whatsapp-web.js/blob/master/example.js
150
+ [examples]: https://github.com/wwebjs/whatsapp-web.js/blob/main/example.js
148
151
  [auth-strategies]: https://wwebjs.dev/guide/creating-your-bot/authentication.html
149
152
  [google-chrome]: https://wwebjs.dev/guide/creating-your-bot/handling-attachments.html#caveat-for-sending-videos-and-gifs
150
153
  [deprecated-video]: https://www.youtube.com/watch?v=hv1R1rLeVVE
151
- [gitHub-sponsors]: https://github.com/sponsors/pedroslopez
154
+ [gitHub-sponsors]: https://github.com/sponsors/wwebjs
152
155
  [support-payPal]: https://www.paypal.me/psla/
153
- [digitalocean]: https://m.do.co/c/73f906a36ed4
154
- [contributing]: https://github.com/pedroslopez/whatsapp-web.js/blob/main/CODE_OF_CONDUCT.md
156
+ [contributing]: .github/CONTRIBUTING.md
155
157
  [whatsapp]: https://whatsapp.com
158
+ [puppeteer]: https://pptr.dev/
@@ -0,0 +1,29 @@
1
+ module.exports = {
2
+ extends: ['@commitlint/config-conventional'],
3
+ rules: {
4
+ 'header-max-length': [2, 'always', 72],
5
+ 'type-enum': [
6
+ 2,
7
+ 'always',
8
+ [
9
+ 'feat',
10
+ 'fix',
11
+ 'docs',
12
+ 'style',
13
+ 'refactor',
14
+ 'perf',
15
+ 'test',
16
+ 'build',
17
+ 'ci',
18
+ 'chore',
19
+ 'types',
20
+ 'revert',
21
+ 'infra',
22
+ ],
23
+ ],
24
+ 'type-case': [0],
25
+ 'scope-case': [0],
26
+ 'subject-case': [0],
27
+ 'subject-exclamation-mark': [0],
28
+ },
29
+ };
@@ -0,0 +1,67 @@
1
+ import globals from 'globals';
2
+ import pluginEslintJs from '@eslint/js';
3
+ import pluginMocha from 'eslint-plugin-mocha';
4
+ import configEslintConfigPrettier from 'eslint-plugin-prettier/recommended';
5
+
6
+ export default [
7
+ pluginEslintJs.configs.recommended,
8
+ {
9
+ name: 'whatsapp-web.js/default/rules',
10
+ plugins: {
11
+ mocha: pluginMocha,
12
+ },
13
+ languageOptions: {
14
+ ecmaVersion: 2025,
15
+
16
+ globals: {
17
+ ...globals.browser,
18
+ ...globals.commonjs,
19
+ ...globals.es6,
20
+ ...globals.node,
21
+
22
+ Atomics: 'readonly',
23
+ SharedArrayBuffer: 'readonly',
24
+ },
25
+ },
26
+ rules: {
27
+ 'no-unused-vars': [
28
+ 'error',
29
+ {
30
+ // TODO: args can be uncommented, but there is code, that causes lint-errors
31
+ // args: 'all',
32
+ vars: 'all',
33
+ caughtErrorsIgnorePattern: '^ignoredError',
34
+ },
35
+ ],
36
+ },
37
+ },
38
+ {
39
+ // be careful, "recommended" settings object has 4 fields:
40
+ // - name (string)
41
+ // - plugins (object)
42
+ // - languageOptions (object)
43
+ // - rules (object)
44
+ //
45
+ // by simple "adding" any of mentioned fields to this object
46
+ // you REPLACE the "recommended" value.
47
+ // If you want to PATCH it - consider nested "..." spread operator
48
+ ...pluginMocha.configs.recommended,
49
+ name: 'whatsapp-web.js/default/mocha',
50
+
51
+ files: ['tests/**/*'],
52
+ },
53
+ {
54
+ name: 'whatsapp-web.js/default/ignores',
55
+ ignores: [
56
+ 'node_modules',
57
+ 'dist',
58
+ 'coverage',
59
+ 'docs',
60
+ '*.min.js',
61
+ '.wa-version',
62
+ '.wwebjs_auth',
63
+ '.wwebjs_cache',
64
+ ],
65
+ },
66
+ configEslintConfigPrettier,
67
+ ];