@awangxcode/qiro-baileys 7.0.0-rc25.6 → 7.0.0-rc26.3

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 (193) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +1445 -1041
  3. package/WAProto/WAProto.proto +4 -0
  4. package/WAProto/index.d.ts +4067 -243
  5. package/WAProto/index.js +74957 -43330
  6. package/assets/branding/qiro-logo.svg +24 -0
  7. package/assets/branding/qiro-mark.png +0 -0
  8. package/assets/branding/qiro-mark.svg +34 -0
  9. package/assets/branding/qiro-social-preview.png +0 -0
  10. package/lib/Defaults/index.d.ts +15 -0
  11. package/lib/Defaults/index.d.ts.map +1 -1
  12. package/lib/Defaults/index.js +40 -7
  13. package/lib/Defaults/index.js.map +1 -1
  14. package/lib/Extensions/experimental.d.ts +0 -2
  15. package/lib/Extensions/experimental.d.ts.map +1 -1
  16. package/lib/Extensions/experimental.js +0 -2
  17. package/lib/Extensions/experimental.js.map +1 -1
  18. package/lib/MessageBuilder/index.d.ts.map +1 -1
  19. package/lib/MessageBuilder/index.js +10 -1
  20. package/lib/MessageBuilder/index.js.map +1 -1
  21. package/lib/Signal/lid-mapping.js +3 -3
  22. package/lib/Signal/lid-mapping.js.map +1 -1
  23. package/lib/Socket/business.d.ts +283 -1
  24. package/lib/Socket/business.d.ts.map +1 -1
  25. package/lib/Socket/chats.d.ts +114 -1
  26. package/lib/Socket/chats.d.ts.map +1 -1
  27. package/lib/Socket/chats.js +285 -10
  28. package/lib/Socket/chats.js.map +1 -1
  29. package/lib/Socket/communities.d.ts +283 -1
  30. package/lib/Socket/communities.d.ts.map +1 -1
  31. package/lib/Socket/groups.d.ts +106 -0
  32. package/lib/Socket/groups.d.ts.map +1 -1
  33. package/lib/Socket/index.d.ts +283 -1
  34. package/lib/Socket/index.d.ts.map +1 -1
  35. package/lib/Socket/index.js +4 -1
  36. package/lib/Socket/index.js.map +1 -1
  37. package/lib/Socket/messages-recv.d.ts +284 -1
  38. package/lib/Socket/messages-recv.d.ts.map +1 -1
  39. package/lib/Socket/messages-recv.js +73 -22
  40. package/lib/Socket/messages-recv.js.map +1 -1
  41. package/lib/Socket/messages-send.d.ts +297 -1
  42. package/lib/Socket/messages-send.d.ts.map +1 -1
  43. package/lib/Socket/messages-send.js +164 -28
  44. package/lib/Socket/messages-send.js.map +1 -1
  45. package/lib/Socket/newsletter.d.ts +322 -37
  46. package/lib/Socket/newsletter.d.ts.map +1 -1
  47. package/lib/Socket/newsletter.js +341 -1
  48. package/lib/Socket/newsletter.js.map +1 -1
  49. package/lib/Socket/socket.d.ts +13 -0
  50. package/lib/Socket/socket.d.ts.map +1 -1
  51. package/lib/Socket/socket.js +84 -31
  52. package/lib/Socket/socket.js.map +1 -1
  53. package/lib/Store/index.d.ts +4 -0
  54. package/lib/Store/index.js +4 -0
  55. package/lib/Store/make-in-memory-store.d.ts +63 -0
  56. package/lib/Store/make-in-memory-store.js +397 -0
  57. package/lib/Store/make-ordered-dictionary.d.ts +13 -0
  58. package/lib/Store/make-ordered-dictionary.js +79 -0
  59. package/lib/Store/object-repository.d.ts +11 -0
  60. package/lib/Store/object-repository.js +24 -0
  61. package/lib/Types/Chat.d.ts +13 -0
  62. package/lib/Types/Chat.d.ts.map +1 -1
  63. package/lib/Types/Chat.js +7 -0
  64. package/lib/Types/Chat.js.map +1 -1
  65. package/lib/Types/Message.d.ts +65 -1
  66. package/lib/Types/Message.d.ts.map +1 -1
  67. package/lib/Types/Message.js +11 -0
  68. package/lib/Types/Message.js.map +1 -1
  69. package/lib/Types/Mex.d.ts +68 -39
  70. package/lib/Types/Mex.d.ts.map +1 -1
  71. package/lib/Types/Mex.js +66 -0
  72. package/lib/Types/Mex.js.map +1 -1
  73. package/lib/Types/Socket.d.ts +45 -0
  74. package/lib/Types/Socket.d.ts.map +1 -1
  75. package/lib/Utils/audio-sticker.d.ts +14 -0
  76. package/lib/Utils/audio-sticker.js +172 -0
  77. package/lib/Utils/auth-store.d.ts +30 -0
  78. package/lib/Utils/auth-store.js +77 -0
  79. package/lib/Utils/chat-theme.d.ts +34 -0
  80. package/lib/Utils/chat-theme.js +336 -0
  81. package/lib/Utils/chat-utils.js +2 -2
  82. package/lib/Utils/chat-utils.js.map +1 -1
  83. package/lib/Utils/decode-wa-message.d.ts +14 -0
  84. package/lib/Utils/decode-wa-message.d.ts.map +1 -1
  85. package/lib/Utils/decode-wa-message.js +55 -0
  86. package/lib/Utils/decode-wa-message.js.map +1 -1
  87. package/lib/Utils/event-buffer.d.ts +2 -1
  88. package/lib/Utils/event-buffer.d.ts.map +1 -1
  89. package/lib/Utils/event-buffer.js +3 -4
  90. package/lib/Utils/event-buffer.js.map +1 -1
  91. package/lib/Utils/generics.d.ts +3 -2
  92. package/lib/Utils/generics.d.ts.map +1 -1
  93. package/lib/Utils/generics.js +10 -19
  94. package/lib/Utils/generics.js.map +1 -1
  95. package/lib/Utils/group-metadata-cache.d.ts +4 -0
  96. package/lib/Utils/group-metadata-cache.js +25 -0
  97. package/lib/Utils/history.js +1 -1
  98. package/lib/Utils/history.js.map +1 -1
  99. package/lib/Utils/html-app.d.ts +19 -0
  100. package/lib/Utils/html-app.js +96 -0
  101. package/lib/Utils/html-multiplayer.d.ts +10 -0
  102. package/lib/Utils/html-multiplayer.js +94 -0
  103. package/lib/Utils/index.d.ts +25 -0
  104. package/lib/Utils/index.d.ts.map +1 -1
  105. package/lib/Utils/index.js +27 -0
  106. package/lib/Utils/index.js.map +1 -1
  107. package/lib/Utils/link-preview-metadata.d.ts +47 -0
  108. package/lib/Utils/link-preview-metadata.js +88 -0
  109. package/lib/Utils/messages-media.d.ts +31 -2
  110. package/lib/Utils/messages-media.d.ts.map +1 -1
  111. package/lib/Utils/messages-media.js +66 -19
  112. package/lib/Utils/messages-media.js.map +1 -1
  113. package/lib/Utils/messages.d.ts +42 -2
  114. package/lib/Utils/messages.d.ts.map +1 -1
  115. package/lib/Utils/messages.js +117 -26
  116. package/lib/Utils/messages.js.map +1 -1
  117. package/lib/Utils/modern-messages.d.ts +150 -0
  118. package/lib/Utils/modern-messages.js +496 -0
  119. package/lib/Utils/native-flow.d.ts +11 -0
  120. package/lib/Utils/native-flow.js +116 -0
  121. package/lib/Utils/newsletter-status.d.ts +158 -0
  122. package/lib/Utils/newsletter-status.js +651 -0
  123. package/lib/Utils/optional-media.d.ts +3 -0
  124. package/lib/Utils/optional-media.js +46 -0
  125. package/lib/Utils/payment-messages.d.ts +38 -0
  126. package/lib/Utils/payment-messages.js +160 -0
  127. package/lib/Utils/process-message.d.ts +11 -0
  128. package/lib/Utils/process-message.d.ts.map +1 -1
  129. package/lib/Utils/process-message.js +80 -0
  130. package/lib/Utils/process-message.js.map +1 -1
  131. package/lib/Utils/scheduled-message.d.ts +51 -0
  132. package/lib/Utils/scheduled-message.js +113 -0
  133. package/lib/Utils/sender-key-memory.d.ts +19 -0
  134. package/lib/Utils/sender-key-memory.js +51 -0
  135. package/lib/Utils/status-stickers.d.ts +127 -0
  136. package/lib/Utils/status-stickers.js +261 -0
  137. package/lib/Utils/ttl-cache.d.ts +29 -0
  138. package/lib/Utils/ttl-cache.js +121 -0
  139. package/lib/Utils/use-mongo-auth-state.d.ts +22 -0
  140. package/lib/Utils/use-mongo-auth-state.js +68 -0
  141. package/lib/Utils/use-multi-file-auth-state.d.ts +1 -0
  142. package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -1
  143. package/lib/Utils/use-multi-file-auth-state.js +26 -13
  144. package/lib/Utils/use-multi-file-auth-state.js.map +1 -1
  145. package/lib/Utils/use-mysql-auth-state.d.ts +20 -0
  146. package/lib/Utils/use-mysql-auth-state.js +80 -0
  147. package/lib/Utils/use-nekodb-auth.d.ts +19 -0
  148. package/lib/Utils/use-nekodb-auth.js +111 -0
  149. package/lib/Utils/use-postgres-auth-state.d.ts +20 -0
  150. package/lib/Utils/use-postgres-auth-state.js +80 -0
  151. package/lib/Utils/use-redis-auth-state.d.ts +20 -0
  152. package/lib/Utils/use-redis-auth-state.js +90 -0
  153. package/lib/Utils/use-single-file-auth-state.d.ts +11 -0
  154. package/lib/Utils/use-single-file-auth-state.js +109 -0
  155. package/lib/Utils/use-sqlite-auth-state.d.ts +13 -0
  156. package/lib/Utils/use-sqlite-auth-state.js +121 -0
  157. package/lib/Utils/username.d.ts +12 -0
  158. package/lib/Utils/username.js +59 -0
  159. package/lib/Utils/voice-recognition.d.ts +53 -0
  160. package/lib/Utils/voice-recognition.js +219 -0
  161. package/lib/VoIP/audio-feeder.d.ts +24 -0
  162. package/lib/VoIP/audio-feeder.js +276 -0
  163. package/lib/VoIP/index.d.ts +93 -0
  164. package/lib/VoIP/index.js +998 -0
  165. package/lib/VoIP/relay-transport.d.ts +5 -0
  166. package/lib/VoIP/relay-transport.js +824 -0
  167. package/lib/VoIP/signaling.d.ts +11 -0
  168. package/lib/VoIP/signaling.js +1099 -0
  169. package/lib/VoIP/types.d.ts +2 -0
  170. package/lib/VoIP/types.js +12 -0
  171. package/lib/VoIP/video-feeder.d.ts +24 -0
  172. package/lib/VoIP/video-feeder.js +276 -0
  173. package/lib/VoIP/wasm-engine.d.ts +26 -0
  174. package/lib/VoIP/wasm-engine.js +1318 -0
  175. package/lib/VoIP/worker-bootstrap.js +1022 -0
  176. package/lib/WABinary/generic-utils.d.ts +2 -0
  177. package/lib/WABinary/generic-utils.d.ts.map +1 -1
  178. package/lib/WABinary/generic-utils.js +2 -0
  179. package/lib/WABinary/generic-utils.js.map +1 -1
  180. package/lib/WABinary/jid-utils.d.ts +2 -0
  181. package/lib/WABinary/jid-utils.d.ts.map +1 -1
  182. package/lib/WABinary/jid-utils.js +3 -1
  183. package/lib/WABinary/jid-utils.js.map +1 -1
  184. package/lib/extensions/awang-MessageBuilder.js +1 -1
  185. package/lib/index.d.ts +4 -0
  186. package/lib/index.d.ts.map +1 -1
  187. package/lib/index.js +4 -0
  188. package/lib/index.js.map +1 -1
  189. package/package.json +78 -31
  190. package/MIGRASI-QIRO-BAILEYS-RC25.md +0 -102
  191. package/QIRO-BAILEYS-RC25.md +0 -168
  192. package/THIRD_PARTY_NOTICES.md +0 -49
  193. /package/{engine-requirements.js → config/engine-requirements.js} +0 -0
