@itsliaaa/baileys 0.1.8 → 0.1.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.
- package/lib/Defaults/index.js +1 -2
- package/lib/Socket/messages-send.js +15 -23
- package/lib/Utils/messages.js +21 -20
- package/lib/WABinary/generic-utils.js +31 -21
- package/package.json +1 -1
package/lib/Defaults/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { Browsers } from '../Utils/browser-utils.js';
|
|
|
4
4
|
import logger from '../Utils/logger.js';
|
|
5
5
|
const version = [2, 3000, 1035194821];
|
|
6
6
|
export const UNAUTHORIZED_CODES = [401, 403, 419];
|
|
7
|
-
export const BIZ_BOT_SUPPORT_PAYLOAD = '{"version":1,"is_ai_message":true,"should_show_system_message":false,"ticket_id":"7004947587700716","citation_items":[],"ticket_locale":"us"}';
|
|
7
|
+
export const BIZ_BOT_SUPPORT_PAYLOAD = '{"version":1,"is_ai_message":true,"should_upload_client_logs":false,"should_show_system_message":false,"ticket_id":"7004947587700716","citation_items":[],"ticket_locale":"us"}';
|
|
8
8
|
export const DEFAULT_ORIGIN = 'https://web.whatsapp.com';
|
|
9
9
|
export const CALL_VIDEO_PREFIX = 'https://call.whatsapp.com/video/';
|
|
10
10
|
export const CALL_AUDIO_PREFIX = 'https://call.whatsapp.com/voice/';
|
|
@@ -26,7 +26,6 @@ export const NOISE_MODE = 'Noise_XX_25519_AESGCM_SHA256\0\0\0\0';
|
|
|
26
26
|
export const DICT_VERSION = 3;
|
|
27
27
|
export const KEY_BUNDLE_TYPE = Buffer.from([5]);
|
|
28
28
|
export const NOISE_WA_HEADER = Buffer.from([87, 65, 6, DICT_VERSION]); // last is "DICT_VERSION"
|
|
29
|
-
export const OLD_GROUP_ID_REGEX = /^(\d{1,15})-(\d+)@g\.us$/;
|
|
30
29
|
/** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
|
|
31
30
|
export const URL_REGEX = /https:\/\/(?![^:@\/\s]+:[^:@\/\s]+@)[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?/g;
|
|
32
31
|
export const WA_CERT_DETAILS = {
|
|
@@ -2,7 +2,7 @@ import NodeCache from '@cacheable/node-cache';
|
|
|
2
2
|
import { Boom } from '@hapi/boom';
|
|
3
3
|
import { randomBytes } from 'crypto';
|
|
4
4
|
import { proto } from '../../WAProto/index.js';
|
|
5
|
-
import { BIZ_BOT_SUPPORT_PAYLOAD, DEFAULT_CACHE_TTLS,
|
|
5
|
+
import { BIZ_BOT_SUPPORT_PAYLOAD, DEFAULT_CACHE_TTLS, WA_DEFAULT_EPHEMERAL } from '../Defaults/index.js';
|
|
6
6
|
import { aggregateMessageKeysNotFromMe, assertMediaContent, bindWaitForEvent, decryptMediaRetryData, delay, encodeNewsletterMessage, encodeSignedDeviceIdentity, encodeWAMessage, encryptMediaRetryRequest, extractDeviceJids, generateMessageIDV2, generateParticipantHashV2, generateWAMessageFromContent, generateWAMessage, getStatusCodeForMediaRetry, getUrlFromDirectPath, getWAUploadToServer, hasValidAlbumMedia, MessageRetryManager, normalizeMessageContent, parseAndInjectE2ESessions, shouldIncludeBizBinaryNode, unixTimestampSeconds } from '../Utils/index.js';
|
|
7
7
|
import { AssociationType } from '../Types/index.js';
|
|
8
8
|
import { getUrlInfo } from '../Utils/link-preview.js';
|
|
@@ -432,7 +432,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
432
432
|
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }) => {
|
|
433
433
|
const meId = authState.creds.me.id;
|
|
434
434
|
const meLid = authState.creds.me?.lid;
|
|
435
|
-
const isRetryResend =
|
|
435
|
+
const isRetryResend = !!participant?.jid;
|
|
436
436
|
let shouldIncludeDeviceIdentity = isRetryResend;
|
|
437
437
|
const statusJid = 'status@broadcast';
|
|
438
438
|
const { user, server } = jidDecode(jid);
|
|
@@ -497,7 +497,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
497
497
|
attrs: {
|
|
498
498
|
to: jid,
|
|
499
499
|
id: msgId,
|
|
500
|
-
type: getMessageType(
|
|
500
|
+
type: getMessageType(innerMessage),
|
|
501
501
|
...(additionalAttributes || {})
|
|
502
502
|
},
|
|
503
503
|
content: binaryNodeContent
|
|
@@ -731,7 +731,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
731
731
|
attrs: {
|
|
732
732
|
id: msgId,
|
|
733
733
|
to: destinationJid,
|
|
734
|
-
type: getMessageType(
|
|
734
|
+
type: getMessageType(innerMessage),
|
|
735
735
|
...(additionalAttributes || {})
|
|
736
736
|
},
|
|
737
737
|
content: binaryNodeContent
|
|
@@ -802,17 +802,10 @@ export const makeMessagesSocket = (config) => {
|
|
|
802
802
|
stanza.content.push(...additionalNodes);
|
|
803
803
|
}
|
|
804
804
|
// Lia@Changes 30-01-26 --- Add Biz Binary Node to support button messages
|
|
805
|
-
|
|
805
|
+
if (shouldIncludeBizBinaryNode(innerMessage)) {
|
|
806
806
|
const bizNode = getBizBinaryNode(innerMessage);
|
|
807
807
|
stanza.content.push(bizNode);
|
|
808
808
|
}
|
|
809
|
-
if (isGroup && OLD_GROUP_ID_REGEX.test(jid) && !innerMessage.reactionMessage) {
|
|
810
|
-
stanza.content.push({
|
|
811
|
-
tag: 'multicast',
|
|
812
|
-
attrs: {},
|
|
813
|
-
content: undefined
|
|
814
|
-
})
|
|
815
|
-
}
|
|
816
809
|
logger.debug({ msgId }, `sending message to ${participants.length} devices`);
|
|
817
810
|
await sendNode(stanza);
|
|
818
811
|
// Add message to retry cache if enabled
|
|
@@ -823,24 +816,23 @@ export const makeMessagesSocket = (config) => {
|
|
|
823
816
|
return msgId;
|
|
824
817
|
};
|
|
825
818
|
const getMessageType = (message) => {
|
|
826
|
-
|
|
827
|
-
if (!normalizedMessage)
|
|
819
|
+
if (!message)
|
|
828
820
|
return 'text';
|
|
829
|
-
if (
|
|
821
|
+
if (message.reactionMessage || message.encReactionMessage) {
|
|
830
822
|
return 'reaction';
|
|
831
823
|
}
|
|
832
|
-
if (
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
824
|
+
if (message.pollCreationMessage ||
|
|
825
|
+
message.pollCreationMessageV2 ||
|
|
826
|
+
message.pollCreationMessageV3 ||
|
|
827
|
+
message.pollCreationMessageV5 ||
|
|
828
|
+
message.pollCreationMessageV6 ||
|
|
829
|
+
message.pollUpdateMessage) {
|
|
838
830
|
return 'poll';
|
|
839
831
|
}
|
|
840
|
-
if (
|
|
832
|
+
if (message.eventMessage) {
|
|
841
833
|
return 'event';
|
|
842
834
|
}
|
|
843
|
-
if (getMediaType(
|
|
835
|
+
if (getMediaType(message) !== '') {
|
|
844
836
|
return 'media';
|
|
845
837
|
}
|
|
846
838
|
return 'text';
|
package/lib/Utils/messages.js
CHANGED
|
@@ -655,35 +655,34 @@ export const generateForwardMessageContent = (message, forceForward) => {
|
|
|
655
655
|
return content;
|
|
656
656
|
};
|
|
657
657
|
export const hasNonNullishProperty = (message, key) => {
|
|
658
|
-
return
|
|
659
|
-
message
|
|
658
|
+
return message != null &&
|
|
659
|
+
typeof message === 'object' &&
|
|
660
660
|
key in message &&
|
|
661
|
-
message[key]
|
|
662
|
-
message[key] !== undefined);
|
|
661
|
+
message[key] != null;
|
|
663
662
|
};
|
|
664
663
|
export const hasOptionalProperty = (obj, key) => {
|
|
665
|
-
return
|
|
666
|
-
obj
|
|
664
|
+
return obj != null &&
|
|
665
|
+
typeof obj === 'object' &&
|
|
667
666
|
key in obj &&
|
|
668
|
-
obj[key]
|
|
667
|
+
obj[key] != null;
|
|
669
668
|
};
|
|
670
669
|
// Lia@Changes 06-02-26 --- Validate album message media to avoid bug 👀
|
|
671
670
|
export const hasValidAlbumMedia = (message) => {
|
|
672
|
-
return
|
|
673
|
-
message.videoMessage
|
|
671
|
+
return message.imageMessage ||
|
|
672
|
+
message.videoMessage;
|
|
674
673
|
};
|
|
675
674
|
export const hasValidInteractiveHeader = (message) => {
|
|
676
|
-
return
|
|
675
|
+
return message.imageMessage ||
|
|
677
676
|
message.videoMessage ||
|
|
678
677
|
message.documentMessage ||
|
|
679
678
|
message.productMessage ||
|
|
680
|
-
message.locationMessage
|
|
679
|
+
message.locationMessage;
|
|
681
680
|
};
|
|
682
681
|
// Lia@Changes 30-01-26 --- Validate carousel cards header to avoid bug 👀
|
|
683
682
|
export const hasValidCarouselHeader = (message) => {
|
|
684
|
-
return
|
|
683
|
+
return message.imageMessage ||
|
|
685
684
|
message.videoMessage ||
|
|
686
|
-
message.productMessage
|
|
685
|
+
message.productMessage;
|
|
687
686
|
};
|
|
688
687
|
export const generateWAMessageContent = async (message, options) => {
|
|
689
688
|
var _a, _b;
|
|
@@ -1875,11 +1874,13 @@ const isWebPBuffer = (buffer) => {
|
|
|
1875
1874
|
* such as buttons or other supported interactive types.
|
|
1876
1875
|
*/
|
|
1877
1876
|
export const shouldIncludeBizBinaryNode = (message) => {
|
|
1878
|
-
const
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1877
|
+
const hasValidInteractive =
|
|
1878
|
+
message.interactiveMessage &&
|
|
1879
|
+
!message.interactiveMessage.carouselMessage &&
|
|
1880
|
+
!message.interactiveMessage.collectionMessage &&
|
|
1881
|
+
!message.interactiveMessage.shopStorefrontMessage;
|
|
1882
|
+
return (message.buttonsMessage ||
|
|
1883
|
+
message.interactiveMessage ||
|
|
1884
|
+
message.listMessage ||
|
|
1885
|
+
hasValidInteractive);
|
|
1885
1886
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Boom } from '@hapi/boom';
|
|
2
|
+
import { randomBytes } from 'crypto';
|
|
2
3
|
import { proto } from '../../WAProto/index.js';
|
|
3
4
|
import {} from './types.js';
|
|
4
5
|
// some extra useful utilities
|
|
@@ -131,21 +132,29 @@ const FLOWS_MAP = {
|
|
|
131
132
|
wa_payment_transaction_details: true,
|
|
132
133
|
automated_greeting_message_view_catalog: true
|
|
133
134
|
};
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
|
|
135
|
+
const DECISION_SOURCE_CONTENT = [
|
|
136
|
+
{
|
|
137
|
+
tag: 'decision_source',
|
|
138
|
+
attrs: { value: 'df' }
|
|
139
|
+
}
|
|
140
|
+
];
|
|
141
|
+
const MIXED_NATIVE_FLOW = [
|
|
140
142
|
{
|
|
141
|
-
tag: '
|
|
142
|
-
attrs: { v: '
|
|
143
|
-
}
|
|
144
|
-
qualityAttribute
|
|
143
|
+
tag: 'native_flow',
|
|
144
|
+
attrs: { v: '9', name: 'mixed' }
|
|
145
|
+
}
|
|
145
146
|
];
|
|
146
147
|
export const getBizBinaryNode = (message) => {
|
|
147
148
|
const flowMsg = message.interactiveMessage?.nativeFlowMessage;
|
|
148
149
|
const buttonName = flowMsg?.buttons?.[0]?.name;
|
|
150
|
+
const qualityContent = {
|
|
151
|
+
tag: 'quality_control',
|
|
152
|
+
attrs: {
|
|
153
|
+
decision_id: randomBytes(20).toString('hex'),
|
|
154
|
+
source_type: 'third_party'
|
|
155
|
+
},
|
|
156
|
+
content: DECISION_SOURCE_CONTENT
|
|
157
|
+
}
|
|
149
158
|
if (buttonName === 'review_and_pay' || buttonName === 'payment_info') {
|
|
150
159
|
return {
|
|
151
160
|
tag: 'biz',
|
|
@@ -154,7 +163,7 @@ export const getBizBinaryNode = (message) => {
|
|
|
154
163
|
'order_details' :
|
|
155
164
|
buttonName
|
|
156
165
|
},
|
|
157
|
-
content:
|
|
166
|
+
content: [qualityContent]
|
|
158
167
|
};
|
|
159
168
|
}
|
|
160
169
|
if (buttonName && FLOWS_MAP[buttonName]) {
|
|
@@ -172,7 +181,7 @@ export const getBizBinaryNode = (message) => {
|
|
|
172
181
|
}
|
|
173
182
|
]
|
|
174
183
|
},
|
|
175
|
-
|
|
184
|
+
qualityContent
|
|
176
185
|
]
|
|
177
186
|
};
|
|
178
187
|
}
|
|
@@ -184,14 +193,9 @@ export const getBizBinaryNode = (message) => {
|
|
|
184
193
|
{
|
|
185
194
|
tag: 'interactive',
|
|
186
195
|
attrs: { type: 'native_flow', v: '1' },
|
|
187
|
-
content:
|
|
188
|
-
{
|
|
189
|
-
tag: 'native_flow',
|
|
190
|
-
attrs: { v: '9', name: 'mixed' }
|
|
191
|
-
}
|
|
192
|
-
]
|
|
196
|
+
content: MIXED_NATIVE_FLOW
|
|
193
197
|
},
|
|
194
|
-
|
|
198
|
+
qualityContent
|
|
195
199
|
]
|
|
196
200
|
};
|
|
197
201
|
}
|
|
@@ -199,12 +203,18 @@ export const getBizBinaryNode = (message) => {
|
|
|
199
203
|
return {
|
|
200
204
|
tag: 'biz',
|
|
201
205
|
attrs: {},
|
|
202
|
-
content:
|
|
206
|
+
content: [
|
|
207
|
+
{
|
|
208
|
+
tag: 'list',
|
|
209
|
+
attrs: { v: '2', type: 'product_list' }
|
|
210
|
+
},
|
|
211
|
+
qualityContent
|
|
212
|
+
]
|
|
203
213
|
};
|
|
204
214
|
}
|
|
205
215
|
return {
|
|
206
216
|
tag: 'biz',
|
|
207
217
|
attrs: {},
|
|
208
|
-
content:
|
|
218
|
+
content: [qualityContent]
|
|
209
219
|
};
|
|
210
220
|
}
|