@poucode/baileys 1.0.2 → 2.0.1

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 (35) hide show
  1. package/README.md +19 -0
  2. package/lib/Defaults/index.js +1 -1
  3. package/lib/Socket/chats.js +5 -0
  4. package/lib/Socket/graphql.js +716 -0
  5. package/lib/Socket/index.js +10 -2
  6. package/lib/Socket/interop.js +463 -0
  7. package/lib/Socket/luxu.js +1 -1
  8. package/lib/Socket/message-builder.js +475 -0
  9. package/lib/Socket/messages-send.js +59 -11
  10. package/lib/Socket/privacy.js +318 -0
  11. package/lib/Store/make-in-memory-store.js +47 -1
  12. package/lib/Utils/index.js +1 -0
  13. package/lib/Utils/messages-media.js +82 -0
  14. package/lib/Utils/messages.js +137 -3
  15. package/lib/Utils/sticker.js +133 -0
  16. package/lib/Utils/use-sqlite-auth-state.js +162 -0
  17. package/lib/WAUSync/Protocols/BotProfileProtocol.js +53 -0
  18. package/lib/WAUSync/Protocols/LIDProtocol.js +30 -0
  19. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +43 -0
  20. package/lib/WAUSync/Protocols/USyncContactProtocol.js +53 -50
  21. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +56 -52
  22. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +29 -25
  23. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +58 -0
  24. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +32 -0
  25. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +28 -0
  26. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -36
  27. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
  28. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +26 -23
  29. package/lib/WAUSync/Protocols/index.js +12 -5
  30. package/lib/WAUSync/USyncQuery.js +150 -96
  31. package/lib/WAUSync/USyncUser.js +55 -29
  32. package/lib/WAUSync/index.js +3 -3
  33. package/package.json +5 -3
  34. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -50
  35. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -28
