keith-baileys 1.0.26

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.
Files changed (109) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/WAProto/GenerateStatics.sh +2 -0
  4. package/WAProto/WAProto.proto +4633 -0
  5. package/WAProto/index.js +165029 -0
  6. package/WAProto/keith +1 -0
  7. package/engine-requirements.js +10 -0
  8. package/lib/Defaults/Keith +1 -0
  9. package/lib/Defaults/baileys-version.json +3 -0
  10. package/lib/Defaults/index.js +105 -0
  11. package/lib/Signal/Group/Keith +1 -0
  12. package/lib/Signal/Group/ciphertext-message.js +15 -0
  13. package/lib/Signal/Group/group-session-builder.js +64 -0
  14. package/lib/Signal/Group/group_cipher.js +96 -0
  15. package/lib/Signal/Group/index.js +57 -0
  16. package/lib/Signal/Group/keyhelper.js +55 -0
  17. package/lib/Signal/Group/queue-job.js +57 -0
  18. package/lib/Signal/Group/sender-chain-key.js +34 -0
  19. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  20. package/lib/Signal/Group/sender-key-message.js +69 -0
  21. package/lib/Signal/Group/sender-key-name.js +51 -0
  22. package/lib/Signal/Group/sender-key-record.js +53 -0
  23. package/lib/Signal/Group/sender-key-state.js +99 -0
  24. package/lib/Signal/Group/sender-message-key.js +29 -0
  25. package/lib/Signal/Keith +1 -0
  26. package/lib/Signal/libsignal.js +174 -0
  27. package/lib/Socket/Client/Keith +1 -0
  28. package/lib/Socket/Client/index.js +18 -0
  29. package/lib/Socket/Client/types.js +13 -0
  30. package/lib/Socket/Client/websocket.js +62 -0
  31. package/lib/Socket/Keith +1 -0
  32. package/lib/Socket/business.js +260 -0
  33. package/lib/Socket/chats.js +880 -0
  34. package/lib/Socket/groups.js +340 -0
  35. package/lib/Socket/groupstatus.js +237 -0
  36. package/lib/Socket/index.js +10 -0
  37. package/lib/Socket/messages-recv.js +1077 -0
  38. package/lib/Socket/messages-send.js +988 -0
  39. package/lib/Socket/mex.js +46 -0
  40. package/lib/Socket/newsletter.js +233 -0
  41. package/lib/Socket/socket.js +617 -0
  42. package/lib/Socket/usync.js +65 -0
  43. package/lib/Types/Auth.js +2 -0
  44. package/lib/Types/Call.js +2 -0
  45. package/lib/Types/Chat.js +10 -0
  46. package/lib/Types/Contact.js +2 -0
  47. package/lib/Types/Events.js +2 -0
  48. package/lib/Types/GroupMetadata.js +2 -0
  49. package/lib/Types/Keith +1 -0
  50. package/lib/Types/Label.js +27 -0
  51. package/lib/Types/LabelAssociation.js +9 -0
  52. package/lib/Types/Message.js +7 -0
  53. package/lib/Types/Newsletter.js +33 -0
  54. package/lib/Types/Product.js +2 -0
  55. package/lib/Types/Signal.js +2 -0
  56. package/lib/Types/Socket.js +2 -0
  57. package/lib/Types/State.js +2 -0
  58. package/lib/Types/USync.js +2 -0
  59. package/lib/Types/index.js +42 -0
  60. package/lib/Utils/Keith +1 -0
  61. package/lib/Utils/auth-utils.js +199 -0
  62. package/lib/Utils/baileys-event-stream.js +63 -0
  63. package/lib/Utils/business.js +240 -0
  64. package/lib/Utils/chat-utils.js +741 -0
  65. package/lib/Utils/crypto.js +187 -0
  66. package/lib/Utils/decode-wa-message.js +283 -0
  67. package/lib/Utils/event-buffer.js +516 -0
  68. package/lib/Utils/generics.js +400 -0
  69. package/lib/Utils/history.js +100 -0
  70. package/lib/Utils/index.js +34 -0
  71. package/lib/Utils/lid-mapping.js +88 -0
  72. package/lib/Utils/link-preview.js +122 -0
  73. package/lib/Utils/logger.js +7 -0
  74. package/lib/Utils/lt-hash.js +51 -0
  75. package/lib/Utils/make-mutex.js +44 -0
  76. package/lib/Utils/messages-media.js +706 -0
  77. package/lib/Utils/messages.js +797 -0
  78. package/lib/Utils/noise-handler.js +150 -0
  79. package/lib/Utils/process-message.js +381 -0
  80. package/lib/Utils/signal.js +155 -0
  81. package/lib/Utils/use-multi-file-auth-state.js +124 -0
  82. package/lib/Utils/validate-connection.js +170 -0
  83. package/lib/WABinary/Keith +1 -0
  84. package/lib/WABinary/constants.js +1303 -0
  85. package/lib/WABinary/decode.js +266 -0
  86. package/lib/WABinary/encode.js +252 -0
  87. package/lib/WABinary/generic-utils.js +110 -0
  88. package/lib/WABinary/index.js +21 -0
  89. package/lib/WABinary/jid-utils.js +66 -0
  90. package/lib/WABinary/types.js +2 -0
  91. package/lib/WAM/BinaryInfo.js +13 -0
  92. package/lib/WAM/constants.js +15243 -0
  93. package/lib/WAM/encode.js +153 -0
  94. package/lib/WAM/index.js +19 -0
  95. package/lib/WAM/keith +1 -0
  96. package/lib/WAUSync/Keith +1 -0
  97. package/lib/WAUSync/Protocols/Keith +1 -0
  98. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  99. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  100. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  101. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  102. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
  103. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
  104. package/lib/WAUSync/Protocols/index.js +20 -0
  105. package/lib/WAUSync/USyncQuery.js +93 -0
  106. package/lib/WAUSync/USyncUser.js +26 -0
  107. package/lib/WAUSync/index.js +19 -0
  108. package/lib/index.js +30 -0
  109. package/package.json +32 -0
