@fvckerss/baileys 1.0.18 → 1.0.20

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.
@@ -959,6 +959,36 @@ const sendRawMessage = async (data) => {
959
959
  const fetchNewChatMessageCap = async () => {
960
960
  return executeWMexQuery({ input: { type: 'INDIVIDUAL_NEW_CHAT_MSG' } }, QueryIds.MESSAGE_CAPPING_INFO, XWAPaths.xwa2_message_capping_info, query, generateMessageTag);
961
961
  };
962
+
963
+ const sendAIRich = async function (jid, content, options = {}) {
964
+ try {
965
+ const sentMsg = await this.sendMessage(jid, content, options);
966
+
967
+ if (!sentMsg || !sentMsg.key) return sentMsg;
968
+
969
+ await this.relayMessage(jid, {
970
+ botForwardedMessage: {
971
+ message: {
972
+ protocolMessage: {
973
+ key: {
974
+ remoteJid: jid,
975
+ fromMe: true,
976
+ id: sentMsg.key.id,
977
+ },
978
+ type: 14,
979
+ editedMessage: sentMsg.message,
980
+ },
981
+ },
982
+ },
983
+ }, { messageId: randomBytes(16).toString('hex').toUpperCase() });
984
+
985
+ return sentMsg;
986
+ } catch (error) {
987
+ logger.error({ error }, "[SEND-AI-RICH ERROR]");
988
+ throw error;
989
+ }
990
+ };
991
+
962
992
  return {
963
993
  type: 'md',
964
994
  ws,
@@ -993,7 +1023,8 @@ const sendRawMessage = async (data) => {
993
1023
  executeUSyncQuery,
994
1024
  onWhatsApp,
995
1025
  fetchAccountReachoutTimelock,
996
- fetchNewChatMessageCap
1026
+ fetchNewChatMessageCap,
1027
+ sendAIRich
997
1028
  };
998
1029
  };
999
1030
  /**
@@ -529,11 +529,16 @@ export const generateWAMessageContent = async (message, options) => {
529
529
  } else if (hasNonNullishProperty(message, "botForwardedMessage")) {
530
530
  m.botForwardedMessage = message.botForwardedMessage;
531
531
  } else if (hasNonNullishProperty(message, 'code') ||
532
- hasNonNullishProperty(message, 'links') ||
533
- hasNonNullishProperty(message, 'table') ||
534
- hasNonNullishProperty(message, 'product') ||
535
- hasNonNullishProperty(message, 'richResponse')) {
536
- m = prepareRichResponseMessage(message);
532
+ hasNonNullishProperty(message, 'links') ||
533
+ hasNonNullishProperty(message, 'table') ||
534
+ hasNonNullishProperty(message, 'product') ||
535
+ hasNonNullishProperty(message, 'richResponse') ||
536
+ hasNonNullishProperty(message, 'contentText') ||
537
+ hasNonNullishProperty(message, 'headerText') ||
538
+ hasNonNullishProperty(message, 'footerText') ||
539
+ hasNonNullishProperty(message, 'items') ||
540
+ hasNonNullishProperty(message, 'suggested')) {
541
+ m = prepareRichResponseMessage(message, options.quoted);
537
542
  } else if (hasNonNullishProperty(message, "buttons")) {
538
543
  const buttons = message.buttons.map((btn, index) => {
539
544
  const button = {
@@ -1231,7 +1236,7 @@ export const generateWAMessageFromContent = (jid, message, options) => {
1231
1236
  const key = getContentType(innerMessage);
1232
1237
  const timestamp = unixTimestampSeconds(options.timestamp);
1233
1238
  const { quoted, userJid } = options;
1234
- if (quoted && !isJidNewsletter(jid)) {
1239
+ if (quoted && !isJidNewsletter(jid) && key !== "botForwardedMessage") {
1235
1240
  const participant = quoted.key.fromMe
1236
1241
  ? userJid // TODO: Add support for LIDs
1237
1242
  : quoted.participant || quoted.key.participant || quoted.key.remoteJid;
@@ -1391,8 +1396,7 @@ export const normalizeMessageContent = (content) => {
1391
1396
  message?.editedMessage ||
1392
1397
  message?.associatedChildMessage ||
1393
1398
  message?.groupStatusMessage ||
1394
- message?.groupStatusMessageV2 ||
1395
- message?.botForwardedMessage
1399
+ message?.groupStatusMessageV2
1396
1400
  );
1397
1401
  }
1398
1402
  };