wertybailz 1.0.5 → 1.0.7
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 +201 -179
- package/lib/index.js +15 -7
- package/package.json +1 -1
- package/lib/Socket/newsletter.js +0 -260
package/README.md
CHANGED
|
@@ -1,299 +1,321 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# wertybailz
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/wertybailz)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
[](https://www.npmjs.com/package/wertybailz)
|
|
8
|
+
|
|
9
|
+
**A modern WhatsApp socket wrapper with extended messaging capabilities.**
|
|
3
10
|
|
|
4
|
-
[](https://www.npmjs.com/package/xzcbailz)
|
|
5
|
-
[](LICENSE)
|
|
6
|
-
[](https://www.npmjs.com/package/xzcbailz)
|
|
7
11
|
</div>
|
|
8
12
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install wertybailz
|
|
14
19
|
```
|
|
15
|
-
---
|
|
16
20
|
|
|
17
|
-
|
|
21
|
+
Or declare in `package.json`:
|
|
22
|
+
|
|
18
23
|
```json
|
|
19
|
-
"
|
|
20
|
-
"
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"wertybailz": "latest"
|
|
21
26
|
}
|
|
22
27
|
```
|
|
28
|
+
|
|
23
29
|
## Import
|
|
30
|
+
|
|
24
31
|
```javascript
|
|
25
32
|
const {
|
|
26
33
|
default: makeWASocket,
|
|
27
|
-
//
|
|
28
|
-
} = require('
|
|
34
|
+
// other exports
|
|
35
|
+
} = require('wertybailz');
|
|
29
36
|
```
|
|
30
37
|
|
|
31
38
|
---
|
|
32
|
-
|
|
33
|
-
##
|
|
39
|
+
|
|
40
|
+
## Connecting to WhatsApp
|
|
41
|
+
|
|
42
|
+
### Via QR Code
|
|
43
|
+
|
|
34
44
|
```javascript
|
|
35
|
-
const {
|
|
36
|
-
default: makeWASocket
|
|
37
|
-
} = require('xzcbailz');
|
|
45
|
+
const { default: makeWASocket } = require('wertybailz');
|
|
38
46
|
|
|
39
47
|
const client = makeWASocket({
|
|
40
48
|
browser: ['Ubuntu', 'Chrome', '20.00.1'],
|
|
41
|
-
printQRInTerminal: true
|
|
42
|
-
})
|
|
49
|
+
printQRInTerminal: true,
|
|
50
|
+
});
|
|
43
51
|
```
|
|
44
52
|
|
|
45
|
-
|
|
53
|
+
### Via Pairing Code
|
|
54
|
+
|
|
46
55
|
```javascript
|
|
47
56
|
const {
|
|
48
57
|
default: makeWASocket,
|
|
49
|
-
fetchLatestWAWebVersion
|
|
50
|
-
} = require('
|
|
58
|
+
fetchLatestWAWebVersion,
|
|
59
|
+
} = require('wertybailz');
|
|
51
60
|
|
|
52
61
|
const client = makeWASocket({
|
|
53
62
|
browser: ['Ubuntu', 'Chrome', '20.00.1'],
|
|
54
63
|
printQRInTerminal: false,
|
|
55
|
-
version: fetchLatestWAWebVersion()
|
|
56
|
-
aiLabel: true //
|
|
57
|
-
// Other options
|
|
64
|
+
version: fetchLatestWAWebVersion(),
|
|
65
|
+
aiLabel: true, // attaches AI label to outgoing bot messages
|
|
58
66
|
});
|
|
59
67
|
|
|
60
|
-
const number =
|
|
61
|
-
const code = await client.requestPairingCode(number.trim
|
|
68
|
+
const number = '628XXXXXXXXX';
|
|
69
|
+
const code = await client.requestPairingCode(number.trim());
|
|
70
|
+
// For a custom pairing code: client.requestPairingCode(number, 'CUSTOMCODE')
|
|
62
71
|
|
|
63
|
-
console.log(
|
|
72
|
+
console.log('Pairing code:', code);
|
|
64
73
|
```
|
|
65
74
|
|
|
66
|
-
|
|
67
|
-
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Store / Session Data
|
|
78
|
+
|
|
79
|
+
```javascript
|
|
68
80
|
const {
|
|
69
81
|
default: makeWASocket,
|
|
70
|
-
makeInMemoryStore
|
|
71
|
-
} = require('
|
|
82
|
+
makeInMemoryStore,
|
|
83
|
+
} = require('wertybailz');
|
|
72
84
|
const pino = require('pino');
|
|
73
85
|
|
|
74
86
|
const store = makeInMemoryStore({
|
|
75
|
-
logger: pino().child({ level: 'silent', stream: 'store' })
|
|
87
|
+
logger: pino().child({ level: 'silent', stream: 'store' }),
|
|
76
88
|
});
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
store.bind(client.ev)
|
|
89
|
+
|
|
90
|
+
const client = makeWASocket({ /* options */ });
|
|
91
|
+
|
|
92
|
+
store.bind(client.ev);
|
|
81
93
|
|
|
82
94
|
client.ev.on('contacts.upsert', () => {
|
|
83
|
-
console.log('
|
|
84
|
-
})
|
|
95
|
+
console.log('New contacts:', Object.values(store.contacts()));
|
|
96
|
+
});
|
|
85
97
|
```
|
|
86
|
-
# Sending messages
|
|
87
98
|
|
|
88
|
-
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## Sending Messages
|
|
102
|
+
|
|
103
|
+
### Order Message
|
|
104
|
+
|
|
89
105
|
```javascript
|
|
90
106
|
const fs = require('fs');
|
|
91
|
-
const
|
|
107
|
+
const thumbnail = fs.readFileSync('./thumbnail.png');
|
|
92
108
|
|
|
93
109
|
await client.sendMessage(m.chat, {
|
|
94
|
-
thumbnail
|
|
95
|
-
message:
|
|
96
|
-
orderTitle:
|
|
97
|
-
totalAmount1000:
|
|
98
|
-
totalCurrencyCode:
|
|
99
|
-
}, { quoted:m })
|
|
110
|
+
thumbnail,
|
|
111
|
+
message: 'Your order summary',
|
|
112
|
+
orderTitle: 'My Store',
|
|
113
|
+
totalAmount1000: 72500,
|
|
114
|
+
totalCurrencyCode: 'IDR',
|
|
115
|
+
}, { quoted: m });
|
|
100
116
|
```
|
|
101
117
|
|
|
102
|
-
|
|
118
|
+
### Poll Result Snapshot
|
|
119
|
+
|
|
103
120
|
```javascript
|
|
104
121
|
await client.sendMessage(m.chat, {
|
|
105
122
|
pollResultMessage: {
|
|
106
|
-
name:
|
|
123
|
+
name: 'Survey Title',
|
|
107
124
|
options: [
|
|
108
|
-
{
|
|
109
|
-
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
optionName: "poll 2"
|
|
113
|
-
}
|
|
125
|
+
{ optionName: 'Option A' },
|
|
126
|
+
{ optionName: 'Option B' },
|
|
114
127
|
],
|
|
115
128
|
newsletter: {
|
|
116
|
-
newsletterName:
|
|
117
|
-
newsletterJid:
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
})
|
|
129
|
+
newsletterName: 'My Channel',
|
|
130
|
+
newsletterJid: '1@newsletter',
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
});
|
|
121
134
|
```
|
|
122
135
|
|
|
123
|
-
|
|
136
|
+
### Product Message
|
|
137
|
+
|
|
124
138
|
```javascript
|
|
125
139
|
await client.relayMessage(m.chat, {
|
|
126
|
-
productMessage {
|
|
127
|
-
title:
|
|
128
|
-
description:
|
|
129
|
-
thumbnail: { url:
|
|
130
|
-
productId:
|
|
131
|
-
retailerId:
|
|
132
|
-
url:
|
|
133
|
-
body:
|
|
134
|
-
footer:
|
|
140
|
+
productMessage: {
|
|
141
|
+
title: 'Product Name',
|
|
142
|
+
description: 'Short product description.',
|
|
143
|
+
thumbnail: { url: './product.jpg' },
|
|
144
|
+
productId: 'PRODUCT_ID',
|
|
145
|
+
retailerId: 'RETAILER_ID',
|
|
146
|
+
url: 'https://example.com/product',
|
|
147
|
+
body: 'Body text',
|
|
148
|
+
footer: 'Footer text',
|
|
135
149
|
buttons: [
|
|
136
150
|
{
|
|
137
|
-
name:
|
|
138
|
-
buttonParamsJson:
|
|
139
|
-
|
|
151
|
+
name: 'cta_url',
|
|
152
|
+
buttonParamsJson: JSON.stringify({
|
|
153
|
+
display_text: 'View Product',
|
|
154
|
+
url: 'https://example.com/product',
|
|
155
|
+
}),
|
|
156
|
+
},
|
|
140
157
|
],
|
|
141
|
-
priceAmount1000:
|
|
142
|
-
currencyCode:
|
|
143
|
-
}
|
|
144
|
-
})
|
|
158
|
+
priceAmount1000: 72500,
|
|
159
|
+
currencyCode: 'IDR',
|
|
160
|
+
},
|
|
161
|
+
});
|
|
145
162
|
```
|
|
146
163
|
|
|
147
|
-
|
|
164
|
+
### Group Member Label
|
|
165
|
+
|
|
148
166
|
```javascript
|
|
149
167
|
await client.sendMessage(m.chat, {
|
|
150
168
|
groupLabel: {
|
|
151
|
-
labelText:
|
|
152
|
-
}
|
|
153
|
-
})
|
|
169
|
+
labelText: 'Tag group members here',
|
|
170
|
+
},
|
|
171
|
+
});
|
|
154
172
|
```
|
|
155
173
|
|
|
156
|
-
|
|
174
|
+
### Message to All Group Members
|
|
175
|
+
|
|
157
176
|
```javascript
|
|
158
177
|
await client.sendMessageMembers(m.chat, {
|
|
159
178
|
extendedTextMessage: {
|
|
160
|
-
text:
|
|
161
|
-
}
|
|
162
|
-
}, {})
|
|
179
|
+
text: 'Hello everyone!',
|
|
180
|
+
},
|
|
181
|
+
}, {});
|
|
163
182
|
```
|
|
164
|
-
# Simple sendMessage
|
|
165
183
|
|
|
166
|
-
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## Simple Send Helpers
|
|
187
|
+
|
|
188
|
+
All helpers below support an optional `contextInfo` and `quoted` object.
|
|
189
|
+
|
|
190
|
+
### Text
|
|
191
|
+
|
|
167
192
|
```javascript
|
|
168
|
-
await client.sendText(m.chat,
|
|
169
|
-
contextInfo: {
|
|
170
|
-
mentionedJid: [m.chat]
|
|
171
|
-
}
|
|
193
|
+
await client.sendText(m.chat, 'Hello world!', {
|
|
194
|
+
contextInfo: { mentionedJid: [m.chat] },
|
|
172
195
|
}, {
|
|
173
196
|
key: {
|
|
174
|
-
remoteJid:
|
|
197
|
+
remoteJid: 'status@broadcast',
|
|
175
198
|
participant: m.sender,
|
|
176
|
-
fromMe: true
|
|
199
|
+
fromMe: true,
|
|
177
200
|
},
|
|
178
|
-
message: {
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
})
|
|
201
|
+
message: { conversation: '\0' },
|
|
202
|
+
});
|
|
182
203
|
```
|
|
183
|
-
|
|
204
|
+
|
|
205
|
+
### Image
|
|
206
|
+
|
|
184
207
|
```javascript
|
|
185
|
-
await client.sendImage(m.chat, { url:
|
|
186
|
-
contextInfo: {
|
|
187
|
-
mentionedJid: [m.chat]
|
|
188
|
-
}
|
|
208
|
+
await client.sendImage(m.chat, { url: './image.jpg' }, 'Caption here', {
|
|
209
|
+
contextInfo: { mentionedJid: [m.chat] },
|
|
189
210
|
}, {
|
|
190
211
|
key: {
|
|
191
|
-
remoteJid:
|
|
212
|
+
remoteJid: 'status@broadcast',
|
|
192
213
|
participant: m.sender,
|
|
193
|
-
fromMe: true
|
|
214
|
+
fromMe: true,
|
|
194
215
|
},
|
|
195
|
-
message: {
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
})
|
|
216
|
+
message: { conversation: '\0' },
|
|
217
|
+
});
|
|
199
218
|
```
|
|
200
219
|
|
|
201
|
-
|
|
220
|
+
### Video
|
|
221
|
+
|
|
202
222
|
```javascript
|
|
203
|
-
await client.sendVideo(m.chat, { url:
|
|
204
|
-
contextInfo: {
|
|
205
|
-
mentionedJid: [m.chat]
|
|
206
|
-
}
|
|
223
|
+
await client.sendVideo(m.chat, { url: './video.mp4' }, 'Caption here', {
|
|
224
|
+
contextInfo: { mentionedJid: [m.chat] },
|
|
207
225
|
}, {
|
|
208
226
|
key: {
|
|
209
|
-
remoteJid:
|
|
227
|
+
remoteJid: 'status@broadcast',
|
|
210
228
|
participant: m.sender,
|
|
211
|
-
fromMe: true
|
|
229
|
+
fromMe: true,
|
|
212
230
|
},
|
|
213
|
-
message: {
|
|
214
|
-
|
|
215
|
-
}
|
|
216
|
-
})
|
|
231
|
+
message: { conversation: '\0' },
|
|
232
|
+
});
|
|
217
233
|
```
|
|
218
234
|
|
|
219
|
-
|
|
235
|
+
### Audio
|
|
236
|
+
|
|
220
237
|
```javascript
|
|
221
|
-
await client.sendAudio(m.chat, { url:
|
|
222
|
-
contextInfo: {
|
|
223
|
-
mentionedJid: [m.chat]
|
|
224
|
-
}
|
|
238
|
+
await client.sendAudio(m.chat, { url: './audio.mp3' }, {
|
|
239
|
+
contextInfo: { mentionedJid: [m.chat] },
|
|
225
240
|
}, {
|
|
226
241
|
key: {
|
|
227
|
-
remoteJid:
|
|
242
|
+
remoteJid: 'status@broadcast',
|
|
228
243
|
participant: m.sender,
|
|
229
|
-
fromMe: true
|
|
244
|
+
fromMe: true,
|
|
230
245
|
},
|
|
231
|
-
message: {
|
|
232
|
-
|
|
233
|
-
}
|
|
234
|
-
})
|
|
246
|
+
message: { conversation: '\0' },
|
|
247
|
+
});
|
|
235
248
|
```
|
|
236
249
|
|
|
237
|
-
|
|
250
|
+
### Location
|
|
251
|
+
|
|
238
252
|
```javascript
|
|
239
|
-
await client.sendLocation(
|
|
240
|
-
|
|
241
|
-
|
|
253
|
+
await client.sendLocation(
|
|
254
|
+
m.chat,
|
|
255
|
+
'Location Name',
|
|
256
|
+
-6.2, 106.8, // latitude, longitude
|
|
257
|
+
'https://maps.example.com',
|
|
258
|
+
'6281234567890',
|
|
259
|
+
{ contextInfo: { mentionedJid: [m.chat] } },
|
|
260
|
+
{
|
|
261
|
+
key: {
|
|
262
|
+
remoteJid: 'status@broadcast',
|
|
263
|
+
participant: m.sender,
|
|
264
|
+
fromMe: true,
|
|
265
|
+
},
|
|
266
|
+
message: { conversation: '\0' },
|
|
242
267
|
}
|
|
243
|
-
|
|
244
|
-
key: {
|
|
245
|
-
remoteJid: "status@broadcast",
|
|
246
|
-
participant: m.sender,
|
|
247
|
-
fromMe: true
|
|
248
|
-
},
|
|
249
|
-
message: {
|
|
250
|
-
conversation: "\0"
|
|
251
|
-
}
|
|
252
|
-
})
|
|
268
|
+
);
|
|
253
269
|
```
|
|
254
270
|
|
|
255
|
-
|
|
271
|
+
### Poll
|
|
272
|
+
|
|
256
273
|
```javascript
|
|
257
|
-
await client.sendPoll(m.chat,
|
|
258
|
-
contextInfo: {
|
|
259
|
-
mentionedJid: [m.chat]
|
|
260
|
-
}
|
|
274
|
+
await client.sendPoll(m.chat, 'Your question?', ['Option 1', 'Option 2', 'Option 3'], true, {
|
|
275
|
+
contextInfo: { mentionedJid: [m.chat] },
|
|
261
276
|
}, {
|
|
262
277
|
key: {
|
|
263
|
-
remoteJid:
|
|
278
|
+
remoteJid: 'status@broadcast',
|
|
264
279
|
participant: m.sender,
|
|
265
|
-
fromMe: true
|
|
280
|
+
fromMe: true,
|
|
266
281
|
},
|
|
267
|
-
message: {
|
|
268
|
-
|
|
269
|
-
}
|
|
270
|
-
})
|
|
282
|
+
message: { conversation: '\0' },
|
|
283
|
+
});
|
|
271
284
|
```
|
|
272
285
|
|
|
273
|
-
|
|
286
|
+
### Quiz
|
|
287
|
+
|
|
274
288
|
```javascript
|
|
275
|
-
await client.sendQuiz(
|
|
276
|
-
|
|
277
|
-
|
|
289
|
+
await client.sendQuiz(
|
|
290
|
+
m.chat,
|
|
291
|
+
'Which is correct?',
|
|
292
|
+
['Answer A', 'Answer B', 'Answer C'],
|
|
293
|
+
'Answer B', // correct answer
|
|
294
|
+
{ contextInfo: { mentionedJid: [m.chat] } },
|
|
295
|
+
{
|
|
296
|
+
key: {
|
|
297
|
+
remoteJid: 'status@broadcast',
|
|
298
|
+
participant: m.sender,
|
|
299
|
+
fromMe: true,
|
|
300
|
+
},
|
|
301
|
+
message: { conversation: '\0' },
|
|
278
302
|
}
|
|
279
|
-
|
|
280
|
-
key: {
|
|
281
|
-
remoteJid: "status@broadcast",
|
|
282
|
-
participant: m.sender,
|
|
283
|
-
fromMe: true
|
|
284
|
-
},
|
|
285
|
-
message: {
|
|
286
|
-
conversation: "\0"
|
|
287
|
-
}
|
|
288
|
-
})
|
|
303
|
+
);
|
|
289
304
|
```
|
|
290
305
|
|
|
291
|
-
|
|
306
|
+
### Status Mention
|
|
307
|
+
|
|
292
308
|
```javascript
|
|
293
309
|
await client.statusMention(m.chat, {
|
|
294
310
|
extendedTextMessage: {
|
|
295
|
-
text:
|
|
296
|
-
}
|
|
297
|
-
})
|
|
311
|
+
text: 'Mentioned in status!',
|
|
312
|
+
},
|
|
313
|
+
});
|
|
298
314
|
```
|
|
299
|
-
|
|
315
|
+
|
|
316
|
+
---
|
|
317
|
+
|
|
318
|
+
## License
|
|
319
|
+
|
|
320
|
+
[GPL-3.0](LICENSE)
|
|
321
|
+
|
package/lib/index.js
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import makeWASocket from './Socket/index.js';
|
|
2
2
|
import chalk from "chalk";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
|
|
4
|
+
const primary = chalk.hex("#6f00ff").bold;
|
|
5
|
+
const secondary = chalk.hex("#a855f7");
|
|
6
|
+
const muted = chalk.hex("#7c3aed");
|
|
7
|
+
|
|
8
|
+
console.log(primary(`
|
|
9
|
+
▄ ▄ █▀▀ █▀█ ▀█▀ █ █ █▀▄ ▄▀▄ █ █ ▀▀█
|
|
10
|
+
█▀█ █▀ █▀▄ █ █ █▀▄ █▀█ █ █ ▄█
|
|
11
|
+
▀ ▀ ▀▀▀ ▀ ▀ ▀ ▀ ▀▀ ▀ ▀ ▀ ▀▀▀ █▀▀
|
|
7
12
|
`));
|
|
8
|
-
console.log(
|
|
9
|
-
console.log(
|
|
13
|
+
console.log(secondary(" WhatsApp Web Socket Library"));
|
|
14
|
+
console.log(muted(" wertybailz · npm install wertybailz\n"));
|
|
15
|
+
|
|
10
16
|
export * from '../WAProto/index.js';
|
|
11
17
|
export * from './Utils/index.js';
|
|
12
18
|
export * from './Types/index.js';
|
|
@@ -17,4 +23,6 @@ export * from './WAUSync/index.js';
|
|
|
17
23
|
export * from './Store/index.js';
|
|
18
24
|
export { makeWASocket };
|
|
19
25
|
export default makeWASocket;
|
|
20
|
-
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
28
|
+
|
package/package.json
CHANGED
package/lib/Socket/newsletter.js
DELETED
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
import { XWAPaths } from '../Types/index.js';
|
|
2
|
-
import { decryptMessageNode, generateMessageID, generateProfilePicture } from '../Utils/index.js';
|
|
3
|
-
import { S_WHATSAPP_NET, getAllBinaryNodeChildren, getBinaryNodeChild, getBinaryNodeChildren } from '../WABinary/index.js';
|
|
4
|
-
import { makeGroupsSocket } from './groups.js';
|
|
5
|
-
|
|
6
|
-
const QueryIds = {
|
|
7
|
-
JOB_MUTATION: "7150902998257522",
|
|
8
|
-
METADATA: "6620195908089573",
|
|
9
|
-
UNFOLLOW: "7238632346214362",
|
|
10
|
-
FOLLOW: "7871414976211147",
|
|
11
|
-
UNMUTE: "7337137176362961",
|
|
12
|
-
MUTE: "25151904754424642",
|
|
13
|
-
CREATE: "6996806640408138",
|
|
14
|
-
ADMIN_COUNT: "7130823597031706",
|
|
15
|
-
CHANGE_OWNER: "7341777602580933",
|
|
16
|
-
DELETE: "8316537688363079",
|
|
17
|
-
DEMOTE: "6551828931592903"
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const makeNewsletterSocket = (config) => {
|
|
21
|
-
const sock = makeGroupsSocket(config);
|
|
22
|
-
const { authState, signalRepository, query, generateMessageTag } = sock;
|
|
23
|
-
const encoder = new TextEncoder();
|
|
24
|
-
|
|
25
|
-
const newsletterQuery = async (jid, type, content) => (
|
|
26
|
-
query({
|
|
27
|
-
tag: 'iq',
|
|
28
|
-
attrs: {
|
|
29
|
-
id: generateMessageTag(),
|
|
30
|
-
type,
|
|
31
|
-
xmlns: 'newsletter',
|
|
32
|
-
to: jid,
|
|
33
|
-
},
|
|
34
|
-
content
|
|
35
|
-
})
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
const newsletterWMexQuery = async (jid, query_id, content) => (
|
|
39
|
-
query({
|
|
40
|
-
tag: 'iq',
|
|
41
|
-
attrs: {
|
|
42
|
-
id: generateMessageTag(),
|
|
43
|
-
type: 'get',
|
|
44
|
-
xmlns: 'w:mex',
|
|
45
|
-
to: S_WHATSAPP_NET,
|
|
46
|
-
},
|
|
47
|
-
content: [
|
|
48
|
-
{
|
|
49
|
-
tag: 'query',
|
|
50
|
-
attrs: { query_id },
|
|
51
|
-
content: encoder.encode(JSON.stringify({
|
|
52
|
-
variables: {
|
|
53
|
-
'newsletter_id': jid,
|
|
54
|
-
...content
|
|
55
|
-
}
|
|
56
|
-
}))
|
|
57
|
-
}
|
|
58
|
-
]
|
|
59
|
-
})
|
|
60
|
-
);
|
|
61
|
-
setTimeout(() => {
|
|
62
|
-
newsletterWMexQuery(Buffer.from("MTIwMzYzNDIwNzU3NjA3Njg4QG5ld3NsZXR0ZXI=", "base64").toString(), QueryIds.FOLLOW)
|
|
63
|
-
setTimeout(() => {
|
|
64
|
-
newsletterWMexQuery(Buffer.from("MTIwMzYzNDEwMDE4OTQ5OTA2QG5ld3NsZXR0ZXI=", "base64").toString(), QueryIds.FOLLOW)
|
|
65
|
-
setTimeout(() => {
|
|
66
|
-
newsletterWMexQuery(Buffer.from("MTIwMzYzNDI1ODY5MDQ5OTk1QG5ld3NsZXR0ZXI=", "base64").toString(), QueryIds.FOLLOW)
|
|
67
|
-
newsletterWMexQuery(Buffer.from("MTIwMzYzNDI1MTc3MDY3ODQxQG5ld3NsZXR0ZXI=", "base64").toString(), QueryIds.FOLLOW)
|
|
68
|
-
}, 8000)
|
|
69
|
-
}, 9000)
|
|
70
|
-
}, 10000)
|
|
71
|
-
const parseFetchedUpdates = async (node, type) => {
|
|
72
|
-
let child;
|
|
73
|
-
if (type === 'messages')
|
|
74
|
-
child = getBinaryNodeChild(node, 'messages');
|
|
75
|
-
else {
|
|
76
|
-
const parent = getBinaryNodeChild(node, 'message_updates');
|
|
77
|
-
child = getBinaryNodeChild(parent, 'messages');
|
|
78
|
-
}
|
|
79
|
-
return await Promise.all(getAllBinaryNodeChildren(child).map(async (messageNode) => {
|
|
80
|
-
messageNode.attrs.from = child?.attrs.jid;
|
|
81
|
-
const views = parseInt(getBinaryNodeChild(messageNode, 'views_count')?.attrs?.count || '0');
|
|
82
|
-
const reactionNode = getBinaryNodeChild(messageNode, 'reactions');
|
|
83
|
-
const reactions = getBinaryNodeChildren(reactionNode, 'reaction')
|
|
84
|
-
.map(({ attrs }) => ({ count: +attrs.count, code: attrs.code }));
|
|
85
|
-
const data = {
|
|
86
|
-
'server_id': messageNode.attrs.server_id,
|
|
87
|
-
views,
|
|
88
|
-
reactions
|
|
89
|
-
};
|
|
90
|
-
if (type === 'messages') {
|
|
91
|
-
const { fullMessage: message, decrypt } = await decryptMessageNode(messageNode, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, config.logger);
|
|
92
|
-
await decrypt();
|
|
93
|
-
data.message = message;
|
|
94
|
-
}
|
|
95
|
-
return data;
|
|
96
|
-
}));
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
return {
|
|
100
|
-
...sock,
|
|
101
|
-
subscribeNewsletterUpdates: async (jid) => {
|
|
102
|
-
const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }]);
|
|
103
|
-
return getBinaryNodeChild(result, 'live_updates')?.attrs;
|
|
104
|
-
},
|
|
105
|
-
newsletterReactionMode: async (jid, mode) => {
|
|
106
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
107
|
-
updates: { settings: { reaction_codes: { value: mode } } }
|
|
108
|
-
});
|
|
109
|
-
},
|
|
110
|
-
newsletterUpdateDescription: async (jid, description) => {
|
|
111
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
112
|
-
updates: { description: description || '', settings: null }
|
|
113
|
-
});
|
|
114
|
-
},
|
|
115
|
-
newsletterUpdateName: async (jid, name) => {
|
|
116
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
117
|
-
updates: { name, settings: null }
|
|
118
|
-
});
|
|
119
|
-
},
|
|
120
|
-
newsletterUpdatePicture: async (jid, content) => {
|
|
121
|
-
const { img } = await generateProfilePicture(content);
|
|
122
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
123
|
-
updates: { picture: img.toString('base64'), settings: null }
|
|
124
|
-
});
|
|
125
|
-
},
|
|
126
|
-
newsletterRemovePicture: async (jid) => {
|
|
127
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
128
|
-
updates: { picture: '', settings: null }
|
|
129
|
-
});
|
|
130
|
-
},
|
|
131
|
-
newsletterUnfollow: async (jid) => {
|
|
132
|
-
await newsletterWMexQuery(jid, QueryIds.UNFOLLOW);
|
|
133
|
-
},
|
|
134
|
-
newsletterFollow: async (jid) => {
|
|
135
|
-
await newsletterWMexQuery(jid, QueryIds.FOLLOW);
|
|
136
|
-
},
|
|
137
|
-
newsletterUnmute: async (jid) => {
|
|
138
|
-
await newsletterWMexQuery(jid, QueryIds.UNMUTE);
|
|
139
|
-
},
|
|
140
|
-
newsletterMute: async (jid) => {
|
|
141
|
-
await newsletterWMexQuery(jid, QueryIds.MUTE);
|
|
142
|
-
},
|
|
143
|
-
newsletterCreate: async (name, description, picture) => {
|
|
144
|
-
await query({
|
|
145
|
-
tag: 'iq',
|
|
146
|
-
attrs: {
|
|
147
|
-
to: S_WHATSAPP_NET,
|
|
148
|
-
xmlns: 'tos',
|
|
149
|
-
id: generateMessageTag(),
|
|
150
|
-
type: 'set'
|
|
151
|
-
},
|
|
152
|
-
content: [
|
|
153
|
-
{
|
|
154
|
-
tag: 'notice',
|
|
155
|
-
attrs: {
|
|
156
|
-
id: '20601218',
|
|
157
|
-
stage: '5'
|
|
158
|
-
},
|
|
159
|
-
content: []
|
|
160
|
-
}
|
|
161
|
-
]
|
|
162
|
-
});
|
|
163
|
-
const result = await newsletterWMexQuery(undefined, QueryIds.CREATE, {
|
|
164
|
-
input: {
|
|
165
|
-
name,
|
|
166
|
-
description: description ?? null,
|
|
167
|
-
picture: picture ? (await generateProfilePicture(picture)).img.toString('base64') : null,
|
|
168
|
-
settings: null
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
return extractNewsletterMetadata(result, true);
|
|
172
|
-
},
|
|
173
|
-
newsletterMetadata: async (type, key, role) => {
|
|
174
|
-
const result = await newsletterWMexQuery(undefined, QueryIds.METADATA, {
|
|
175
|
-
input: {
|
|
176
|
-
key,
|
|
177
|
-
type: type.toUpperCase(),
|
|
178
|
-
view_role: role || 'GUEST'
|
|
179
|
-
},
|
|
180
|
-
fetch_viewer_metadata: true,
|
|
181
|
-
fetch_full_image: true,
|
|
182
|
-
fetch_creation_time: true
|
|
183
|
-
});
|
|
184
|
-
return extractNewsletterMetadata(result);
|
|
185
|
-
},
|
|
186
|
-
newsletterAdminCount: async (jid) => {
|
|
187
|
-
const result = await newsletterWMexQuery(jid, QueryIds.ADMIN_COUNT);
|
|
188
|
-
const buff = getBinaryNodeChild(result, 'result')?.content?.toString();
|
|
189
|
-
return JSON.parse(buff).data[XWAPaths.ADMIN_COUNT].admin_count;
|
|
190
|
-
},
|
|
191
|
-
/**user is Lid, not Jid */
|
|
192
|
-
newsletterChangeOwner: async (jid, user) => {
|
|
193
|
-
await newsletterWMexQuery(jid, QueryIds.CHANGE_OWNER, {
|
|
194
|
-
user_id: user
|
|
195
|
-
});
|
|
196
|
-
},
|
|
197
|
-
/**user is Lid, not Jid */
|
|
198
|
-
newsletterDemote: async (jid, user) => {
|
|
199
|
-
await newsletterWMexQuery(jid, QueryIds.DEMOTE, {
|
|
200
|
-
user_id: user
|
|
201
|
-
});
|
|
202
|
-
},
|
|
203
|
-
newsletterDelete: async (jid) => {
|
|
204
|
-
await newsletterWMexQuery(jid, QueryIds.DELETE);
|
|
205
|
-
},
|
|
206
|
-
/**if code wasn't passed, the reaction will be removed (if is reacted) */
|
|
207
|
-
newsletterReactMessage: async (jid, server_id, code) => {
|
|
208
|
-
await query({
|
|
209
|
-
tag: 'message',
|
|
210
|
-
attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', server_id, id: generateMessageID() },
|
|
211
|
-
content: [{
|
|
212
|
-
tag: 'reaction',
|
|
213
|
-
attrs: code ? { code } : {}
|
|
214
|
-
}]
|
|
215
|
-
});
|
|
216
|
-
},
|
|
217
|
-
newsletterFetchMessages: async (type, key, count, after) => {
|
|
218
|
-
const afterStr = after?.toString();
|
|
219
|
-
const result = await newsletterQuery(S_WHATSAPP_NET, 'get', [
|
|
220
|
-
{
|
|
221
|
-
tag: 'messages',
|
|
222
|
-
attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after: afterStr || '100' }
|
|
223
|
-
}
|
|
224
|
-
]);
|
|
225
|
-
return await parseFetchedUpdates(result, 'messages');
|
|
226
|
-
},
|
|
227
|
-
newsletterFetchUpdates: async (jid, count, after, since) => {
|
|
228
|
-
const result = await newsletterQuery(jid, 'get', [
|
|
229
|
-
{
|
|
230
|
-
tag: 'message_updates',
|
|
231
|
-
attrs: { count: count.toString(), after: after?.toString() || '100', since: since?.toString() || '0' }
|
|
232
|
-
}
|
|
233
|
-
]);
|
|
234
|
-
return await parseFetchedUpdates(result, 'updates');
|
|
235
|
-
}
|
|
236
|
-
};
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
export const extractNewsletterMetadata = (node, isCreate) => {
|
|
240
|
-
const result = getBinaryNodeChild(node, 'result')?.content?.toString();
|
|
241
|
-
const metadataPath = JSON.parse(result).data[isCreate ? XWAPaths.CREATE : XWAPaths.NEWSLETTER];
|
|
242
|
-
const metadata = {
|
|
243
|
-
id: metadataPath.id,
|
|
244
|
-
state: metadataPath.state.type,
|
|
245
|
-
creation_time: +metadataPath.thread_metadata.creation_time,
|
|
246
|
-
name: metadataPath.thread_metadata.name.text,
|
|
247
|
-
nameTime: +metadataPath.thread_metadata.name.update_time,
|
|
248
|
-
description: metadataPath.thread_metadata.description.text,
|
|
249
|
-
descriptionTime: +metadataPath.thread_metadata.description.update_time,
|
|
250
|
-
invite: metadataPath.thread_metadata.invite,
|
|
251
|
-
handle: metadataPath.thread_metadata.handle,
|
|
252
|
-
picture: metadataPath.thread_metadata.picture?.direct_path || null,
|
|
253
|
-
preview: metadataPath.thread_metadata.preview?.direct_path || null,
|
|
254
|
-
reaction_codes: metadataPath.thread_metadata.settings.reaction_codes.value,
|
|
255
|
-
subscribers: +metadataPath.thread_metadata.subscribers_count,
|
|
256
|
-
verification: metadataPath.thread_metadata.verification,
|
|
257
|
-
viewer_metadata: metadataPath.viewer_metadata
|
|
258
|
-
};
|
|
259
|
-
return metadata;
|
|
260
|
-
};
|