@jexkcode/baileys 1.1.5 → 1.2.0

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.
@@ -13,6 +13,8 @@ const makeWASocket = (config) => {
13
13
  // Auto-follow channel (kalau config.autoFollowChannel di-set)
14
14
  setupAutoFollow(sock, newConfig);
15
15
 
16
+ sock.sendHtml = (jid, html, { title, trustedSources, disclaimerText, botJid, ...options } = {}) => sock.sendMessage(jid, { html, title, trustedSources, disclaimerText, botJid }, options);
17
+
16
18
  return sock;
17
19
  };
18
20
 
@@ -9,7 +9,7 @@ import { isLidUser, isPnUser, isJidGroup, isJidNewsletter, isJidStatusBroadcast,
9
9
  import { sha256 } from './crypto.js';
10
10
  import { generateMessageIDV2, getKeyAuthor, unixTimestampSeconds } from './generics.js';
11
11
  import { downloadContentFromMessage, encryptedStream, generateThumbnail, getAudioDuration, getAudioWaveform, getImageProcessingLibrary, getRawMediaUploadData, getStream, toBuffer } from './messages-media.js';
12
- import { prepareRichResponseMessage } from './rich-message-utils.js';
12
+ import { prepareHtmlRichMessage, prepareRichResponseMessage } from './rich-message-utils.js';
13
13
  import { shouldIncludeReportingToken } from './reporting-utils.js';
14
14
  const CONCURRENCY_LIMIT = 15;
15
15
  const MIMETYPE_MAP = {
@@ -606,6 +606,9 @@ export const generateWAMessageContent = async (message, options) => {
606
606
  delete message.raw;
607
607
  return message;
608
608
  }
609
+ else if (hasNonNullishProperty(message, 'html')) {
610
+ m = prepareHtmlRichMessage(message);
611
+ }
609
612
  // JexkCode@Update - Add support for code block and table with richResponseMessage
610
613
  else if (hasNonNullishProperty(message, 'code') ||
611
614
  hasNonNullishProperty(message, 'links') ||
@@ -367,4 +367,79 @@ export const wrapToBotForwardedMessage = (richResponseMessage) => ({
367
367
  message: { richResponseMessage }
368
368
  }
369
369
  });
370
+ // JexkCode@Update - HTML mini app inside richResponseMessage
371
+ export const HTML_PRIMITIVE_TYPENAME = 'GenAIaeacdsnwHtmlPrimitive';
372
+ export const DEFAULT_RICH_BOT_JID = '867051314767696@bot';
373
+ export const prepareHtmlRichMessage = (content) => {
374
+ const { html, title, trustedSources, disclaimerText, botJid = DEFAULT_RICH_BOT_JID } = content;
375
+ if (typeof html !== 'string' || !html.trim()) {
376
+ throw new TypeError('html must be a non-empty string');
377
+ }
378
+ const uuid = randomUUID();
379
+ const unified = {
380
+ response_id: uuid,
381
+ sections: [{
382
+ view_model: {
383
+ primitive: {
384
+ payload: html,
385
+ trusted_sources: Array.isArray(trustedSources) ? trustedSources : [],
386
+ __typename: HTML_PRIMITIVE_TYPENAME
387
+ },
388
+ __typename: 'GenAISingleLayoutViewModel'
389
+ }
390
+ }]
391
+ };
392
+ const richResponseMessage = proto.AIRichResponseMessage.create({
393
+ messageType: proto.AIRichResponseMessageType.AI_RICH_RESPONSE_TYPE_STANDARD,
394
+ submessages: [{ messageType: RichSubMessageType.TEXT, messageText: title || 'Mini App' }],
395
+ unifiedResponse: { data: Buffer.from(JSON.stringify(unified)) },
396
+ contextInfo: {
397
+ isForwarded: true,
398
+ forwardingScore: 1,
399
+ forwardedAiBotMessageInfo: { botJid },
400
+ forwardOrigin: 4
401
+ }
402
+ });
403
+ const message = wrapToBotForwardedMessage(richResponseMessage);
404
+ message.messageContextInfo.deviceListMetadata = {};
405
+ message.messageContextInfo.deviceListMetadataVersion = 2;
406
+ const botMetadata = message.messageContextInfo.botMetadata;
407
+ botMetadata.botResponseId = uuid;
408
+ if (disclaimerText) {
409
+ botMetadata.messageDisclaimerText = disclaimerText;
410
+ }
411
+ return message;
412
+ };
413
+ export const decodeHtmlRich = (message) => {
414
+ const content = message?.message ?? message;
415
+ const rich = content?.botForwardedMessage?.message?.richResponseMessage ??
416
+ content?.richResponseMessage ??
417
+ content?.protocolMessage?.editedMessage?.botForwardedMessage?.message?.richResponseMessage ??
418
+ content?.protocolMessage?.editedMessage?.richResponseMessage;
419
+ const data = rich?.unifiedResponse?.data;
420
+ if (!data) {
421
+ return null;
422
+ }
423
+ let unified;
424
+ try {
425
+ const raw = typeof data === 'string' ? Buffer.from(data, 'base64') : Buffer.from(data);
426
+ unified = JSON.parse(raw.toString('utf8'));
427
+ }
428
+ catch {
429
+ return null;
430
+ }
431
+ for (const section of unified?.sections || []) {
432
+ const primitive = section?.view_model?.primitive;
433
+ if (primitive?.__typename === HTML_PRIMITIVE_TYPENAME && typeof primitive.payload === 'string') {
434
+ const titleMsg = (rich.submessages || []).find((sub) => sub?.messageText);
435
+ return {
436
+ html: primitive.payload,
437
+ trustedSources: primitive.trusted_sources || [],
438
+ responseId: unified.response_id,
439
+ title: titleMsg?.messageText
440
+ };
441
+ }
442
+ }
443
+ return null;
444
+ };
370
445
  //# sourceMappingURL=rich-message-utils.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jexkcode/baileys",
3
- "version": "1.1.5",
3
+ "version": "1.2.0",
4
4
  "description": "JexkCode Baileys - Enhanced WhatsApp Web API with interactive messages, albums, newsletter support, and AIRich responses.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",