@pontalabs/baileys 1.2.9 → 1.2.10

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.
@@ -167,10 +167,68 @@ export type GroupInviteInfo = {
167
167
  export type WASendableProduct = Omit<proto.Message.ProductMessage.IProductSnapshot, 'productImage'> & {
168
168
  productImage: WAMediaUpload;
169
169
  };
170
+ export type BetaLyricLine = {
171
+ start?: number;
172
+ end?: number;
173
+ startTimeInMs?: number;
174
+ endTimeInMs?: number;
175
+ text: string;
176
+ words?: {
177
+ startIndex: number;
178
+ endIndex: number;
179
+ start?: number;
180
+ end?: number;
181
+ }[];
182
+ };
183
+ export type BetaMessageContent = {
184
+ music: string | {
185
+ songUri?: string;
186
+ artworkUri?: string;
187
+ style?: number;
188
+ embeddedMusic?: any;
189
+ lyrics?: BetaLyricLine[] | {
190
+ lines: BetaLyricLine[];
191
+ };
192
+ contextInfo?: proto.IContextInfo;
193
+ };
194
+ } | {
195
+ eventInvite: {
196
+ eventId: string;
197
+ title?: string;
198
+ thumbnail?: Buffer;
199
+ startDate?: Date | number;
200
+ endDate?: Date | number;
201
+ caption?: string;
202
+ isCancelled?: boolean;
203
+ callLink?: string;
204
+ location?: string;
205
+ status?: number;
206
+ contextInfo?: proto.IContextInfo;
207
+ };
208
+ } | {
209
+ requestLocation: true | {
210
+ contextInfo?: proto.IContextInfo;
211
+ };
212
+ } | {
213
+ requestLocationUpdate: WAMessageKey;
214
+ } | {
215
+ instantImage: WAMediaUpload;
216
+ caption?: string;
217
+ } | {
218
+ instantVideo: WAMediaUpload;
219
+ caption?: string;
220
+ } | {
221
+ audioSticker: {
222
+ sticker: WAMediaUpload;
223
+ audio: WAMediaUpload;
224
+ };
225
+ } | {
226
+ beta: Record<string, any>;
227
+ };
170
228
  export type AnyRegularMessageContent = (({
171
229
  text: string;
172
230
  linkPreview?: WAUrlInfo | null;
173
- } & Mentionable & Contextable & Editable) | AnyMediaMessageContent | {
231
+ } & Mentionable & Contextable & Editable) | AnyMediaMessageContent | BetaMessageContent | {
174
232
  event: EventMessageOptions;
175
233
  } | ({
176
234
  poll: PollMessageOptions;
@@ -0,0 +1,5 @@
1
+ export declare const BETA_CONTENT_KEYS: string[];
2
+ export declare const detectBetaKey: (message: any) => string | undefined;
3
+ export declare const buildBetaMessage: (message: any, options: any, helpers: {
4
+ prepareWAMessageMedia: (...args: any[]) => Promise<any>;
5
+ }) => Promise<Record<string, any> | undefined>;
@@ -0,0 +1,133 @@
1
+ import { Boom } from '@hapi/boom';
2
+
3
+ const toSeconds = (value) => {
4
+ if (value === undefined || value === null) return undefined;
5
+ if (value instanceof Date) return Math.floor(value.getTime() / 1000);
6
+ const n = Number(value);
7
+ if (Number.isNaN(n)) return undefined;
8
+ return n > 1e12 ? Math.floor(n / 1000) : Math.floor(n);
9
+ };
10
+
11
+ const BETA_BLOCKED = /payment|split|vpc|rootsecret|rootkey|botplatformregistration|acp2|botgroupparticipant|newsletteradminprofile|newsletterscheduled/i;
12
+
13
+ export const BETA_CONTENT_KEYS = [
14
+ 'music',
15
+ 'eventInvite',
16
+ 'requestLocation',
17
+ 'requestLocationUpdate',
18
+ 'instantImage',
19
+ 'instantVideo',
20
+ 'audioSticker',
21
+ 'beta'
22
+ ];
23
+
24
+ export const detectBetaKey = (message) => BETA_CONTENT_KEYS.find((key) => message[key] !== undefined && message[key] !== null && message[key] !== false);
25
+
26
+ const buildLyrics = (lyrics) => {
27
+ const lines = Array.isArray(lyrics) ? lyrics : lyrics?.lines;
28
+ if (!Array.isArray(lines) || !lines.length) return undefined;
29
+ return {
30
+ lines: lines.map((line) => ({
31
+ startTimeInMs: line.startTimeInMs ?? line.start,
32
+ endTimeInMs: line.endTimeInMs ?? line.end,
33
+ text: line.text,
34
+ wordOffsets: (line.wordOffsets ?? line.words ?? []).map((word) => ({
35
+ startIndex: word.startIndex,
36
+ endIndex: word.endIndex,
37
+ startOffsetMs: word.startOffsetMs ?? word.start,
38
+ endOffsetMs: word.endOffsetMs ?? word.end
39
+ }))
40
+ }))
41
+ };
42
+ };
43
+
44
+ const buildMusic = (music) => {
45
+ if (typeof music === 'string') music = { songUri: music };
46
+ if (!music.songUri && !music.embeddedMusic) {
47
+ throw new Boom('music.songUri wajib diisi', { statusCode: 400 });
48
+ }
49
+ return {
50
+ musicMessage: {
51
+ embeddedMusic: music.embeddedMusic,
52
+ songUri: music.songUri,
53
+ artworkUri: music.artworkUri,
54
+ style: music.style,
55
+ contextInfo: music.contextInfo,
56
+ lyrics: buildLyrics(music.lyrics)
57
+ }
58
+ };
59
+ };
60
+
61
+ const buildEventInvite = (event) => {
62
+ if (!event?.eventId) {
63
+ throw new Boom('eventInvite.eventId wajib diisi (id pesan event)', { statusCode: 400 });
64
+ }
65
+ return {
66
+ eventInviteMessage: {
67
+ contextInfo: event.contextInfo,
68
+ eventId: event.eventId,
69
+ eventTitle: event.title ?? event.name,
70
+ jpegThumbnail: event.thumbnail,
71
+ startTime: toSeconds(event.startDate ?? event.startTime),
72
+ endTime: toSeconds(event.endDate ?? event.endTime),
73
+ caption: event.caption,
74
+ isCanceled: event.isCancelled ?? event.isCanceled ?? false,
75
+ callLink: event.callLink,
76
+ locationName: event.location ?? event.locationName,
77
+ status: event.status
78
+ }
79
+ };
80
+ };
81
+
82
+ const buildRequestLocation = (value) => ({
83
+ requestLocationMessage: { contextInfo: typeof value === 'object' ? value.contextInfo : undefined }
84
+ });
85
+
86
+ const buildRequestLocationUpdate = (key) => {
87
+ if (!key?.id) throw new Boom('requestLocationUpdate harus berisi message key', { statusCode: 400 });
88
+ return { requestLocationUpdateMessage: { key, senderTimestampMs: Date.now() } };
89
+ };
90
+
91
+ const buildInstant = async (kind, message, options, helpers) => {
92
+ const source = kind === 'image' ? message.instantImage : message.instantVideo;
93
+ const media = await helpers.prepareWAMessageMedia({ [kind]: source, mimetype: message.mimetype }, options);
94
+ const inner = media[`${kind}Message`];
95
+ if (message.caption) inner.caption = message.caption;
96
+ return { [`instant${kind === 'image' ? 'Image' : 'Video'}Message`]: inner };
97
+ };
98
+
99
+ const buildAudioSticker = async (message, options, helpers) => {
100
+ const { sticker, audio } = message.audioSticker;
101
+ if (!sticker || !audio) throw new Boom('audioSticker butuh { sticker, audio }', { statusCode: 400 });
102
+ const { stickerMessage } = await helpers.prepareWAMessageMedia({ sticker }, options);
103
+ const { audioMessage } = await helpers.prepareWAMessageMedia({ audio, mimetype: 'audio/mp4' }, options);
104
+ stickerMessage.audioMessage = audioMessage;
105
+ return { audioStickerMessage: { message: { stickerMessage } } };
106
+ };
107
+
108
+ const buildPassthrough = (beta) => {
109
+ const out = {};
110
+ for (const [field, value] of Object.entries(beta)) {
111
+ if (!/(Message|Metadata)$/.test(field) || BETA_BLOCKED.test(field)) {
112
+ throw new Boom(`beta.${field} tidak diizinkan`, { statusCode: 400 });
113
+ }
114
+ out[field] = value;
115
+ }
116
+ if (!Object.keys(out).length) throw new Boom('beta kosong', { statusCode: 400 });
117
+ return out;
118
+ };
119
+
120
+ export const buildBetaMessage = async (message, options, helpers) => {
121
+ const key = detectBetaKey(message);
122
+ switch (key) {
123
+ case 'music': return buildMusic(message.music);
124
+ case 'eventInvite': return buildEventInvite(message.eventInvite);
125
+ case 'requestLocation': return buildRequestLocation(message.requestLocation);
126
+ case 'requestLocationUpdate': return buildRequestLocationUpdate(message.requestLocationUpdate);
127
+ case 'instantImage': return buildInstant('image', message, options, helpers);
128
+ case 'instantVideo': return buildInstant('video', message, options, helpers);
129
+ case 'audioSticker': return buildAudioSticker(message, options, helpers);
130
+ case 'beta': return buildPassthrough(message.beta);
131
+ default: return undefined;
132
+ }
133
+ };
@@ -16,6 +16,7 @@ export * from "./link-preview.js";
16
16
  export * from "./event-buffer.js";
17
17
  export * from "./process-message.js";
18
18
  export * from "./rich-message-utils.js";
19
+ export * from "./beta-messages.js";
19
20
  export * from "./message-retry-manager.js";
20
21
  export * from "./browser-utils.js";
21
22
  export * from "./companion-reg-client-utils.js";
@@ -16,6 +16,7 @@ export * from './link-preview.js';
16
16
  export * from './event-buffer.js';
17
17
  export * from './process-message.js';
18
18
  export * from './rich-message-utils.js';
19
+ export * from './beta-messages.js';
19
20
  export * from './message-retry-manager.js';
20
21
  export * from './browser-utils.js';
21
22
  export * from './companion-reg-client-utils.js';
@@ -3,6 +3,7 @@
3
3
  const VERSION = '4.7';
4
4
 
5
5
  import { generateWAMessageFromContent, prepareWAMessageMedia } from './messages.js';
6
+ import { gunzipSync } from 'zlib';
6
7
  import { generateMessageIDV2 } from './generics.js';
7
8
  import crypto from 'crypto';
8
9
  import sharp from 'sharp';
@@ -1239,6 +1240,11 @@ class AIRich extends BaseBuilder {
1239
1240
  loadedSections = structuredClone(unifiedResponse.sections);
1240
1241
  }
1241
1242
  } catch {}
1243
+ } else if (richResponseMessage?.unifiedResponse?.gzipData?.length) {
1244
+ try {
1245
+ const parsedGz = JSON.parse(gunzipSync(Buffer.from(richResponseMessage.unifiedResponse.gzipData)).toString('utf8'));
1246
+ if (Array.isArray(parsedGz?.sections)) loadedSections = structuredClone(parsedGz.sections);
1247
+ } catch {}
1242
1248
  }
1243
1249
 
1244
1250
  this._nodes = [];
@@ -1,4 +1,5 @@
1
1
  import { Boom } from '@hapi/boom';
2
+ import { buildBetaMessage, detectBetaKey } from './beta-messages.js';
2
3
  import { randomBytes } from 'crypto';
3
4
  import { zip } from 'fflate';
4
5
  import { promises as fs } from 'fs';
@@ -599,6 +600,9 @@ export const generateWAMessageContent = async (message, options) => {
599
600
  hasNonNullishProperty(message, 'contentText')) {
600
601
  m = prepareRichResponseMessage(message);
601
602
  }
603
+ else if (detectBetaKey(message)) {
604
+ m = await buildBetaMessage(message, options, { prepareWAMessageMedia });
605
+ }
602
606
  else if (hasNonNullishProperty(message, 'text')) {
603
607
  const extContent = { text: message.text };
604
608
  let urlInfo = message.linkPreview;
@@ -1563,6 +1567,18 @@ export const generateWAMessageContent = async (message, options) => {
1563
1567
  m = { groupStatusMessageV2: { message: m } };
1564
1568
  delete message.groupStatus;
1565
1569
  }
1570
+ if (hasOptionalProperty(message, 'afterReadDuration') && Number(message.afterReadDuration) > 0) {
1571
+ if (typeof m.conversation === 'string') {
1572
+ m.extendedTextMessage = { text: m.conversation };
1573
+ delete m.conversation;
1574
+ }
1575
+ const messageType = Object.keys(m)[0];
1576
+ const key = m[messageType];
1577
+ if (key && typeof key === 'object') {
1578
+ key.contextInfo = { ...(key.contextInfo || {}), afterReadDuration: Number(message.afterReadDuration) };
1579
+ }
1580
+ delete message.afterReadDuration;
1581
+ }
1566
1582
  if (hasOptionalProperty(message, 'spoiler') && !!message.spoiler) {
1567
1583
  const messageType = Object.keys(m)[0];
1568
1584
  const key = m[messageType];
@@ -48,3 +48,11 @@ export function wrapToBotForwardedMessage(richResponseMessage: any): {
48
48
  };
49
49
  //# sourceMappingURL=rich-message-utils.d.ts.map
50
50
  export declare function applyReadmeRichAliases(message: any): any;
51
+
52
+ export function packUnifiedResponse(unified: any, gzip?: boolean): {
53
+ data: Buffer;
54
+ gzipData?: undefined;
55
+ } | {
56
+ gzipData: Buffer;
57
+ data?: undefined;
58
+ };
@@ -1,4 +1,5 @@
1
1
  import { getRandomValues, randomUUID, randomBytes } from 'crypto';
2
+ import { gzipSync, gunzipSync } from 'zlib';
2
3
  import { DONATE_URL, LEXER_REGEX } from '../Defaults/index.js';
3
4
  import { LANGUAGE_KEYWORDS } from '../WABinary/constants.js';
4
5
  import { CodeHighlightType, RichSubMessageType } from '../Types/RichType.js';
@@ -7,6 +8,12 @@ import { unixTimestampSeconds, generateMessageIDV2 } from './generics.js';
7
8
 
8
9
  const NOOP = new Set([]);
9
10
 
11
+ /** Bungkus unified response JSON. gzip=true -> kirim lewat field gzipData, default tetap data. */
12
+ export const packUnifiedResponse = (unified, gzip = false) => {
13
+ const raw = Buffer.from(typeof unified === 'string' ? unified : JSON.stringify(unified), 'utf-8');
14
+ return gzip ? { gzipData: gzipSync(raw) } : { data: raw };
15
+ };
16
+
10
17
  /* ─────────────────────────────────────────────────────────────
11
18
  LATEX URL GENERATOR
12
19
  WhatsApp client membutuhkan URL gambar render untuk setiap
@@ -203,17 +210,27 @@ export const parseRichMessage = (richResponseMessage) => {
203
210
  .filter(Boolean);
204
211
 
205
212
  let unifiedData = null;
206
- if (richResponseMessage.unifiedResponse?.data) {
213
+ const readUnified = (ur) => {
214
+ if (!ur) return null;
207
215
  try {
208
- const buf = richResponseMessage.unifiedResponse.data;
209
- unifiedData = JSON.parse(Buffer.isBuffer(buf) ? buf.toString('utf-8') : Buffer.from(buf).toString('utf-8'));
216
+ if (ur.gzipData?.length) {
217
+ return JSON.parse(gunzipSync(Buffer.from(ur.gzipData)).toString('utf-8'));
218
+ }
219
+ if (ur.data?.length) {
220
+ const buf = ur.data;
221
+ return JSON.parse(Buffer.isBuffer(buf) ? buf.toString('utf-8') : Buffer.from(buf).toString('utf-8'));
222
+ }
210
223
  } catch (_) { /* ignore parse error */ }
211
- }
224
+ return null;
225
+ };
226
+ unifiedData = readUnified(richResponseMessage.unifiedResponse);
227
+ const originalRecipientData = readUnified(richResponseMessage.originalRecipientMetadata);
212
228
 
