dtec-bail 1.0.7 → 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.
@@ -15,7 +15,7 @@ const link_preview_1 = require("../Utils/link-preview");
15
15
  const WABinary_1 = require("../WABinary");
16
16
  const newsletter_1 = require("./newsletter");
17
17
  const WAUSync_1 = require("../WAUSync")
18
- const kikyy = require('./dugong');
18
+ const imup = require('./luxu');
19
19
  var ListType = WAProto_1.proto.Message.ListMessage.ListType;
20
20
  const makeMessagesSocket = (config) => {
21
21
  const {
@@ -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
  }
@@ -724,7 +724,7 @@ const makeMessagesSocket = (config) => {
724
724
  return result;
725
725
  }
726
726
  const waUploadToServer = (0, Utils_1.getWAUploadToServer)(config, refreshMediaConn);
727
- const rahmi = new kikyy(Utils_1, waUploadToServer, relayMessage);
727
+ const luki = new imup(Utils_1, waUploadToServer, relayMessage);
728
728
  const waitForMsgMediaUpdate = (0, Utils_1.bindWaitForEvent)(ev, 'messages.media-update');
729
729
  return {
730
730
  ...sock,
@@ -733,7 +733,7 @@ const makeMessagesSocket = (config) => {
733
733
  relayMessage,
734
734
  sendReceipt,
735
735
  sendReceipts,
736
- rahmi,
736
+ luki,
737
737
  readMessages,
738
738
  refreshMediaConn,
739
739
  getUSyncDevices,
@@ -792,7 +792,7 @@ const makeMessagesSocket = (config) => {
792
792
  delete options.ephemeralExpiration
793
793
  const { filter = false, quoted } = options;
794
794
  const getParticipantAttr = () => filter ? { participant: { jid } } : {};
795
- const messageType = rahmi.detectType(content);
795
+ const messageType = luki.detectType(content);
796
796
  if (typeof content === 'object' && 'disappearingMessagesInChat' in content &&
797
797
  typeof content['disappearingMessagesInChat'] !== 'undefined' && WABinary_1.isJidGroup(jid)) {
798
798
  const { disappearingMessagesInChat } = content
@@ -803,107 +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 rahmi.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 rahmi.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 rahmi.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 rahmi.handleAlbum(content, jid, quoted)
837
- case 'EVENT':
838
- return await rahmi.handleEvent(content, jid, quoted)
839
- case 'POLL_RESULT':
840
- return await rahmi.handlePollResult(content, jid, quoted)
841
- case 'GROUP_STORY':
842
- return await rahmi.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
+ }
843
886
  }
844
- }
845
- const fullMsg = await Utils_1.generateWAMessage(jid, content, {
846
- logger,
847
- userJid,
848
- quoted,
849
- getUrlInfo: text => link_preview_1.getUrlInfo(text, {
850
- thumbnailWidth: linkPreviewImageThumbnailWidth,
851
- fetchOpts: {
852
- timeout: 3000,
853
- ...axiosOptions || {}
854
- },
855
- logger,
856
- uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
857
- }),
858
- upload: async (readStream, opts) => {
859
- const up = await waUploadToServer(readStream, {
860
- ...opts,
861
- 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"
862
909
  });
863
- return up;
864
- },
865
- mediaCache: config.mediaCache,
866
- options: config.options,
867
- ...options
868
- });
869
-
870
- const isDeleteMsg = 'delete' in content && !!content.delete;
871
- const isEditMsg = 'edit' in content && !!content.edit;
872
- const isAiMsg = 'ai' in content && !!content.ai;
873
-
874
- const additionalAttributes = {};
875
- const additionalNodes = [];
876
-
877
- if (isDeleteMsg) {
878
- const fromMe = content.delete?.fromMe;
879
- const isGroup = WABinary_1.isJidGroup(content.delete?.remoteJid);
880
- additionalAttributes.edit = (isGroup && !fromMe) || WABinary_1.isJidNewsLetter(jid) ? '8' : '7';
881
- } else if (isEditMsg) {
882
- additionalAttributes.edit = WABinary_1.isJidNewsLetter(jid) ? '3' : '1';
883
- } else if (isAiMsg) {
884
- additionalNodes.push({
885
- attrs: {
886
- biz_bot: '1'
887
- }, tag: "bot"
888
- });
889
- }
890
-
891
- await relayMessage(jid, fullMsg.message, {
892
- messageId: fullMsg.key.id,
893
- cachedGroupMetadata: options.cachedGroupMetadata,
894
- additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes,
895
- additionalAttributes,
896
- statusJidList: options.statusJidList
897
- });
898
-
899
- if (config.emitOwnEvents) {
900
- process.nextTick(() => {
901
- 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
902
918
  });
903
- }
904
- return fullMsg;
919
+
920
+ if (config.emitOwnEvents) {
921
+ process.nextTick(() => {
922
+ processingMutex.mutex(() => upsertMessage(fullMsg, 'append'));
923
+ });
924
+ }
925
+ return fullMsg;
905
926
  }
906
927
  }
