amiudmodz 4.0.6 → 5.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 +130 -0
- package/lib/Defaults/index.js +9 -4
- package/lib/Socket/Client/web-socket-client.js +13 -5
- package/lib/Socket/chats.js +50 -77
- package/lib/Socket/groupStatus.js +51 -41
- package/lib/Socket/groups.js +8 -5
- package/lib/Socket/messages-recv.js +26 -10
- package/lib/Socket/messages-send.js +38 -42
- package/lib/Socket/newsletter.js +1 -1
- package/lib/Socket/socket.js +18 -6
- package/lib/Utils/auth-utils.js +9 -1
- package/lib/Utils/crypto.js +10 -2
- package/lib/Utils/event-buffer.js +14 -17
- package/lib/Utils/make-mutex.js +20 -16
- package/lib/Utils/messages-media.js +15 -10
- package/lib/Utils/messages.js +6 -2
- package/lib/Utils/noise-handler.js +27 -13
- package/lib/Utils/process-message.js +30 -22
- package/lib/Utils/use-multi-file-auth-state.js +10 -5
- package/lib/WABinary/decode.js +21 -11
- package/lib/WABinary/encode.js +8 -8
- package/package.json +11 -1
package/README.md
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
<img src="https://capsule-render.vercel.app/api?type=waving&color=0:4000ff,50:7c3aed,100:00d4ff&height=220§ion=header&text=Baileys%20-%20UDMODZ&fontSize=52&fontColor=ffffff&animation=fadeIn&fontAlignY=35&desc=⚡%20Lightweight%20WhatsApp%20Web%20API&descAlignY=55&descSize=18" width="100%"/>
|
|
4
|
+
|
|
5
|
+
<br/>
|
|
6
|
+
|
|
7
|
+
[](https://nodejs.org)
|
|
8
|
+
[](https://www.typescriptlang.org/)
|
|
9
|
+
[](https://web.whatsapp.com)
|
|
10
|
+
|
|
11
|
+
[](https://www.npmjs.com/package/amiudmodz)
|
|
12
|
+
[](https://github.com/udmodz0)
|
|
13
|
+
[](https://github.com/udmodz0)
|
|
14
|
+
|
|
15
|
+
<br/>
|
|
16
|
+
|
|
17
|
+
```text
|
|
18
|
+
██╗░░░██╗██████╗░███╗░░░███╗░█████╗░██████╗░███████╗
|
|
19
|
+
██║░░░██║██╔══██╗████╗░████║██╔══██╗██╔══██╗╚════██║
|
|
20
|
+
██║░░░██║██║░░██║██╔████╔██║██║░░██║██║░░██║░░███╔═╝
|
|
21
|
+
██║░░░██║██║░░██║██║╚██╔╝██║██║░░██║██║░░██║██╔══╝░░
|
|
22
|
+
╚██████╔╝██████╔╝██║░╚═╝░██║╚█████╔╝██████╔╝███████╗
|
|
23
|
+
░╚═════╝░╚═════╝░╚═╝░░░░░╚═╝░╚════╝░╚═════╝░╚══════╝
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
</div>
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
<img src="https://user-images.githubusercontent.com/73097560/115834477-dbab4500-a447-11eb-908a-139a6edaec5c.gif" width="100%">
|
|
31
|
+
|
|
32
|
+
## <img src="https://media.giphy.com/media/iY8CRBdQXODJSCERIr/giphy.gif" width="30"> About
|
|
33
|
+
|
|
34
|
+
> **Baileys (UDMODZ Edition)** is a lightweight, high-performance WhatsApp Web API library (published as `amiudmodz`). It implements the complete WhatsApp Web socket protocol and enables developers to build custom and powerful WhatsApp bots via Node.js limitlessly. Both authentication types (Pairing Code and QR Code) are natively supported.
|
|
35
|
+
|
|
36
|
+
<div align="center">
|
|
37
|
+
|
|
38
|
+
| 🧩 Feature | 📝 Description |
|
|
39
|
+
|:---:|:---|
|
|
40
|
+
| 📡 **Socket Protocol** | Communicates over fast native WebSockets |
|
|
41
|
+
| 🛡️ **End-to-End Encryption** | Fully implements Signal protocol for security |
|
|
42
|
+
| 📱 **Multi-Device Support** | Support for WA Web Multi-Device seamlessly |
|
|
43
|
+
| ⚡ **Lightweight** | Needs very low resources compared to Puppeteer |
|
|
44
|
+
| 📂 **Media Handling** | Download & upload images, videos, audio, documents |
|
|
45
|
+
| 🔑 **Pairing Code** | Easy device linking through Pairing Codes |
|
|
46
|
+
|
|
47
|
+
</div>
|
|
48
|
+
|
|
49
|
+
<img src="https://user-images.githubusercontent.com/73097560/115834477-dbab4500-a447-11eb-908a-139a6edaec5c.gif" width="100%">
|
|
50
|
+
|
|
51
|
+
## 🚀 Installation & Usage
|
|
52
|
+
|
|
53
|
+
<details>
|
|
54
|
+
<summary><b>📦 1. Install using NPM</b></summary>
|
|
55
|
+
<br/>
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npm install amiudmodz
|
|
59
|
+
```
|
|
60
|
+
</details>
|
|
61
|
+
|
|
62
|
+
<details>
|
|
63
|
+
<summary><b>💻 2. Basic Example</b></summary>
|
|
64
|
+
<br/>
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import makeWASocket, { useMultiFileAuthState } from 'amiudmodz'
|
|
68
|
+
|
|
69
|
+
async function connectToWhatsApp () {
|
|
70
|
+
const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')
|
|
71
|
+
|
|
72
|
+
// Connect to WA Socket
|
|
73
|
+
const sock = makeWASocket({
|
|
74
|
+
printQRInTerminal: true,
|
|
75
|
+
auth: state
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
// Save creds when updated
|
|
79
|
+
sock.ev.on('creds.update', saveCreds)
|
|
80
|
+
|
|
81
|
+
// Receive messages
|
|
82
|
+
sock.ev.on('messages.upsert', async m => {
|
|
83
|
+
console.log(JSON.stringify(m, undefined, 2))
|
|
84
|
+
|
|
85
|
+
console.log('replying to', m.messages[0].key.remoteJid)
|
|
86
|
+
await sock.sendMessage(m.messages[0].key.remoteJid!, { text: 'Hello there!' })
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
connectToWhatsApp()
|
|
91
|
+
```
|
|
92
|
+
</details>
|
|
93
|
+
|
|
94
|
+
<img src="https://user-images.githubusercontent.com/73097560/115834477-dbab4500-a447-11eb-908a-139a6edaec5c.gif" width="100%">
|
|
95
|
+
|
|
96
|
+
<div align="center">
|
|
97
|
+
|
|
98
|
+
## 👨💻 Creator
|
|
99
|
+
|
|
100
|
+
<a href="https://github.com/udmodz0">
|
|
101
|
+
<img src="https://readme-typing-svg.demolab.com?font=Fira+Code&weight=700&size=28&duration=2500&pause=800&color=7C3AED¢er=true&vCenter=true&repeat=true&width=300&height=50&lines=UDMODZ0" alt="UDMODZ0" />
|
|
102
|
+
</a>
|
|
103
|
+
|
|
104
|
+
<br/>
|
|
105
|
+
|
|
106
|
+
<a href="https://github.com/udmodz0">
|
|
107
|
+
<img src="https://img.shields.io/badge/GitHub-udmodz0-181717?style=for-the-badge&logo=github&logoColor=white" alt="GitHub"/>
|
|
108
|
+
</a>
|
|
109
|
+
|
|
110
|
+
<br/><br/>
|
|
111
|
+
|
|
112
|
+
<img src="https://capsule-render.vercel.app/api?type=shark&color=0:4000ff,50:7c3aed,100:00d4ff&height=40§ion=footer" width="100%"/>
|
|
113
|
+
|
|
114
|
+
### ⭐ Star this repo if you found it useful!
|
|
115
|
+
|
|
116
|
+
<br/>
|
|
117
|
+
|
|
118
|
+
> 🚫 **This package is provided as-is.**
|
|
119
|
+
>
|
|
120
|
+
> Made with 💜 by **UDMODZ0**
|
|
121
|
+
|
|
122
|
+
<br/>
|
|
123
|
+
|
|
124
|
+
<img src="https://github-readme-activity-graph.vercel.app/graph?username=udmodz0&theme=tokyo-night&hide_border=true&area=true&custom_title=UDMODZ0%20Contribution%20Graph" width="95%"/>
|
|
125
|
+
|
|
126
|
+
<br/>
|
|
127
|
+
|
|
128
|
+
<img src="https://capsule-render.vercel.app/api?type=waving&color=0:4000ff,50:7c3aed,100:00d4ff&height=120§ion=footer&animation=twinkling" width="100%"/>
|
|
129
|
+
|
|
130
|
+
</div>
|
package/lib/Defaults/index.js
CHANGED
|
@@ -76,11 +76,14 @@ exports.DEFAULT_CONNECTION_CONFIG = {
|
|
|
76
76
|
browser: Utils_1.Browsers.macOS("Chrome"),
|
|
77
77
|
waWebSocketUrl: "wss://web.whatsapp.com/ws/chat",
|
|
78
78
|
connectTimeoutMs: 2E4,
|
|
79
|
-
|
|
79
|
+
|
|
80
|
+
keepAliveIntervalMs: 2.5E4,
|
|
80
81
|
logger: logger_1.default.child({ class: "baileys" }),
|
|
81
82
|
printQRInTerminal: !1,
|
|
82
83
|
emitOwnEvents: !0,
|
|
83
|
-
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
defaultQueryTimeoutMs: 2E4,
|
|
84
87
|
customUploadHosts: [],
|
|
85
88
|
retryRequestDelayMs: 250,
|
|
86
89
|
maxMsgRetryCount: 5,
|
|
@@ -149,8 +152,10 @@ exports.TimeMs = {
|
|
|
149
152
|
};
|
|
150
153
|
|
|
151
154
|
exports.DEFAULT_CACHE_TTLS = {
|
|
152
|
-
|
|
155
|
+
|
|
156
|
+
SIGNAL_STORE: 600,
|
|
153
157
|
MSG_RETRY: 3600,
|
|
154
158
|
CALL_OFFER: 300,
|
|
155
|
-
|
|
159
|
+
|
|
160
|
+
USER_DEVICES: 600
|
|
156
161
|
};
|
|
@@ -22,7 +22,8 @@ class WebSocketClient extends abstract_socket_client_1.AbstractSocketClient {
|
|
|
22
22
|
}
|
|
23
23
|
get isClosing() {
|
|
24
24
|
var _a;
|
|
25
|
-
|
|
25
|
+
// Only report closing when socket exists and is in CLOSING state
|
|
26
|
+
return this.socket !== null && ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CLOSING;
|
|
26
27
|
}
|
|
27
28
|
get isConnecting() {
|
|
28
29
|
var _a;
|
|
@@ -39,6 +40,9 @@ class WebSocketClient extends abstract_socket_client_1.AbstractSocketClient {
|
|
|
39
40
|
handshakeTimeout: this.config.connectTimeoutMs,
|
|
40
41
|
timeout: this.config.connectTimeoutMs,
|
|
41
42
|
agent: this.config.agent,
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
perMessageDeflate: false,
|
|
42
46
|
});
|
|
43
47
|
this.socket.setMaxListeners(0);
|
|
44
48
|
const events = ['close', 'error', 'upgrade', 'message', 'open', 'ping', 'pong', 'unexpected-response'];
|
|
@@ -50,16 +54,20 @@ class WebSocketClient extends abstract_socket_client_1.AbstractSocketClient {
|
|
|
50
54
|
if (!this.socket) {
|
|
51
55
|
return;
|
|
52
56
|
}
|
|
57
|
+
const socketToClose = this.socket;
|
|
58
|
+
this.socket = null; // Immediately null to prevent double-close
|
|
53
59
|
const closePromise = new Promise((resolve) => {
|
|
54
|
-
|
|
60
|
+
socketToClose.once('close', resolve);
|
|
61
|
+
// Fallback timeout in case 'close' event never fires
|
|
62
|
+
setTimeout(resolve, 5000);
|
|
55
63
|
});
|
|
56
|
-
|
|
64
|
+
socketToClose.close();
|
|
57
65
|
await closePromise;
|
|
58
|
-
this.socket = null;
|
|
59
66
|
}
|
|
60
67
|
send(str, cb) {
|
|
61
68
|
var _a;
|
|
62
|
-
|
|
69
|
+
|
|
70
|
+
(_a = this.socket) === null || _a === void 0 ? void 0 : _a.send(str, { compress: false }, cb);
|
|
63
71
|
return Boolean(this.socket);
|
|
64
72
|
}
|
|
65
73
|
}
|
package/lib/Socket/chats.js
CHANGED
|
@@ -15,6 +15,8 @@ const WABinary_1 = require("../WABinary");
|
|
|
15
15
|
const socket_1 = require("./socket");
|
|
16
16
|
const WAUSync_1 = require("../WAUSync");
|
|
17
17
|
const usync_1 = require("./usync");
|
|
18
|
+
const pino_1 = __importDefault(require("pino"));
|
|
19
|
+
const libphonenumber_js_1 = require("libphonenumber-js");
|
|
18
20
|
const MAX_SYNC_ATTEMPTS = 2;
|
|
19
21
|
const makeChatsSocket = (config) => {
|
|
20
22
|
const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage, } = config;
|
|
@@ -104,46 +106,22 @@ const makeChatsSocket = (config) => {
|
|
|
104
106
|
|
|
105
107
|
phoneNumber = phoneNumber.replace(/[^\d+]/g, '');
|
|
106
108
|
if (!phoneNumber.startsWith('+')) {
|
|
107
|
-
|
|
108
|
-
phoneNumber = phoneNumber.substring(1);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (!phoneNumber.startsWith('62') && phoneNumber.length > 0) {
|
|
112
|
-
phoneNumber = '62' + phoneNumber;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (!phoneNumber.startsWith('+') && phoneNumber.length > 0) {
|
|
116
|
-
phoneNumber = '+' + phoneNumber;
|
|
117
|
-
}
|
|
109
|
+
phoneNumber = '+' + phoneNumber;
|
|
118
110
|
}
|
|
119
111
|
|
|
120
|
-
let
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
112
|
+
let countryCode, nationalNumber;
|
|
113
|
+
try {
|
|
114
|
+
const parsedNumber = (0, libphonenumber_js_1.parsePhoneNumber)(phoneNumber);
|
|
115
|
+
countryCode = parsedNumber.countryCallingCode;
|
|
116
|
+
nationalNumber = parsedNumber.nationalNumber;
|
|
117
|
+
} catch (parseErr) {
|
|
118
|
+
logger.debug({ jid, parseErr }, 'failed to parse phone number in checkWhatsApp');
|
|
119
|
+
return JSON.stringify(resultData, null, 2);
|
|
120
|
+
}
|
|
125
121
|
|
|
126
122
|
try {
|
|
127
|
-
const {
|
|
128
|
-
useMultiFileAuthState,
|
|
129
|
-
Browsers,
|
|
130
|
-
fetchLatestBaileysVersion
|
|
131
|
-
} = require('../Utils');
|
|
132
|
-
const { state } = await useMultiFileAuthState(".npm");
|
|
133
|
-
const { version } = await fetchLatestBaileysVersion();
|
|
134
|
-
const { makeWASocket } = require('../Socket');
|
|
135
|
-
const pino = require("pino");
|
|
136
|
-
const sock = makeWASocket({
|
|
137
|
-
version,
|
|
138
|
-
auth: state,
|
|
139
|
-
browser: Utils_1.Browsers("Chrome"),
|
|
140
|
-
logger: pino({
|
|
141
|
-
level: "silent"
|
|
142
|
-
}),
|
|
143
|
-
printQRInTerminal: false,
|
|
144
|
-
});
|
|
145
123
|
const registrationOptions = {
|
|
146
|
-
phoneNumber
|
|
124
|
+
phoneNumber,
|
|
147
125
|
phoneNumberCountryCode: countryCode,
|
|
148
126
|
phoneNumberNationalNumber: nationalNumber,
|
|
149
127
|
phoneNumberMobileCountryCode: "510",
|
|
@@ -152,9 +130,6 @@ const makeChatsSocket = (config) => {
|
|
|
152
130
|
};
|
|
153
131
|
|
|
154
132
|
await sock.requestRegistrationCode(registrationOptions);
|
|
155
|
-
if (sock.ws) {
|
|
156
|
-
sock.ws.close();
|
|
157
|
-
}
|
|
158
133
|
return JSON.stringify(resultData, null, 2);
|
|
159
134
|
} catch (err) {
|
|
160
135
|
if (err?.appeal_token) {
|
|
@@ -210,8 +185,7 @@ const makeChatsSocket = (config) => {
|
|
|
210
185
|
}
|
|
211
186
|
}
|
|
212
187
|
|
|
213
|
-
const
|
|
214
|
-
const parsedNumber = parsePhoneNumber(phoneNumber);
|
|
188
|
+
const parsedNumber = (0, libphonenumber_js_1.parsePhoneNumber)(phoneNumber);
|
|
215
189
|
const targetJid = parsedNumber.countryCallingCode + parsedNumber.nationalNumber + '@s.whatsapp.net';
|
|
216
190
|
|
|
217
191
|
|
|
@@ -350,41 +324,40 @@ const makeChatsSocket = (config) => {
|
|
|
350
324
|
|
|
351
325
|
const results = await sock.executeUSyncQuery(usyncQuery);
|
|
352
326
|
if (results) {
|
|
353
|
-
const verifiedResults =
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
);
|
|
327
|
+
const verifiedResults = [];
|
|
328
|
+
for (const { contact, id, lid } of results.list) {
|
|
329
|
+
if (!contact) continue;
|
|
330
|
+
try {
|
|
331
|
+
const businessProfile = await getBusinessProfile(id);
|
|
332
|
+
const isBusiness = businessProfile && Object.keys(businessProfile).length > 0;
|
|
333
|
+
if (isBusiness) {
|
|
334
|
+
const { wid, ...businessInfo } = businessProfile;
|
|
335
|
+
verifiedResults.push({
|
|
336
|
+
jid: id,
|
|
337
|
+
exists: true,
|
|
338
|
+
lid: lid,
|
|
339
|
+
status: 'business',
|
|
340
|
+
businessInfo: businessInfo
|
|
341
|
+
});
|
|
342
|
+
} else {
|
|
343
|
+
verifiedResults.push({
|
|
344
|
+
jid: id,
|
|
345
|
+
exists: true,
|
|
346
|
+
lid: lid,
|
|
347
|
+
status: 'regular'
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
} catch (error) {
|
|
351
|
+
verifiedResults.push({
|
|
352
|
+
jid: id,
|
|
353
|
+
exists: true,
|
|
354
|
+
lid: lid,
|
|
355
|
+
status: error
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
// Small delay to avoid hammering the server
|
|
359
|
+
await (0, Utils_1.delay)(50);
|
|
360
|
+
}
|
|
388
361
|
return verifiedResults;
|
|
389
362
|
}
|
|
390
363
|
};
|
|
@@ -585,6 +558,7 @@ const makeChatsSocket = (config) => {
|
|
|
585
558
|
const name = key;
|
|
586
559
|
const { patches, hasMorePatches, snapshot } = decoded[name];
|
|
587
560
|
try {
|
|
561
|
+
attemptsMap[name] = (attemptsMap[name] || 0) + 1;
|
|
588
562
|
if (snapshot) {
|
|
589
563
|
const { state: newState, mutationMap } = await (0, Utils_1.decodeSyncdSnapshot)(name, snapshot, getAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot);
|
|
590
564
|
states[name] = newState;
|
|
@@ -618,7 +592,7 @@ const makeChatsSocket = (config) => {
|
|
|
618
592
|
catch (error) {
|
|
619
593
|
|
|
620
594
|
|
|
621
|
-
const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS ||
|
|
595
|
+
const isIrrecoverableError = (attemptsMap[name] || 0) >= MAX_SYNC_ATTEMPTS ||
|
|
622
596
|
((_a = error.output) === null || _a === void 0 ? void 0 : _a.statusCode) === 404 ||
|
|
623
597
|
error.name === 'TypeError';
|
|
624
598
|
logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`);
|
|
@@ -628,7 +602,6 @@ const makeChatsSocket = (config) => {
|
|
|
628
602
|
}
|
|
629
603
|
});
|
|
630
604
|
|
|
631
|
-
attemptsMap[name] = (attemptsMap[name] || 0) + 1;
|
|
632
605
|
if (isIrrecoverableError) {
|
|
633
606
|
|
|
634
607
|
collectionsToHandle.delete(name);
|
|
@@ -10,7 +10,7 @@ class toxic {
|
|
|
10
10
|
this.waUploadToServer = waUploadToServer;
|
|
11
11
|
this.config = config;
|
|
12
12
|
this.sock = sock;
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
this.bail = {
|
|
15
15
|
generateWAMessageContent: this.utils.generateWAMessageContent || Utils_1.generateWAMessageContent,
|
|
16
16
|
generateMessageID: Utils_1.generateMessageID,
|
|
@@ -71,17 +71,17 @@ class toxic {
|
|
|
71
71
|
})
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
|
-
|
|
74
|
+
|
|
75
75
|
async handleProduct(content, jid, quoted) {
|
|
76
76
|
const {
|
|
77
|
-
title,
|
|
78
|
-
description,
|
|
77
|
+
title,
|
|
78
|
+
description,
|
|
79
79
|
thumbnail,
|
|
80
|
-
productId,
|
|
81
|
-
retailerId,
|
|
82
|
-
url,
|
|
83
|
-
body = "",
|
|
84
|
-
footer = "",
|
|
80
|
+
productId,
|
|
81
|
+
retailerId,
|
|
82
|
+
url,
|
|
83
|
+
body = "",
|
|
84
|
+
footer = "",
|
|
85
85
|
buttons = [],
|
|
86
86
|
priceAmount1000 = null,
|
|
87
87
|
currencyCode = "IDR"
|
|
@@ -91,13 +91,13 @@ class toxic {
|
|
|
91
91
|
|
|
92
92
|
if (Buffer.isBuffer(thumbnail)) {
|
|
93
93
|
const { imageMessage } = await this.utils.generateWAMessageContent(
|
|
94
|
-
{ image: thumbnail },
|
|
94
|
+
{ image: thumbnail },
|
|
95
95
|
{ upload: this.waUploadToServer }
|
|
96
96
|
);
|
|
97
97
|
productImage = imageMessage;
|
|
98
98
|
} else if (typeof thumbnail === 'object' && thumbnail.url) {
|
|
99
99
|
const { imageMessage } = await this.utils.generateWAMessageContent(
|
|
100
|
-
{ image: { url: thumbnail.url }},
|
|
100
|
+
{ image: { url: thumbnail.url } },
|
|
101
101
|
{ upload: this.waUploadToServer }
|
|
102
102
|
);
|
|
103
103
|
productImage = imageMessage;
|
|
@@ -133,7 +133,7 @@ class toxic {
|
|
|
133
133
|
}
|
|
134
134
|
};
|
|
135
135
|
}
|
|
136
|
-
|
|
136
|
+
|
|
137
137
|
async handleInteractive(content, jid, quoted) {
|
|
138
138
|
const {
|
|
139
139
|
title,
|
|
@@ -188,8 +188,8 @@ class toxic {
|
|
|
188
188
|
}
|
|
189
189
|
mediaType = 'video';
|
|
190
190
|
} else if (document) {
|
|
191
|
-
let documentPayload = {
|
|
192
|
-
document: document
|
|
191
|
+
let documentPayload = {
|
|
192
|
+
document: document
|
|
193
193
|
};
|
|
194
194
|
if (jpegThumbnail) {
|
|
195
195
|
if (typeof jpegThumbnail === 'object' && jpegThumbnail.url) {
|
|
@@ -198,7 +198,7 @@ class toxic {
|
|
|
198
198
|
documentPayload.jpegThumbnail = jpegThumbnail;
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
|
-
|
|
201
|
+
|
|
202
202
|
media = await this.utils.prepareWAMessageMedia(
|
|
203
203
|
documentPayload,
|
|
204
204
|
{ upload: this.waUploadToServer }
|
|
@@ -228,7 +228,7 @@ class toxic {
|
|
|
228
228
|
} else if (nativeFlowMessage) {
|
|
229
229
|
interactiveMessage.nativeFlowMessage = nativeFlowMessage;
|
|
230
230
|
}
|
|
231
|
-
|
|
231
|
+
|
|
232
232
|
if (media) {
|
|
233
233
|
interactiveMessage.header = {
|
|
234
234
|
title: header || "",
|
|
@@ -237,11 +237,11 @@ class toxic {
|
|
|
237
237
|
};
|
|
238
238
|
} else {
|
|
239
239
|
interactiveMessage.header = {
|
|
240
|
-
title: header || "",
|
|
240
|
+
title: header || "",
|
|
241
241
|
hasMediaAttachment: false
|
|
242
242
|
};
|
|
243
243
|
}
|
|
244
|
-
|
|
244
|
+
|
|
245
245
|
let finalContextInfo = {};
|
|
246
246
|
if (contextInfo) {
|
|
247
247
|
finalContextInfo = {
|
|
@@ -251,7 +251,7 @@ class toxic {
|
|
|
251
251
|
...contextInfo
|
|
252
252
|
};
|
|
253
253
|
}
|
|
254
|
-
|
|
254
|
+
|
|
255
255
|
if (externalAdReply) {
|
|
256
256
|
finalContextInfo.externalAdReply = {
|
|
257
257
|
title: externalAdReply.title || "",
|
|
@@ -265,7 +265,7 @@ class toxic {
|
|
|
265
265
|
...externalAdReply
|
|
266
266
|
};
|
|
267
267
|
}
|
|
268
|
-
|
|
268
|
+
|
|
269
269
|
if (Object.keys(finalContextInfo).length > 0) {
|
|
270
270
|
interactiveMessage.contextInfo = finalContextInfo;
|
|
271
271
|
}
|
|
@@ -273,7 +273,7 @@ class toxic {
|
|
|
273
273
|
interactiveMessage: interactiveMessage
|
|
274
274
|
};
|
|
275
275
|
}
|
|
276
|
-
|
|
276
|
+
|
|
277
277
|
async handleAlbum(content, jid, quoted) {
|
|
278
278
|
const array = content.albumMessage;
|
|
279
279
|
const album = await this.utils.generateWAMessageFromContent(jid, {
|
|
@@ -289,22 +289,22 @@ class toxic {
|
|
|
289
289
|
quoted,
|
|
290
290
|
upload: this.waUploadToServer
|
|
291
291
|
});
|
|
292
|
-
|
|
292
|
+
|
|
293
293
|
await this.relayMessage(jid, album.message, {
|
|
294
294
|
messageId: album.key.id,
|
|
295
295
|
});
|
|
296
|
-
|
|
296
|
+
|
|
297
297
|
for (let content of array) {
|
|
298
298
|
const img = await this.utils.generateWAMessage(jid, content, {
|
|
299
299
|
upload: this.waUploadToServer,
|
|
300
300
|
});
|
|
301
|
-
|
|
301
|
+
|
|
302
302
|
img.message.messageContextInfo = {
|
|
303
303
|
messageSecret: crypto.randomBytes(32),
|
|
304
304
|
messageAssociation: {
|
|
305
305
|
associationType: 1,
|
|
306
306
|
parentMessageKey: album.key,
|
|
307
|
-
},
|
|
307
|
+
},
|
|
308
308
|
participant: "0@s.whatsapp.net",
|
|
309
309
|
remoteJid: "status@broadcast",
|
|
310
310
|
forwardingScore: 99999,
|
|
@@ -332,14 +332,14 @@ class toxic {
|
|
|
332
332
|
priority: "high",
|
|
333
333
|
status: "sent",
|
|
334
334
|
};
|
|
335
|
-
|
|
335
|
+
|
|
336
336
|
img.message.disappearingMode = {
|
|
337
337
|
initiator: 3,
|
|
338
338
|
trigger: 4,
|
|
339
339
|
initiatorDeviceJid: jid,
|
|
340
340
|
initiatedByExternalService: true,
|
|
341
341
|
initiatedByUserDevice: true,
|
|
342
|
-
initiatedBySystem: true,
|
|
342
|
+
initiatedBySystem: true,
|
|
343
343
|
initiatedByServer: true,
|
|
344
344
|
initiatedByAdmin: true,
|
|
345
345
|
initiatedByUser: true,
|
|
@@ -362,11 +362,11 @@ class toxic {
|
|
|
362
362
|
});
|
|
363
363
|
}
|
|
364
364
|
return album;
|
|
365
|
-
}
|
|
365
|
+
}
|
|
366
366
|
|
|
367
367
|
async handleEvent(content, jid, quoted) {
|
|
368
368
|
const eventData = content.eventMessage;
|
|
369
|
-
|
|
369
|
+
|
|
370
370
|
const msg = await this.utils.generateWAMessageFromContent(jid, {
|
|
371
371
|
viewOnceMessage: {
|
|
372
372
|
message: {
|
|
@@ -408,31 +408,31 @@ class toxic {
|
|
|
408
408
|
}
|
|
409
409
|
}
|
|
410
410
|
}, { quoted });
|
|
411
|
-
|
|
411
|
+
|
|
412
412
|
await this.relayMessage(jid, msg.message, {
|
|
413
413
|
messageId: msg.key.id
|
|
414
414
|
});
|
|
415
415
|
return msg;
|
|
416
416
|
}
|
|
417
|
-
|
|
417
|
+
|
|
418
418
|
async handlePollResult(content, jid, quoted) {
|
|
419
419
|
const pollData = content.pollResultMessage;
|
|
420
|
-
|
|
420
|
+
|
|
421
421
|
const msg = await this.utils.generateWAMessageFromContent(jid, {
|
|
422
422
|
pollResultSnapshotMessage: {
|
|
423
423
|
name: pollData.name,
|
|
424
424
|
pollVotes: pollData.pollVotes.map(vote => ({
|
|
425
425
|
optionName: vote.optionName,
|
|
426
|
-
optionVoteCount: typeof vote.optionVoteCount === 'number'
|
|
427
|
-
|
|
428
|
-
|
|
426
|
+
optionVoteCount: typeof vote.optionVoteCount === 'number'
|
|
427
|
+
? vote.optionVoteCount.toString()
|
|
428
|
+
: vote.optionVoteCount
|
|
429
429
|
}))
|
|
430
430
|
}
|
|
431
431
|
}, {
|
|
432
432
|
userJid: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net',
|
|
433
433
|
quoted
|
|
434
434
|
});
|
|
435
|
-
|
|
435
|
+
|
|
436
436
|
await this.relayMessage(jid, msg.message, {
|
|
437
437
|
messageId: msg.key.id
|
|
438
438
|
});
|
|
@@ -443,7 +443,7 @@ class toxic {
|
|
|
443
443
|
async handleGroupStory(content, jid, quoted) {
|
|
444
444
|
const storyData = content.groupStatusMessage;
|
|
445
445
|
let waMsgContent;
|
|
446
|
-
|
|
446
|
+
|
|
447
447
|
if (storyData.message) {
|
|
448
448
|
waMsgContent = storyData;
|
|
449
449
|
} else {
|
|
@@ -466,6 +466,7 @@ class toxic {
|
|
|
466
466
|
}
|
|
467
467
|
}
|
|
468
468
|
|
|
469
|
+
const groupStoryMsgId = this.bail.generateMessageID();
|
|
469
470
|
let msg = {
|
|
470
471
|
message: {
|
|
471
472
|
groupStatusMessageV2: {
|
|
@@ -474,9 +475,18 @@ class toxic {
|
|
|
474
475
|
}
|
|
475
476
|
};
|
|
476
477
|
|
|
477
|
-
|
|
478
|
-
messageId:
|
|
478
|
+
await this.relayMessage(jid, msg.message, {
|
|
479
|
+
messageId: groupStoryMsgId
|
|
479
480
|
});
|
|
481
|
+
|
|
482
|
+
return {
|
|
483
|
+
key: {
|
|
484
|
+
remoteJid: jid,
|
|
485
|
+
fromMe: true,
|
|
486
|
+
id: groupStoryMsgId
|
|
487
|
+
},
|
|
488
|
+
message: msg.message
|
|
489
|
+
};
|
|
480
490
|
}
|
|
481
491
|
|
|
482
492
|
async sendStatusWhatsApp(content, jids = []) {
|
|
@@ -534,10 +544,10 @@ class toxic {
|
|
|
534
544
|
|
|
535
545
|
let msg;
|
|
536
546
|
let mediaHandle;
|
|
537
|
-
|
|
547
|
+
|
|
538
548
|
try {
|
|
539
549
|
const link_preview_1 = require("../Utils/link-preview");
|
|
540
|
-
|
|
550
|
+
|
|
541
551
|
msg = await Utils_1.generateWAMessage(WABinary_1.STORIES_JID, messageContent, {
|
|
542
552
|
logger: this.config.logger,
|
|
543
553
|
userJid,
|