@nam088/zca-js 1.0.0

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.
package/README.md ADDED
@@ -0,0 +1,225 @@
1
+ # ZCA-JS
2
+
3
+ > [!NOTE]
4
+ > This is an unofficial Zalo API for personal account. It work by simulating the browser to interact with Zalo Web.
5
+
6
+ > [!WARNING]
7
+ > Using this API could get your account locked or banned. We are not responsible for any issues that may happen. Use it at your own risk.
8
+
9
+ ---
10
+
11
+ ## Table of Contents
12
+
13
+ - [Installation](#installation)
14
+ - [Migrate to V2](#migrate-to-v2)
15
+ - [Documentation](#documentation)
16
+ - [Basic Usages](#basic-usages)
17
+ - [Login](#login)
18
+ - [Listen for new messages](#listen-for-new-messages)
19
+ - [Send a message](#send-a-message)
20
+ - [Get/Send a sticker](#getsend-a-sticker)
21
+ - [Example](#example)
22
+ - [Projects & Useful Resources](#projects--useful-resources)
23
+ - [Contributing](#contributing)
24
+ - [License](#license)
25
+ - [Support Us](#support-us)
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ bun add zca-js # or npm install zca-js
31
+ ```
32
+
33
+ ### Migrate to V2
34
+
35
+ Since official version 2.0.0, `zca-js` has removed sharp dependency for image metadata extraction. It now requires users to provide their own `imageMetadataGetter` function when initializing the `Zalo` class if they want to send images/gifs by file path.
36
+
37
+ Example of custom `imageMetadataGetter` using `sharp`:
38
+
39
+ ```bash
40
+ bun add sharp # or npm install sharp
41
+ ```
42
+
43
+ ```javascript
44
+ import { Zalo } from "zca-js";
45
+ import sharp from "sharp";
46
+ import fs from "fs";
47
+
48
+ async function imageMetadataGetter(filePath) {
49
+ const data = await fs.promises.readFile(filePath);
50
+ const metadata = await sharp(data).metadata();
51
+ return {
52
+ height: metadata.height,
53
+ width: metadata.width,
54
+ size: metadata.size || data.length,
55
+ };
56
+ }
57
+
58
+ const zalo = new Zalo({
59
+ imageMetadataGetter,
60
+ });
61
+ ```
62
+
63
+ ---
64
+
65
+ ## Documentation
66
+
67
+ See [API Documentation](https://tdung.gitbook.io/zca-js) for more details.
68
+
69
+ ---
70
+
71
+ ## Basic Usages
72
+
73
+ ### Login
74
+
75
+ ```javascript
76
+ import { Zalo } from "zca-js";
77
+
78
+ const zalo = new Zalo();
79
+ const api = await zalo.loginQR();
80
+ ```
81
+
82
+ ### Listen for new messages
83
+
84
+ ```javascript
85
+ import { Zalo, ThreadType } from "zca-js";
86
+
87
+ const zalo = new Zalo();
88
+ const api = await zalo.loginQR();
89
+
90
+ api.listener.on("message", (message) => {
91
+ const isPlainText = typeof message.data.content === "string";
92
+
93
+ switch (message.type) {
94
+ case ThreadType.User: {
95
+ if (isPlainText) {
96
+ // received plain text direct message
97
+ }
98
+ break;
99
+ }
100
+ case ThreadType.Group: {
101
+ if (isPlainText) {
102
+ // received plain text group message
103
+ }
104
+ break;
105
+ }
106
+ }
107
+ });
108
+
109
+ api.listener.start();
110
+ ```
111
+
112
+ > [!IMPORTANT]
113
+ > Only one web listener can run per account at a time. If you open Zalo in the browser while the listener is active, the listener will be automatically stopped.
114
+
115
+ ### Send a message
116
+
117
+ ```javascript
118
+ import { Zalo, ThreadType } from "zca-js";
119
+
120
+ const zalo = new Zalo();
121
+ const api = await zalo.loginQR();
122
+
123
+ // Echo bot
124
+ api.listener.on("message", (message) => {
125
+ const isPlainText = typeof message.data.content === "string";
126
+ if (message.isSelf || !isPlainText) return;
127
+
128
+ switch (message.type) {
129
+ case ThreadType.User: {
130
+ api.sendMessage(
131
+ {
132
+ msg: "echo: " + message.data.content,
133
+ quote: message.data, // the message to reply to (optional)
134
+ },
135
+ message.threadId,
136
+ message.type, // ThreadType.User
137
+ );
138
+ break;
139
+ }
140
+ case ThreadType.Group: {
141
+ api.sendMessage(
142
+ {
143
+ msg: "echo: " + message.data.content,
144
+ quote: message.data, // the message to reply to (optional)
145
+ },
146
+ message.threadId,
147
+ message.type, // ThreadType.Group
148
+ );
149
+ break;
150
+ }
151
+ }
152
+ });
153
+
154
+ api.listener.start();
155
+ ```
156
+
157
+ ### Get/Send a sticker
158
+
159
+ ```javascript
160
+ api.getStickers("hello").then(async (stickerIds) => {
161
+ // Get the first sticker
162
+ const stickerObject = await api.getStickersDetail(stickerIds[0]);
163
+ api.sendMessageSticker(
164
+ stickerObject,
165
+ message.threadId,
166
+ message.type, // ThreadType.User or ThreadType.Group
167
+ );
168
+ });
169
+ ```
170
+
171
+ ---
172
+
173
+ ## Example
174
+
175
+ See [examples](examples) folder for more details.
176
+
177
+ ---
178
+
179
+ ## Projects & Useful Resources
180
+
181
+ <div align="center">
182
+
183
+ | Repository | Description |
184
+ | :--- | :--- |
185
+ | [**ZaloDataExtractor**](https://github.com/JustKemForFun/ZaloDataExtractor) | A browser `Extension` to extract IMEI, cookies, and user agent from Zalo Web. |
186
+ | [**MultiZlogin**](https://github.com/ChickenAI/multizlogin) | A multi-account Zalo management system that lets you log in to and manage multiple accounts simultaneously, with proxy and webhook integration. |
187
+ | [**n8n-nodes-zalo-tools**](https://github.com/ChickenAI/zalo-node) | N8N node for personal Zalo account. |
188
+ | [**Zalo-F12**](https://github.com/ElectroHeavenVN/Zalo-F12) | A collection of JavaScript code snippets to paste into DevTools to change how Zalo Web/PC works. |
189
+ | [**Zalo-F12-Tools**](https://github.com/JustKemForFun/Zalo-F12-Tools) | Toggle hidden modes for Zalo Web. |
190
+
191
+ </div>
192
+
193
+ ---
194
+
195
+ ## Contributing
196
+
197
+ We welcome contributions from the community! Please see our [Contributing Guidelines](CONTRIBUTING.md) for details on how to:
198
+
199
+ - ๐Ÿ› Report bugs and issues
200
+ - โœจ Suggest new features
201
+ - ๐Ÿ”ง Submit code contributions
202
+ - ๐Ÿ“š Improve documentation
203
+ - ๐Ÿงช Add or improve tests
204
+ - ๐Ÿ”’ Report security vulnerabilities
205
+
206
+ For more information, please read our [Code of Conduct](CODE_OF_CONDUCT.md) and [Security Policy](SECURITY.md) before participating.
207
+
208
+ ---
209
+
210
+ ## License
211
+
212
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
213
+
214
+ ---
215
+
216
+ ## **Support Us**
217
+
218
+ - โญ **Star our repositories** if you find them useful!
219
+ - ๐Ÿ”„ **Share** with your network to help us grow
220
+ - ๐Ÿ’ก **Contribute** your ideas and code
221
+ - โ˜• **A coffee**:
222
+ - [Buy Me a Coffee](https://ko-fi.com/grosse)
223
+ - [Paypal](https://www.paypal.com/paypalme/dungto213)
224
+ - [VietQR](https://github.com/user-attachments/assets/e1f319d6-9d11-4082-8248-55b55e645caa)
225
+ - [Momo](https://me.momo.vn/gMIMulsaUqsbf6iAiXt3)
package/SECURITY.md ADDED
@@ -0,0 +1,83 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ We actively maintain and provide security updates for the following versions:
6
+
7
+ | Version | Supported |
8
+ | ------- | ------------------ |
9
+ | 2.0.x | :white_check_mark: |
10
+ | 1.x.x | :x: |
11
+ | < 1.0 | :x: |
12
+
13
+ ## Reporting a Vulnerability
14
+
15
+ We take security vulnerabilities seriously. If you discover a security vulnerability in zca-js, please follow these steps:
16
+
17
+ ### 1. **DO NOT** create a public GitHub issue
18
+ Security vulnerabilities should be reported privately to prevent potential exploitation.
19
+
20
+ ### 2. Report the vulnerability
21
+ Send an email to the maintainers with the following information:
22
+ - **Subject**: `[SECURITY] zca-js vulnerability report`
23
+ - **Description**: Detailed description of the vulnerability
24
+ - **Steps to reproduce**: Clear steps to reproduce the issue
25
+ - **Impact assessment**: Potential impact of the vulnerability
26
+ - **Suggested fix** (if available): Any suggestions for fixing the issue
27
+
28
+ ### 3. Response timeline
29
+ - **Initial response**: Within 48 hours
30
+ - **Status update**: Within 1 week
31
+ - **Resolution**: As soon as possible, typically within 30 days
32
+
33
+ ## Security Considerations
34
+
35
+ ### Important Warnings
36
+
37
+ โš ๏ธ **This is an unofficial API library** that simulates browser interactions with Zalo Web. Please be aware of the following security considerations:
38
+
39
+ 1. **Account Risk**: Using this API may result in your Zalo account being locked or banned. Use at your own risk.
40
+
41
+ 2. **Authentication**: The library handles sensitive authentication data. Ensure proper security measures when storing or transmitting this information.
42
+
43
+ 3. **Rate Limiting**: Respect Zalo's rate limits to avoid triggering security measures.
44
+
45
+ 4. **Data Privacy**: Be mindful of user privacy and comply with relevant data protection regulations.
46
+
47
+ ### Best Practices
48
+
49
+ 1. **Environment Variables**: Store sensitive configuration in environment variables, not in code
50
+ 2. **HTTPS Only**: Always use HTTPS when transmitting data
51
+ 3. **Input Validation**: Validate all inputs before processing
52
+ 4. **Error Handling**: Implement proper error handling to avoid information disclosure
53
+ 5. **Regular Updates**: Keep the library updated to the latest version
54
+
55
+ ### Known Limitations
56
+
57
+ - This library is not officially supported by Zalo
58
+ - API endpoints and behavior may change without notice
59
+ - No guarantee of service availability or stability
60
+ - May break with Zalo Web updates
61
+
62
+ ## Security Updates
63
+
64
+ Security updates will be released as patch versions (e.g., 2.0.1, 2.0.2) and will be clearly marked in the changelog.
65
+
66
+ ## Contact Information
67
+
68
+ For security-related issues, please contact:
69
+ - **GitHub Issues**: Create a private issue with the `[SECURITY]` label
70
+ - **GitHub Discussions**: Use the "Security" category for general security questions
71
+ - **Team Members**:
72
+ - [@RFS-ADRENO](https://github.com/RFS-ADRENO)
73
+ - [@truong9c2208](https://github.com/truong9c2208)
74
+ - [@JustKemForFun](https://github.com/JustKemForFun)
75
+ - **Alternative**: Contact any team member through GitHub for urgent security matters
76
+
77
+ ## Acknowledgments
78
+
79
+ We appreciate security researchers and community members who responsibly disclose vulnerabilities. Contributors will be acknowledged in our security advisories unless they prefer to remain anonymous.
80
+
81
+ ---
82
+
83
+ **Note**: This security policy is subject to change. Please check back regularly for updates.