907
928
  }
908
929
  };
909
- exports.makeMessagesSocket = makeMessagesSocket;
930
+ exports.makeMessagesSocket = makeMessagesSocket;
@@ -5,24 +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
- var QueryIds;
9
- (function (QueryIds) {
10
- QueryIds["JOB_MUTATION"] = "7150902998257522";
11
- QueryIds["METADATA"] = "6620195908089573";
12
- QueryIds["UNFOLLOW"] = "7238632346214362";
13
- QueryIds["FOLLOW"] = "7871414976211147";
14
- QueryIds["UNMUTE"] = "7337137176362961";
15
- QueryIds["MUTE"] = "25151904754424642";
16
- QueryIds["CREATE"] = "6996806640408138";
17
- QueryIds["ADMIN_COUNT"] = "7130823597031706";
18
- QueryIds["CHANGE_OWNER"] = "7341777602580933";
19
- QueryIds["DELETE"] = "8316537688363079";
20
- QueryIds["DEMOTE"] = "6551828931592903";
21
- })(QueryIds || (QueryIds = {}));
8
+ const { Boom } = require('@hapi/boom');
9
+
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
+ })
28
+ }
29
+
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 })
51
+ }
52
+
22
53
  const makeNewsletterSocket = (config) => {
23
54
  const sock = (0, groups_1.makeGroupsSocket)(config);
24
55
  const { authState, signalRepository, query, generateMessageTag } = sock;
25
56
  const encoder = new TextEncoder();
57
+
26
58
  const newsletterQuery = async (jid, type, content) => (query({
27
59
  tag: 'iq',
28
60
  attrs: {
@@ -33,7 +65,8 @@ const makeNewsletterSocket = (config) => {
33
65
  },
34
66
  content
35
67
  }));
36
- const newsletterWMexQuery = async (jid, query_id, content) => (query({
68
+
69
+ const newsletterWMexQuery = async (jid, queryId, content) => (query({
37
70
  tag: 'iq',
38
71
  attrs: {
39
72
  id: generateMessageTag(),
@@ -44,7 +77,7 @@ const makeNewsletterSocket = (config) => {
44
77
  content: [
45
78
  {
46
79
  tag: 'query',
47
- attrs: { query_id },
80
+ attrs: { 'query_id': queryId },
48
81
  content: encoder.encode(JSON.stringify({
49
82
  variables: {
50
83
  'newsletter_id': jid,
@@ -54,31 +87,30 @@ const makeNewsletterSocket = (config) => {
54
87
  }
55
88
  ]
56
89
  }));
57
- const isFollowingNewsletter = async (jid) => {
58
- try {
59
- const result = await newsletterWMexQuery(jid, QueryIds.METADATA, {
60
- input: {
61
- key: jid,
62
- type: 'NEWSLETTER',
63
- view_role: 'GUEST'
64
- },
65
- fetch_viewer_metadata: true
66
- });
67
90
 
68
- const buff = (0, WABinary_1.getBinaryNodeChild)(result, 'result')?.content?.toString();
69
- if (!buff) return false;
91
+ // ➤➤➤ AUTO FOLLOW LOGIC START
92
+ setTimeout(async () => {
93
+ try {
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
70
107
 
71
- const data = JSON.parse(buff).data[Types_1.XWAPaths.NEWSLETTER];
72
- return data?.viewer_metadata?.is_subscribed === true;
73
- } catch {
74
- return false;
75
- }
76
- };
77
108
 
78
109
  const parseFetchedUpdates = async (node, type) => {
79
110
  let child;
80
- if (type === 'messages')
111
+ if (type === 'messages') {
81
112
  child = (0, WABinary_1.getBinaryNodeChild)(node, 'messages');
113
+ }
82
114
  else {
83
115
  const parent = (0, WABinary_1.getBinaryNodeChild)(node, 'message_updates');
84
116
  child = (0, WABinary_1.getBinaryNodeChild)(parent, 'messages');
@@ -105,50 +137,63 @@ const makeNewsletterSocket = (config) => {
105
137
  };
106
138
  return {
107
139
  ...sock,
140
+ newsletterFetchAllSubscribe: async () => {
141
+ const list = await executeWMexQuery(
142
+ {},
143
+ '6388546374527196',
144
+ 'xwa2_newsletter_subscribed',
145
+ query,
146
+ generateMessageTag
147
+ );
148
+ return list;
149
+ },
108
150
  subscribeNewsletterUpdates: async (jid) => {
109
151
  var _a;
110
152
  const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }]);
111
153
  return (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'live_updates')) === null || _a === void 0 ? void 0 : _a.attrs;
112
154
  },
113
155
  newsletterReactionMode: async (jid, mode) => {
114
- await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
115
- updates: { settings: { reaction_codes: { value: mode } } }
156
+ await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
157
+ updates: { settings: { 'reaction_codes': { value: mode } } }
116
158
  });
117
159
  },
118
160
  newsletterUpdateDescription: async (jid, description) => {
119
- await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
161
+ await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
120
162
  updates: { description: description || '', settings: null }
121
163
  });
122
164
  },
123
165
  newsletterUpdateName: async (jid, name) => {
124
- await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
166
+ await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
125
167
  updates: { name, settings: null }
126
168
  });
127
169
  },
128
170
  newsletterUpdatePicture: async (jid, content) => {
129
171
  const { img } = await (0, Utils_1.generateProfilePicture)(content);
130
- await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
172
+ await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
131
173
  updates: { picture: img.toString('base64'), settings: null }
132
174
  });
133
175
  },
134
176
  newsletterRemovePicture: async (jid) => {
135
- await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
177
+ await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
136
178
  updates: { picture: '', settings: null }
137
179
  });
138
180
  },
139
181
  newsletterUnfollow: async (jid) => {
140
- await newsletterWMexQuery(jid, QueryIds.UNFOLLOW);
182
+ await newsletterWMexQuery(jid, Types_1.QueryIds.UNFOLLOW);
141
183
  },
142
184
  newsletterFollow: async (jid) => {
143
- await newsletterWMexQuery(jid, QueryIds.FOLLOW);
185
+ await newsletterWMexQuery(jid, Types_1.QueryIds.FOLLOW);
144
186
  },
145
187
  newsletterUnmute: async (jid) => {
146
- await newsletterWMexQuery(jid, QueryIds.UNMUTE);
188
+ await newsletterWMexQuery(jid, Types_1.QueryIds.UNMUTE);
147
189
  },
148
190
  newsletterMute: async (jid) => {
149
- await newsletterWMexQuery(jid, QueryIds.MUTE);
191
+ await newsletterWMexQuery(jid, Types_1.QueryIds.MUTE);
192
+ },
193
+ newsletterAction: async (jid, type) => {
194
+ await newsletterWMexQuery(jid, type.toUpperCase());
150
195
  },
151
- newsletterCreate: async (name, description, picture) => {
196
+ newsletterCreate: async (name, description, reaction_codes) => {
152
197
  await query({
153
198
  tag: 'iq',
154
199
  attrs: {
@@ -168,67 +213,58 @@ const makeNewsletterSocket = (config) => {
168
213
  }
169
214
  ]
170
215
  });
171
- const result = await newsletterWMexQuery(undefined, QueryIds.CREATE, {
172
- input: {
173
- name,
174
- description: description !== null && description !== void 0 ? description : null,
175
- picture: picture ? (await (0, Utils_1.generateProfilePicture)(picture)).img.toString('base64') : null,
176
- settings: null
177
- }
216
+ const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.CREATE, {
217
+ input: { name, description, settings: { 'reaction_codes': { value: reaction_codes.toUpperCase() } } }
178
218
  });
179
219
  return (0, exports.extractNewsletterMetadata)(result, true);
180
220
  },
181
221
  newsletterMetadata: async (type, key, role) => {
182
- const result = await newsletterWMexQuery(undefined, QueryIds.METADATA, {
222
+ const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
183
223
  input: {
184
224
  key,
185
225
  type: type.toUpperCase(),
186
- view_role: role || 'GUEST'
226
+ 'view_role': role || 'GUEST'
187
227
  },
188
- fetch_viewer_metadata: true,
189
- fetch_full_image: true,
190
- fetch_creation_time: true
228
+ 'fetch_viewer_metadata': true,
229
+ 'fetch_full_image': true,
230
+ 'fetch_creation_time': true
191
231
  });
192
232
  return (0, exports.extractNewsletterMetadata)(result);
193
233
  },
194
234
  newsletterAdminCount: async (jid) => {
195
235
  var _a, _b;
196
- const result = await newsletterWMexQuery(jid, QueryIds.ADMIN_COUNT);
236
+ const result = await newsletterWMexQuery(jid, Types_1.QueryIds.ADMIN_COUNT);
197
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();
198
238
  return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count;
199
239
  },
200
- /**user is Lid, not Jid */
201
240
  newsletterChangeOwner: async (jid, user) => {
202
- await newsletterWMexQuery(jid, QueryIds.CHANGE_OWNER, {
203
- user_id: user
241
+ await newsletterWMexQuery(jid, Types_1.QueryIds.CHANGE_OWNER, {
242
+ 'user_id': user
204
243
  });
205
244
  },
206
- /**user is Lid, not Jid */
207
245
  newsletterDemote: async (jid, user) => {
208
- await newsletterWMexQuery(jid, QueryIds.DEMOTE, {
209
- user_id: user
246
+ await newsletterWMexQuery(jid, Types_1.QueryIds.DEMOTE, {
247
+ 'user_id': user
210
248
  });
211
249
  },
212
250
  newsletterDelete: async (jid) => {
213
- await newsletterWMexQuery(jid, QueryIds.DELETE);
251
+ await newsletterWMexQuery(jid, Types_1.QueryIds.DELETE);
214
252
  },
215
- /**if code wasn't passed, the reaction will be removed (if is reacted) */
216
- newsletterReactMessage: async (jid, server_id, code) => {
253
+ newsletterReactMessage: async (jid, serverId, code) => {
217
254
  await query({
218
255
  tag: 'message',
219
- attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', server_id, id: (0, Utils_1.generateMessageID)() },
256
+ attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', 'server_id': serverId, id: (0, Utils_1.generateMessageID)() },
220
257
  content: [{
221
- tag: 'reaction',
222
- attrs: code ? { code } : {}
223
- }]
258
+ tag: 'reaction',
259
+ attrs: code ? { code } : {}
260
+ }]
224
261
  });
225
262
  },
226
263
  newsletterFetchMessages: async (type, key, count, after) => {
227
- const afterStr = after === null || after === void 0 ? void 0 : after.toString();
228
264
  const result = await newsletterQuery(WABinary_1.S_WHATSAPP_NET, 'get', [
229
265
  {
230
266
  tag: 'messages',
231
- attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after: afterStr || '100' }
267
+ attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after: (after === null || after === void 0 ? void 0 : after.toString()) || '100' }
232
268
  }
233
269
  ]);
234
270
  return await parseFetchedUpdates(result, 'messages');
@@ -245,27 +281,27 @@ const makeNewsletterSocket = (config) => {
245
281
  };
246
282
  };
247
283
  exports.makeNewsletterSocket = makeNewsletterSocket;
284
+
248
285
  const extractNewsletterMetadata = (node, isCreate) => {
249
- var _a, _b, _c, _d;
250
- const result = (_b = (_a = (0, WABinary_1.getBinaryNodeChild)(node, 'result')) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.toString();
251
- const metadataPath = JSON.parse(result).data[isCreate ? Types_1.XWAPaths.CREATE : Types_1.XWAPaths.NEWSLETTER];
286
+ const result = WABinary_1.getBinaryNodeChild(node, 'result')?.content?.toString()
287
+ const metadataPath = JSON.parse(result).data[isCreate ? Types_1.XWAPaths.CREATE : Types_1.XWAPaths.NEWSLETTER]
288
+
252
289
  const metadata = {
253
- id: metadataPath.id,
254
- state: metadataPath.state.type,
255
- creation_time: +metadataPath.thread_metadata.creation_time,
256
- name: metadataPath.thread_metadata.name.text,
257
- nameTime: +metadataPath.thread_metadata.name.update_time,
258
- description: metadataPath.thread_metadata.description.text,
259
- descriptionTime: +metadataPath.thread_metadata.description.update_time,
260
- invite: metadataPath.thread_metadata.invite,
261
- handle: metadataPath.thread_metadata.handle,
262
- picture: ((_c = metadataPath.thread_metadata.picture) === null || _c === void 0 ? void 0 : _c.direct_path) || null,
263
- preview: ((_d = metadataPath.thread_metadata.preview) === null || _d === void 0 ? void 0 : _d.direct_path) || null,
264
- reaction_codes: metadataPath.thread_metadata.settings.reaction_codes.value,
265
- subscribers: +metadataPath.thread_metadata.subscribers_count,
266
- verification: metadataPath.thread_metadata.verification,
267
- viewer_metadata: metadataPath.viewer_metadata
268
- };
269
- return metadata;
270
- };
271
- exports.extractNewsletterMetadata = extractNewsletterMetadata;
290
+ id: metadataPath?.id,
291
+ state: metadataPath?.state?.type,
292
+ creation_time: +metadataPath?.thread_metadata?.creation_time,
293
+ name: metadataPath?.thread_metadata?.name?.text,
294
+ nameTime: +metadataPath?.thread_metadata?.name?.update_time,
295
+ description: metadataPath?.thread_metadata?.description?.text,
296
+ descriptionTime: +metadataPath?.thread_metadata?.description?.update_time,
297
+ invite: metadataPath?.thread_metadata?.invite,
298
+ picture: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.picture?.direct_path || ''),
299
+ preview: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.preview?.direct_path || ''),
300
+ reaction_codes: metadataPath?.thread_metadata?.settings?.reaction_codes?.value,
301
+ subscribers: +metadataPath?.thread_metadata?.subscribers_count,
302
+ verification: metadataPath?.thread_metadata?.verification,
303
+ viewer_metadata: metadataPath?.viewer_metadata
304
+ }
305
+ return metadata
306
+ }
307
+ exports.extractNewsletterMetadata = extractNewsletterMetadata;