@@ -0,0 +1,475 @@
1
+ import crypto from 'crypto';
2
+ import { proto } from '../../WAProto/index.js';
3
+ import { generateWAMessageFromContent, prepareWAMessageMedia } from '../Utils/index.js';
4
+
5
+ export const makeMessageBuilderSocket = (sock) => {
6
+ const { relayMessage, sendMessage, waUploadToServer } = sock;
7
+
8
+ // per-socket-instance poll state: id -> [{ vote, action }]
9
+ const pollActionStore = new Map();
10
+
11
+ /**
12
+ * Relay an arbitrary raw message content object, bypassing the normal
13
+ * content-type detection in sendMessage(). Useful when you've already
14
+ * built a proto-shaped message (e.g. from generateWAMessageFromContent)
15
+ * and just need it sent as-is.
16
+ */
17
+ const sendJsonMessage = async (jid, content = {}, options = {}) => {
18
+ const msg = generateWAMessageFromContent(jid, content, {});
19
+ return relayMessage(jid, msg.message, { messageId: msg.key.id, ...options });
20
+ };
21
+
22
+ /**
23
+ * Sends a WA poll and remembers which "action" each option maps to, so
24
+ * a caller can look up what the voter selected once the vote comes back
25
+ * through a `messages.update` event (see resolvePollAction below).
26
+ *
27
+ * pollOptions: [{ vote: 'Option label', action: 'anything you want back' }]
28
+ */
29
+ const sendActionPoll = async (jid, name = '', pollOptions = [], options = {}) => {
30
+ const values = pollOptions.map(o => o.vote);
31
+ const pollMsg = await sendMessage(jid, { poll: { name, values, selectableCount: options.selectableCount || 1 } }, options);
32
+ pollActionStore.set(pollMsg.key.id, pollOptions);
33
+ return pollMsg;
34
+ };
35
+
36
+ /**
37
+ * Given a poll creation message id and the selected option label (as
38
+ * resolved via getAggregateVotesInPollMessage), returns the `action`
39
+ * that was registered for it in sendActionPoll, or undefined if this
40
+ * poll wasn't created through sendActionPoll (or already forgotten).
41
+ */
42
+ const resolvePollAction = (pollMessageId, selectedVoteLabel) => {
43
+ const options = pollActionStore.get(pollMessageId);
44
+ return options?.find(o => o.vote === selectedVoteLabel)?.action;
45
+ };
46
+
47
+ /**
48
+ * Sends a set of media files as a single WA album (grouped gallery).
49
+ * media: array of local file paths or URLs; extension picks image/video.
50
+ */
51
+ const sendAlbumMessage = async (jid, media = [], contextInfo = {}) => {
52
+ const albumMsg = generateWAMessageFromContent(jid, proto.Message.fromObject({
53
+ albumMessage: {
54
+ expectedImageCount: media.filter(m => !/\.mp4$/i.test(m)).length,
55
+ expectedVideoCount: media.filter(m => /\.mp4$/i.test(m)).length,
56
+ contextInfo
57
+ }
58
+ }), {});
59
+
60
+ const albumKey = {
61
+ id: await relayMessage(jid, albumMsg.message, { messageId: albumMsg.key.id }),
62
+ remoteJid: jid,
63
+ fromMe: true
64
+ };
65
+
66
+ const keys = { album: albumKey };
67
+ let i = 1;
68
+
69
+ const mimetypes = {
70
+ jpg: 'image/jpeg', jpeg: 'image/jpeg', png: 'image/png',
71
+ gif: 'image/gif', webp: 'image/webp', mp4: 'video/mp4'
72
+ };
73
+ const messagetypes = {
74
+ jpg: 'imageMessage', jpeg: 'imageMessage', png: 'imageMessage',
75
+ gif: 'imageMessage', webp: 'imageMessage', mp4: 'videoMessage'
76
+ };
77
+
78
+ for (const source of media) {
79
+ const ext = source.split('.').pop().toLowerCase();
80
+ const mimetype = mimetypes[ext];
81
+ const type = messagetypes[ext];
82
+
83
+ if (!mimetype || !type) {
84
+ continue;
85
+ }
86
+
87
+ const msg = await prepareWAMessageMedia(
88
+ { [type.startsWith('image') ? 'image' : 'video']: { url: source }, mimetype },
89
+ { upload: waUploadToServer }
90
+ );
91
+
92
+ const mediaMessage = generateWAMessageFromContent(jid, proto.Message.fromObject({
93
+ associatedChildMessage: {
94
+ message: {
95
+ messageContextInfo: {
96
+ messageSecret: crypto.randomBytes(32),
97
+ messageAssociation: {
98
+ associationType: 'MEDIA_ALBUM',
99
+ parentMessageKey: albumKey
100
+ }
101
+ },
102
+ [type]: { ...msg[type] }
103
+ }
104
+ }
105
+ }), {});
106
+
107
+ keys[`media_${i++}`] = {
108
+ id: await relayMessage(jid, mediaMessage.message, { messageId: mediaMessage.key.id }),
109
+ fromMe: true,
110
+ remoteJid: jid
111
+ };
112
+ }
113
+
114
+ return keys;
115
+ };
116
+
117
+ /**
118
+ * Posts `content` to status@broadcast and mentions `jid` in it (i.e. a
119
+ * status update that notifies a specific contact).
120
+ */
121
+ const sendStatusMention = async (jid, content) => {
122
+ const media = generateWAMessageFromContent('status@broadcast', content, {});
123
+
124
+ const additionalNodes = [
125
+ {
126
+ tag: 'meta',
127
+ attrs: {},
128
+ content: [
129
+ {
130
+ tag: 'mentioned_users',
131
+ attrs: {},
132
+ content: [{ tag: 'to', attrs: { jid }, content: undefined }]
133
+ }
134
+ ]
135
+ }
136
+ ];
137
+
138
+ await relayMessage('status@broadcast', media.message, {
139
+ messageId: media.key.id,
140
+ statusJidList: [jid, sock.user?.id],
141
+ additionalNodes
142
+ });
143
+
144
+ return media;
145
+ };
146
+
147
+ /**
148
+ * Builds and sends a "rich response" card (WA's GenAI-style unified
149
+ * response widget: optional header image/title, body buttons or a
150
+ * carousel/row of cards, and an optional footer link).
151
+ *
152
+ * content.header: { title, image: { url, mime_type, inline, width, height }, disclaimer, disclaimerText }
153
+ * content.body: { title, buttons: [labels] } OR { carousel|row: true, cards: [{ title, buttons, toast }] }
154
+ * content.footer: { text, url, image }
155
+ */
156
+ const sendRichResponse = async (jid, content = {}) => {
157
+ const header = content?.header;
158
+ const body = content?.body;
159
+ const footer = content?.footer;
160
+ let messageContextInfo = {};
161
+ const sections = [];
162
+
163
+ if (header) {
164
+ const { disclaimer = false, disclaimerText = ' ', image = { inline: false }, title = '' } = header ?? {};
165
+
166
+ if (disclaimer) {
167
+ messageContextInfo = { messageContextInfo: { botMetadata: { messageDisclaimerText: disclaimerText } } };
168
+ }
169
+
170
+ if (title) {
171
+ sections.push({
172
+ __typename: 'GenAIUnifiedResponseSection',
173
+ view_model: {
174
+ __typename: 'GenAISingleLayoutViewModel',
175
+ primitive: { __typename: 'FOATextPrimitive', text: '# ' + title }
176
+ }
177
+ });
178
+ }
179
+
180
+ if (image?.url) {
181
+ sections.push(image.inline ? {
182
+ __typename: 'GenAIUnifiedResponseSection',
183
+ view_model: {
184
+ __typename: 'GenAISingleLayoutViewModel',
185
+ primitive: {
186
+ __typename: 'GenAIMarkdownTextUXPrimitive',
187
+ text: '{{header}}.{{/header}}',
188
+ inline_entities: [{
189
+ __typename: 'GenAITextInlineEntity',
190
+ key: 'header',
191
+ metadata: {
192
+ __typename: 'GenAILatexItem',
193
+ latex_expression: '.',
194
+ font_height: 24,
195
+ padding: 4,
196
+ latex_image: {
197
+ __typename: 'GenAIMediaItem',
198
+ mime_type: image.mime_type || 'image/png',
199
+ url: image.url,
200
+ url_fallback: image.url,
201
+ width: image.width || 500,
202
+ height: image.height || 500,
203
+ expiration_timestamp_ms: Date.now() + 86400000
204
+ }
205
+ }
206
+ }]
207
+ }
208
+ }
209
+ } : {
210
+ __typename: 'GenAIUnifiedResponseSection',
211
+ view_model: {
212
+ __typename: 'GenAISingleLayoutViewModel',
213
+ primitive: {
214
+ __typename: 'GenAIImagePrimitive',
215
+ preview_image: { __typename: 'GenAIMediaItem', mime_type: image.mime_type || 'image/png', url: image.url },
216
+ full_image: { __typename: 'GenAIMediaItem', mime_type: image.mime_type || 'image/png', url: image.url }
217
+ }
218
+ }
219
+ });
220
+ }
221
+ }
222
+
223
+ if (body) {
224
+ const { cards = null, buttons = null, title = '', toast = '', carousel = false, row = false } = body ?? {};
225
+
226
+ if ((carousel || row) && cards?.length >= 1) {
227
+ sections.push({
228
+ __typename: 'GenAIUnifiedResponseSection',
229
+ view_model: {
230
+ primitives: cards.map((card, cardIndex) => ({
231
+ __typename: 'GenAI3PExtWidgetPrimitive',
232
+ header: { __typename: 'GenAI3PExtWidgetStandardHeader', title: card?.title || '' },
233
+ body: {
234
+ __typename: 'GenAI3PExtCalendarEventList',
235
+ ctas: (card?.buttons || []).map((text, buttonIndex) => ({
236
+ label: text,
237
+ state: 'PENDING',
238
+ kind: 'OTHER',
239
+ tool_call_id: `${cardIndex}${buttonIndex}`,
240
+ toast: { label: card?.toast || '', __typename: 'GenAI3PExtWidgetToast' },
241
+ __typename: 'GenAI3PExtWidgetCTA'
242
+ })),
243
+ sections: []
244
+ }
245
+ })),
246
+ __typename: carousel ? 'GenAIHScrollLayoutViewModel' : 'GenAIActionRowLayoutViewModel'
247
+ }
248
+ });
249
+ } else if (buttons?.length) {
250
+ sections.push({
251
+ __typename: 'GenAIUnifiedResponseSection',
252
+ view_model: {
253
+ primitive: {
254
+ __typename: 'GenAI3PExtWidgetPrimitive',
255
+ header: { __typename: 'GenAI3PExtWidgetStandardHeader', title: title || '' },
256
+ body: {
257
+ __typename: 'GenAI3PExtCalendarEventList',
258
+ ctas: buttons.map((text, buttonIndex) => ({
259
+ label: text,
260
+ state: 'PENDING',
261
+ kind: 'OTHER',
262
+ tool_call_id: `${buttonIndex}`,
263
+ toast: { label: toast, __typename: 'GenAI3PExtWidgetToast' },
264
+ __typename: 'GenAI3PExtWidgetCTA'
265
+ })),
266
+ sections: []
267
+ }
268
+ },
269
+ __typename: 'GenAISingleLayoutViewModel'
270
+ }
271
+ });
272
+ }
273
+ }
274
+
275
+ if (footer) {
276
+ const { text = '', url = '', image = {} } = footer ?? {};
277
+ const img = [];
278
+ if (image?.url) {
279
+ img.push({
280
+ __typename: 'GenAIMarkdownTextUXPrimitive',
281
+ text: '{{header}}.{{/header}}',
282
+ inline_entities: [{
283
+ __typename: 'GenAITextInlineEntity',
284
+ key: 'header',
285
+ metadata: {
286
+ __typename: 'GenAILatexItem',
287
+ latex_expression: '.',
288
+ font_height: 24,
289
+ padding: -5,
290
+ latex_image: {
291
+ __typename: 'GenAIMediaItem',
292
+ mime_type: image.mime_type || 'image/png',
293
+ url: image.url,
294
+ url_fallback: image.url,
295
+ width: image.width || 100,
296
+ height: image.height || 100,
297
+ expiration_timestamp_ms: Date.now() + 86400000
298
+ }
299
+ }
300
+ }]
301
+ });
302
+ }
303
+ sections.push({
304
+ view_model: {
305
+ primitives: [
306
+ { cta_text: text || '', cta_type: 'OPEN_URL', cta_url: url || '', __typename: 'GenAIFooterActionPrimitive' },
307
+ ...img
308
+ ],
309
+ __typename: 'GenAIActionRowLayoutViewModel'
310
+ }
311
+ });
312
+ }
313
+
314
+ return sendJsonMessage(jid, {
315
+ ...messageContextInfo,
316
+ richResponseMessage: {
317
+ unifiedResponse: { data: Buffer.from(JSON.stringify({ sections })).toString('base64') },
318
+ contextInfo: content?.contextInfo ?? {}
319
+ }
320
+ });
321
+ };
322
+
323
+ /**
324
+ * Sends a native quick-reply buttons message.
325
+ * buttons: [{ id: 'unique_id', text: 'Label' }]
326
+ */
327
+ const sendButtonsMessage = async (jid, { text = '', footer = '', buttons = [] } = {}, options = {}) => {
328
+ const interactiveMessage = {
329
+ body: { text },
330
+ ...(footer ? { footer: { text: footer } } : {}),
331
+ nativeFlowMessage: {
332
+ buttons: buttons.map(b => ({
333
+ name: b.name || 'quick_reply',
334
+ buttonParamsJson: JSON.stringify({ display_text: b.text, id: b.id })
335
+ }))
336
+ }
337
+ };
338
+ return sendJsonMessage(jid, { viewOnceMessage: { message: { interactiveMessage } } }, options);
339
+ };
340
+
341
+ /**
342
+ * Sends a native single-select list message.
343
+ * sections: [{ title: 'Section', rows: [{ title, description, id }] }]
344
+ */
345
+ const sendListMessage = async (jid, { text = '', footer = '', buttonText = 'Menu', sections = [] } = {}, options = {}) => {
346
+ const interactiveMessage = {
347
+ body: { text },
348
+ ...(footer ? { footer: { text: footer } } : {}),
349
+ nativeFlowMessage: {
350
+ buttons: [{
351
+ name: 'single_select',
352
+ buttonParamsJson: JSON.stringify({ title: buttonText, sections })
353
+ }]
354
+ }
355
+ };
356
+ return sendJsonMessage(jid, { viewOnceMessage: { message: { interactiveMessage } } }, options);
357
+ };
358
+
359
+ /**
360
+ * Sends a native horizontal-scroll carousel of cards (the correct native
361
+ * mechanism for side-by-side buttons — unlike the GenAI rich-response
362
+ * widget, which is designed as a vertical list).
363
+ * cards: [{ image: 'url or local path', mimetype, title, body, buttons: [{ id, text }] }]
364
+ */
365
+ const sendCarouselMessage = async (jid, { text = '', footer = '', cards = [] } = {}, options = {}) => {
366
+ const cardMessages = [];
367
+
368
+ for (const card of cards) {
369
+ let headerMedia = {};
370
+ if (card.image) {
371
+ const uploaded = await prepareWAMessageMedia(
372
+ { image: { url: card.image }, mimetype: card.mimetype || 'image/jpeg' },
373
+ { upload: waUploadToServer }
374
+ );
375
+ headerMedia = { imageMessage: uploaded.imageMessage };
376
+ }
377
+
378
+ cardMessages.push({
379
+ header: { title: card.title || '', hasMediaAttachment: !!card.image, ...headerMedia },
380
+ body: { text: card.body || '' },
381
+ nativeFlowMessage: {
382
+ buttons: (card.buttons || []).map(b => ({
383
+ name: b.name || 'quick_reply',
384
+ buttonParamsJson: JSON.stringify({ display_text: b.text, id: b.id })
385
+ }))
386
+ }
387
+ });
388
+ }
389
+
390
+ const message = {
391
+ viewOnceMessage: {
392
+ message: {
393
+ interactiveMessage: {
394
+ body: { text },
395
+ ...(footer ? { footer: { text: footer } } : {}),
396
+ carouselMessage: { cards: cardMessages, messageVersion: 1 }
397
+ }
398
+ }
399
+ }
400
+ };
401
+ return sendJsonMessage(jid, message, options);
402
+ };
403
+
404
+ /**
405
+ * Forwards an existing message (e.g. one pulled from the store) to
406
+ * another chat. Delegates to the library's own forward content builder
407
+ * (sendMessage's `forward` content type) so conversation→extendedText
408
+ * conversion, forwardingScore, and isForwarded are handled correctly
409
+ * instead of being reimplemented here.
410
+ */
411
+ const forwardMessage = async (jid, message, options = {}) => {
412
+ return sendMessage(jid, { forward: message, force: options.force }, options);
413
+ };
414
+
415
+ /**
416
+ * Builds a proper vCard string and sends it as a contact message.
417
+ * contact: { name, phone (E.164, no '+'), organization, waid }
418
+ * If multiple contacts are given, sends a contactsArrayMessage.
419
+ */
420
+ const sendVCard = async (jid, contacts, options = {}) => {
421
+ const list = Array.isArray(contacts) ? contacts : [contacts];
422
+ const built = list.map(c => {
423
+ const waid = c.waid || c.phone;
424
+ const vcard = 'BEGIN:VCARD\n'
425
+ + 'VERSION:3.0\n'
426
+ + `FN:${c.name || 'Unknown'}\n`
427
+ + (c.organization ? `ORG:${c.organization};\n` : '')
428
+ + `TEL;type=CELL;type=VOICE;waid=${waid}:+${c.phone}\n`
429
+ + 'END:VCARD';
430
+ return { displayName: c.name || 'Unknown', vcard };
431
+ });
432
+
433
+ if (built.length === 1) {
434
+ return sendMessage(jid, { contacts: { contacts: built } }, options);
435
+ }
436
+ return sendMessage(jid, { contacts: { displayName: `${built.length} contacts`, contacts: built } }, options);
437
+ };
438
+
439
+ /**
440
+ * Sends the same content to a list of jids sequentially, with an
441
+ * optional delay between sends (helps avoid rate limiting). Returns
442
+ * an array of { jid, ok, result|error } for each recipient.
443
+ * options.delayMs is stripped before being passed to sendMessage.
444
+ */
445
+ const broadcastMessage = async (jids, content, options = {}) => {
446
+ const { delayMs = 0, ...sendOptions } = options;
447
+ const results = [];
448
+ for (const jid of jids) {
449
+ try {
450
+ const result = await sendMessage(jid, content, sendOptions);
451
+ results.push({ jid, ok: true, result });
452
+ } catch (error) {
453
+ results.push({ jid, ok: false, error });
454
+ }
455
+ if (delayMs) await new Promise(resolve => setTimeout(resolve, delayMs));
456
+ }
457
+ return results;
458
+ };
459
+
460
+ return {
461
+ ...sock,
462
+ sendJsonMessage,
463
+ sendActionPoll,
464
+ resolvePollAction,
465
+ sendAlbumMessage,
466
+ sendStatusMention,
467
+ sendRichResponse,
468
+ sendButtonsMessage,
469
+ sendListMessage,
470
+ sendCarouselMessage,
471
+ forwardMessage,
472
+ sendVCard,
473
+ broadcastMessage
474
+ };
475
+ };
@@ -12,7 +12,7 @@ import { USyncQuery, USyncUser } from '../WAUSync/index.js';
12
12
  import { makeUsernameSocket } from './username.js';