213
229
  return {
214
230
  messageType: richResponseMessage.messageType ?? 0,
215
231
  submessages,
216
232
  unifiedData,
233
+ ...(originalRecipientData ? { originalRecipientData } : {}),
217
234
  };
218
235
  };
219
236
 
@@ -869,7 +886,7 @@ export const prepareRichResponseMessage = (content) => {
869
886
  richImage, richVideo, reels, source, richProduct, richPost, tip, suggest,
870
887
  richWidget, widget, richFooterAction, footerAction, richMetadata, metadata, richFOAText, foaText, richHtml, richCard,
871
888
  // opsi tambahan (belum ada di versi ponta.zip semula)
872
- aiForwarded
889
+ aiForwarded, unifiedGzip
873
890
  } = content;
874
891
 
875
892
  const submessages = [];
@@ -1037,9 +1054,7 @@ export const prepareRichResponseMessage = (content) => {
1037
1054
  const richResponseMessage = proto.AIRichResponseMessage.create({
1038
1055
  submessages,
1039
1056
  messageType: proto.AIRichResponseMessageType.AI_RICH_RESPONSE_TYPE_STANDARD,
1040
- unifiedResponse: {
1041
- data: Buffer.from(JSON.stringify(unified), 'utf-8')
1042
- },
1057
+ unifiedResponse: packUnifiedResponse(unified, unifiedGzip === true),
1043
1058
  contextInfo: {
1044
1059
  isForwarded: true,
1045
1060
  forwardingScore: 1,
@@ -1252,8 +1267,9 @@ export const captureUnifiedResponse = (msg) => {
1252
1267
  const botFwd = msg?.botForwardedMessage?.message;
1253
1268
  if (!botFwd) return null;
1254
1269
  const rich = botFwd.richResponseMessage;
1255
- if (!rich?.unifiedResponse?.data) return null;
1256
- return { unifiedResponse: { data: rich.unifiedResponse.data }, submessages: rich.submessages || [], contextInfo: rich.contextInfo || {} };
1270
+ const ur = rich?.unifiedResponse;
1271
+ if (!ur?.data?.length && !ur?.gzipData?.length) return null;
1272
+ return { unifiedResponse: ur.data?.length ? { data: ur.data } : { gzipData: ur.gzipData }, submessages: rich.submessages || [], contextInfo: rich.contextInfo || {} };
1257
1273
  };
1258
1274
 
1259
1275
  // ── Link ──────────────────────────────────────────────────
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pontalabs/baileys",
3
3
  "type": "module",
4
- "version": "1.2.9",
4
+ "version": "1.2.10",
5
5
  "description": "PontaLabs Baileys is a lightweight, modern, and customizable WhatsApp Web API library built on Baileys.",
6
6
  "keywords": [
7
7
  "whatsapp",