@kaels/casileys 0.4.3 → 0.4.5

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 (69) hide show
  1. package/README.md +1099 -539
  2. package/WAProto/index.d.ts +237 -34
  3. package/WAProto/index.js +1729 -211
  4. package/lib/Defaults/index.d.ts +8 -2
  5. package/lib/Defaults/index.d.ts.map +1 -1
  6. package/lib/Defaults/index.js +12 -6
  7. package/lib/Defaults/index.js.map +1 -1
  8. package/lib/Socket/business.d.ts +1 -1
  9. package/lib/Socket/chats.d.ts +8 -1
  10. package/lib/Socket/chats.d.ts.map +1 -1
  11. package/lib/Socket/chats.js +13 -8
  12. package/lib/Socket/chats.js.map +1 -1
  13. package/lib/Socket/communities.d.ts +1 -1
  14. package/lib/Socket/groups.d.ts +1 -1
  15. package/lib/Socket/index.d.ts +1 -1
  16. package/lib/Socket/index.js +2 -19
  17. package/lib/Socket/messages-recv.d.ts +1 -1
  18. package/lib/Socket/messages-send.d.ts +1 -1
  19. package/lib/Socket/newsletter.d.ts +1 -1
  20. package/lib/Socket/socket.d.ts.map +1 -1
  21. package/lib/Socket/socket.js +3 -0
  22. package/lib/Socket/socket.js.map +1 -1
  23. package/lib/Store/make-in-memory-store.js +2 -2
  24. package/lib/Utils/auth-utils.d.ts.map +1 -1
  25. package/lib/Utils/auth-utils.js +5 -1
  26. package/lib/Utils/auth-utils.js.map +1 -1
  27. package/lib/Utils/browser-utils.d.ts +2 -1
  28. package/lib/Utils/browser-utils.d.ts.map +1 -1
  29. package/lib/Utils/browser-utils.js +2 -1
  30. package/lib/Utils/browser-utils.js.map +1 -1
  31. package/lib/Utils/chat-utils.js +1 -1
  32. package/lib/Utils/decode-wa-message.d.ts.map +1 -1
  33. package/lib/Utils/decode-wa-message.js +6 -0
  34. package/lib/Utils/decode-wa-message.js.map +1 -1
  35. package/lib/Utils/event-buffer.js +1 -1
  36. package/lib/Utils/generics.d.ts +1 -1
  37. package/lib/Utils/generics.js +10 -10
  38. package/lib/Utils/group-status.d.ts +58 -0
  39. package/lib/Utils/group-status.js +477 -0
  40. package/lib/Utils/index.d.ts +1 -0
  41. package/lib/Utils/index.js +2 -0
  42. package/lib/Utils/index.js.map +1 -1
  43. package/lib/Utils/messages.d.ts +4 -4
  44. package/lib/Utils/messages.d.ts.map +1 -1
  45. package/lib/Utils/messages.js +32 -64
  46. package/lib/Utils/messages.js.map +1 -1
  47. package/lib/Utils/process-message.d.ts.map +1 -1
  48. package/lib/Utils/process-message.js.map +1 -1
  49. package/lib/Utils/rich-message-utils.d.ts +1 -1
  50. package/lib/Utils/rich-message-utils.d.ts.map +1 -1
  51. package/lib/Utils/rich-message-utils.js +124 -12
  52. package/lib/Utils/rich-message-utils.js.map +1 -1
  53. package/lib/Utils/tc-token-utils.d.ts.map +1 -1
  54. package/lib/Utils/tc-token-utils.js +3 -2
  55. package/lib/Utils/tc-token-utils.js.map +1 -1
  56. package/lib/Utils/use-single-file-auth-state.js +1 -1
  57. package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
  58. package/lib/Utils/use-sqlite-auth-state.d.ts.map +1 -0
  59. package/lib/Utils/use-sqlite-auth-state.js +109 -0
  60. package/lib/Utils/use-sqlite-auth-state.js.map +1 -0
  61. package/lib/Utils/validate-connection.d.ts.map +1 -1
  62. package/lib/Utils/validate-connection.js +9 -2
  63. package/lib/Utils/validate-connection.js.map +1 -1
  64. package/lib/WABinary/constants.d.ts +16 -0
  65. package/lib/WABinary/constants.d.ts.map +1 -1
  66. package/lib/WABinary/constants.js +99 -5
  67. package/lib/WABinary/constants.js.map +1 -1
  68. package/lib/WABinary/generic-utils.js +1 -1
  69. package/package.json +109 -105
