@synacwave/baileys 0.4.0 → 0.4.2
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/CHANGELOG.md +12 -0
- package/README.md +210 -404
- package/lib/Utils/messages.js +11 -3
- package/lib/Utils/synacwave.js +93 -3
- package/package.json +1 -1
- package/README.upstream.md +0 -2077
package/lib/Utils/messages.js
CHANGED
|
@@ -616,11 +616,19 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
616
616
|
else if (hasNonNullishProperty(message, 'text')) {
|
|
617
617
|
const extContent = { text: message.text };
|
|
618
618
|
let urlInfo = message.linkPreview;
|
|
619
|
-
|
|
619
|
+
// Synacwave: boolean linkPreview support
|
|
620
|
+
// true → force generate; false/null → disable; object → use as-is; undefined → auto
|
|
621
|
+
if (urlInfo === true) {
|
|
620
622
|
urlInfo = await generateLinkPreviewIfRequired(message.text, options.getUrlInfo, options.logger);
|
|
621
623
|
}
|
|
622
|
-
if (urlInfo) {
|
|
623
|
-
|
|
624
|
+
else if (urlInfo === false || urlInfo === null) {
|
|
625
|
+
urlInfo = undefined;
|
|
626
|
+
}
|
|
627
|
+
else if (typeof urlInfo === 'undefined') {
|
|
628
|
+
urlInfo = await generateLinkPreviewIfRequired(message.text, options.getUrlInfo, options.logger);
|
|
629
|
+
}
|
|
630
|
+
if (urlInfo && typeof urlInfo === 'object') {
|
|
631
|
+
extContent.matchedText = urlInfo['matched-text'] || urlInfo.matchedText;
|
|
624
632
|
extContent.jpegThumbnail = urlInfo.jpegThumbnail;
|
|
625
633
|
extContent.description = urlInfo.description;
|
|
626
634
|
extContent.title = urlInfo.title;
|
package/lib/Utils/synacwave.js
CHANGED
|
@@ -246,10 +246,10 @@ const toBuffer = async (input, opts) => {
|
|
|
246
246
|
if (Buffer.isBuffer(input)) {
|
|
247
247
|
return input;
|
|
248
248
|
}
|
|
249
|
-
if (typeof input === 'string' && /^https
|
|
249
|
+
if (typeof input === 'string' && /^https?:\/\//i.test(input)) {
|
|
250
250
|
return downloadRemoteMedia(input, opts);
|
|
251
251
|
}
|
|
252
|
-
if (input?.url && /^https
|
|
252
|
+
if (input?.url && /^https?:\/\//i.test(input.url)) {
|
|
253
253
|
return downloadRemoteMedia(input.url, opts);
|
|
254
254
|
}
|
|
255
255
|
throw new Boom('Expected a Buffer or an http(s) URL', { statusCode: 400 });
|
|
@@ -330,6 +330,93 @@ export const isMetaAiParticipant = (p) => participantIds(p).some(id => id.endsWi
|
|
|
330
330
|
|
|
331
331
|
export const formatMention = (jid) => `@${jidNormalizedUser(jid).split('@')[0]}`;
|
|
332
332
|
|
|
333
|
+
/**
|
|
334
|
+
* Build buttonsMessage with locationMessage header (headerType 6).
|
|
335
|
+
* Matches the extracted WhatsApp buttons+location card structure.
|
|
336
|
+
*/
|
|
337
|
+
export const buildLocationButtonCardPayload = (options = {}) => {
|
|
338
|
+
const text = options.text ?? options.contentText ?? '';
|
|
339
|
+
const footer = options.footer ?? options.footerText ?? '';
|
|
340
|
+
const loc = options.location || {};
|
|
341
|
+
const buttons = Array.isArray(options.buttons) ? options.buttons : [];
|
|
342
|
+
if (!buttons.length) {
|
|
343
|
+
throw new Boom('sendLocationButtonCard requires at least one button', { statusCode: 400 });
|
|
344
|
+
}
|
|
345
|
+
let jpegThumbnail = loc.thumbnail ?? loc.jpegThumbnail;
|
|
346
|
+
if (typeof jpegThumbnail === 'string') {
|
|
347
|
+
jpegThumbnail = Buffer.from(jpegThumbnail, 'base64');
|
|
348
|
+
}
|
|
349
|
+
const mappedButtons = buttons.map((b, i) => ({
|
|
350
|
+
buttonId: String(b.id ?? b.buttonId ?? `btn_${i}`),
|
|
351
|
+
buttonText: { displayText: String(b.text ?? b.displayText ?? b.buttonText?.displayText ?? '') },
|
|
352
|
+
type: 1
|
|
353
|
+
}));
|
|
354
|
+
return {
|
|
355
|
+
buttonsMessage: {
|
|
356
|
+
buttons: mappedButtons,
|
|
357
|
+
locationMessage: {
|
|
358
|
+
degreesLatitude: Number(loc.latitude ?? loc.degreesLatitude ?? 0),
|
|
359
|
+
degreesLongitude: Number(loc.longitude ?? loc.degreesLongitude ?? 0),
|
|
360
|
+
name: loc.name ?? '',
|
|
361
|
+
address: loc.address ?? '',
|
|
362
|
+
...(jpegThumbnail ? { jpegThumbnail } : {})
|
|
363
|
+
},
|
|
364
|
+
header: 'locationMessage',
|
|
365
|
+
contentText: text,
|
|
366
|
+
footerText: footer,
|
|
367
|
+
headerType: 6
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
/** Additional binary nodes required for location button cards to render as interactive. */
|
|
373
|
+
export const buildLocationButtonCardAdditionalNodes = (jid) => {
|
|
374
|
+
const nodes = [{
|
|
375
|
+
tag: 'biz',
|
|
376
|
+
attrs: {},
|
|
377
|
+
content: [{
|
|
378
|
+
tag: 'interactive',
|
|
379
|
+
attrs: { type: 'native_flow', v: '1' },
|
|
380
|
+
content: [{
|
|
381
|
+
tag: 'native_flow',
|
|
382
|
+
attrs: { v: '9', name: 'mixed' },
|
|
383
|
+
content: undefined
|
|
384
|
+
}]
|
|
385
|
+
}]
|
|
386
|
+
}];
|
|
387
|
+
if (jid && !String(jid).endsWith('@g.us')) {
|
|
388
|
+
nodes.push({ tag: 'bot', attrs: { biz_bot: '1' }, content: undefined });
|
|
389
|
+
}
|
|
390
|
+
return nodes;
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Generate a location button card message without sending.
|
|
395
|
+
* @returns {{ key, message, additionalNodes }}
|
|
396
|
+
*/
|
|
397
|
+
export const generateLocationButtonCard = (jid, options, sock) => {
|
|
398
|
+
const payloadObject = buildLocationButtonCardPayload(options);
|
|
399
|
+
const payload = proto.Message.fromObject(payloadObject);
|
|
400
|
+
const additionalNodes = buildLocationButtonCardAdditionalNodes(jid);
|
|
401
|
+
const msg = generateWAMessageFromContent(jid, payload, {
|
|
402
|
+
userJid: sock?.user?.id,
|
|
403
|
+
messageId: options?.messageId
|
|
404
|
+
});
|
|
405
|
+
return { ...msg, additionalNodes };
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Send a location-header buttons card via relayMessage + additionalNodes.
|
|
410
|
+
*/
|
|
411
|
+
export const sendLocationButtonCardWithSocket = async (sock, jid, options = {}) => {
|
|
412
|
+
const generated = generateLocationButtonCard(jid, options, sock);
|
|
413
|
+
await sock.relayMessage(jid, generated.message, {
|
|
414
|
+
messageId: generated.key.id,
|
|
415
|
+
additionalNodes: generated.additionalNodes
|
|
416
|
+
});
|
|
417
|
+
return generated;
|
|
418
|
+
};
|
|
419
|
+
|
|
333
420
|
export const extendSocket = (sock, config = {}) => {
|
|
334
421
|
const selfJid = () => (sock.user?.id ? jidNormalizedUser(sock.user.id) : undefined);
|
|
335
422
|
const selfLid = () => (sock.user?.lid ? jidNormalizedUser(sock.user.lid) : undefined);
|
|
@@ -402,7 +489,7 @@ export const extendSocket = (sock, config = {}) => {
|
|
|
402
489
|
if (value == null || (typeof value === 'string' && /^(clear|off|reset|none)$/i.test(value.trim()))) {
|
|
403
490
|
return relayTheme(jid, buildChatThemeSetting({ clear: true }));
|
|
404
491
|
}
|
|
405
|
-
if (Buffer.isBuffer(value) || (typeof value === 'string' && /^https
|
|
492
|
+
if (Buffer.isBuffer(value) || (typeof value === 'string' && /^https?:\/\//i.test(value))) {
|
|
406
493
|
return relayTheme(jid, buildChatThemeSetting({ wallpaper: await uploadChatWallpaper(sock, await toBuffer(value, { maxBytes: 5 * 1024 * 1024 })) }));
|
|
407
494
|
}
|
|
408
495
|
if (typeof value === 'string') {
|
|
@@ -449,6 +536,9 @@ export const extendSocket = (sock, config = {}) => {
|
|
|
449
536
|
api.sendViewOnceTextMessage = viewOnceText;
|
|
450
537
|
api.sendVotext = viewOnceText;
|
|
451
538
|
|
|
539
|
+
api.generateLocationButtonCard = (jid, options) => generateLocationButtonCard(jid, options, sock);
|
|
540
|
+
api.sendLocationButtonCard = (jid, options) => sendLocationButtonCardWithSocket(sock, jid, options);
|
|
541
|
+
|
|
452
542
|
const uniq = (a) => [...new Set(a)];
|
|
453
543
|
api.addToFavorites = (jids, { current = [] } = {}) => sock.chatModify({ favorites: { jids: uniq([...current, ...[].concat(jids)]), add: true } }, '');
|
|
454
544
|
api.removeFromFavorites = (jids, { current = [] } = {}) => {
|
package/package.json
CHANGED