@badzz88/baileys 8.5.4 → 8.5.6
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/README.md +2 -2
- package/WAProto/fix-imports.js +69 -79
- package/WAProto/index.d.ts +15305 -87935
- package/WAProto/index.js +41109 -194076
- package/engine-requirements.js +15 -8
- package/package.json +23 -19
- package/src/Defaults/index.js +186 -0
- package/src/Signal/Group/ciphertext-message.js +15 -0
- package/src/Signal/Group/group-session-builder.js +86 -0
- package/src/Signal/Group/group_cipher.js +82 -0
- package/src/Signal/Group/index.js +140 -0
- package/src/Signal/Group/keyhelper.js +77 -0
- package/src/Signal/Group/sender-chain-key.js +29 -0
- package/src/Signal/Group/sender-key-distribution-message.js +66 -0
- package/src/Signal/Group/sender-key-message.js +69 -0
- package/src/Signal/Group/sender-key-name.js +51 -0
- package/src/Signal/Group/sender-key-record.js +44 -0
- package/src/Signal/Group/sender-key-state.js +87 -0
- package/src/Signal/Group/sender-message-key.js +29 -0
- package/src/Signal/libsignal.js +455 -0
- package/src/Signal/lid-mapping.js +273 -0
- package/src/Socket/Client/index.js +31 -0
- package/src/Socket/Client/types.js +13 -0
- package/src/Socket/Client/websocket.js +61 -0
- package/src/Socket/aigroups.js +221 -0
- package/src/Socket/business.js +411 -0
- package/src/Socket/chats.js +1449 -0
- package/src/Socket/communities.js +463 -0
- package/src/Socket/graphql.js +523 -0
- package/src/Socket/groups.js +516 -0
- package/src/Socket/index.js +31 -0
- package/src/Socket/interactive-handler.js +527 -0
- package/src/Socket/interop.js +339 -0
- package/src/Socket/luxu.js +349 -0
- package/src/Socket/managed-account.js +98 -0
- package/src/Socket/messages-recv.js +2685 -0
- package/src/Socket/messages-send.js +2047 -0
- package/src/Socket/mex.js +57 -0
- package/src/Socket/newsletter.js +455 -0
- package/src/Socket/privacy.js +125 -0
- package/src/Socket/registration.js +236 -0
- package/src/Socket/socket.js +983 -0
- package/src/Socket/text-router.js +65 -0
- package/src/Socket/username.js +130 -0
- package/src/Store/index.js +33 -0
- package/src/Store/keyed-db.js +118 -0
- package/src/Store/make-cache-manager-store.js +84 -0
- package/src/Store/make-in-memory-store.js +551 -0
- package/src/Store/make-ordered-dictionary.js +81 -0
- package/src/Store/object-repository.js +26 -0
- package/src/Types/Auth.js +31 -0
- package/src/Types/Bussines.js +2 -0
- package/src/Types/Call.js +2 -0
- package/src/Types/Chat.js +4 -0
- package/src/Types/Contact.js +2 -0
- package/src/Types/Events.js +2 -0
- package/src/Types/GroupMetadata.js +2 -0
- package/src/Types/Label.js +26 -0
- package/src/Types/LabelAssociation.js +8 -0
- package/src/Types/Message.js +93 -0
- package/src/Types/Mex.js +112 -0
- package/src/Types/Newsletter.js +109 -0
- package/src/Types/Product.js +2 -0
- package/src/Types/Signal.js +2 -0
- package/src/Types/Socket.js +2 -0
- package/src/Types/State.js +62 -0
- package/src/Types/USync.js +2 -0
- package/src/Types/index.js +56 -0
- package/src/Utils/auth-utils.js +254 -0
- package/src/Utils/browser-utils.js +112 -0
- package/src/Utils/business.js +240 -0
- package/src/Utils/chat-utils.js +1230 -0
- package/src/Utils/command-loader.d.ts +27 -0
- package/src/Utils/command-loader.js +89 -0
- package/src/Utils/companion-reg-client-utils.js +40 -0
- package/src/Utils/consumer-application.js +105 -0
- package/src/Utils/crypto.js +118 -0
- package/src/Utils/curve25519-js.js +242 -0
- package/src/Utils/decode-wa-message.js +529 -0
- package/src/Utils/event-buffer.js +580 -0
- package/src/Utils/generics.js +483 -0
- package/src/Utils/group-history.js +44 -0
- package/src/Utils/history.js +232 -0
- package/src/Utils/identity-change-handler.js +52 -0
- package/src/Utils/index.js +58 -0
- package/src/Utils/jid-display-normalization.js +195 -0
- package/src/Utils/link-preview.js +135 -0
- package/src/Utils/logger.js +8 -0
- package/src/Utils/lt-hash.js +25 -0
- package/src/Utils/make-mutex.js +36 -0
- package/src/Utils/message-composer.js +471 -0
- package/src/Utils/message-retry-manager.js +217 -0
- package/src/Utils/messages-media.js +843 -0
- package/src/Utils/messages.js +2817 -0
- package/src/Utils/meta-ai-msmsg.js +222 -0
- package/src/Utils/native-bridge.js +68 -0
- package/src/Utils/noise-handler.js +169 -0
- package/src/Utils/offline-node-processor.js +34 -0
- package/src/Utils/pre-key-manager.js +90 -0
- package/src/Utils/process-message.js +950 -0
- package/src/Utils/reporting-utils.js +261 -0
- package/src/Utils/session-pool.d.ts +14 -0
- package/src/Utils/session-pool.js +70 -0
- package/src/Utils/signal.js +217 -0
- package/src/Utils/stanza-ack.js +30 -0
- package/src/Utils/sticker.d.ts +13 -0
- package/src/Utils/sticker.js +123 -0
- package/src/Utils/sync-action-utils.js +45 -0
- package/src/Utils/tc-token-utils.js +158 -0
- package/src/Utils/use-multi-file-auth-state.js +111 -0
- package/src/Utils/validate-connection.js +209 -0
- package/src/Utils/view-once-cache.d.ts +12 -0
- package/src/Utils/view-once-cache.js +63 -0
- package/src/Utils/voip-rekey.js +22 -0
- package/src/WABinary/constants.js +1304 -0
- package/src/WABinary/decode.js +342 -0
- package/src/WABinary/encode.js +225 -0
- package/src/WABinary/generic-utils.js +238 -0
- package/src/WABinary/index.js +34 -0
- package/src/WABinary/jid-utils.js +351 -0
- package/src/WABinary/types.js +2 -0
- package/src/WAM/BinaryInfo.js +13 -0
- package/src/WAM/constants.js +39484 -0
- package/src/WAM/encode.js +149 -0
- package/src/WAM/index.js +32 -0
- package/src/WAUSync/Protocols/USyncBotProfileProtocol.js +53 -0
- package/src/WAUSync/Protocols/USyncBusinessProtocol.js +44 -0
- package/src/WAUSync/Protocols/USyncContactProtocol.js +55 -0
- package/src/WAUSync/Protocols/USyncDeviceProtocol.js +55 -0
- package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.js +31 -0
- package/src/WAUSync/Protocols/USyncFeatureProtocol.js +54 -0
- package/src/WAUSync/Protocols/USyncLIDProtocol.js +32 -0
- package/src/WAUSync/Protocols/USyncNewsletterProtocol.js +473 -0
- package/src/WAUSync/Protocols/USyncPictureProtocol.js +34 -0
- package/src/WAUSync/Protocols/USyncSidelistProtocol.js +29 -0
- package/src/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
- package/src/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
- package/src/WAUSync/Protocols/USyncUsernameProtocol.js +28 -0
- package/src/WAUSync/Protocols/index.js +40 -0
- package/src/WAUSync/USyncQuery.js +126 -0
- package/src/WAUSync/USyncUser.js +50 -0
- package/src/WAUSync/index.js +32 -0
- package/src/antiban.js +4152 -0
- package/{lib → src}/index.js +51 -49
- package/lib/Defaults/index.js +0 -195
- package/lib/Signal/Group/ciphertext-message.js +0 -15
- package/lib/Signal/Group/group-session-builder.js +0 -92
- package/lib/Signal/Group/group_cipher.js +0 -89
- package/lib/Signal/Group/index.js +0 -136
- package/lib/Signal/Group/keyhelper.js +0 -73
- package/lib/Signal/Group/sender-chain-key.js +0 -32
- package/lib/Signal/Group/sender-key-distribution-message.js +0 -66
- package/lib/Signal/Group/sender-key-message.js +0 -69
- package/lib/Signal/Group/sender-key-name.js +0 -50
- package/lib/Signal/Group/sender-key-record.js +0 -44
- package/lib/Signal/Group/sender-key-state.js +0 -97
- package/lib/Signal/Group/sender-message-key.js +0 -30
- package/lib/Signal/libsignal.js +0 -470
- package/lib/Signal/lid-mapping.js +0 -280
- package/lib/Socket/Client/index.js +0 -30
- package/lib/Socket/Client/types.js +0 -13
- package/lib/Socket/Client/websocket.js +0 -62
- package/lib/Socket/aigroups.js +0 -240
- package/lib/Socket/business.js +0 -414
- package/lib/Socket/chats.js +0 -2165
- package/lib/Socket/communities.js +0 -545
- package/lib/Socket/graphql.js +0 -863
- package/lib/Socket/groups.js +0 -685
- package/lib/Socket/index.js +0 -41
- package/lib/Socket/interactive-handler.js +0 -579
- package/lib/Socket/interop.js +0 -430
- package/lib/Socket/managed-account.js +0 -214
- package/lib/Socket/messages-recv.js +0 -3000
- package/lib/Socket/messages-send.js +0 -2155
- package/lib/Socket/mex.js +0 -47
- package/lib/Socket/newsletter.js +0 -814
- package/lib/Socket/privacy.js +0 -261
- package/lib/Socket/registration.js +0 -434
- package/lib/Socket/socket.js +0 -1074
- package/lib/Socket/username.js +0 -160
- package/lib/Store/index.js +0 -36
- package/lib/Store/make-cache-manager-store.js +0 -90
- package/lib/Store/make-in-memory-store.js +0 -488
- package/lib/Store/make-ordered-dictionary.js +0 -81
- package/lib/Store/object-repository.js +0 -29
- package/lib/Types/Auth.js +0 -38
- package/lib/Types/Bussines.js +0 -2
- package/lib/Types/Call.js +0 -2
- package/lib/Types/Chat.js +0 -4
- package/lib/Types/Contact.js +0 -2
- package/lib/Types/Events.js +0 -2
- package/lib/Types/GroupMetadata.js +0 -2
- package/lib/Types/Label.js +0 -27
- package/lib/Types/LabelAssociation.js +0 -9
- package/lib/Types/Message.js +0 -95
- package/lib/Types/Newsletter.js +0 -152
- package/lib/Types/Product.js +0 -2
- package/lib/Types/Signal.js +0 -2
- package/lib/Types/Socket.js +0 -2
- package/lib/Types/State.js +0 -70
- package/lib/Types/USync.js +0 -2
- package/lib/Types/index.js +0 -55
- package/lib/Utils/auth-utils.js +0 -301
- package/lib/Utils/browser-utils.js +0 -114
- package/lib/Utils/business.js +0 -243
- package/lib/Utils/chat-utils.js +0 -1272
- package/lib/Utils/consumer-application.js +0 -107
- package/lib/Utils/crypto.js +0 -125
- package/lib/Utils/decode-wa-message.js +0 -793
- package/lib/Utils/event-buffer.js +0 -583
- package/lib/Utils/generics.js +0 -617
- package/lib/Utils/group-history.js +0 -51
- package/lib/Utils/history.js +0 -244
- package/lib/Utils/identity-change-handler.js +0 -52
- package/lib/Utils/index.js +0 -53
- package/lib/Utils/jid-display-normalization.js +0 -218
- package/lib/Utils/link-preview.js +0 -138
- package/lib/Utils/logger.js +0 -9
- package/lib/Utils/lt-hash.js +0 -6
- package/lib/Utils/make-mutex.js +0 -36
- package/lib/Utils/message-composer.js +0 -479
- package/lib/Utils/message-inspect.js +0 -393
- package/lib/Utils/message-retry-manager.js +0 -205
- package/lib/Utils/messages-media.js +0 -925
- package/lib/Utils/messages.js +0 -2482
- package/lib/Utils/meta-ai-msmsg.js +0 -122
- package/lib/Utils/noise-handler.js +0 -194
- package/lib/Utils/offline-node-processor.js +0 -37
- package/lib/Utils/pre-key-manager.js +0 -97
- package/lib/Utils/process-message.js +0 -1139
- package/lib/Utils/reporting-utils.js +0 -262
- package/lib/Utils/signal.js +0 -189
- package/lib/Utils/stanza-ack.js +0 -67
- package/lib/Utils/sync-action-utils.js +0 -51
- package/lib/Utils/tc-token-utils.js +0 -156
- package/lib/Utils/use-multi-file-auth-state.js +0 -137
- package/lib/Utils/validate-connection.js +0 -259
- package/lib/Utils/voip-rekey.js +0 -22
- package/lib/WABinary/constants.js +0 -1304
- package/lib/WABinary/decode.js +0 -377
- package/lib/WABinary/encode.js +0 -58
- package/lib/WABinary/generic-utils.js +0 -150
- package/lib/WABinary/index.js +0 -33
- package/lib/WABinary/jid-utils.js +0 -374
- package/lib/WABinary/types.js +0 -2
- package/lib/WAM/BinaryInfo.js +0 -13
- package/lib/WAM/constants.js +0 -39486
- package/lib/WAM/encode.js +0 -142
- package/lib/WAM/index.js +0 -31
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +0 -55
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +0 -100
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -60
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -65
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -27
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +0 -72
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -31
- package/lib/WAUSync/Protocols/USyncNewsletterProtocol.js +0 -865
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +0 -32
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +0 -29
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -44
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +0 -38
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +0 -28
- package/lib/WAUSync/Protocols/index.js +0 -40
- package/lib/WAUSync/USyncBackoff.js +0 -26
- package/lib/WAUSync/USyncQuery.js +0 -204
- package/lib/WAUSync/USyncUser.js +0 -58
- package/lib/WAUSync/index.js +0 -32
- package/lib/antiban.js +0 -4391
- /package/{lib → src}/Defaults/phonenumber-mcc.json +0 -0
package/lib/Socket/index.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
-
const Defaults_1 = require('../Defaults')
|
|
4
|
-
const communities_1 = require('./communities')
|
|
5
|
-
const { makeInteropSocket } = require('./interop')
|
|
6
|
-
const { makePrivacySocket } = require('./privacy')
|
|
7
|
-
const { makeRegistrationSocket } = require('./registration')
|
|
8
|
-
const { makeManagedAccountSocket } = require('./managed-account')
|
|
9
|
-
const { makeGraphQLSocket } = require('./graphql')
|
|
10
|
-
|
|
11
|
-
const { wrapSocket: _wrapSocket } = require('../antiban')
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const makeWASocket = config => {
|
|
15
|
-
const userExplicitSyncFlag = typeof config?.syncFullHistory === 'boolean'
|
|
16
|
-
const initialFullSyncDone = !!config?.auth?.creds?.initialFullSyncDone
|
|
17
|
-
const effectiveSyncFullHistory = userExplicitSyncFlag ? config.syncFullHistory : !initialFullSyncDone
|
|
18
|
-
const newConfig = {
|
|
19
|
-
...Defaults_1.DEFAULT_CONNECTION_CONFIG,
|
|
20
|
-
...config,
|
|
21
|
-
syncFullHistory: effectiveSyncFullHistory
|
|
22
|
-
}
|
|
23
|
-
newConfig.logger?.debug?.(
|
|
24
|
-
{ initialFullSyncDone, effectiveSyncFullHistory, userExplicitSyncFlag },
|
|
25
|
-
'computed syncFullHistory policy'
|
|
26
|
-
)
|
|
27
|
-
const baseSock = (0, communities_1.makeCommunitiesSocket)(newConfig)
|
|
28
|
-
const interopSock = makeInteropSocket(baseSock)
|
|
29
|
-
const privacySock = makePrivacySocket(interopSock)
|
|
30
|
-
const registrationSock = makeRegistrationSocket(privacySock)
|
|
31
|
-
const managedSock = makeManagedAccountSocket(registrationSock)
|
|
32
|
-
const sock = makeGraphQLSocket(managedSock)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (_wrapSocket && config?.antiban !== false) {
|
|
36
|
-
const antibanConfig = config?.antiban || 'aggressive'
|
|
37
|
-
return _wrapSocket(sock, antibanConfig)
|
|
38
|
-
}
|
|
39
|
-
return sock
|
|
40
|
-
}
|
|
41
|
-
exports.default = makeWASocket
|
|
@@ -1,579 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const crypto = require('crypto')
|
|
4
|
-
const { proto } = require('../../WAProto/index.js')
|
|
5
|
-
const {
|
|
6
|
-
delay,
|
|
7
|
-
generateMessageID,
|
|
8
|
-
generateWAMessage,
|
|
9
|
-
generateWAMessageContent,
|
|
10
|
-
generateWAMessageFromContent,
|
|
11
|
-
getUrlFromDirectPath,
|
|
12
|
-
normalizeMessageContent,
|
|
13
|
-
prepareWAMessageMedia
|
|
14
|
-
} = require('../Utils/index.js')
|
|
15
|
-
const { isJidGroup, isPnUser, jidNormalizedUser, STORIES_JID } = require('../WABinary/index.js')
|
|
16
|
-
|
|
17
|
-
class badzz88 {
|
|
18
|
-
constructor(waUploadToServer, relayMessageFn, config, sock) {
|
|
19
|
-
this.relayMessage = relayMessageFn
|
|
20
|
-
this.waUploadToServer = waUploadToServer
|
|
21
|
-
this.config = config
|
|
22
|
-
this.sock = sock
|
|
23
|
-
}
|
|
24
|
-
detectType(content) {
|
|
25
|
-
if (content.requestPaymentMessage) return 'PAYMENT'
|
|
26
|
-
if (content.productMessage) return 'PRODUCT'
|
|
27
|
-
if (content.interactiveButtons) return 'INTERACTIVE_BUTTONS'
|
|
28
|
-
if (content.interactiveMessage) return 'INTERACTIVE'
|
|
29
|
-
if (content.albumMessage || content.album) return 'ALBUM'
|
|
30
|
-
if (content.eventMessage) return 'EVENT'
|
|
31
|
-
if (content.pollResultMessage) return 'POLL_RESULT'
|
|
32
|
-
if (content.groupStatusMessage) return 'GROUP_STORY'
|
|
33
|
-
return null
|
|
34
|
-
}
|
|
35
|
-
async handlePayment(content, quoted) {
|
|
36
|
-
const data = content.requestPaymentMessage
|
|
37
|
-
let notes = {}
|
|
38
|
-
if (data.sticker?.stickerMessage) {
|
|
39
|
-
notes = {
|
|
40
|
-
stickerMessage: {
|
|
41
|
-
...data.sticker.stickerMessage,
|
|
42
|
-
contextInfo: {
|
|
43
|
-
stanzaId: quoted?.key?.id,
|
|
44
|
-
participant: quoted?.key?.participant || content.sender,
|
|
45
|
-
quotedMessage: quoted?.message
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
} else if (data.note) {
|
|
50
|
-
notes = {
|
|
51
|
-
extendedTextMessage: {
|
|
52
|
-
text: data.note,
|
|
53
|
-
contextInfo: {
|
|
54
|
-
stanzaId: quoted?.key?.id,
|
|
55
|
-
participant: quoted?.key?.participant || content.sender,
|
|
56
|
-
quotedMessage: quoted?.message
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return {
|
|
62
|
-
requestPaymentMessage: proto.Message.RequestPaymentMessage.fromObject({
|
|
63
|
-
expiryTimestamp: data.expiry || 0,
|
|
64
|
-
amount1000: data.amount || 0,
|
|
65
|
-
currencyCodeIso4217: data.currency || 'IDR',
|
|
66
|
-
requestFrom: data.from || '0@s.whatsapp.net',
|
|
67
|
-
noteMessage: notes,
|
|
68
|
-
background: data.background ?? {
|
|
69
|
-
id: 'DEFAULT',
|
|
70
|
-
placeholderArgb: 0xfff0f0f0
|
|
71
|
-
}
|
|
72
|
-
})
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
async handleProduct(content, _jid, _quoted) {
|
|
76
|
-
const {
|
|
77
|
-
title,
|
|
78
|
-
description,
|
|
79
|
-
thumbnail,
|
|
80
|
-
productId,
|
|
81
|
-
retailerId,
|
|
82
|
-
url,
|
|
83
|
-
body = '',
|
|
84
|
-
footer = '',
|
|
85
|
-
buttons = [],
|
|
86
|
-
priceAmount1000 = null,
|
|
87
|
-
currencyCode = 'IDR'
|
|
88
|
-
} = content.productMessage
|
|
89
|
-
let productImage
|
|
90
|
-
if (Buffer.isBuffer(thumbnail)) {
|
|
91
|
-
const { imageMessage } = await generateWAMessageContent({ image: thumbnail }, { upload: this.waUploadToServer })
|
|
92
|
-
productImage = imageMessage
|
|
93
|
-
} else if (typeof thumbnail === 'object' && thumbnail.url) {
|
|
94
|
-
const { imageMessage } = await generateWAMessageContent(
|
|
95
|
-
{ image: { url: thumbnail.url } },
|
|
96
|
-
{ upload: this.waUploadToServer }
|
|
97
|
-
)
|
|
98
|
-
productImage = imageMessage
|
|
99
|
-
}
|
|
100
|
-
return {
|
|
101
|
-
viewOnceMessage: {
|
|
102
|
-
message: {
|
|
103
|
-
interactiveMessage: {
|
|
104
|
-
body: { text: body },
|
|
105
|
-
footer: { text: footer },
|
|
106
|
-
header: {
|
|
107
|
-
title,
|
|
108
|
-
hasMediaAttachment: true,
|
|
109
|
-
productMessage: {
|
|
110
|
-
product: {
|
|
111
|
-
productImage,
|
|
112
|
-
productId,
|
|
113
|
-
title,
|
|
114
|
-
description,
|
|
115
|
-
currencyCode,
|
|
116
|
-
priceAmount1000,
|
|
117
|
-
retailerId,
|
|
118
|
-
url,
|
|
119
|
-
productImageCount: 1
|
|
120
|
-
},
|
|
121
|
-
businessOwnerJid: '0@s.whatsapp.net'
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
nativeFlowMessage: { buttons }
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
async handleInteractive(content, _jid, _quoted) {
|
|
131
|
-
const {
|
|
132
|
-
title,
|
|
133
|
-
footer,
|
|
134
|
-
thumbnail,
|
|
135
|
-
image,
|
|
136
|
-
video,
|
|
137
|
-
document,
|
|
138
|
-
mimetype,
|
|
139
|
-
fileName,
|
|
140
|
-
jpegThumbnail,
|
|
141
|
-
contextInfo,
|
|
142
|
-
externalAdReply,
|
|
143
|
-
buttons = [],
|
|
144
|
-
nativeFlowMessage,
|
|
145
|
-
header
|
|
146
|
-
} = content.interactiveMessage
|
|
147
|
-
let media = null
|
|
148
|
-
let _mediaType = null
|
|
149
|
-
if (thumbnail) {
|
|
150
|
-
media = await prepareWAMessageMedia({ image: { url: thumbnail } }, { upload: this.waUploadToServer })
|
|
151
|
-
_mediaType = 'image'
|
|
152
|
-
} else if (image) {
|
|
153
|
-
const src = typeof image === 'object' && image.url ? { image: { url: image.url } } : { image }
|
|
154
|
-
media = await prepareWAMessageMedia(src, { upload: this.waUploadToServer })
|
|
155
|
-
_mediaType = 'image'
|
|
156
|
-
} else if (video) {
|
|
157
|
-
const src = typeof video === 'object' && video.url ? { video: { url: video.url } } : { video }
|
|
158
|
-
media = await prepareWAMessageMedia(src, { upload: this.waUploadToServer })
|
|
159
|
-
_mediaType = 'video'
|
|
160
|
-
} else if (document) {
|
|
161
|
-
const docPayload = { document }
|
|
162
|
-
if (jpegThumbnail) {
|
|
163
|
-
docPayload.jpegThumbnail =
|
|
164
|
-
typeof jpegThumbnail === 'object' && jpegThumbnail.url ? { url: jpegThumbnail.url } : jpegThumbnail
|
|
165
|
-
}
|
|
166
|
-
media = await prepareWAMessageMedia(docPayload, { upload: this.waUploadToServer })
|
|
167
|
-
if (fileName) media.documentMessage.fileName = fileName
|
|
168
|
-
if (mimetype) media.documentMessage.mimetype = mimetype
|
|
169
|
-
_mediaType = 'document'
|
|
170
|
-
}
|
|
171
|
-
const interactiveMessage = {
|
|
172
|
-
body: { text: title || '' },
|
|
173
|
-
footer: { text: footer || '' }
|
|
174
|
-
}
|
|
175
|
-
if (buttons && buttons.length > 0) {
|
|
176
|
-
interactiveMessage.nativeFlowMessage = { buttons }
|
|
177
|
-
if (nativeFlowMessage) {
|
|
178
|
-
interactiveMessage.nativeFlowMessage = {
|
|
179
|
-
...interactiveMessage.nativeFlowMessage,
|
|
180
|
-
...nativeFlowMessage
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
} else if (nativeFlowMessage) {
|
|
184
|
-
interactiveMessage.nativeFlowMessage = nativeFlowMessage
|
|
185
|
-
}
|
|
186
|
-
if (media) {
|
|
187
|
-
interactiveMessage.header = {
|
|
188
|
-
title: header || '',
|
|
189
|
-
hasMediaAttachment: true,
|
|
190
|
-
...media
|
|
191
|
-
}
|
|
192
|
-
} else {
|
|
193
|
-
interactiveMessage.header = {
|
|
194
|
-
title: header || '',
|
|
195
|
-
hasMediaAttachment: false
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
const finalContextInfo = {}
|
|
199
|
-
if (contextInfo) {
|
|
200
|
-
Object.assign(finalContextInfo, {
|
|
201
|
-
mentionedJid: contextInfo.mentionedJid || [],
|
|
202
|
-
forwardingScore: contextInfo.forwardingScore || 0,
|
|
203
|
-
isForwarded: contextInfo.isForwarded || false,
|
|
204
|
-
...contextInfo
|
|
205
|
-
})
|
|
206
|
-
}
|
|
207
|
-
if (externalAdReply) {
|
|
208
|
-
finalContextInfo.externalAdReply = {
|
|
209
|
-
title: externalAdReply.title || '',
|
|
210
|
-
body: externalAdReply.body || '',
|
|
211
|
-
mediaType: externalAdReply.mediaType || 1,
|
|
212
|
-
thumbnailUrl: externalAdReply.thumbnailUrl || '',
|
|
213
|
-
mediaUrl: externalAdReply.mediaUrl || '',
|
|
214
|
-
sourceUrl: externalAdReply.sourceUrl || '',
|
|
215
|
-
showAdAttribution: externalAdReply.showAdAttribution || false,
|
|
216
|
-
renderLargerThumbnail: externalAdReply.renderLargerThumbnail || false,
|
|
217
|
-
...externalAdReply
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
if (Object.keys(finalContextInfo).length > 0) {
|
|
221
|
-
interactiveMessage.contextInfo = finalContextInfo
|
|
222
|
-
}
|
|
223
|
-
return { interactiveMessage }
|
|
224
|
-
}
|
|
225
|
-
async handleInteractiveButtons(content, _jid, _quoted) {
|
|
226
|
-
const {
|
|
227
|
-
text,
|
|
228
|
-
caption,
|
|
229
|
-
title,
|
|
230
|
-
subtitle,
|
|
231
|
-
footer,
|
|
232
|
-
interactiveButtons,
|
|
233
|
-
hasMediaAttachment,
|
|
234
|
-
image,
|
|
235
|
-
video,
|
|
236
|
-
document,
|
|
237
|
-
mimetype,
|
|
238
|
-
jpegThumbnail,
|
|
239
|
-
location,
|
|
240
|
-
product,
|
|
241
|
-
businessOwnerJid
|
|
242
|
-
} = content
|
|
243
|
-
const bodyText = text || caption || ''
|
|
244
|
-
const buttons = interactiveButtons.map(btn => ({
|
|
245
|
-
name: btn.name,
|
|
246
|
-
buttonParamsJson:
|
|
247
|
-
typeof btn.buttonParamsJson === 'string' ? btn.buttonParamsJson : JSON.stringify(btn.buttonParamsJson)
|
|
248
|
-
}))
|
|
249
|
-
let headerContent = {}
|
|
250
|
-
let mediaAttached = typeof hasMediaAttachment === 'boolean' ? hasMediaAttachment : false
|
|
251
|
-
if (image) {
|
|
252
|
-
const src = typeof image === 'object' && image.url ? { image: { url: image.url } } : { image }
|
|
253
|
-
const uploaded = await prepareWAMessageMedia(src, { upload: this.waUploadToServer })
|
|
254
|
-
headerContent = { ...uploaded }
|
|
255
|
-
mediaAttached = typeof hasMediaAttachment === 'boolean' ? hasMediaAttachment : true
|
|
256
|
-
} else if (video) {
|
|
257
|
-
const src = typeof video === 'object' && video.url ? { video: { url: video.url } } : { video }
|
|
258
|
-
const uploaded = await prepareWAMessageMedia(src, { upload: this.waUploadToServer })
|
|
259
|
-
headerContent = { ...uploaded }
|
|
260
|
-
mediaAttached = typeof hasMediaAttachment === 'boolean' ? hasMediaAttachment : true
|
|
261
|
-
} else if (document) {
|
|
262
|
-
const docPayload =
|
|
263
|
-
typeof document === 'object' && document.url ? { document: { url: document.url } } : { document }
|
|
264
|
-
if (mimetype) docPayload.mimetype = mimetype
|
|
265
|
-
const uploaded = await prepareWAMessageMedia(docPayload, { upload: this.waUploadToServer })
|
|
266
|
-
if (jpegThumbnail) {
|
|
267
|
-
uploaded.documentMessage.jpegThumbnail =
|
|
268
|
-
typeof jpegThumbnail === 'string' ? Buffer.from(jpegThumbnail, 'base64') : jpegThumbnail
|
|
269
|
-
}
|
|
270
|
-
headerContent = { ...uploaded }
|
|
271
|
-
mediaAttached = typeof hasMediaAttachment === 'boolean' ? hasMediaAttachment : true
|
|
272
|
-
} else if (location) {
|
|
273
|
-
headerContent = {
|
|
274
|
-
locationMessage: {
|
|
275
|
-
degreesLatitude: location.degressLatitude || location.degreesLatitude || 0,
|
|
276
|
-
degreesLongitude: location.degressLongitude || location.degreesLongitude || 0,
|
|
277
|
-
name: location.name || ''
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
mediaAttached = typeof hasMediaAttachment === 'boolean' ? hasMediaAttachment : true
|
|
281
|
-
} else if (product) {
|
|
282
|
-
let productImage
|
|
283
|
-
if (product.productImage) {
|
|
284
|
-
const imgSrc =
|
|
285
|
-
typeof product.productImage === 'object' && product.productImage.url
|
|
286
|
-
? { image: { url: product.productImage.url } }
|
|
287
|
-
: { image: product.productImage }
|
|
288
|
-
const uploaded = await prepareWAMessageMedia(imgSrc, { upload: this.waUploadToServer })
|
|
289
|
-
productImage = uploaded.imageMessage
|
|
290
|
-
}
|
|
291
|
-
headerContent = {
|
|
292
|
-
productMessage: {
|
|
293
|
-
product: {
|
|
294
|
-
productImage,
|
|
295
|
-
productId: product.productId,
|
|
296
|
-
title: product.title,
|
|
297
|
-
description: product.description,
|
|
298
|
-
currencyCode: product.currencyCode || 'IDR',
|
|
299
|
-
priceAmount1000: product.priceAmount1000,
|
|
300
|
-
retailerId: product.retailerId,
|
|
301
|
-
url: product.url,
|
|
302
|
-
productImageCount: product.productImageCount || 1
|
|
303
|
-
},
|
|
304
|
-
businessOwnerJid: businessOwnerJid || '0@s.whatsapp.net'
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
mediaAttached = typeof hasMediaAttachment === 'boolean' ? hasMediaAttachment : true
|
|
308
|
-
}
|
|
309
|
-
const interactiveMessage = {
|
|
310
|
-
body: { text: bodyText },
|
|
311
|
-
footer: { text: footer || '' },
|
|
312
|
-
header: {
|
|
313
|
-
title: title || '',
|
|
314
|
-
subtitle: subtitle || '',
|
|
315
|
-
hasMediaAttachment: mediaAttached,
|
|
316
|
-
...headerContent
|
|
317
|
-
},
|
|
318
|
-
nativeFlowMessage: { buttons }
|
|
319
|
-
}
|
|
320
|
-
return {
|
|
321
|
-
viewOnceMessage: {
|
|
322
|
-
message: {
|
|
323
|
-
messageContextInfo: {
|
|
324
|
-
deviceListMetadata: {},
|
|
325
|
-
deviceListMetadataVersion: 2,
|
|
326
|
-
messageSecret: crypto.randomBytes(32)
|
|
327
|
-
},
|
|
328
|
-
interactiveMessage
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
async handleAlbum(content, jid, quoted) {
|
|
334
|
-
const array = content.albumMessage || content.album
|
|
335
|
-
const ctxInfo = content.contextInfo || {}
|
|
336
|
-
const album = await generateWAMessageFromContent(
|
|
337
|
-
jid,
|
|
338
|
-
{
|
|
339
|
-
messageContextInfo: {
|
|
340
|
-
messageSecret: crypto.randomBytes(32)
|
|
341
|
-
},
|
|
342
|
-
albumMessage: {
|
|
343
|
-
expectedImageCount: array.filter(a => 'image' in a).length,
|
|
344
|
-
expectedVideoCount: array.filter(a => 'video' in a).length
|
|
345
|
-
}
|
|
346
|
-
},
|
|
347
|
-
{ userJid: jidNormalizedUser(this.sock.authState?.creds?.me?.id || '') }
|
|
348
|
-
)
|
|
349
|
-
await this.relayMessage(jid, album.message, {
|
|
350
|
-
messageId: album.key.id
|
|
351
|
-
})
|
|
352
|
-
for (let item of array) {
|
|
353
|
-
if (ctxInfo && Object.keys(ctxInfo).length > 0 && !item.contextInfo) {
|
|
354
|
-
item = { ...item, contextInfo: ctxInfo }
|
|
355
|
-
}
|
|
356
|
-
const img = await generateWAMessage(jid, item, {
|
|
357
|
-
upload: this.waUploadToServer,
|
|
358
|
-
userJid: jidNormalizedUser(this.sock.authState?.creds?.me?.id || '')
|
|
359
|
-
})
|
|
360
|
-
img.message.messageContextInfo = {
|
|
361
|
-
messageSecret: crypto.randomBytes(32),
|
|
362
|
-
messageAssociation: {
|
|
363
|
-
associationType: 1,
|
|
364
|
-
parentMessageKey: album.key
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
await this.relayMessage(jid, img.message, {
|
|
368
|
-
messageId: img.key.id
|
|
369
|
-
})
|
|
370
|
-
}
|
|
371
|
-
return album
|
|
372
|
-
}
|
|
373
|
-
async handleEvent(content, jid, quoted) {
|
|
374
|
-
const eventData = content.eventMessage
|
|
375
|
-
const msg = await generateWAMessageFromContent(
|
|
376
|
-
jid,
|
|
377
|
-
{
|
|
378
|
-
viewOnceMessage: {
|
|
379
|
-
message: {
|
|
380
|
-
messageContextInfo: {
|
|
381
|
-
deviceListMetadata: {},
|
|
382
|
-
deviceListMetadataVersion: 2,
|
|
383
|
-
messageSecret: crypto.randomBytes(32)
|
|
384
|
-
},
|
|
385
|
-
eventMessage: {
|
|
386
|
-
isCanceled: eventData.isCanceled || false,
|
|
387
|
-
name: eventData.name,
|
|
388
|
-
description: eventData.description,
|
|
389
|
-
location: eventData.location || {
|
|
390
|
-
degreesLatitude: 0,
|
|
391
|
-
degreesLongitude: 0,
|
|
392
|
-
name: 'Location'
|
|
393
|
-
},
|
|
394
|
-
joinLink: eventData.joinLink || '',
|
|
395
|
-
startTime:
|
|
396
|
-
typeof eventData.startTime === 'string'
|
|
397
|
-
? parseInt(eventData.startTime, 10)
|
|
398
|
-
: eventData.startTime || Date.now(),
|
|
399
|
-
endTime:
|
|
400
|
-
typeof eventData.endTime === 'string'
|
|
401
|
-
? parseInt(eventData.endTime, 10)
|
|
402
|
-
: eventData.endTime || Date.now() + 3600000,
|
|
403
|
-
extraGuestsAllowed: eventData.extraGuestsAllowed !== false
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
},
|
|
408
|
-
{ quoted, userJid: jidNormalizedUser(this.sock.authState?.creds?.me?.id || '') }
|
|
409
|
-
)
|
|
410
|
-
await this.relayMessage(jid, msg.message, {
|
|
411
|
-
messageId: msg.key.id
|
|
412
|
-
})
|
|
413
|
-
return msg
|
|
414
|
-
}
|
|
415
|
-
async handlePollResult(content, jid, quoted) {
|
|
416
|
-
const pollData = content.pollResultMessage
|
|
417
|
-
const msg = await generateWAMessageFromContent(
|
|
418
|
-
jid,
|
|
419
|
-
{
|
|
420
|
-
pollResultSnapshotMessage: {
|
|
421
|
-
name: pollData.name,
|
|
422
|
-
pollVotes: pollData.pollVotes.map(vote => ({
|
|
423
|
-
optionName: vote.optionName,
|
|
424
|
-
optionVoteCount:
|
|
425
|
-
typeof vote.optionVoteCount === 'number' ? vote.optionVoteCount.toString() : vote.optionVoteCount
|
|
426
|
-
}))
|
|
427
|
-
}
|
|
428
|
-
},
|
|
429
|
-
{ quoted, userJid: jidNormalizedUser(this.sock.authState?.creds?.me?.id || '') }
|
|
430
|
-
)
|
|
431
|
-
await this.relayMessage(jid, msg.message, {
|
|
432
|
-
messageId: msg.key.id
|
|
433
|
-
})
|
|
434
|
-
return msg
|
|
435
|
-
}
|
|
436
|
-
async handleGroupStory(content, jid, _quoted) {
|
|
437
|
-
const storyData = content.groupStatusMessage
|
|
438
|
-
let waMsgContent
|
|
439
|
-
if (storyData.message) {
|
|
440
|
-
waMsgContent = storyData
|
|
441
|
-
} else {
|
|
442
|
-
waMsgContent = await generateWAMessageContent(storyData, {
|
|
443
|
-
upload: this.waUploadToServer
|
|
444
|
-
})
|
|
445
|
-
}
|
|
446
|
-
const msg = {
|
|
447
|
-
message: {
|
|
448
|
-
groupStatusMessageV2: {
|
|
449
|
-
message: waMsgContent.message || waMsgContent
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
return await this.relayMessage(jid, msg.message, {
|
|
454
|
-
messageId: generateMessageID()
|
|
455
|
-
})
|
|
456
|
-
}
|
|
457
|
-
async sendStatusWhatsApp(content, jids = []) {
|
|
458
|
-
const userJid = jidNormalizedUser(this.sock.authState.creds.me.id)
|
|
459
|
-
const allUsers = new Set()
|
|
460
|
-
allUsers.add(userJid)
|
|
461
|
-
for (const id of jids) {
|
|
462
|
-
if (isJidGroup(id)) {
|
|
463
|
-
try {
|
|
464
|
-
const metadata = await this.sock.groupMetadata(id)
|
|
465
|
-
metadata.participants.forEach(p => allUsers.add(jidNormalizedUser(p.id)))
|
|
466
|
-
} catch (error) {
|
|
467
|
-
this.config.logger.error(`Error getting metadata for group ${id}: ${error}`)
|
|
468
|
-
}
|
|
469
|
-
} else if (isPnUser(id)) {
|
|
470
|
-
allUsers.add(jidNormalizedUser(id))
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
const uniqueUsers = Array.from(allUsers)
|
|
474
|
-
const getRandomHexColor = () =>
|
|
475
|
-
'#' +
|
|
476
|
-
Math.floor(Math.random() * 16777215)
|
|
477
|
-
.toString(16)
|
|
478
|
-
.padStart(6, '0')
|
|
479
|
-
const isMedia = content.image || content.video || content.audio
|
|
480
|
-
const isAudio = !!content.audio
|
|
481
|
-
const messageContent = { ...content }
|
|
482
|
-
if (isMedia && !isAudio) {
|
|
483
|
-
if (messageContent.text) {
|
|
484
|
-
messageContent.caption = messageContent.text
|
|
485
|
-
delete messageContent.text
|
|
486
|
-
}
|
|
487
|
-
delete messageContent.ptt
|
|
488
|
-
delete messageContent.font
|
|
489
|
-
delete messageContent.backgroundColor
|
|
490
|
-
delete messageContent.textColor
|
|
491
|
-
}
|
|
492
|
-
if (isAudio) {
|
|
493
|
-
delete messageContent.text
|
|
494
|
-
delete messageContent.caption
|
|
495
|
-
delete messageContent.font
|
|
496
|
-
delete messageContent.textColor
|
|
497
|
-
}
|
|
498
|
-
const font = !isMedia ? content.font || Math.floor(Math.random() * 9) : undefined
|
|
499
|
-
const textColor = !isMedia ? content.textColor || getRandomHexColor() : undefined
|
|
500
|
-
const backgroundColor = !isMedia || isAudio ? content.backgroundColor || getRandomHexColor() : undefined
|
|
501
|
-
const ptt = isAudio ? (typeof content.ptt === 'boolean' ? content.ptt : true) : undefined
|
|
502
|
-
const { getUrlInfo } = require('../Utils/link-preview.js')
|
|
503
|
-
const msg = await generateWAMessage(STORIES_JID, messageContent, {
|
|
504
|
-
logger: this.config.logger,
|
|
505
|
-
userJid,
|
|
506
|
-
getUrlInfo: text =>
|
|
507
|
-
getUrlInfo(text, {
|
|
508
|
-
thumbnailWidth: this.config.linkPreviewImageThumbnailWidth,
|
|
509
|
-
fetchOpts: { timeout: 3000, ...(this.config.options || {}) },
|
|
510
|
-
logger: this.config.logger,
|
|
511
|
-
uploadImage: this.config.generateHighQualityLinkPreview ? this.waUploadToServer : undefined
|
|
512
|
-
}),
|
|
513
|
-
upload: this.waUploadToServer,
|
|
514
|
-
mediaCache: this.config.mediaCache,
|
|
515
|
-
options: this.config.options,
|
|
516
|
-
font,
|
|
517
|
-
textColor,
|
|
518
|
-
backgroundColor,
|
|
519
|
-
ptt
|
|
520
|
-
})
|
|
521
|
-
await this.relayMessage(STORIES_JID, msg.message, {
|
|
522
|
-
messageId: msg.key.id,
|
|
523
|
-
statusJidList: uniqueUsers,
|
|
524
|
-
additionalNodes: [
|
|
525
|
-
{
|
|
526
|
-
tag: 'meta',
|
|
527
|
-
attrs: {},
|
|
528
|
-
content: [
|
|
529
|
-
{
|
|
530
|
-
tag: 'mentioned_users',
|
|
531
|
-
attrs: {},
|
|
532
|
-
content: jids.map(jid => ({
|
|
533
|
-
tag: 'to',
|
|
534
|
-
attrs: { jid: jidNormalizedUser(jid) }
|
|
535
|
-
}))
|
|
536
|
-
}
|
|
537
|
-
]
|
|
538
|
-
}
|
|
539
|
-
]
|
|
540
|
-
})
|
|
541
|
-
for (const id of jids) {
|
|
542
|
-
try {
|
|
543
|
-
const normalizedId = jidNormalizedUser(id)
|
|
544
|
-
const isPrivate = isPnUser(normalizedId)
|
|
545
|
-
const type = isPrivate ? 'statusMentionMessage' : 'groupStatusMentionMessage'
|
|
546
|
-
const protocolMessage = {
|
|
547
|
-
[type]: {
|
|
548
|
-
message: {
|
|
549
|
-
protocolMessage: {
|
|
550
|
-
key: msg.key,
|
|
551
|
-
type: 25
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
},
|
|
555
|
-
messageContextInfo: {
|
|
556
|
-
messageSecret: crypto.randomBytes(32)
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
const statusMsg = await generateWAMessageFromContent(normalizedId, protocolMessage, {
|
|
560
|
-
userJid: jidNormalizedUser(this.sock.authState?.creds?.me?.id || '')
|
|
561
|
-
})
|
|
562
|
-
await this.relayMessage(normalizedId, statusMsg.message, {
|
|
563
|
-
additionalNodes: [
|
|
564
|
-
{
|
|
565
|
-
tag: 'meta',
|
|
566
|
-
attrs: isPrivate ? { is_status_mention: 'true' } : { is_group_status_mention: 'true' }
|
|
567
|
-
}
|
|
568
|
-
]
|
|
569
|
-
})
|
|
570
|
-
await delay(2000)
|
|
571
|
-
} catch (error) {
|
|
572
|
-
this.config.logger.error(`Error sending to ${id}: ${error}`)
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
return msg
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
module.exports = { badzz88 }
|