@@ -0,0 +1,340 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractGroupMetadata = exports.makeGroupsSocket = void 0;
4
+ const WAProto_1 = require("../../WAProto");
5
+ const Types_1 = require("../Types");
6
+ const Utils_1 = require("../Utils");
7
+ const WABinary_1 = require("../WABinary");
8
+ const chats_1 = require("./chats");
9
+ const makeGroupsSocket = (config) => {
10
+ const sock = (0, chats_1.makeChatsSocket)(config);
11
+ const { authState, ev, query, upsertMessage } = sock;
12
+ const groupQuery = async (jid, type, content) => query({
13
+ tag: 'iq',
14
+ attrs: {
15
+ type,
16
+ xmlns: 'w:g2',
17
+ to: jid
18
+ },
19
+ content
20
+ });
21
+ const groupMetadata = async (jid) => {
22
+ const result = await groupQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
23
+ return (0, exports.extractGroupMetadata)(result);
24
+ };
25
+ const groupFetchAllParticipating = async () => {
26
+ const result = await query({
27
+ tag: 'iq',
28
+ attrs: {
29
+ to: '@g.us',
30
+ xmlns: 'w:g2',
31
+ type: 'get'
32
+ },
33
+ content: [
34
+ {
35
+ tag: 'participating',
36
+ attrs: {},
37
+ content: [
38
+ { tag: 'participants', attrs: {} },
39
+ { tag: 'description', attrs: {} }
40
+ ]
41
+ }
42
+ ]
43
+ });
44
+ const data = {};
45
+ const groupsChild = (0, WABinary_1.getBinaryNodeChild)(result, 'groups');
46
+ if (groupsChild) {
47
+ const groups = (0, WABinary_1.getBinaryNodeChildren)(groupsChild, 'group');
48
+ for (const groupNode of groups) {
49
+ const meta = (0, exports.extractGroupMetadata)({
50
+ tag: 'result',
51
+ attrs: {},
52
+ content: [groupNode]
53
+ });
54
+ data[meta.id] = meta;
55
+ }
56
+ }
57
+ sock.ev.emit('groups.update', Object.values(data));
58
+ return data;
59
+ };
60
+ sock.ws.on('CB:ib,,dirty', async (node) => {
61
+ const { attrs } = (0, WABinary_1.getBinaryNodeChild)(node, 'dirty');
62
+ if (attrs.type !== 'groups') {
63
+ return;
64
+ }
65
+ await groupFetchAllParticipating();
66
+ await sock.cleanDirtyBits('groups');
67
+ });
68
+ return {
69
+ ...sock,
70
+ groupMetadata,
71
+ groupCreate: async (subject, participants) => {
72
+ const key = (0, Utils_1.generateMessageIDV2)();
73
+ const result = await groupQuery('@g.us', 'set', [
74
+ {
75
+ tag: 'create',
76
+ attrs: {
77
+ subject,
78
+ key
79
+ },
80
+ content: participants.map(jid => ({
81
+ tag: 'participant',
82
+ attrs: { jid }
83
+ }))
84
+ }
85
+ ]);
86
+ return (0, exports.extractGroupMetadata)(result);
87
+ },
88
+ groupLeave: async (id) => {
89
+ await groupQuery('@g.us', 'set', [
90
+ {
91
+ tag: 'leave',
92
+ attrs: {},
93
+ content: [{ tag: 'group', attrs: { id } }]
94
+ }
95
+ ]);
96
+ },
97
+ groupUpdateSubject: async (jid, subject) => {
98
+ await groupQuery(jid, 'set', [
99
+ {
100
+ tag: 'subject',
101
+ attrs: {},
102
+ content: Buffer.from(subject, 'utf-8')
103
+ }
104
+ ]);
105
+ },
106
+ groupRequestParticipantsList: async (jid) => {
107
+ const result = await groupQuery(jid, 'get', [
108
+ {
109
+ tag: 'membership_approval_requests',
110
+ attrs: {}
111
+ }
112
+ ]);
113
+ const node = (0, WABinary_1.getBinaryNodeChild)(result, 'membership_approval_requests');
114
+ const participants = (0, WABinary_1.getBinaryNodeChildren)(node, 'membership_approval_request');
115
+ return participants.map(v => v.attrs);
116
+ },
117
+ groupRequestParticipantsUpdate: async (jid, participants, action) => {
118
+ const result = await groupQuery(jid, 'set', [
119
+ {
120
+ tag: 'membership_requests_action',
121
+ attrs: {},
122
+ content: [
123
+ {
124
+ tag: action,
125
+ attrs: {},
126
+ content: participants.map(jid => ({
127
+ tag: 'participant',
128
+ attrs: { jid }
129
+ }))
130
+ }
131
+ ]
132
+ }
133
+ ]);
134
+ const node = (0, WABinary_1.getBinaryNodeChild)(result, 'membership_requests_action');
135
+ const nodeAction = (0, WABinary_1.getBinaryNodeChild)(node, action);
136
+ const participantsAffected = (0, WABinary_1.getBinaryNodeChildren)(nodeAction, 'participant');
137
+ return participantsAffected.map(p => {
138
+ return { status: p.attrs.error || '200', jid: p.attrs.jid };
139
+ });
140
+ },
141
+ groupParticipantsUpdate: async (jid, participants, action) => {
142
+ const result = await groupQuery(jid, 'set', [
143
+ {
144
+ tag: action,
145
+ attrs: {},
146
+ content: participants.map(jid => ({
147
+ tag: 'participant',
148
+ attrs: { jid }
149
+ }))
150
+ }
151
+ ]);
152
+ const node = (0, WABinary_1.getBinaryNodeChild)(result, action);
153
+ const participantsAffected = (0, WABinary_1.getBinaryNodeChildren)(node, 'participant');
154
+ return participantsAffected.map(p => {
155
+ return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p };
156
+ });
157
+ },
158
+ groupUpdateDescription: async (jid, description) => {
159
+ var _a;
160
+ const metadata = await groupMetadata(jid);
161
+ const prev = (_a = metadata.descId) !== null && _a !== void 0 ? _a : null;
162
+ await groupQuery(jid, 'set', [
163
+ {
164
+ tag: 'description',
165
+ attrs: {
166
+ ...(description ? { id: (0, Utils_1.generateMessageIDV2)() } : { delete: 'true' }),
167
+ ...(prev ? { prev } : {})
168
+ },
169
+ content: description ? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }] : undefined
170
+ }
171
+ ]);
172
+ },
173
+ groupInviteCode: async (jid) => {
174
+ const result = await groupQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
175
+ const inviteNode = (0, WABinary_1.getBinaryNodeChild)(result, 'invite');
176
+ return inviteNode === null || inviteNode === void 0 ? void 0 : inviteNode.attrs.code;
177
+ },
178
+ groupRevokeInvite: async (jid) => {
179
+ const result = await groupQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
180
+ const inviteNode = (0, WABinary_1.getBinaryNodeChild)(result, 'invite');
181
+ return inviteNode === null || inviteNode === void 0 ? void 0 : inviteNode.attrs.code;
182
+ },
183
+ groupAcceptInvite: async (code) => {
184
+ const results = await groupQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }]);
185
+ const result = (0, WABinary_1.getBinaryNodeChild)(results, 'group');
186
+ return result === null || result === void 0 ? void 0 : result.attrs.jid;
187
+ },
188
+ /**
189
+ * revoke a v4 invite for someone
190
+ * @param groupJid group jid
191
+ * @param invitedJid jid of person you invited
192
+ * @returns true if successful
193
+ */
194
+ groupRevokeInviteV4: async (groupJid, invitedJid) => {
195
+ const result = await groupQuery(groupJid, 'set', [
196
+ { tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
197
+ ]);
198
+ return !!result;
199
+ },
200
+ /**
201
+ * accept a GroupInviteMessage
202
+ * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
203
+ * @param inviteMessage the message to accept
204
+ */
205
+ groupAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
206
+ var _a;
207
+ key = typeof key === 'string' ? { remoteJid: key } : key;
208
+ const results = await groupQuery(inviteMessage.groupJid, 'set', [
209
+ {
210
+ tag: 'accept',
211
+ attrs: {
212
+ code: inviteMessage.inviteCode,
213
+ expiration: inviteMessage.inviteExpiration.toString(),
214
+ admin: key.remoteJid
215
+ }
216
+ }
217
+ ]);
218
+ // if we have the full message key
219
+ // update the invite message to be expired
220
+ if (key.id) {
221
+ // create new invite message that is expired
222
+ inviteMessage = WAProto_1.proto.Message.GroupInviteMessage.fromObject(inviteMessage);
223
+ inviteMessage.inviteExpiration = 0;
224
+ inviteMessage.inviteCode = '';
225
+ ev.emit('messages.update', [
226
+ {
227
+ key,
228
+ update: {
229
+ message: {
230
+ groupInviteMessage: inviteMessage
231
+ }
232
+ }
233
+ }
234
+ ]);
235
+ }
236
+ // generate the group add message
237
+ await upsertMessage({
238
+ key: {
239
+ remoteJid: inviteMessage.groupJid,
240
+ id: (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id),
241
+ fromMe: false,
242
+ participant: key.remoteJid
243
+ },
244
+ messageStubType: Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD,
245
+ messageStubParameters: [authState.creds.me.id],
246
+ participant: key.remoteJid,
247
+ messageTimestamp: (0, Utils_1.unixTimestampSeconds)()
248
+ }, 'notify');
249
+ return results.attrs.from;
250
+ }),
251
+ groupGetInviteInfo: async (code) => {
252
+ const results = await groupQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }]);
253
+ return (0, exports.extractGroupMetadata)(results);
254
+ },
255
+ groupToggleEphemeral: async (jid, ephemeralExpiration) => {
256
+ const content = ephemeralExpiration
257
+ ? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
258
+ : { tag: 'not_ephemeral', attrs: {} };
259
+ await groupQuery(jid, 'set', [content]);
260
+ },
261
+ groupSettingUpdate: async (jid, setting) => {
262
+ await groupQuery(jid, 'set', [{ tag: setting, attrs: {} }]);
263
+ },
264
+ groupMemberAddMode: async (jid, mode) => {
265
+ await groupQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
266
+ },
267
+ groupJoinApprovalMode: async (jid, mode) => {
268
+ await groupQuery(jid, 'set', [
269
+ { tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'group_join', attrs: { state: mode } }] }
270
+ ]);
271
+ },
272
+ groupFetchAllParticipating
273
+ };
274
+ };
275
+ exports.makeGroupsSocket = makeGroupsSocket;
276
+ const extractGroupMetadata = (result) => {
277
+ var _a, _b;
278
+ const group = (0, WABinary_1.getBinaryNodeChild)(result, 'group');
279
+ const descChild = (0, WABinary_1.getBinaryNodeChild)(group, 'description');
280
+ let desc;
281
+ let descId;
282
+ let descOwner;
283
+ let descOwnerJid;
284
+ let descTime;
285
+ if (descChild) {
286
+ desc = (0, WABinary_1.getBinaryNodeChildString)(descChild, 'body');
287
+ descOwner = descChild.attrs.participant ? (0, WABinary_1.jidNormalizedUser)(descChild.attrs.participant) : undefined;
288
+ descOwnerJid = descChild.attrs.participant_pn ? (0, WABinary_1.jidNormalizedUser)(descChild.attrs.participant_pn) : undefined;
289
+ descTime = +descChild.attrs.t;
290
+ descId = descChild.attrs.id;
291
+ }
292
+ const groupId = group.attrs.id.includes('@') ? group.attrs.id : (0, WABinary_1.jidEncode)(group.attrs.id, 'g.us');
293
+ const eph = (_a = (0, WABinary_1.getBinaryNodeChild)(group, 'ephemeral')) === null || _a === void 0 ? void 0 : _a.attrs.expiration;
294
+ const memberAddMode = (0, WABinary_1.getBinaryNodeChildString)(group, 'member_add_mode') === 'all_member_add';
295
+ const metadata = {
296
+ id: groupId,
297
+ addressingMode: group.attrs.addressing_mode,
298
+ subject: group.attrs.subject,
299
+ subjectOwner: group.attrs.s_o,
300
+ subjectOwnerJid: group.attrs.s_o_pn,
301
+ subjectTime: +group.attrs.s_t,
302
+ size: (0, WABinary_1.getBinaryNodeChildren)(group, 'participant').length,
303
+ creation: +group.attrs.creation,
304
+ owner: group.attrs.creator ? (0, WABinary_1.jidNormalizedUser)(group.attrs.creator) : undefined,
305
+ ownerJid: group.attrs.creator_pn ? (0, WABinary_1.jidNormalizedUser)(group.attrs.creator_pn) : undefined,
306
+ desc,
307
+ descId,
308
+ descOwner,
309
+ descOwnerJid,
310
+ descTime,
311
+ linkedParent: ((_b = (0, WABinary_1.getBinaryNodeChild)(group, 'linked_parent')) === null || _b === void 0 ? void 0 : _b.attrs.jid) || undefined,
312
+ restrict: !!(0, WABinary_1.getBinaryNodeChild)(group, 'locked'),
313
+ announce: !!(0, WABinary_1.getBinaryNodeChild)(group, 'announcement'),
314
+ isCommunity: !!(0, WABinary_1.getBinaryNodeChild)(group, 'parent'),
315
+ isCommunityAnnounce: !!(0, WABinary_1.getBinaryNodeChild)(group, 'default_sub_group'),
316
+ joinApprovalMode: !!(0, WABinary_1.getBinaryNodeChild)(group, 'membership_approval_mode'),
317
+ memberAddMode,
318
+ participants: (0, WABinary_1.getBinaryNodeChildren)(group, 'participant').map(({ attrs }) => {
319
+ let pn;
320
+ let lid;
321
+ if ((0, WABinary_1.isJidUser)(attrs.jid)) {
322
+ pn = attrs.jid;
323
+ lid = attrs.lid;
324
+ }
325
+ else if ((0, WABinary_1.isLidUser)(attrs.jid)) {
326
+ lid = attrs.jid;
327
+ pn = attrs.phone_number;
328
+ }
329
+ return {
330
+ id: attrs.jid,
331
+ pn,
332
+ lid,
333
+ jid: (0, WABinary_1.isJidUser)(attrs.jid) ? attrs.jid : (0, WABinary_1.jidNormalizedUser)(attrs.phone_number),
334
+ admin: (attrs.type || null)
335
+ };
336
+ }) // Added missing closing parenthesis and brace for the map function
337
+ };
338
+ return metadata;
339
+ };
340
+ exports.extractGroupMetadata = extractGroupMetadata;
@@ -0,0 +1,237 @@
1
+ "use strict";
2
+ const crypto = require('crypto');
3
+ const Utils_1 = require("../Utils");
4
+ const WABinary_1 = require("../WABinary");
5
+
6
+ class keithStatus {
7
+ constructor(utils, waUploadToServer, relayMessageFn, config, sock) {
8
+ this.utils = utils;
9
+ this.relayMessage = relayMessageFn;
10
+ this.waUploadToServer = waUploadToServer;
11
+ this.config = config;
12
+ this.sock = sock;
13
+
14
+ this.bail = {
15
+ generateWAMessageContent: this.utils.generateWAMessageContent || Utils_1.generateWAMessageContent,
16
+ generateMessageID: Utils_1.generateMessageID,
17
+ getContentType: (msg) => Object.keys(msg.message || {})[0]
18
+ };
19
+ }
20
+
21
+ detectType(content) {
22
+ if (content.groupStatusMessage) return 'GROUP_STORY';
23
+ if (content.interactiveMessage) return 'INTERACTIVE';
24
+ if (content.albumMessage) return 'ALBUM';
25
+ if (content.eventMessage) return 'EVENT';
26
+ return null;
27
+ }
28
+
29
+ async sendGroupStatus(groupJid, content, options = {}) {
30
+ let waMsgContent;
31
+
32
+ if (content.message) {
33
+ waMsgContent = content;
34
+ } else {
35
+ waMsgContent = await Utils_1.generateWAMessageContent(content, {
36
+ upload: this.waUploadToServer,
37
+ logger: this.config.logger,
38
+ mediaCache: this.config.mediaCache,
39
+ options: this.config.options
40
+ });
41
+ }
42
+
43
+ const msg = {
44
+ message: {
45
+ groupStatusMessageV2: {
46
+ message: waMsgContent.message || waMsgContent
47
+ }
48
+ }
49
+ };
50
+
51
+ const messageId = options.messageId || this.bail.generateMessageID();
52
+
53
+ return await this.relayMessage(groupJid, msg.message, {
54
+ messageId,
55
+ ...options
56
+ });
57
+ }
58
+
59
+ async handleGroupStory(content, jid, quoted) {
60
+ const storyData = content.groupStatusMessage;
61
+ let waMsgContent;
62
+
63
+ if (storyData.message) {
64
+ waMsgContent = storyData;
65
+ } else {
66
+ waMsgContent = await Utils_1.generateWAMessageContent(storyData, {
67
+ upload: this.waUploadToServer,
68
+ logger: this.config.logger,
69
+ mediaCache: this.config.mediaCache,
70
+ options: this.config.options
71
+ });
72
+ }
73
+
74
+ let msg = {
75
+ message: {
76
+ groupStatusMessageV2: {
77
+ message: waMsgContent.message || waMsgContent
78
+ }
79
+ }
80
+ };
81
+
82
+ return await this.relayMessage(jid, msg.message, {
83
+ messageId: this.bail.generateMessageID()
84
+ });
85
+ }
86
+
87
+ async sendStatusToGroups(content, jids = []) {
88
+ const userJid = WABinary_1.jidNormalizedUser(this.sock.authState.creds.me.id);
89
+ let allUsers = new Set();
90
+ allUsers.add(userJid);
91
+
92
+ for (const id of jids) {
93
+ const isGroup = WABinary_1.isJidGroup(id);
94
+ const isPrivate = WABinary_1.isJidUser(id);
95
+
96
+ if (isGroup) {
97
+ try {
98
+ const metadata = await this.sock.groupMetadata(id);
99
+ const participants = metadata.participants.map(p => WABinary_1.jidNormalizedUser(p.id));
100
+ participants.forEach(jid => allUsers.add(jid));
101
+ } catch (error) {
102
+ this.config.logger?.error?.(`Error getting metadata for group ${id}: ${error}`);
103
+ }
104
+ } else if (isPrivate) {
105
+ allUsers.add(WABinary_1.jidNormalizedUser(id));
106
+ }
107
+ }
108
+
109
+ const uniqueUsers = Array.from(allUsers);
110
+ const getRandomHexColor = () => "#" + Math.floor(Math.random() * 16777215).toString(16).padStart(6, "0");
111
+
112
+ const isMedia = content.image || content.video || content.audio;
113
+ const isAudio = !!content.audio;
114
+
115
+ const messageContent = { ...content };
116
+
117
+ if (isMedia && !isAudio) {
118
+ if (messageContent.text) {
119
+ messageContent.caption = messageContent.text;
120
+ delete messageContent.text;
121
+ }
122
+ delete messageContent.ptt;
123
+ delete messageContent.font;
124
+ delete messageContent.backgroundColor;
125
+ delete messageContent.textColor;
126
+ }
127
+
128
+ if (isAudio) {
129
+ delete messageContent.text;
130
+ delete messageContent.caption;
131
+ delete messageContent.font;
132
+ delete messageContent.textColor;
133
+ }
134
+
135
+ const font = !isMedia ? (content.font || Math.floor(Math.random() * 9)) : undefined;
136
+ const textColor = !isMedia ? (content.textColor || getRandomHexColor()) : undefined;
137
+ const backgroundColor = (!isMedia || isAudio) ? (content.backgroundColor || getRandomHexColor()) : undefined;
138
+ const ptt = isAudio ? (typeof content.ptt === 'boolean' ? content.ptt : true) : undefined;
139
+
140
+ let msg;
141
+
142
+ try {
143
+ const link_preview_1 = require("../Utils/link-preview");
144
+
145
+ msg = await Utils_1.generateWAMessage(WABinary_1.STORIES_JID, messageContent, {
146
+ logger: this.config.logger,
147
+ userJid,
148
+ getUrlInfo: text => link_preview_1.getUrlInfo(text, {
149
+ thumbnailWidth: this.config.linkPreviewImageThumbnailWidth,
150
+ fetchOpts: { timeout: 3000, ...this.config.options || {} },
151
+ logger: this.config.logger,
152
+ uploadImage: this.config.generateHighQualityLinkPreview ? this.waUploadToServer : undefined
153
+ }),
154
+ upload: this.waUploadToServer,
155
+ mediaCache: this.config.mediaCache,
156
+ options: this.config.options,
157
+ font,
158
+ textColor,
159
+ backgroundColor,
160
+ ptt
161
+ });
162
+ } catch (error) {
163
+ this.config.logger?.error?.(`Error generating message: ${error}`);
164
+ throw error;
165
+ }
166
+
167
+ await this.relayMessage(WABinary_1.STORIES_JID, msg.message, {
168
+ messageId: msg.key.id,
169
+ statusJidList: uniqueUsers,
170
+ additionalNodes: [
171
+ {
172
+ tag: 'meta',
173
+ attrs: {},
174
+ content: [
175
+ {
176
+ tag: 'mentioned_users',
177
+ attrs: {},
178
+ content: jids.map(jid => ({
179
+ tag: 'to',
180
+ attrs: { jid: WABinary_1.jidNormalizedUser(jid) }
181
+ }))
182
+ }
183
+ ]
184
+ }
185
+ ]
186
+ });
187
+
188
+ for (const id of jids) {
189
+ try {
190
+ const normalizedId = WABinary_1.jidNormalizedUser(id);
191
+ const isPrivate = WABinary_1.isJidUser(normalizedId);
192
+ const type = isPrivate ? 'statusMentionMessage' : 'groupStatusMentionMessage';
193
+
194
+ const protocolMessage = {
195
+ [type]: {
196
+ message: {
197
+ protocolMessage: {
198
+ key: msg.key,
199
+ type: 25
200
+ }
201
+ }
202
+ },
203
+ messageContextInfo: {
204
+ messageSecret: crypto.randomBytes(32)
205
+ }
206
+ };
207
+
208
+ const statusMsg = await Utils_1.generateWAMessageFromContent(
209
+ normalizedId,
210
+ protocolMessage,
211
+ {}
212
+ );
213
+
214
+ await this.relayMessage(
215
+ normalizedId,
216
+ statusMsg.message,
217
+ {
218
+ additionalNodes: [{
219
+ tag: 'meta',
220
+ attrs: isPrivate ?
221
+ { is_status_mention: 'true' } :
222
+ { is_group_status_mention: 'true' }
223
+ }]
224
+ }
225
+ );
226
+
227
+ await Utils_1.delay(2000);
228
+ } catch (error) {
229
+ this.config.logger?.error?.(`Error sending to ${id}: ${error}`);
230
+ }
231
+ }
232
+
233
+ return msg;
234
+ }
235
+ }
236
+
237
+ module.exports = keithStatus;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const Defaults_1 = require("../Defaults");
4
+ const business_1 = require("./business");
5
+ // export the last socket layer
6
+ const makeWASocket = (config) => (0, business_1.makeBusinessSocket)({
7
+ ...Defaults_1.DEFAULT_CONNECTION_CONFIG,
8
+ ...config
9
+ });
10
+ exports.default = makeWASocket;