@@ -0,0 +1,477 @@
1
+ import fs from 'fs/promises';
2
+ import fsSync from 'fs';
3
+ import path from 'path';
4
+ import { tmpdir } from 'os';
5
+ import crypto from 'crypto';
6
+
7
+ import ff from 'fluent-ffmpeg';
8
+ import webpMux from 'node-webpmux';
9
+
10
+ import { prepareWAMessageMedia } from './messages.js';
11
+
12
+ try {
13
+ const ffmpegInstaller = await import('@ffmpeg-installer/ffmpeg');
14
+ ff.setFfmpegPath(ffmpegInstaller.path);
15
+ } catch {
16
+ // Fallback to ffmpeg available in system PATH.
17
+ }
18
+
19
+ const TEMP_DIR = path.join(tmpdir(), 'casileys-group-status');
20
+
21
+ const ensureTempDir = async () => {
22
+ await fs.mkdir(TEMP_DIR, { recursive: true });
23
+ };
24
+
25
+ const randomId = () =>
26
+ crypto.randomBytes(8).toString('hex');
27
+
28
+ const toNumber = (value) => {
29
+ if (typeof value === 'number') {
30
+ return value;
31
+ }
32
+
33
+ if (value && typeof value === 'object' && 'low' in value) {
34
+ return value.low;
35
+ }
36
+
37
+ if (typeof value === 'string') {
38
+ const parsed = Number.parseInt(value, 10);
39
+ return Number.isNaN(parsed) ? 0 : parsed;
40
+ }
41
+
42
+ return 0;
43
+ };
44
+
45
+ /**
46
+ * Convert a static WebP sticker into PNG.
47
+ */
48
+ export const stickerToImage = async (buffer) => {
49
+ await ensureTempDir();
50
+
51
+ const id = randomId();
52
+ const input = path.join(TEMP_DIR, `${id}.webp`);
53
+ const output = path.join(TEMP_DIR, `${id}.png`);
54
+
55
+ fsSync.writeFileSync(input, buffer);
56
+
57
+ try {
58
+ await new Promise((resolve, reject) => {
59
+ ff(input)
60
+ .frames(1)
61
+ .output(output)
62
+ .on('error', reject)
63
+ .on('end', resolve)
64
+ .run();
65
+ });
66
+
67
+ return fsSync.readFileSync(output);
68
+ } finally {
69
+ try {
70
+ fsSync.unlinkSync(input);
71
+ } catch {}
72
+
73
+ try {
74
+ fsSync.unlinkSync(output);
75
+ } catch {}
76
+ }
77
+ };
78
+
79
+ /**
80
+ * Convert an animated WebP sticker into MP4.
81
+ */
82
+ export const stickerToVideo = async (buffer) => {
83
+ await ensureTempDir();
84
+
85
+ const id = randomId();
86
+ const frameDir = path.join(TEMP_DIR, `webp-${id}`);
87
+ const output = path.join(TEMP_DIR, `${id}.mp4`);
88
+
89
+ fsSync.mkdirSync(frameDir, { recursive: true });
90
+
91
+ try {
92
+ const image = new webpMux.Image();
93
+
94
+ await image.load(buffer);
95
+
96
+ if (!image.hasAnim) {
97
+ throw new Error('Bukan sticker animasi');
98
+ }
99
+
100
+ const frames = await image.demux({
101
+ buffers: true
102
+ });
103
+
104
+ if (!frames?.length) {
105
+ throw new Error('Tidak ada frame sticker yang ditemukan');
106
+ }
107
+
108
+ const delay =
109
+ image.anim?.frames?.[0]?.delay || 100;
110
+
111
+ const fps = Math.max(
112
+ 1,
113
+ Math.round(1000 / delay)
114
+ );
115
+
116
+ for (let index = 0; index < frames.length; index++) {
117
+ const framePath = path.join(
118
+ frameDir,
119
+ `frame${String(index).padStart(5, '0')}.webp`
120
+ );
121
+
122
+ fsSync.writeFileSync(
123
+ framePath,
124
+ frames[index]
125
+ );
126
+ }
127
+
128
+ await new Promise((resolve, reject) => {
129
+ ff()
130
+ .input(
131
+ path.join(
132
+ frameDir,
133
+ 'frame%05d.webp'
134
+ )
135
+ )
136
+ .inputOptions([
137
+ '-framerate',
138
+ String(fps)
139
+ ])
140
+ .outputOptions([
141
+ '-c:v',
142
+ 'libx264',
143
+
144
+ '-pix_fmt',
145
+ 'yuv420p',
146
+
147
+ '-vf',
148
+ "scale='if(mod(iw,2),iw-1,iw)':'if(mod(ih,2),ih-1,ih)'",
149
+
150
+ '-movflags',
151
+ '+faststart'
152
+ ])
153
+ .toFormat('mp4')
154
+ .on('error', reject)
155
+ .on('end', resolve)
156
+ .save(output);
157
+ });
158
+
159
+ return fsSync.readFileSync(output);
160
+ } finally {
161
+ try {
162
+ fsSync.rmSync(
163
+ frameDir,
164
+ {
165
+ recursive: true,
166
+ force: true
167
+ }
168
+ );
169
+ } catch {}
170
+
171
+ try {
172
+ fsSync.unlinkSync(output);
173
+ } catch {}
174
+ }
175
+ };
176
+
177
+ /**
178
+ * Send plain text as a group status.
179
+ */
180
+ export const sendGroupStatusText = async (
181
+ sock,
182
+ jid,
183
+ text,
184
+ options = {}
185
+ ) => {
186
+ if (!text || typeof text !== 'string') {
187
+ throw new Error('Text status harus berupa string');
188
+ }
189
+
190
+ await sock.relayMessage(
191
+ jid,
192
+ {
193
+ groupStatusMessageV2: {
194
+ message: {
195
+ extendedTextMessage: {
196
+ text,
197
+ font: options.font ?? 1,
198
+ backgroundArgb:
199
+ options.backgroundArgb ??
200
+ 0xff000000
201
+ }
202
+ }
203
+ }
204
+ },
205
+ {}
206
+ );
207
+ };
208
+
209
+ /**
210
+ * Send image as a group status.
211
+ */
212
+ export const sendGroupStatusImage = async (
213
+ sock,
214
+ jid,
215
+ image,
216
+ options = {}
217
+ ) => {
218
+ const prepared = await prepareWAMessageMedia(
219
+ {
220
+ image,
221
+ ...(options.mimetype
222
+ ? { mimetype: options.mimetype }
223
+ : {})
224
+ },
225
+ {
226
+ upload: sock.waUploadToServer,
227
+ logger: options.logger
228
+ }
229
+ );
230
+
231
+ const imageMessage = {
232
+ ...prepared.imageMessage
233
+ };
234
+
235
+ if (options.caption) {
236
+ imageMessage.caption = options.caption;
237
+ }
238
+
239
+ await sock.relayMessage(
240
+ jid,
241
+ {
242
+ groupStatusMessageV2: {
243
+ message: {
244
+ imageMessage
245
+ }
246
+ }
247
+ },
248
+ {}
249
+ );
250
+ };
251
+
252
+ /**
253
+ * Send video as a group status.
254
+ */
255
+ export const sendGroupStatusVideo = async (
256
+ sock,
257
+ jid,
258
+ video,
259
+ options = {}
260
+ ) => {
261
+ const prepared = await prepareWAMessageMedia(
262
+ {
263
+ video,
264
+ ...(options.mimetype
265
+ ? { mimetype: options.mimetype }
266
+ : {})
267
+ },
268
+ {
269
+ upload: sock.waUploadToServer,
270
+ logger: options.logger
271
+ }
272
+ );
273
+
274
+ const videoMessage = {
275
+ ...prepared.videoMessage
276
+ };
277
+
278
+ if (options.caption) {
279
+ videoMessage.caption = options.caption;
280
+ }
281
+
282
+ await sock.relayMessage(
283
+ jid,
284
+ {
285
+ groupStatusMessageV2: {
286
+ message: {
287
+ videoMessage
288
+ }
289
+ }
290
+ },
291
+ {}
292
+ );
293
+ };
294
+
295
+ /**
296
+ * Send audio as a group status.
297
+ */
298
+ export const sendGroupStatusAudio = async (
299
+ sock,
300
+ jid,
301
+ audio,
302
+ options = {}
303
+ ) => {
304
+ const prepared = await prepareWAMessageMedia(
305
+ {
306
+ audio,
307
+ mimetype:
308
+ options.mimetype ||
309
+ 'audio/mpeg',
310
+ ptt: true
311
+ },
312
+ {
313
+ upload: sock.waUploadToServer,
314
+ logger: options.logger
315
+ }
316
+ );
317
+
318
+ const audioMessage = {
319
+ ...prepared.audioMessage
320
+ };
321
+
322
+ audioMessage.fileLength =
323
+ toNumber(audioMessage.fileLength);
324
+
325
+ audioMessage.mediaKeyTimestamp =
326
+ toNumber(audioMessage.mediaKeyTimestamp);
327
+
328
+ if (
329
+ typeof audioMessage.seconds === 'string'
330
+ ) {
331
+ audioMessage.seconds =
332
+ toNumber(audioMessage.seconds);
333
+ }
334
+
335
+ audioMessage.ptt = true;
336
+
337
+ audioMessage.contextInfo = {
338
+ ...(audioMessage.contextInfo || {}),
339
+ isGroupStatus: true
340
+ };
341
+
342
+ audioMessage.waveform =
343
+ audioMessage.waveform ||
344
+ Buffer.from([]);
345
+
346
+ audioMessage.backgroundArgb =
347
+ options.backgroundArgb ??
348
+ 0xff000000;
349
+
350
+ await sock.relayMessage(
351
+ jid,
352
+ {
353
+ groupStatusMessageV2: {
354
+ message: {
355
+ audioMessage
356
+ }
357
+ }
358
+ },
359
+ {}
360
+ );
361
+ };
362
+
363
+ /**
364
+ * Send a sticker as a group status.
365
+ *
366
+ * Static WebP -> PNG image
367
+ * Animated WebP -> MP4 video
368
+ */
369
+ export const sendGroupStatusSticker = async (
370
+ sock,
371
+ jid,
372
+ sticker,
373
+ options = {}
374
+ ) => {
375
+ const image = new webpMux.Image();
376
+
377
+ await image.load(sticker);
378
+
379
+ if (image.hasAnim) {
380
+ const video = await stickerToVideo(
381
+ sticker
382
+ );
383
+
384
+ return sendGroupStatusVideo(
385
+ sock,
386
+ jid,
387
+ video,
388
+ {
389
+ ...options,
390
+ mimetype:
391
+ options.mimetype ||
392
+ 'video/mp4'
393
+ }
394
+ );
395
+ }
396
+
397
+ const png = await stickerToImage(
398
+ sticker
399
+ );
400
+
401
+ return sendGroupStatusImage(
402
+ sock,
403
+ jid,
404
+ png,
405
+ {
406
+ ...options,
407
+ mimetype:
408
+ options.mimetype ||
409
+ 'image/png'
410
+ }
411
+ );
412
+ };
413
+
414
+ /**
415
+ * Send group status media based on type.
416
+ *
417
+ * Supported types:
418
+ * - text
419
+ * - image
420
+ * - video
421
+ * - audio
422
+ * - sticker
423
+ */
424
+ export const sendGroupStatus = async (
425
+ sock,
426
+ jid,
427
+ type,
428
+ data,
429
+ options = {}
430
+ ) => {
431
+ switch (type) {
432
+ case 'text':
433
+ return sendGroupStatusText(
434
+ sock,
435
+ jid,
436
+ data,
437
+ options
438
+ );
439
+
440
+ case 'image':
441
+ return sendGroupStatusImage(
442
+ sock,
443
+ jid,
444
+ data,
445
+ options
446
+ );
447
+
448
+ case 'video':
449
+ return sendGroupStatusVideo(
450
+ sock,
451
+ jid,
452
+ data,
453
+ options
454
+ );
455
+
456
+ case 'audio':
457
+ return sendGroupStatusAudio(
458
+ sock,
459
+ jid,
460
+ data,
461
+ options
462
+ );
463
+
464
+ case 'sticker':
465
+ return sendGroupStatusSticker(
466
+ sock,
467
+ jid,
468
+ data,
469
+ options
470
+ );
471
+
472
+ default:
473
+ throw new Error(
474
+ `Unsupported group status type: ${type}`
475
+ );
476
+ }
477
+ };
@@ -12,6 +12,7 @@ export * from "./lt-hash.js";
12
12
  export * from "./auth-utils.js";