13
13
  import imup from './luxu.js';
14
14
  import * as Utils_1 from '../Utils/index.js';
15
- import { randomBytes } from 'crypto';
15
+ import { randomBytes, createHmac } from 'crypto';
16
16
  export const makeMessagesSocket = (config) => {
17
17
  const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: httpRequestOptions, patchMessageBeforeSending, cachedGroupMetadata, enableRecentMessageCache, maxMsgRetryCount, aiLabel } = config;
18
18
  const sock = makeUsernameSocket(config);
@@ -428,6 +428,20 @@ export const makeMessagesSocket = (config) => {
428
428
  }
429
429
  return { nodes, shouldIncludeDeviceIdentity };
430
430
  };
431
+ /** Hapus penanda AI label dari konten pesan (chat 1:1 biasa, bukan bot). */
432
+ const stripAiLabelMarkers = (root) => {
433
+ const seen = new WeakSet()
434
+ const walk = (obj) => {
435
+ if (!obj || typeof obj !== 'object' || seen.has(obj)) return
436
+ seen.add(obj)
437
+ if (obj.messageContextInfo && typeof obj.messageContextInfo === 'object') {
438
+ delete obj.messageContextInfo.aiLabel
439
+ delete obj.messageContextInfo.botForwarded
440
+ }
441
+ for (const key of Object.keys(obj)) walk(obj[key])
442
+ }
443
+ walk(root)
444
+ }
431
445
  const relayMessage = async (
432
446
  jid,
433
447
  message,
@@ -439,12 +453,18 @@ export const makeMessagesSocket = (config) => {
439
453
  additionalNodes,
440
454
  useUserDevicesCache,
441
455
  useCachedGroupMetadata,
442
- statusJidList
456
+ statusJidList,
457
+ cstoken = true
443
458
  }
444
459
  ) => {
445
460
  const meId = authState.creds.me.id
446
461
  const meLid = authState.creds.me?.lid
447
462
  const isRetryResend = Boolean(participant?.jid)
463
+ // Retry ke participant: selalu lewati sinkron ke perangkat sendiri (adaptasi XzBailss FIX 1)
464
+ if (isRetryResend) noSelfSync = true
465
+ // Bersihkan penanda AI label hanya untuk chat personal biasa (adaptasi XzBailss FIX 3)
466
+ const isPlainChat = !isJidGroup(jid) && jid !== 'status@broadcast' && jidDecode(jid)?.server !== 'newsletter' && !isJidBot(jid) && !isJidMetaAI(jid)
467
+ if (isPlainChat) stripAiLabelMarkers(message)
448
468
  let shouldIncludeDeviceIdentity = isRetryResend
449
469
  const statusJid = 'status@broadcast'
450
470
  const { user, server } = jidDecode(jid)
@@ -475,6 +495,13 @@ export const makeMessagesSocket = (config) => {
475
495
  const pollMessage =
476
496
  messages.pollCreationMessage || messages.pollCreationMessageV2 || messages.pollCreationMessageV3
477
497
  await authState.keys.transaction(async () => {
498
+ if (isRetryResend && participant?.jid) {
499
+ try {
500
+ await assertSessions([participant.jid], true)
501
+ } catch (e) {
502
+ logger.warn({ participant, e }, 'Failed to assert session for participant, continuing anyway')
503
+ }
504
+ }
478
505
  const mediaType = getMediaType(message)
479
506
  if (mediaType) extraAttrs.mediatype = mediaType
480
507
  if (isNewsletter) {
@@ -830,13 +857,7 @@ export const makeMessagesSocket = (config) => {
830
857
  stanza.content.push(buttonsNode)
831
858
  }
832
859
  }
833
- if (!aiLabel && isPnUser(destinationJid)) {
834
- const alreadyHasBizBot = getBinaryFilteredBizBot(additionalNodes || []) || getBinaryFilteredBizBot(stanza.content)
835
- if (!alreadyHasBizBot) stanza.content.push({ tag: 'bot', attrs: { biz_bot: '1' } })
836
- } else if (aiLabel &&!isGroup &&!isStatus &&!isNewsletter) {
837
- const existingBizBot = getBinaryFilteredBizBot(additionalNodes || [])
838
- if (!existingBizBot) stanza.content.push({ tag: 'bot', attrs: { biz_bot: '1' } })
839
- }
860
+ // Catatan: node <bot biz_bot> tidak lagi disuntikkan ke chat 1:1 biasa (penyebab pesan private gagal terkirim)
840
861
  const isPeerMessage = additionalAttributes?.['category'] === 'peer'
841
862
  const is1on1Send =!isGroup &&!isRetryResend &&!isStatus &&!isNewsletter &&!isPeerMessage
842
863
  const tcTokenJid = is1on1Send? await resolveTcTokenJid(destinationJid, getLIDForPN) : destinationJid
@@ -855,11 +876,34 @@ export const makeMessagesSocket = (config) => {
855
876
  }
856
877
  if (tcTokenBuffer?.length && sock.serverProps.privacyTokenOn1to1) {
857
878
  stanza.content.push({ tag: 'tctoken', attrs: {}, content: tcTokenBuffer })
879
+ }
880
+ if (cstoken && is1on1Send &&!tcTokenBuffer?.length) {
881
+ try {
882
+ const lidJid = await resolveTcTokenJid(destinationJid, getLIDForPN)
883
+ if (isLidUser(lidJid)) {
884
+ const saltRes = await authState.keys.get('nct-salt', ['default'])
885
+ const nctSalt = saltRes?.default
886
+ if (nctSalt?.length) {
887
+ const cs = createHmac('sha256', Buffer.from(nctSalt)).update(Buffer.from(lidJid, 'utf8')).digest()
888
+ stanza.content.push({ tag: 'cstoken', attrs: {}, content: cs })
889
+ logger.debug({ jid: destinationJid, lid: lidJid }, 'attached cstoken (nct fallback)')
890
+ } else {
891
+ logger.debug({ jid: destinationJid }, 'cstoken requested but no nct salt stored yet')
892
+ }
893
+ } else {
894
+ logger.debug({ jid: destinationJid }, 'cstoken requested but recipient has no LID')
895
+ }
896
+ } catch (err) {
897
+ logger.debug({ jid: destinationJid, err: err?.message }, 'cstoken attach failed')
898
+ }
858
899
  }
859
900
  if (additionalNodes && additionalNodes.length > 0 &&!didPushAdditional) {
860
901
  stanza.content.push(...additionalNodes)
861
902
  }
862
903
  logger.debug({ msgId }, `sending message to ${participants.length} devices`)
904
+ if (isPlainChat && Array.isArray(stanza.content)) {
905
+ stanza.content = stanza.content.filter(node => node?.tag !== 'bot')
906
+ }
863
907
  await sendNode(stanza)
864
908
  if (message.messageContextInfo?.messageSecret) {
865
909
  setBotMessageSecret(msgId, message.messageContextInfo.messageSecret, destinationJid)
@@ -944,6 +988,9 @@ export const makeMessagesSocket = (config) => {
944
988
  else if (message.stickerMessage) {
945
989
  return 'sticker';
946
990
  }
991
+ else if (message.stickerPackMessage) {
992
+ return 'sticker';
993
+ }
947
994
  else if (message.listMessage) {
948
995
  return 'list';
949
996
  }
@@ -1275,7 +1322,7 @@ export const makeMessagesSocket = (config) => {
1275
1322
  sendMessage: async (jid, content, options = {}) => {
1276
1323
  const userJid = authState.creds.me.id;
1277
1324
  const luki = new imup(Utils_1, waUploadToServer, relayMessage)
1278
- const { quoted, participant = false } = options;
1325
+ const { quoted, participant = false, cstoken } = options;
1279
1326
  const messageType = luki.detectType(content);
1280
1327
  if (typeof content === 'object' &&
1281
1328
  'disappearingMessagesInChat' in content &&
@@ -1387,7 +1434,8 @@ export const makeMessagesSocket = (config) => {
1387
1434
  statusJidList: options.statusJidList,
1388
1435
  additionalNodes: aiLabel ? additionalNodes : options.additionalNodes,
1389
1436
  participant,
1390
- noSelfSync: options.noSelfSync
1437
+ noSelfSync: options.noSelfSync,
1438
+ ...(cstoken !== undefined ? { cstoken } : {})
1391
1439
  });
1392
1440
  if (config.emitOwnEvents) {
1393
1441
  process.nextTick(async () => {