@@ -0,0 +1,172 @@
1
+ /* QIRO utility module. */
2
+ import { Boom } from '@hapi/boom';
3
+ import { PassThrough } from 'stream';
4
+ import { prepareWAMessageMedia } from './messages.js';
5
+ import { getImageProcessingLibrary, getStream, toBuffer } from './messages-media.js';
6
+ import { loadFfmpeg } from './optional-media.js';
7
+
8
+ const AUDIO_MIMETYPES = new Set(['audio/ogg; codecs=opus', 'audio/mp4', 'audio/m4a', 'audio/x-m4a']);
9
+ const STICKER_MIMETYPES = new Set(['image/webp', 'application/was']);
10
+
11
+ const mediaInput = value => typeof value === 'string' || value instanceof URL ? { url: value } : value;
12
+
13
+ const isWebp = buffer => buffer.length >= 12
14
+ && buffer.toString('ascii', 0, 4) === 'RIFF'
15
+ && buffer.toString('ascii', 8, 12) === 'WEBP';
16
+
17
+ const isAnimatedWebp = buffer => {
18
+ let offset = 12;
19
+ while (offset + 8 <= buffer.length) {
20
+ const chunk = buffer.toString('ascii', offset, offset + 4);
21
+ const size = buffer.readUInt32LE(offset + 4);
22
+ if (chunk === 'ANIM' || chunk === 'ANMF') {
23
+ return true;
24
+ }
25
+ if (chunk === 'VP8X' && offset + 8 < buffer.length && (buffer[offset + 8] & 0x02)) {
26
+ return true;
27
+ }
28
+ offset += 8 + size + (size % 2);
29
+ }
30
+ return false;
31
+ };
32
+
33
+ const imageToWebp = async (image, options) => {
34
+ const { stream } = await getStream(mediaInput(image), options.options);
35
+ const source = await toBuffer(stream);
36
+ if (isWebp(source)) {
37
+ return { buffer: source, isAnimated: isAnimatedWebp(source), isVideo: false };
38
+ }
39
+ if (source.length >= 12 && source.toString('ascii', 4, 8) === 'ftyp') {
40
+ return { buffer: await videoToWebp(source, options), isAnimated: true, isVideo: true };
41
+ }
42
+ const lib = await getImageProcessingLibrary();
43
+ let buffer;
44
+ if (lib.sharp?.default) {
45
+ buffer = await lib.sharp.default(source, { animated: true })
46
+ .resize(512, 512, { fit: 'inside' })
47
+ .webp({ quality: 80 })
48
+ .toBuffer();
49
+ }
50
+ else if (lib.image?.Transformer) {
51
+ buffer = await new lib.image.Transformer(source)
52
+ .resize(512, 512)
53
+ .webp(80);
54
+ }
55
+ else {
56
+ throw new Boom('image conversion needs sharp or @napi-rs/image', { statusCode: 400 });
57
+ }
58
+ buffer = Buffer.from(buffer);
59
+ return { buffer, isAnimated: isAnimatedWebp(buffer) };
60
+ };
61
+
62
+ const runFfmpeg = async (media, options, outputOptions, errorMessage) => {
63
+ const ffmpeg = await loadFfmpeg();
64
+ const { stream } = await getStream(mediaInput(media), options.options);
65
+ const output = new PassThrough();
66
+ const chunks = [];
67
+ output.on('data', chunk => chunks.push(chunk));
68
+ await new Promise((resolve, reject) => {
69
+ output.on('end', resolve);
70
+ output.on('error', reject);
71
+ ffmpeg(stream)
72
+ .outputOptions(outputOptions)
73
+ .on('error', reject)
74
+ .pipe(output, { end: true });
75
+ });
76
+ const buffer = Buffer.concat(chunks);
77
+ if (!buffer.length) {
78
+ throw new Boom(errorMessage, { statusCode: 400 });
79
+ }
80
+ return buffer;
81
+ };
82
+
83
+ const videoToWebp = (video, options) => runFfmpeg(video, options, [
84
+ '-vf', 'format=rgba,scale=512:512:force_original_aspect_ratio=decrease,pad=512:512:(ow-iw)/2:(oh-ih)/2:color=0x00000000',
85
+ '-c:v', 'libwebp_anim',
86
+ '-lossless', '0',
87
+ '-q:v', '75',
88
+ '-loop', '0',
89
+ '-an',
90
+ '-f', 'webp'
91
+ ], 'ffmpeg produced an empty animated sticker');
92
+
93
+ const prepareAudio = async (audio, audioOptions, options) => {
94
+ const { stream } = await getStream(mediaInput(audio), options.options);
95
+ const source = await toBuffer(stream);
96
+ if (!source.length) {
97
+ throw new Boom('audio sticker audio is empty', { statusCode: 400 });
98
+ }
99
+ if (source.toString('ascii', 0, 4) === 'OggS' && source.includes(Buffer.from('OpusHead'))) {
100
+ audioOptions.mimetype = 'audio/ogg; codecs=opus';
101
+ return { media: source, audioOptions };
102
+ }
103
+ if (source.length >= 12 && source.toString('ascii', 4, 8) === 'ftyp') {
104
+ if (!AUDIO_MIMETYPES.has(audioOptions.mimetype?.toLowerCase()) || audioOptions.mimetype === 'audio/ogg; codecs=opus') {
105
+ audioOptions.mimetype = 'audio/mp4';
106
+ }
107
+ return { media: source, audioOptions };
108
+ }
109
+ const media = await runFfmpeg(source, options, [
110
+ '-vn',
111
+ '-c:a', 'libopus',
112
+ '-b:a', '64k',
113
+ '-f', 'ogg'
114
+ ], 'ffmpeg produced empty ogg/opus audio');
115
+ audioOptions.mimetype = 'audio/ogg; codecs=opus';
116
+ return { media, audioOptions };
117
+ };
118
+
119
+ export const prepareAudioStickerMessage = async (content, options = {}) => {
120
+ const kinds = ['sticker', 'image', 'video'].filter(kind => content?.[kind] != null);
121
+ if (kinds.length !== 1) {
122
+ throw new Boom('sendStAudioMessage needs exactly one of { sticker, image, video }', { statusCode: 400 });
123
+ }
124
+ const audio = content.audio ?? content.audioUrl;
125
+ if (audio == null) {
126
+ throw new Boom('sendStAudioMessage needs { audio } or { audioUrl }', { statusCode: 400 });
127
+ }
128
+ const stickerOptions = { ...content.stickerOptions };
129
+ const audioOptions = { ...content.audioOptions };
130
+ stickerOptions.mimetype ||= 'image/webp';
131
+ if (!STICKER_MIMETYPES.has(stickerOptions.mimetype.toLowerCase())) {
132
+ throw new Boom('audio sticker media must be image/webp or application/was', { statusCode: 400 });
133
+ }
134
+ const kind = kinds[0];
135
+ let visual;
136
+ let isAnimated = true;
137
+ if (kind === 'video') {
138
+ visual = await videoToWebp(content[kind], options);
139
+ stickerOptions.mimetype = 'image/webp';
140
+ stickerOptions.width = 512;
141
+ stickerOptions.height = 512;
142
+ }
143
+ else if (kind === 'image') {
144
+ const converted = await imageToWebp(content[kind], options);
145
+ visual = converted.buffer;
146
+ isAnimated = converted.isAnimated;
147
+ stickerOptions.mimetype = 'image/webp';
148
+ if (converted.isVideo) {
149
+ stickerOptions.width = 512;
150
+ stickerOptions.height = 512;
151
+ }
152
+ }
153
+ else {
154
+ visual = mediaInput(content[kind]);
155
+ }
156
+ const preparedAudio = await prepareAudio(audio, audioOptions, options);
157
+ const [sticker, sound] = await Promise.all([
158
+ prepareWAMessageMedia({
159
+ sticker: visual,
160
+ isAnimated,
161
+ ...stickerOptions
162
+ }, options),
163
+ prepareWAMessageMedia({
164
+ audio: preparedAudio.media,
165
+ ...preparedAudio.audioOptions,
166
+ ptt: false
167
+ }, options)
168
+ ]);
169
+ sticker.stickerMessage.stickerSentTs ??= Date.now();
170
+ sticker.stickerMessage.audioMessage = sound.audioMessage;
171
+ return { audioStickerMessage: { message: sticker } };
172
+ };
@@ -0,0 +1,30 @@
1
+ /* QIRO utility module. */
2
+ export const CREDS_KEY: string;
3
+ export function encodeAuthValue(value: any): string;
4
+ export function decodeAuthValue(type: string, raw: any): any;
5
+ export function loadOptionalModule(name: string, usedBy: string): Promise<any>;
6
+ export interface AuthStoreEntry {
7
+ type: string;
8
+ id: string;
9
+ value: string;
10
+ }
11
+ export interface AuthStore {
12
+ read: (type: string, id: string) => Promise<any>;
13
+ readMany: (type: string, ids: string[]) => Promise<Record<string, any>>;
14
+ write: (type: string, id: string, value: string) => Promise<void>;
15
+ apply: (writes: AuthStoreEntry[], removals: Omit<AuthStoreEntry, 'value'>[]) => Promise<void>;
16
+ clear: () => Promise<void>;
17
+ close?: () => Promise<void>;
18
+ }
19
+ export function makeAuthStateFromStore(store: AuthStore): Promise<{
20
+ state: {
21
+ creds: any;
22
+ keys: {
23
+ get: (type: any, ids: any) => Promise<{}>;
24
+ set: (data: any) => Promise<void>;
25
+ };
26
+ };
27
+ saveCreds: () => Promise<void>;
28
+ clearAuth: () => Promise<void>;
29
+ close: () => Promise<void>;
30
+ }>;
@@ -0,0 +1,77 @@
1
+ /* QIRO utility module. */
2
+ import { proto } from '../../WAProto/index.js';
3
+ import { initAuthCreds } from './auth-utils.js';
4
+ import { BufferJSON } from './generics.js';
5
+ export const CREDS_KEY = 'creds';
6
+ export const encodeAuthValue = (value) => JSON.stringify(value, BufferJSON.replacer);
7
+ export const decodeAuthValue = (type, raw) => {
8
+ if (raw === null || raw === undefined) {
9
+ return null;
10
+ }
11
+ const value = typeof raw === 'string' ? JSON.parse(raw, BufferJSON.reviver) : raw;
12
+ if (type === 'app-state-sync-key' && value) {
13
+ return proto.Message.AppStateSyncKeyData.fromObject(value);
14
+ }
15
+ return value;
16
+ };
17
+ export const loadOptionalModule = async (name, usedBy) => {
18
+ try {
19
+ const mod = await import(name);
20
+ return mod.default ?? mod;
21
+ }
22
+ catch (err) {
23
+ const helpful = new Error(`\`${name}\` is required for \`${usedBy}\`. Install it as a peer dependency: \`npm install ${name}\`.`);
24
+ helpful.cause = err;
25
+ throw helpful;
26
+ }
27
+ };
28
+ export const makeAuthStateFromStore = async (store) => {
29
+ const stored = await store.read(CREDS_KEY, CREDS_KEY);
30
+ const creds = decodeAuthValue(CREDS_KEY, stored) ?? initAuthCreds();
31
+ const state = {
32
+ creds,
33
+ keys: {
34
+ get: async (type, ids) => {
35
+ const data = {};
36
+ const rows = await store.readMany(type, ids);
37
+ for (const id of ids) {
38
+ const value = decodeAuthValue(type, rows[id]);
39
+ if (value) {
40
+ data[id] = value;
41
+ }
42
+ }
43
+ return data;
44
+ },
45
+ set: async (data) => {
46
+ const writes = [];
47
+ const removals = [];
48
+ for (const type in data) {
49
+ for (const id in data[type]) {
50
+ const value = data[type][id];
51
+ if (value) {
52
+ writes.push({ type, id, value: encodeAuthValue(value) });
53
+ }
54
+ else {
55
+ removals.push({ type, id });
56
+ }
57
+ }
58
+ }
59
+ if (writes.length || removals.length) {
60
+ await store.apply(writes, removals);
61
+ }
62
+ }
63
+ }
64
+ };
65
+ return {
66
+ state,
67
+ saveCreds: async () => {
68
+ await store.write(CREDS_KEY, CREDS_KEY, encodeAuthValue(creds));
69
+ },
70
+ clearAuth: async () => {
71
+ await store.clear();
72
+ },
73
+ close: async () => {
74
+ await store.close?.();
75
+ }
76
+ };
77
+ };
@@ -0,0 +1,34 @@
1
+ /* QIRO utility module. */
2
+ export const CHAT_THEME_COLOR_PRESETS: Readonly<Record<string, string>>;
3
+ export const CHAT_THEME_PRESETS: Readonly<Record<string, string>>;
4
+ export const CHAT_BUBBLE_PRESETS: Readonly<Record<string, string>>;
5
+ export const CHAT_ANIMATED_WALLPAPER_PRESETS: Readonly<Record<string, string>>;
6
+
7
+ export type ChatThemeMedia = string | Buffer | Uint8Array | URL | {
8
+ url: string | URL;
9
+ } | {
10
+ stream: any;
11
+ };
12
+
13
+ export type ChatThemeContent = string | Buffer | Uint8Array | URL | {
14
+ theme?: string | ChatThemeMedia;
15
+ bubble?: string;
16
+ color?: string;
17
+ wallpaper?: ChatThemeMedia;
18
+ animatedWallpaper?: string;
19
+ reset?: boolean;
20
+ colorSchemeId?: string;
21
+ dimLevel?: number;
22
+ };
23
+
24
+ export interface ChatThemeCatalog {
25
+ themes: Readonly<Record<string, string>>;
26
+ bubbles: Readonly<Record<string, string>>;
27
+ animatedWallpapers: Readonly<Record<string, string>>;
28
+ usage: string[];
29
+ }
30
+
31
+ export function isChatThemeExample(content: any): boolean;
32
+ export function getChatThemeExamples(): ChatThemeCatalog;
33
+ export function prepareChatThemeMessages(content: ChatThemeContent, options?: any): Promise<any[]>;
34
+ export function prepareChatThemeMessage(content: ChatThemeContent, options?: any): Promise<any>;
@@ -0,0 +1,336 @@
1
+ /* QIRO utility module. */
2
+ import { Boom } from '@hapi/boom';
3
+ import { promises as fs } from 'fs';
4
+ import { tmpdir } from 'os';
5
+ import { join } from 'path';
6
+ import { proto } from '../../WAProto/index.js';
7
+ import { encryptedStream, extractVideoThumbBuffer as extractVideoThumb, getStream, toBuffer } from './messages-media.js';
8
+
9
+ export const CHAT_THEME_COLOR_PRESETS = Object.freeze({
10
+ pink: '#ff69b4',
11
+ biru: '#1e90ff',
12
+ ungu: '#9b59b6',
13
+ hitam: '#121212',
14
+ hijau: '#2ecc71',
15
+ merah: '#e74c3c',
16
+ kuning: '#f1c40f',
17
+ oren: '#e67e22',
18
+ putih: '#f5f6fa'
19
+ });
20
+
21
+ const THEME_FAMILIES = {
22
+ default: 'Default',
23
+ 'whatsapp-green': 'WhatsApp-Green',
24
+ 'pearl-indigo': 'Pearl-Indigo',
25
+ 'tyrian-purple': 'Tyrian-Purple',
26
+ 'sunset-orange': 'Sunset-Orange',
27
+ 'merino-teal': 'Merino-Teal',
28
+ 'royal-blue': 'Royal-Blue',
29
+ 'dark-cerulean': 'Dark-Cerulean',
30
+ 'charcoal-green': 'Charcoal-Green',
31
+ 'persian-plum': 'Persian-Plum',
32
+ 'dune-mono': 'Dune-Mono',
33
+ 'default-blue': 'Default-Blue',
34
+ 'default-mono': 'Default-Mono',
35
+ 'sky-blue': 'Sky-Blue',
36
+ brown: 'Brown',
37
+ cream: 'Cream',
38
+ emerald: 'Emerald',
39
+ lemon: 'Lemon',
40
+ lime: 'Lime',
41
+ pink: 'Pink',
42
+ red: 'Red',
43
+ 'sunrise-orange': 'Sunrise-Orange',
44
+ 'warm-yellow': 'Warm-Yellow'
45
+ };
46
+
47
+ const MINIMAL_THEMES = new Set(['default-blue', 'default-mono', 'sky-blue', 'pearl-indigo']);
48
+ const schemes = { ...THEME_FAMILIES };
49
+ for (const [alias, id] of Object.entries(THEME_FAMILIES)) {
50
+ if (alias !== 'default') {
51
+ schemes[`${alias}-tonal`] = `${id}@Tonal`;
52
+ }
53
+ if (MINIMAL_THEMES.has(alias)) {
54
+ schemes[`${alias}-minimal`] = `${id}@Minimal`;
55
+ }
56
+ }
57
+
58
+ export const CHAT_THEME_PRESETS = Object.freeze(schemes);
59
+ export const CHAT_BUBBLE_PRESETS = CHAT_THEME_PRESETS;
60
+ export const CHAT_ANIMATED_WALLPAPER_PRESETS = Object.freeze({
61
+ gradient: 'gradient',
62
+ iridescent: 'iridescent',
63
+ aurora: 'aurora',
64
+ 'lava-lamp': 'lavaLamp'
65
+ });
66
+ const CHAT_SCHEME_IDS = new Set(Object.values(CHAT_THEME_PRESETS));
67
+ const CHAT_ANIMATED_WALLPAPER_IDS = new Set(Object.values(CHAT_ANIMATED_WALLPAPER_PRESETS));
68
+
69
+ const RESET_WORDS = new Set(['reset', 'clear', 'hapus', 'default']);
70
+ const EXAMPLE_WORDS = new Set(['example', 'examples', 'contoh', 'list']);
71
+ const WALLPAPER_HKDF_INFO = 'Chat Wallpaper';
72
+ const ARGB_ALPHA = 0xff000000;
73
+
74
+ export const isChatThemeExample = content => typeof content === 'string' && EXAMPLE_WORDS.has(content.trim().toLowerCase());
75
+
76
+ export const getChatThemeExamples = () => ({
77
+ themes: CHAT_THEME_PRESETS,
78
+ bubbles: CHAT_BUBBLE_PRESETS,
79
+ animatedWallpapers: CHAT_ANIMATED_WALLPAPER_PRESETS,
80
+ usage: [
81
+ "conn.setThemeGroup(m.chat, { theme: 'pink' })",
82
+ "conn.setThemeGroup(m.chat, { bubble: 'royal-blue' })",
83
+ "conn.setThemeGroup(m.chat, { theme: 'pink', bubble: 'royal-blue' })",
84
+ "conn.setThemeGroup(m.chat, { theme: './wallpaper.jpg', bubble: 'pink-tonal' })",
85
+ "conn.setThemeGroup(m.chat, { animatedWallpaper: 'aurora', dimLevel: 0.2 })",
86
+ "conn.setThemeGroup(m.chat, { reset: true })"
87
+ ]
88
+ });
89
+
90
+ const parseColor = value => {
91
+ if (typeof value !== 'string') {
92
+ throw new Boom('chat theme color must be a hex string', { statusCode: 400 });
93
+ }
94
+ const input = value.trim().toLowerCase();
95
+ const resolved = CHAT_THEME_COLOR_PRESETS[input] || input;
96
+ const hex = resolved.startsWith('#') ? resolved.slice(1) : resolved;
97
+ if (!/^[0-9a-f]{6}$/.test(hex)) {
98
+ throw new Boom('chat theme color must be #RRGGBB or a known preset', { statusCode: 400 });
99
+ }
100
+ return (ARGB_ALPHA | parseInt(hex, 16)) >>> 0;
101
+ };
102
+
103
+ const findScheme = value => {
104
+ const input = value.trim();
105
+ if (CHAT_SCHEME_IDS.has(input)) {
106
+ return input;
107
+ }
108
+ const alias = input.toLowerCase().replace(/[\s_@]+/g, '-');
109
+ return CHAT_THEME_PRESETS[alias] || null;
110
+ };
111
+
112
+ const resolveScheme = (value, label) => {
113
+ if (typeof value !== 'string' || !value.trim()) {
114
+ throw new Boom(`${label} must be a theme ID from setThemeGroup(jid, 'example')`, { statusCode: 400 });
115
+ }
116
+ const scheme = findScheme(value);
117
+ if (!scheme) {
118
+ throw new Boom(`${label} is unknown; use setThemeGroup(jid, 'example')`, { statusCode: 400 });
119
+ }
120
+ return scheme;
121
+ };
122
+
123
+ const findAnimatedWallpaper = value => {
124
+ if (typeof value !== 'string') {
125
+ return null;
126
+ }
127
+ const input = value.trim();
128
+ if (CHAT_ANIMATED_WALLPAPER_IDS.has(input)) {
129
+ return input;
130
+ }
131
+ const alias = input.toLowerCase().replace(/[\s_@]+/g, '-');
132
+ return CHAT_ANIMATED_WALLPAPER_PRESETS[alias] || null;
133
+ };
134
+
135
+ const resolveAnimatedWallpaper = value => {
136
+ const id = findAnimatedWallpaper(value);
137
+ if (!id) {
138
+ throw new Boom('animatedWallpaper must be gradient, iridescent, aurora, or lava-lamp', { statusCode: 400 });
139
+ }
140
+ return id;
141
+ };
142
+
143
+ const normalizeContent = content => {
144
+ if (content == null) {
145
+ throw new Boom('setThemeGroup needs a theme, bubble, wallpaper, animatedWallpaper, color, or reset', { statusCode: 400 });
146
+ }
147
+ if (typeof content === 'string') {
148
+ const value = content.trim();
149
+ if (RESET_WORDS.has(value.toLowerCase())) {
150
+ return { reset: true };
151
+ }
152
+ if (findAnimatedWallpaper(value)) {
153
+ return { animatedWallpaper: value };
154
+ }
155
+ if (value.startsWith('#') || CHAT_THEME_COLOR_PRESETS[value.toLowerCase()] || /^[0-9a-f]{6}$/i.test(value)) {
156
+ return { color: value };
157
+ }
158
+ return { wallpaper: content };
159
+ }
160
+ if (Buffer.isBuffer(content) || content instanceof Uint8Array || content instanceof URL) {
161
+ return { wallpaper: content };
162
+ }
163
+ if (typeof content !== 'object') {
164
+ throw new Boom('setThemeGroup content is invalid', { statusCode: 400 });
165
+ }
166
+ return { ...content };
167
+ };
168
+
169
+ const normalizeWallpaper = wallpaper => {
170
+ if (typeof wallpaper === 'string' || wallpaper instanceof URL) {
171
+ return { url: wallpaper };
172
+ }
173
+ if (!Buffer.isBuffer(wallpaper) && wallpaper instanceof Uint8Array) {
174
+ return Buffer.from(wallpaper);
175
+ }
176
+ return wallpaper;
177
+ };
178
+
179
+ const isGif = buffer => buffer.length >= 6 && ['GIF87a', 'GIF89a'].includes(buffer.toString('ascii', 0, 6));
180
+ const isVideo = buffer => buffer.length >= 12 && (
181
+ buffer.toString('ascii', 4, 8) === 'ftyp'
182
+ || (buffer[0] === 0x1a && buffer[1] === 0x45 && buffer[2] === 0xdf && buffer[3] === 0xa3)
183
+ || (buffer.toString('ascii', 0, 4) === 'RIFF' && buffer.toString('ascii', 8, 12) === 'AVI ')
184
+ );
185
+
186
+ const prepareWallpaper = async (wallpaper, options) => {
187
+ const { stream } = await getStream(normalizeWallpaper(wallpaper), options.options);
188
+ const source = await toBuffer(stream);
189
+ if (!source.length) {
190
+ throw new Boom('chat wallpaper is empty', { statusCode: 400 });
191
+ }
192
+ if (!isGif(source) && !isVideo(source)) {
193
+ return source;
194
+ }
195
+ const directory = await fs.mkdtemp(join(tmpdir(), 'qiro-chat-wallpaper-'));
196
+ try {
197
+ const sourcePath = join(directory, 'source');
198
+ await fs.writeFile(sourcePath, source);
199
+ const converted = await extractVideoThumb(sourcePath, '00:00:00', { width: 1080, height: 1080 });
200
+ if (!converted.length) {
201
+ throw new Boom('ffmpeg produced an empty wallpaper frame', { statusCode: 400 });
202
+ }
203
+ return converted;
204
+ }
205
+ catch (error) {
206
+ throw new Boom(`failed to convert GIF/video wallpaper to JPEG: ${error.message}`, { statusCode: 400 });
207
+ }
208
+ finally {
209
+ await fs.rm(directory, { recursive: true, force: true });
210
+ }
211
+ };
212
+
213
+ const uploadWallpaper = async (wallpaper, options) => {
214
+ if (typeof options.upload !== 'function') {
215
+ throw new Boom('setThemeGroup wallpaper needs an uploaded media backend', { statusCode: 500 });
216
+ }
217
+ const media = await prepareWallpaper(wallpaper, options);
218
+ const encrypted = await encryptedStream(media, 'chat-wallpaper', {
219
+ logger: options.logger,
220
+ opts: options.options
221
+ }, WALLPAPER_HKDF_INFO);
222
+ try {
223
+ const { directPath } = await options.upload(encrypted.encFilePath, {
224
+ fileEncSha256B64: encrypted.fileEncSha256.toString('base64'),
225
+ mediaType: 'chat-wallpaper',
226
+ timeoutMs: options.mediaUploadTimeoutMs
227
+ });
228
+ if (!directPath) {
229
+ throw new Boom('chat wallpaper upload returned no direct path', { statusCode: 500 });
230
+ }
231
+ return {
232
+ directPath,
233
+ mediaKey: encrypted.mediaKey,
234
+ fileEncSha256: encrypted.fileEncSha256,
235
+ fileSha256: encrypted.fileSha256
236
+ };
237
+ }
238
+ finally {
239
+ await fs.unlink(encrypted.encFilePath).catch(() => {});
240
+ }
241
+ };
242
+
243
+ const buildMessage = ({ bubble, color, wallpaper, animatedWallpaper, reset, defaultWallpaper }) => {
244
+ const chatThemeSetting = proto.Message.ChatThemeSetting.fromObject({
245
+ settingTimestampMs: Date.now(),
246
+ ...(reset ? { clearTheme: true } : {}),
247
+ ...(bubble ? { colorSchemeId: bubble } : {}),
248
+ ...(defaultWallpaper ? { defaultWallpaper: {} } : {}),
249
+ ...(color != null ? { solidColor: { backgroundLightArgb: color, backgroundDarkArgb: color } } : {}),
250
+ ...(wallpaper ? { customImage: wallpaper } : {}),
251
+ ...(animatedWallpaper ? { animatedWallpaper } : {})
252
+ });
253
+ return proto.Message.fromObject({
254
+ protocolMessage: {
255
+ type: proto.Message.ProtocolMessage.Type.CHAT_THEME_SETTING,
256
+ chatThemeSetting
257
+ }
258
+ });
259
+ };
260
+
261
+ export const prepareChatThemeMessages = async (content, options = {}) => {
262
+ const input = normalizeContent(content);
263
+ if (input.theme != null) {
264
+ if (input.color != null || input.wallpaper != null || input.animatedWallpaper != null || input.reset === true) {
265
+ throw new Boom('theme cannot be combined with color, wallpaper, animatedWallpaper, or reset', { statusCode: 400 });
266
+ }
267
+ if (typeof input.theme === 'string') {
268
+ const value = input.theme.trim();
269
+ if (!value) {
270
+ throw new Boom('theme must not be empty', { statusCode: 400 });
271
+ }
272
+ const scheme = findScheme(value);
273
+ if (scheme) {
274
+ input.themeScheme = scheme;
275
+ }
276
+ else if (findAnimatedWallpaper(value)) {
277
+ input.animatedWallpaper = value;
278
+ }
279
+ else if (value.startsWith('#') || CHAT_THEME_COLOR_PRESETS[value.toLowerCase()] || /^[0-9a-f]{6}$/i.test(value)) {
280
+ input.color = value;
281
+ }
282
+ else {
283
+ input.wallpaper = input.theme;
284
+ }
285
+ }
286
+ else {
287
+ input.wallpaper = input.theme;
288
+ }
289
+ }
290
+ if (input.bubble != null && input.colorSchemeId != null) {
291
+ throw new Boom('use only one of bubble or colorSchemeId', { statusCode: 400 });
292
+ }
293
+ const bubble = input.bubble != null ? resolveScheme(input.bubble, 'bubble') : input.colorSchemeId;
294
+ if (bubble != null && (typeof bubble !== 'string' || !bubble.trim())) {
295
+ throw new Boom('chatThemeSetting.colorSchemeId must be a non-empty string', { statusCode: 400 });
296
+ }
297
+ const reset = input.reset === true;
298
+ const sources = [reset, input.color != null, input.wallpaper != null, input.animatedWallpaper != null, input.themeScheme != null].filter(Boolean).length;
299
+ if (sources > 1 || (sources === 0 && bubble == null) || (reset && bubble != null)) {
300
+ throw new Boom('setThemeGroup needs exactly one theme source, optionally one bubble, or reset', { statusCode: 400 });
301
+ }
302
+ if (reset) {
303
+ return [buildMessage({ reset })];
304
+ }
305
+ const color = input.color != null ? parseColor(input.color) : undefined;
306
+ let wallpaper;
307
+ if (input.wallpaper != null) {
308
+ wallpaper = await uploadWallpaper(input.wallpaper, options);
309
+ if (input.dimLevel != null) {
310
+ wallpaper.dimLevel = Number(input.dimLevel);
311
+ }
312
+ }
313
+ let animatedWallpaper;
314
+ if (input.animatedWallpaper != null) {
315
+ animatedWallpaper = { animatedWallpaperId: resolveAnimatedWallpaper(input.animatedWallpaper) };
316
+ if (input.dimLevel != null) {
317
+ animatedWallpaper.dimLevel = Number(input.dimLevel);
318
+ }
319
+ }
320
+ if (input.themeScheme) {
321
+ const themeMessage = buildMessage({ bubble: input.themeScheme, defaultWallpaper: true });
322
+ if (bubble && bubble !== input.themeScheme) {
323
+ return [themeMessage, buildMessage({ bubble })];
324
+ }
325
+ return [themeMessage];
326
+ }
327
+ return [buildMessage({ bubble, color, wallpaper, animatedWallpaper })];
328
+ };
329
+
330
+ export const prepareChatThemeMessage = async (content, options = {}) => {
331
+ const messages = await prepareChatThemeMessages(content, options);
332
+ if (messages.length !== 1) {
333
+ throw new Boom('named theme and bubble overrides require prepareChatThemeMessages', { statusCode: 400 });
334
+ }
335
+ return messages[0];
336
+ };
@@ -107,7 +107,7 @@ export const isAppStateSyncIrrecoverable = (error, attempts) => {
107
107
  return attempts >= MAX_SYNC_ATTEMPTS || error?.name === 'TypeError';
108
108
  };
109
109
  export const encodeSyncdPatch = async ({ type, index, syncAction, apiVersion, operation }, myAppStateKeyId, state, getAppStateSyncKey) => {
110
- const key = !!myAppStateKeyId ? await getAppStateSyncKey(myAppStateKeyId) : undefined;
110
+ const key = myAppStateKeyId ? await getAppStateSyncKey(myAppStateKeyId) : undefined;
111
111
  if (!key) {
112
112
  throw new Boom(`myAppStateKey ("${myAppStateKeyId}") not present`, { data: { isMissingKey: true } });
113
113
  }
@@ -708,7 +708,7 @@ export const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) =
708
708
  ev.emit('chats.update', [
709
709
  {
710
710
  id,
711
- unreadCount: isNullUpdate ? null : !!markReadAction?.read ? 0 : -1,
711
+ unreadCount: isNullUpdate ? null : markReadAction?.read ? 0 : -1,
712
712
  conditional: getChatUpdateConditional(id, markReadAction?.messageRange)
713
713
  }
714
714
  ]);