13
13
  export * from "./use-multi-file-auth-state.js";
14
14
  export * from "./use-single-file-auth-state.js";
15
+ export * from "./use-sqlite-auth-state.js";
15
16
  export * from "./link-preview.js";
16
17
  export * from "./event-buffer.js";
17
18
  export * from "./process-message.js";
@@ -12,6 +12,7 @@ export * from './lt-hash.js';
12
12
  export * from './auth-utils.js';
13
13
  export * from './use-multi-file-auth-state.js';
14
14
  export * from './use-single-file-auth-state.js';
15
+ export * from './use-sqlite-auth-state.js';
15
16
  export * from './link-preview.js';
16
17
  export * from './event-buffer.js';
17
18
  export * from './process-message.js';
@@ -21,4 +22,5 @@ export * from './browser-utils.js';
21
22
  export * from './companion-reg-client-utils.js';
22
23
  export * from './identity-change-handler.js';
23
24
  export * from './stanza-ack.js';
25
+ export * from './group-status.js';
24
26
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Utils/index.js"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,iCAAiC,CAAC;AAChD,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oBAAoB,CAAC;AACnC,cAAc,iCAAiC,CAAC;AAChD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Utils/index.js"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,iCAAiC,CAAC;AAChD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oBAAoB,CAAC;AACnC,cAAc,iCAAiC,CAAC;AAChD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iBAAiB,CAAC"}
@@ -24,9 +24,9 @@ export function prepareDisappearingMessageSettingContent(ephemeralExpiration: an
24
24
  export function generateForwardMessageContent(message: any, forceForward: any): any;
25
25
  export function hasNonNullishProperty(message: any, key: any): boolean;
26
26
  export function hasOptionalProperty(obj: any, key: any): boolean;
27
- export function hasValidAlbumMedia(message: any): any;
28
- export function hasValidInteractiveHeader(message: any): any;
29
- export function hasValidCarouselHeader(message: any): any;
27
+ export function hasValidAlbumMedia(message: any): boolean;
28
+ export function hasValidInteractiveHeader(message: any): boolean;
29
+ export function hasValidCarouselHeader(message: any): boolean;
30
30
  export function generateWAMessageContent(message: any, options: any): Promise<any>;
31
31
  export function generateWAMessageFromContent(jid: any, message: any, options: any): proto.WebMessageInfo;
32
32
  export function generateWAMessage(jid: any, content: any, options: any): Promise<proto.WebMessageInfo>;
@@ -41,6 +41,6 @@ export function updateMessageWithEventResponse(msg: any, update: any): void;
41
41
  export function aggregateMessageKeysNotFromMe(keys: any): any[];
42
42
  export function downloadMediaMessage(message: any, type: any, options: any, ctx: any): Promise<any>;
43
43
  export function assertMediaContent(content: any): any;
44
- export function shouldIncludeBizBinaryNode(message: any): any;
44
+ export function shouldIncludeBizBinaryNode(message: any): boolean;
45
45
  import { proto } from '../../WAProto/index.js';
46
46
  //# sourceMappingURL=messages.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/Utils/messages.js"],"names":[],"mappings":"AAmnDA;;;;;GAKG;AACH;;;qBAgCC;AACD;;;;;GAKG;AACH;;qBAgBC;AAvnDM,mDAA+D;AAC/D,qGAYN;AAeM,0FAmKN;AAuTM,kGAaN;AAMM,oFAwBN;AACM,uEAKN;AACM,iEAKN;AAEM,sDAGN;AACM,6DAMN;AAEM,0DAIN;AACM,mFAmxBN;AACM,yGA4EN;AACM,uGAQN;AAEM,iEAMN;AAOM,2DA2CN;AAKM,yDAkCN;AAIM,sFAQoB;AAEpB,uEASN;AAEM,yEAMN;AAEM,yEAON;AAEM,4EAKN;AAgEM,gEAgBN;AAKM,oGA8CN;AAEM,sDAWN;AAkEM,8DAUN;sBAz0DqB,wBAAwB"}
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/Utils/messages.js"],"names":[],"mappings":"AAslDA;;;;;GAKG;AACH;;;qBAgCC;AACD;;;;;GAKG;AACH;;qBAgBC;AAhnDM,mDAA+D;AAC/D,qGAYN;AAeM,0FAgKN;AAmTM,kGAaN;AAMM,oFAwBN;AACM,uEAKN;AACM,iEAKN;AAEM,0DAGN;AACM,iEAMN;AAEM,8DAIN;AACM,mFAmxBN;AACM,yGA4EN;AACM,uGAQN;AAEM,iEAMN;AAOM,2DA2CN;AAKM,yDAkCN;AAIM,sFAQoB;AAEpB,uEASN;AAEM,yEAMN;AAEM,yEAON;AAEM,4EAKN;AAgEM,gEAgBN;AAKM,oGA8CN;AAEM,sDAWN;AAkEM,kEAOF;sBAzyDiB,wBAAwB"}