@hbmodsofc/baileys 2.4.0 → 3.0.0
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/LICENSE +1 -1
- package/README.MD +220 -1198
- package/WAProto/GenerateStatics.sh +4 -0
- package/WAProto/WAProto.proto +5619 -0
- package/engine-requirements.js +1 -1
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +97 -122
- package/lib/Defaults/phonenumber_mcc.json +223 -0
- package/lib/Socket/Client/index.js +2 -3
- package/lib/Socket/Client/{web-socket-client.js → websocket.js} +54 -5
- package/lib/Socket/business.js +8 -2
- package/lib/Socket/chats.js +455 -288
- package/lib/Socket/communities.js +441 -0
- package/lib/Socket/groups.js +38 -23
- package/lib/Socket/hbmods.js +374 -406
- package/lib/Socket/index.js +43 -11
- package/lib/Socket/messages-recv.js +24 -69
- package/lib/Socket/messages-send.js +391 -419
- package/lib/Socket/newsletter.js +104 -190
- package/lib/Socket/socket.js +40 -54
- package/lib/Store/index.js +1 -3
- package/lib/Store/make-in-memory-store.js +27 -15
- package/lib/Store/make-ordered-dictionary.js +2 -2
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.js +0 -2
- package/lib/Types/Newsletter.js +18 -38
- package/lib/Types/index.js +2 -2
- package/lib/Utils/async-iterable.js +41 -0
- package/lib/Utils/audioToBuffer.js +29 -0
- package/lib/Utils/auth-utils.js +6 -13
- package/lib/Utils/baileys-event-stream.js +1 -1
- package/lib/Utils/browser-utils.js +35 -0
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.js +36 -35
- package/lib/Utils/crypto.js +71 -29
- package/lib/Utils/decode-wa-message.js +65 -56
- package/lib/Utils/event-buffer.js +13 -9
- package/lib/Utils/generics.js +88 -84
- package/lib/Utils/history.js +4 -6
- package/lib/Utils/index.js +3 -0
- package/lib/Utils/link-preview.js +34 -1
- package/lib/Utils/lt-hash.js +6 -6
- package/lib/Utils/message-retry-manager.js +128 -0
- package/lib/Utils/messages-media.js +340 -246
- package/lib/Utils/messages.js +329 -192
- package/lib/Utils/noise-handler.js +18 -23
- package/lib/Utils/process-message.js +108 -25
- package/lib/Utils/resolveJid.js +52 -0
- package/lib/Utils/signal.js +26 -26
- package/lib/Utils/streamToBuffer.js +15 -0
- package/lib/Utils/use-multi-file-auth-state.js +3 -0
- package/lib/Utils/validate-connection.js +1 -3
- package/lib/WABinary/constants.js +1276 -13
- package/lib/WABinary/decode.js +26 -13
- package/lib/WABinary/encode.js +137 -152
- package/lib/WABinary/generic-utils.js +37 -125
- package/lib/WABinary/jid-utils.js +28 -5
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
- package/lib/index.js +53 -7
- package/package.json +112 -104
- package/lib/Defaults/index.d.ts +0 -53
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
- package/lib/Signal/Group/group-session-builder.d.ts +0 -14
- package/lib/Signal/Group/group_cipher.d.ts +0 -17
- package/lib/Signal/Group/index.d.ts +0 -11
- package/lib/Signal/Group/keyhelper.d.ts +0 -10
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/sender-chain-key.d.ts +0 -13
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -16
- package/lib/Signal/Group/sender-key-message.d.ts +0 -18
- package/lib/Signal/Group/sender-key-name.d.ts +0 -17
- package/lib/Signal/Group/sender-key-record.d.ts +0 -30
- package/lib/Signal/Group/sender-key-state.d.ts +0 -38
- package/lib/Signal/Group/sender-message-key.d.ts +0 -11
- package/lib/Signal/libsignal.d.ts +0 -3
- package/lib/Socket/Client/abstract-socket-client.d.ts +0 -17
- package/lib/Socket/Client/index.d.ts +0 -3
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/web-socket-client.d.ts +0 -12
- package/lib/Socket/business.d.ts +0 -171
- package/lib/Socket/chats.d.ts +0 -267
- package/lib/Socket/groups.d.ts +0 -115
- package/lib/Socket/hbmods.d.ts +0 -254
- package/lib/Socket/index.d.ts +0 -173
- package/lib/Socket/messages-recv.d.ts +0 -161
- package/lib/Socket/messages-send.d.ts +0 -149
- package/lib/Socket/newsletter.d.ts +0 -134
- package/lib/Socket/registration.d.ts +0 -267
- package/lib/Socket/registration.js +0 -166
- package/lib/Socket/socket.d.ts +0 -43
- package/lib/Socket/usync.d.ts +0 -36
- package/lib/Store/index.d.ts +0 -3
- package/lib/Store/make-cache-manager-store.d.ts +0 -13
- package/lib/Store/make-cache-manager-store.js +0 -83
- package/lib/Store/make-in-memory-store.d.ts +0 -118
- package/lib/Store/make-ordered-dictionary.d.ts +0 -13
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Types/Auth.d.ts +0 -110
- package/lib/Types/Call.d.ts +0 -13
- package/lib/Types/Chat.d.ts +0 -102
- package/lib/Types/Contact.d.ts +0 -19
- package/lib/Types/Events.d.ts +0 -157
- package/lib/Types/GroupMetadata.d.ts +0 -55
- package/lib/Types/Label.d.ts +0 -35
- package/lib/Types/LabelAssociation.d.ts +0 -29
- package/lib/Types/Message.d.ts +0 -273
- package/lib/Types/Newsletter.d.ts +0 -103
- package/lib/Types/Product.d.ts +0 -78
- package/lib/Types/Signal.d.ts +0 -57
- package/lib/Types/Socket.d.ts +0 -111
- package/lib/Types/State.d.ts +0 -27
- package/lib/Types/USync.d.ts +0 -25
- package/lib/Types/index.d.ts +0 -57
- package/lib/Utils/auth-utils.d.ts +0 -18
- package/lib/Utils/baileys-event-stream.d.ts +0 -16
- package/lib/Utils/business.d.ts +0 -22
- package/lib/Utils/chat-utils.d.ts +0 -71
- package/lib/Utils/crypto.d.ts +0 -41
- package/lib/Utils/decode-wa-message.d.ts +0 -19
- package/lib/Utils/event-buffer.d.ts +0 -35
- package/lib/Utils/generics.d.ts +0 -92
- package/lib/Utils/generics.js.bak +0 -433
- package/lib/Utils/history.d.ts +0 -15
- package/lib/Utils/index.d.ts +0 -17
- package/lib/Utils/link-preview.d.ts +0 -21
- package/lib/Utils/logger.d.ts +0 -4
- package/lib/Utils/lt-hash.d.ts +0 -12
- package/lib/Utils/make-mutex.d.ts +0 -7
- package/lib/Utils/messages-media.d.ts +0 -116
- package/lib/Utils/messages.d.ts +0 -77
- package/lib/Utils/noise-handler.d.ts +0 -21
- package/lib/Utils/process-message.d.ts +0 -41
- package/lib/Utils/signal.d.ts +0 -32
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
- package/lib/Utils/validate-connection.d.ts +0 -11
- package/lib/Utils/validate-connection.js.bak +0 -237
- package/lib/WABinary/constants.d.ts +0 -30
- package/lib/WABinary/decode.d.ts +0 -7
- package/lib/WABinary/encode.d.ts +0 -3
- package/lib/WABinary/generic-utils.d.ts +0 -17
- package/lib/WABinary/index.d.ts +0 -5
- package/lib/WABinary/jid-utils.d.ts +0 -31
- package/lib/WABinary/types.d.ts +0 -18
- package/lib/WAM/BinaryInfo.d.ts +0 -17
- package/lib/WAM/constants.d.ts +0 -38
- package/lib/WAM/encode.d.ts +0 -3
- package/lib/WAM/index.d.ts +0 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -25
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -8
- package/lib/WAUSync/Protocols/index.d.ts +0 -4
- package/lib/WAUSync/USyncQuery.d.ts +0 -28
- package/lib/WAUSync/USyncUser.d.ts +0 -12
- package/lib/WAUSync/index.d.ts +0 -3
- package/lib/index.d.ts +0 -12
- /package/lib/Socket/Client/{abstract-socket-client.js → types.js} +0 -0
package/lib/Socket/hbmods.js
CHANGED
|
@@ -1,450 +1,417 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
|
|
5
|
+
const WAProto = require("../../WAProto").proto;
|
|
6
|
+
const crypto = require("crypto");
|
|
3
7
|
const Utils_1 = require("../Utils");
|
|
4
8
|
|
|
5
|
-
class
|
|
9
|
+
class hbmodsofc {
|
|
6
10
|
constructor(utils, waUploadToServer, relayMessageFn) {
|
|
7
11
|
this.utils = utils;
|
|
8
|
-
this.relayMessage = relayMessageFn
|
|
12
|
+
this.relayMessage = relayMessageFn;
|
|
9
13
|
this.waUploadToServer = waUploadToServer;
|
|
10
|
-
|
|
11
14
|
this.bail = {
|
|
12
15
|
generateWAMessageContent: this.utils.generateWAMessageContent || Utils_1.generateWAMessageContent,
|
|
13
16
|
generateMessageID: Utils_1.generateMessageID,
|
|
14
|
-
getContentType: (msg) =>
|
|
17
|
+
getContentType: (msg) => {
|
|
18
|
+
if (!msg || typeof msg !== "object") return null;
|
|
19
|
+
const m = msg.message || {};
|
|
20
|
+
if (typeof m !== "object") return null;
|
|
21
|
+
return Object.keys(m)[0] || null;
|
|
22
|
+
}
|
|
15
23
|
};
|
|
16
24
|
}
|
|
17
25
|
|
|
18
26
|
detectType(content) {
|
|
19
|
-
if (content.requestPaymentMessage) return
|
|
20
|
-
if (content.productMessage) return
|
|
21
|
-
if (content.interactiveMessage) return
|
|
22
|
-
if (content.albumMessage) return
|
|
23
|
-
if (content.eventMessage) return
|
|
24
|
-
if (content.pollResultMessage) return
|
|
25
|
-
if (content.groupStatusMessage) return
|
|
27
|
+
if (content.requestPaymentMessage) return "PAYMENT";
|
|
28
|
+
if (content.productMessage) return "PRODUCT";
|
|
29
|
+
if (content.interactiveMessage) return "INTERACTIVE";
|
|
30
|
+
if (content.albumMessage) return "ALBUM";
|
|
31
|
+
if (content.eventMessage) return "EVENT";
|
|
32
|
+
if (content.pollResultMessage) return "POLL_RESULT";
|
|
33
|
+
if (content.groupStatusMessage) return "GROUP_STORY";
|
|
26
34
|
return null;
|
|
27
35
|
}
|
|
28
36
|
|
|
29
37
|
async handlePayment(content, quoted) {
|
|
30
|
-
const data = content
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
const data = content?.requestPaymentMessage;
|
|
39
|
+
if (!data) throw new Error("Missing requestPaymentMessage in content");
|
|
40
|
+
try {
|
|
41
|
+
let notes = {};
|
|
42
|
+
if (data.sticker?.stickerMessage) {
|
|
43
|
+
notes = {
|
|
44
|
+
stickerMessage: {
|
|
45
|
+
...data.sticker.stickerMessage,
|
|
46
|
+
contextInfo: {
|
|
47
|
+
stanzaId: quoted?.key?.id,
|
|
48
|
+
participant: quoted?.key?.participant || content.sender,
|
|
49
|
+
quotedMessage: quoted?.message
|
|
50
|
+
}
|
|
41
51
|
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
};
|
|
53
|
+
} else if (data.note) {
|
|
54
|
+
notes = {
|
|
55
|
+
extendedTextMessage: {
|
|
56
|
+
text: data.note,
|
|
57
|
+
contextInfo: {
|
|
58
|
+
stanzaId: quoted?.key?.id,
|
|
59
|
+
participant: quoted?.key?.participant || content.sender,
|
|
60
|
+
quotedMessage: quoted?.message
|
|
61
|
+
}
|
|
52
62
|
}
|
|
53
|
-
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
requestPaymentMessage: WAProto.Message.RequestPaymentMessage.fromObject({
|
|
67
|
+
expiryTimestamp: data.expiry || 0,
|
|
68
|
+
amount1000: data.amount || 0,
|
|
69
|
+
currencyCodeIso4217: data.currency || "IDR",
|
|
70
|
+
requestFrom: data.from || "0@s.whatsapp.net",
|
|
71
|
+
noteMessage: notes,
|
|
72
|
+
background: data.background ?? {
|
|
73
|
+
id: "DEFAULT",
|
|
74
|
+
placeholderArgb: 0xfff0f0f0
|
|
75
|
+
}
|
|
76
|
+
})
|
|
54
77
|
};
|
|
78
|
+
} catch (err) {
|
|
79
|
+
console.error("handlePayment error:", err);
|
|
80
|
+
throw err;
|
|
55
81
|
}
|
|
56
|
-
|
|
57
|
-
return {
|
|
58
|
-
requestPaymentMessage: WAProto.Message.RequestPaymentMessage.fromObject({
|
|
59
|
-
expiryTimestamp: data.expiry || 0,
|
|
60
|
-
amount1000: data.amount || 0,
|
|
61
|
-
currencyCodeIso4217: data.currency || "INR",
|
|
62
|
-
requestFrom: data.from || "0@s.whatsapp.net",
|
|
63
|
-
noteMessage: notes,
|
|
64
|
-
background: data.background ?? {
|
|
65
|
-
id: "DEFAULT",
|
|
66
|
-
placeholderArgb: 0xFFF0F0F0
|
|
67
|
-
}
|
|
68
|
-
})
|
|
69
|
-
};
|
|
70
82
|
}
|
|
71
|
-
|
|
72
|
-
async handleProduct(content, jid, quoted) {
|
|
73
|
-
const {
|
|
74
|
-
title,
|
|
75
|
-
description,
|
|
76
|
-
thumbnail,
|
|
77
|
-
productId,
|
|
78
|
-
retailerId,
|
|
79
|
-
url,
|
|
80
|
-
body = "",
|
|
81
|
-
footer = "",
|
|
82
|
-
buttons = [],
|
|
83
|
-
priceAmount1000 = null,
|
|
84
|
-
currencyCode = "INR"
|
|
85
|
-
} = content.productMessage;
|
|
86
|
-
|
|
87
|
-
let productImage;
|
|
88
|
-
|
|
89
|
-
if (Buffer.isBuffer(thumbnail)) {
|
|
90
|
-
const { imageMessage } = await this.utils.generateWAMessageContent(
|
|
91
|
-
{ image: thumbnail },
|
|
92
|
-
{ upload: this.waUploadToServer }
|
|
93
|
-
);
|
|
94
|
-
productImage = imageMessage;
|
|
95
|
-
} else if (typeof thumbnail === 'object' && thumbnail.url) {
|
|
96
|
-
const { imageMessage } = await this.utils.generateWAMessageContent(
|
|
97
|
-
{ image: { url: thumbnail.url }},
|
|
98
|
-
{ upload: this.waUploadToServer }
|
|
99
|
-
);
|
|
100
|
-
productImage = imageMessage;
|
|
101
|
-
}
|
|
102
83
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
nativeFlowMessage: { buttons }
|
|
84
|
+
async handleProduct(content, jid, quoted) {
|
|
85
|
+
try {
|
|
86
|
+
const {
|
|
87
|
+
title = "",
|
|
88
|
+
description = "",
|
|
89
|
+
thumbnail,
|
|
90
|
+
productId,
|
|
91
|
+
retailerId,
|
|
92
|
+
url,
|
|
93
|
+
body = "",
|
|
94
|
+
footer = "",
|
|
95
|
+
buttons = [],
|
|
96
|
+
priceAmount1000 = null,
|
|
97
|
+
currencyCode = "IDR"
|
|
98
|
+
} = content.productMessage || {};
|
|
99
|
+
let productImage = null;
|
|
100
|
+
if (thumbnail) {
|
|
101
|
+
try {
|
|
102
|
+
if (Buffer.isBuffer(thumbnail)) {
|
|
103
|
+
const res = await this.utils.generateWAMessageContent({ image: thumbnail }, { upload: this.waUploadToServer });
|
|
104
|
+
productImage = res?.imageMessage || res?.message?.imageMessage || null;
|
|
105
|
+
} else if (typeof thumbnail === "object" && thumbnail.url) {
|
|
106
|
+
const res = await this.utils.generateWAMessageContent({ image: { url: thumbnail.url } }, { upload: this.waUploadToServer });
|
|
107
|
+
productImage = res?.imageMessage || res?.message?.imageMessage || null;
|
|
128
108
|
}
|
|
129
|
-
}
|
|
109
|
+
} catch {}
|
|
130
110
|
}
|
|
131
|
-
|
|
111
|
+
const product = {
|
|
112
|
+
productId,
|
|
113
|
+
title,
|
|
114
|
+
description,
|
|
115
|
+
currencyCode,
|
|
116
|
+
priceAmount1000,
|
|
117
|
+
retailerId,
|
|
118
|
+
url,
|
|
119
|
+
productImageCount: productImage ? 1 : 0
|
|
120
|
+
};
|
|
121
|
+
if (productImage) product.productImage = productImage;
|
|
122
|
+
return {
|
|
123
|
+
viewOnceMessage: {
|
|
124
|
+
message: {
|
|
125
|
+
interactiveMessage: {
|
|
126
|
+
body: { text: body },
|
|
127
|
+
footer: { text: footer },
|
|
128
|
+
header: {
|
|
129
|
+
title,
|
|
130
|
+
hasMediaAttachment: !!productImage,
|
|
131
|
+
productMessage: {
|
|
132
|
+
product,
|
|
133
|
+
businessOwnerJid: "0@s.whatsapp.net"
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
nativeFlowMessage: { buttons }
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
} catch (err) {
|
|
142
|
+
console.error("handleProduct error:", err);
|
|
143
|
+
throw err;
|
|
144
|
+
}
|
|
132
145
|
}
|
|
133
|
-
|
|
134
|
-
async handleInteractive(content, jid, quoted) {
|
|
135
|
-
const {
|
|
136
|
-
title,
|
|
137
|
-
footer,
|
|
138
|
-
thumbnail,
|
|
139
|
-
image,
|
|
140
|
-
video,
|
|
141
|
-
document,
|
|
142
|
-
mimetype,
|
|
143
|
-
fileName,
|
|
144
|
-
jpegThumbnail,
|
|
145
|
-
contextInfo,
|
|
146
|
-
externalAdReply,
|
|
147
|
-
buttons = [],
|
|
148
|
-
nativeFlowMessage,
|
|
149
|
-
header
|
|
150
|
-
} = content.interactiveMessage;
|
|
151
|
-
|
|
152
|
-
let media = null;
|
|
153
|
-
let mediaType = null;
|
|
154
146
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
147
|
+
async handleInteractive(content, jid, quoted) {
|
|
148
|
+
try {
|
|
149
|
+
const {
|
|
150
|
+
title,
|
|
151
|
+
footer,
|
|
152
|
+
thumbnail,
|
|
153
|
+
image,
|
|
154
|
+
video,
|
|
155
|
+
document,
|
|
156
|
+
mimetype,
|
|
157
|
+
fileName,
|
|
158
|
+
jpegThumbnail,
|
|
159
|
+
contextInfo,
|
|
160
|
+
externalAdReply,
|
|
161
|
+
buttons = [],
|
|
162
|
+
nativeFlowMessage,
|
|
163
|
+
header
|
|
164
|
+
} = content.interactiveMessage || {};
|
|
165
|
+
let media = null;
|
|
166
|
+
if (thumbnail) {
|
|
167
|
+
media = await this.utils.prepareWAMessageMedia({ image: { url: thumbnail } }, { upload: this.waUploadToServer });
|
|
168
|
+
} else if (image) {
|
|
176
169
|
media = await this.utils.prepareWAMessageMedia(
|
|
177
|
-
{
|
|
170
|
+
typeof image === "object" && image.url ? { image: { url: image.url } } : { image },
|
|
178
171
|
{ upload: this.waUploadToServer }
|
|
179
172
|
);
|
|
180
|
-
} else {
|
|
173
|
+
} else if (video) {
|
|
181
174
|
media = await this.utils.prepareWAMessageMedia(
|
|
182
|
-
{ video: video },
|
|
175
|
+
typeof video === "object" && video.url ? { video: { url: video.url } } : { video },
|
|
183
176
|
{ upload: this.waUploadToServer }
|
|
184
177
|
);
|
|
178
|
+
} else if (document) {
|
|
179
|
+
const docPayload = { document };
|
|
180
|
+
if (jpegThumbnail) {
|
|
181
|
+
docPayload.jpegThumbnail = typeof jpegThumbnail === "object" && jpegThumbnail.url ? { url: jpegThumbnail.url } : jpegThumbnail;
|
|
182
|
+
}
|
|
183
|
+
media = await this.utils.prepareWAMessageMedia(docPayload, { upload: this.waUploadToServer });
|
|
184
|
+
if (fileName) media.documentMessage.fileName = fileName;
|
|
185
|
+
if (mimetype) media.documentMessage.mimetype = mimetype;
|
|
185
186
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
document: document
|
|
187
|
+
const interactiveMessage = {
|
|
188
|
+
body: { text: title || "" },
|
|
189
|
+
footer: { text: footer || "" }
|
|
190
190
|
};
|
|
191
|
-
if (
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
191
|
+
if (buttons.length > 0) {
|
|
192
|
+
interactiveMessage.nativeFlowMessage = { buttons };
|
|
193
|
+
if (nativeFlowMessage) Object.assign(interactiveMessage.nativeFlowMessage, nativeFlowMessage);
|
|
194
|
+
} else if (nativeFlowMessage) {
|
|
195
|
+
interactiveMessage.nativeFlowMessage = nativeFlowMessage;
|
|
197
196
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
197
|
+
if (media) {
|
|
198
|
+
const headerMedia = {};
|
|
199
|
+
if (media.imageMessage) headerMedia.imageMessage = media.imageMessage;
|
|
200
|
+
if (media.videoMessage) headerMedia.videoMessage = media.videoMessage;
|
|
201
|
+
if (media.documentMessage) headerMedia.documentMessage = media.documentMessage;
|
|
202
|
+
interactiveMessage.header = { title: header || "", hasMediaAttachment: true, ...headerMedia };
|
|
203
|
+
} else {
|
|
204
|
+
interactiveMessage.header = { title: header || "", hasMediaAttachment: false };
|
|
205
205
|
}
|
|
206
|
-
|
|
207
|
-
|
|
206
|
+
let finalContextInfo = {};
|
|
207
|
+
if (contextInfo) {
|
|
208
|
+
finalContextInfo = {
|
|
209
|
+
mentionedJid: contextInfo.mentionedJid || [],
|
|
210
|
+
forwardingScore: contextInfo.forwardingScore || 0,
|
|
211
|
+
isForwarded: contextInfo.isForwarded || false,
|
|
212
|
+
...contextInfo
|
|
213
|
+
};
|
|
208
214
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
interactiveMessage.nativeFlowMessage = {
|
|
221
|
-
...interactiveMessage.nativeFlowMessage,
|
|
222
|
-
...nativeFlowMessage
|
|
215
|
+
if (externalAdReply) {
|
|
216
|
+
finalContextInfo.externalAdReply = {
|
|
217
|
+
title: externalAdReply.title || "",
|
|
218
|
+
body: externalAdReply.body || "",
|
|
219
|
+
mediaType: externalAdReply.mediaType || 1,
|
|
220
|
+
thumbnailUrl: externalAdReply.thumbnailUrl || "",
|
|
221
|
+
mediaUrl: externalAdReply.mediaUrl || "",
|
|
222
|
+
sourceUrl: externalAdReply.sourceUrl || "",
|
|
223
|
+
showAdAttribution: externalAdReply.showAdAttribution || false,
|
|
224
|
+
renderLargerThumbnail: externalAdReply.renderLargerThumbnail || false,
|
|
225
|
+
...externalAdReply
|
|
223
226
|
};
|
|
224
227
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
hasMediaAttachment: true,
|
|
233
|
-
...media
|
|
234
|
-
};
|
|
235
|
-
} else {
|
|
236
|
-
interactiveMessage.header = {
|
|
237
|
-
title: header || "",
|
|
238
|
-
hasMediaAttachment: false
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
let finalContextInfo = {};
|
|
243
|
-
if (contextInfo) {
|
|
244
|
-
finalContextInfo = {
|
|
245
|
-
mentionedJid: contextInfo.mentionedJid || [],
|
|
246
|
-
forwardingScore: contextInfo.forwardingScore || 0,
|
|
247
|
-
isForwarded: contextInfo.isForwarded || false,
|
|
248
|
-
...contextInfo
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if (externalAdReply) {
|
|
253
|
-
finalContextInfo.externalAdReply = {
|
|
254
|
-
title: externalAdReply.title || "",
|
|
255
|
-
body: externalAdReply.body || "",
|
|
256
|
-
mediaType: externalAdReply.mediaType || 1,
|
|
257
|
-
thumbnailUrl: externalAdReply.thumbnailUrl || "",
|
|
258
|
-
mediaUrl: externalAdReply.mediaUrl || "",
|
|
259
|
-
sourceUrl: externalAdReply.sourceUrl || "",
|
|
260
|
-
showAdAttribution: externalAdReply.showAdAttribution || false,
|
|
261
|
-
renderLargerThumbnail: externalAdReply.renderLargerThumbnail || false,
|
|
262
|
-
...externalAdReply
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
if (Object.keys(finalContextInfo).length > 0) {
|
|
267
|
-
interactiveMessage.contextInfo = finalContextInfo;
|
|
228
|
+
if (Object.keys(finalContextInfo).length > 0) {
|
|
229
|
+
interactiveMessage.contextInfo = finalContextInfo;
|
|
230
|
+
}
|
|
231
|
+
return { interactiveMessage };
|
|
232
|
+
} catch (err) {
|
|
233
|
+
console.error("handleInteractive error:", err);
|
|
234
|
+
throw err;
|
|
268
235
|
}
|
|
269
|
-
return {
|
|
270
|
-
interactiveMessage: interactiveMessage
|
|
271
|
-
};
|
|
272
236
|
}
|
|
273
|
-
|
|
237
|
+
|
|
274
238
|
async handleAlbum(content, jid, quoted) {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
quoted,
|
|
287
|
-
upload: this.waUploadToServer
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
await this.relayMessage(jid, album.message, {
|
|
291
|
-
messageId: album.key.id,
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
for (let content of array) {
|
|
295
|
-
const img = await this.utils.generateWAMessage(jid, content, {
|
|
296
|
-
upload: this.waUploadToServer,
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
img.message.messageContextInfo = {
|
|
300
|
-
messageSecret: crypto.randomBytes(32),
|
|
301
|
-
messageAssociation: {
|
|
302
|
-
associationType: 1,
|
|
303
|
-
parentMessageKey: album.key,
|
|
304
|
-
},
|
|
305
|
-
participant: "0@s.whatsapp.net",
|
|
306
|
-
remoteJid: "status@broadcast",
|
|
307
|
-
forwardingScore: 99999,
|
|
308
|
-
isForwarded: true,
|
|
309
|
-
mentionedJid: [jid],
|
|
310
|
-
starred: true,
|
|
311
|
-
labels: ["Y", "Important"],
|
|
312
|
-
isHighlighted: true,
|
|
313
|
-
businessMessageForwardInfo: {
|
|
314
|
-
businessOwnerJid: jid,
|
|
315
|
-
},
|
|
316
|
-
dataSharingContext: {
|
|
317
|
-
showMmDisclosure: true,
|
|
239
|
+
try {
|
|
240
|
+
const array = Array.isArray(content.albumMessage) ? content.albumMessage : [];
|
|
241
|
+
if (array.length === 0) throw new Error("albumMessage harus berupa array dengan isi media");
|
|
242
|
+
const album = await this.utils.generateWAMessageFromContent(
|
|
243
|
+
jid,
|
|
244
|
+
{
|
|
245
|
+
messageContextInfo: { messageSecret: crypto.randomBytes(32) },
|
|
246
|
+
albumMessage: {
|
|
247
|
+
expectedImageCount: array.filter((a) => a.image).length,
|
|
248
|
+
expectedVideoCount: array.filter((a) => a.video).length
|
|
249
|
+
}
|
|
318
250
|
},
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
img.message.disappearingMode = {
|
|
334
|
-
initiator: 3,
|
|
335
|
-
trigger: 4,
|
|
336
|
-
initiatorDeviceJid: jid,
|
|
337
|
-
initiatedByExternalService: true,
|
|
338
|
-
initiatedByUserDevice: true,
|
|
339
|
-
initiatedBySystem: true,
|
|
340
|
-
initiatedByServer: true,
|
|
341
|
-
initiatedByAdmin: true,
|
|
342
|
-
initiatedByUser: true,
|
|
343
|
-
initiatedByApp: true,
|
|
344
|
-
initiatedByBot: true,
|
|
345
|
-
initiatedByMe: true,
|
|
346
|
-
};
|
|
347
|
-
|
|
348
|
-
await this.relayMessage(jid, img.message, {
|
|
349
|
-
messageId: img.key.id,
|
|
350
|
-
quoted: {
|
|
351
|
-
key: {
|
|
352
|
-
remoteJid: album.key.remoteJid,
|
|
353
|
-
id: album.key.id,
|
|
354
|
-
fromMe: true,
|
|
355
|
-
participant: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net',
|
|
251
|
+
{
|
|
252
|
+
userJid: this.utils.generateMessageID().split("@")[0] + "@s.whatsapp.net",
|
|
253
|
+
quoted,
|
|
254
|
+
upload: this.waUploadToServer
|
|
255
|
+
}
|
|
256
|
+
);
|
|
257
|
+
await this.relayMessage(jid, album.message, { messageId: album.key.id });
|
|
258
|
+
for (const item of array) {
|
|
259
|
+
const img = await this.utils.generateWAMessage(jid, item, { upload: this.waUploadToServer });
|
|
260
|
+
img.message.messageContextInfo = {
|
|
261
|
+
messageSecret: crypto.randomBytes(32),
|
|
262
|
+
messageAssociation: {
|
|
263
|
+
associationType: 1,
|
|
264
|
+
parentMessageKey: album.key
|
|
356
265
|
},
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
266
|
+
participant: "0@s.whatsapp.net",
|
|
267
|
+
remoteJid: "status@broadcast",
|
|
268
|
+
forwardingScore: 99999,
|
|
269
|
+
isForwarded: true,
|
|
270
|
+
mentionedJid: [jid],
|
|
271
|
+
starred: true,
|
|
272
|
+
labels: ["Y", "Important"],
|
|
273
|
+
isHighlighted: true,
|
|
274
|
+
businessMessageForwardInfo: { businessOwnerJid: jid },
|
|
275
|
+
dataSharingContext: { showMmDisclosure: true }
|
|
276
|
+
};
|
|
277
|
+
img.message.forwardedNewsletterMessageInfo = {
|
|
278
|
+
newsletterJid: "0@newsletter",
|
|
279
|
+
serverMessageId: 1,
|
|
280
|
+
newsletterName: "WhatsApp",
|
|
281
|
+
contentType: 1,
|
|
282
|
+
timestamp: new Date().toISOString(),
|
|
283
|
+
senderName: "kikyy dugonggg",
|
|
284
|
+
content: "Text Message",
|
|
285
|
+
priority: "high",
|
|
286
|
+
status: "sent"
|
|
287
|
+
};
|
|
288
|
+
img.message.disappearingMode = {
|
|
289
|
+
initiator: 3,
|
|
290
|
+
trigger: 4,
|
|
291
|
+
initiatorDeviceJid: jid,
|
|
292
|
+
initiatedByExternalService: true,
|
|
293
|
+
initiatedByUserDevice: true,
|
|
294
|
+
initiatedBySystem: true,
|
|
295
|
+
initiatedByServer: true,
|
|
296
|
+
initiatedByAdmin: true,
|
|
297
|
+
initiatedByUser: true,
|
|
298
|
+
initiatedByApp: true,
|
|
299
|
+
initiatedByBot: true,
|
|
300
|
+
initiatedByMe: true
|
|
301
|
+
};
|
|
302
|
+
await this.relayMessage(jid, img.message, {
|
|
303
|
+
messageId: img.key.id,
|
|
304
|
+
quoted: {
|
|
305
|
+
key: {
|
|
306
|
+
remoteJid: album.key.remoteJid,
|
|
307
|
+
id: album.key.id,
|
|
308
|
+
fromMe: true,
|
|
309
|
+
participant: this.utils.generateMessageID().split("@")[0] + "@s.whatsapp.net"
|
|
310
|
+
},
|
|
311
|
+
message: album.message
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
return album;
|
|
316
|
+
} catch (err) {
|
|
317
|
+
console.error("handleAlbum error:", err);
|
|
318
|
+
throw err;
|
|
360
319
|
}
|
|
361
|
-
|
|
362
|
-
}
|
|
320
|
+
}
|
|
363
321
|
|
|
364
322
|
async handleEvent(content, jid, quoted) {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
323
|
+
try {
|
|
324
|
+
const eventData = content.eventMessage;
|
|
325
|
+
if (!eventData) throw new Error("Missing eventMessage");
|
|
326
|
+
const msg = await this.utils.generateWAMessageFromContent(
|
|
327
|
+
jid,
|
|
328
|
+
{
|
|
329
|
+
viewOnceMessage: {
|
|
330
|
+
message: {
|
|
331
|
+
messageContextInfo: {
|
|
332
|
+
deviceListMetadata: {},
|
|
333
|
+
deviceListMetadataVersion: 2,
|
|
334
|
+
messageSecret: crypto.randomBytes(32),
|
|
335
|
+
supportPayload: JSON.stringify({
|
|
336
|
+
version: 2,
|
|
337
|
+
is_ai_message: true,
|
|
338
|
+
should_show_system_message: true,
|
|
339
|
+
ticket_id: crypto.randomBytes(16).toString("hex")
|
|
340
|
+
})
|
|
341
|
+
},
|
|
342
|
+
eventMessage: {
|
|
343
|
+
contextInfo: {
|
|
344
|
+
mentionedJid: [jid],
|
|
345
|
+
participant: jid,
|
|
346
|
+
remoteJid: "status@broadcast",
|
|
347
|
+
forwardedNewsletterMessageInfo: {
|
|
348
|
+
newsletterName: "shenvn.",
|
|
349
|
+
newsletterJid: "120363297591152843@newsletter",
|
|
350
|
+
serverMessageId: 1
|
|
351
|
+
}
|
|
352
|
+
},
|
|
353
|
+
isCanceled: eventData.isCanceled || false,
|
|
354
|
+
name: eventData.name,
|
|
355
|
+
description: eventData.description,
|
|
356
|
+
location: eventData.location || {
|
|
357
|
+
degreesLatitude: 0,
|
|
358
|
+
degreesLongitude: 0,
|
|
359
|
+
name: "Location"
|
|
360
|
+
},
|
|
361
|
+
joinLink: eventData.joinLink || "",
|
|
362
|
+
startTime: typeof eventData.startTime === "string" ? parseInt(eventData.startTime) : eventData.startTime || Date.now(),
|
|
363
|
+
endTime: typeof eventData.endTime === "string" ? parseInt(eventData.endTime) : eventData.endTime || Date.now() + 3600000,
|
|
364
|
+
extraGuestsAllowed: eventData.extraGuestsAllowed !== false
|
|
390
365
|
}
|
|
391
|
-
}
|
|
392
|
-
isCanceled: eventData.isCanceled || false,
|
|
393
|
-
name: eventData.name,
|
|
394
|
-
description: eventData.description,
|
|
395
|
-
location: eventData.location || {
|
|
396
|
-
degreesLatitude: 0,
|
|
397
|
-
degreesLongitude: 0,
|
|
398
|
-
name: "Location"
|
|
399
|
-
},
|
|
400
|
-
joinLink: eventData.joinLink || '',
|
|
401
|
-
startTime: typeof eventData.startTime === 'string' ? parseInt(eventData.startTime) : eventData.startTime || Date.now(),
|
|
402
|
-
endTime: typeof eventData.endTime === 'string' ? parseInt(eventData.endTime) : eventData.endTime || Date.now() + 3600000,
|
|
403
|
-
extraGuestsAllowed: eventData.extraGuestsAllowed !== false
|
|
366
|
+
}
|
|
404
367
|
}
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
368
|
+
},
|
|
369
|
+
{ quoted }
|
|
370
|
+
);
|
|
371
|
+
await this.relayMessage(jid, msg.message, { messageId: msg.key.id });
|
|
372
|
+
return msg;
|
|
373
|
+
} catch (err) {
|
|
374
|
+
console.error("handleEvent error:", err);
|
|
375
|
+
throw err;
|
|
376
|
+
}
|
|
413
377
|
}
|
|
414
|
-
|
|
415
|
-
async handlePollResult(content, jid, quoted) {
|
|
416
|
-
const pollData = content.pollResultMessage;
|
|
417
|
-
|
|
418
|
-
const msg = await this.utils.generateWAMessageFromContent(jid, {
|
|
419
|
-
pollResultSnapshotMessage: {
|
|
420
|
-
name: pollData.name,
|
|
421
|
-
pollVotes: pollData.pollVotes.map(vote => ({
|
|
422
|
-
optionName: vote.optionName,
|
|
423
|
-
optionVoteCount: typeof vote.optionVoteCount === 'number'
|
|
424
|
-
? vote.optionVoteCount.toString()
|
|
425
|
-
: vote.optionVoteCount
|
|
426
|
-
}))
|
|
427
|
-
}
|
|
428
|
-
}, {
|
|
429
|
-
userJid: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net',
|
|
430
|
-
quoted
|
|
431
|
-
});
|
|
432
|
-
|
|
433
|
-
await this.relayMessage(jid, msg.message, {
|
|
434
|
-
messageId: msg.key.id
|
|
435
|
-
});
|
|
436
378
|
|
|
437
|
-
|
|
379
|
+
async handlePollResult(content, jid, quoted) {
|
|
380
|
+
try {
|
|
381
|
+
const pollData = content.pollResultMessage;
|
|
382
|
+
if (!pollData) throw new Error("Missing pollResultMessage");
|
|
383
|
+
const msg = await this.utils.generateWAMessageFromContent(
|
|
384
|
+
jid,
|
|
385
|
+
{
|
|
386
|
+
pollResultSnapshotMessage: {
|
|
387
|
+
name: pollData.name,
|
|
388
|
+
pollVotes: (pollData.pollVotes || []).map((v) => ({
|
|
389
|
+
optionName: v.optionName,
|
|
390
|
+
optionVoteCount: typeof v.optionVoteCount === "number" ? v.optionVoteCount.toString() : v.optionVoteCount
|
|
391
|
+
}))
|
|
392
|
+
}
|
|
393
|
+
},
|
|
394
|
+
{
|
|
395
|
+
userJid: this.utils.generateMessageID().split("@")[0] + "@s.whatsapp.net",
|
|
396
|
+
quoted
|
|
397
|
+
}
|
|
398
|
+
);
|
|
399
|
+
await this.relayMessage(jid, msg.message, { messageId: msg.key.id });
|
|
400
|
+
return msg;
|
|
401
|
+
} catch (err) {
|
|
402
|
+
console.error("handlePollResult error:", err);
|
|
403
|
+
throw err;
|
|
404
|
+
}
|
|
438
405
|
}
|
|
439
406
|
|
|
440
407
|
async handleGroupStory(content, jid, quoted) {
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
if (typeof this.bail?.generateWAMessageContent === "function") {
|
|
408
|
+
try {
|
|
409
|
+
const storyData = content.groupStatusMessage;
|
|
410
|
+
if (!storyData) throw new Error("Missing groupStatusMessage");
|
|
411
|
+
let waMsgContent;
|
|
412
|
+
if (storyData.message) {
|
|
413
|
+
waMsgContent = storyData;
|
|
414
|
+
} else if (typeof this.bail?.generateWAMessageContent === "function") {
|
|
448
415
|
waMsgContent = await this.bail.generateWAMessageContent(storyData, {
|
|
449
416
|
upload: this.waUploadToServer
|
|
450
417
|
});
|
|
@@ -461,20 +428,21 @@ class hbmodofc {
|
|
|
461
428
|
upload: this.waUploadToServer
|
|
462
429
|
});
|
|
463
430
|
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
message: waMsgContent.message || waMsgContent
|
|
431
|
+
const msg = {
|
|
432
|
+
message: {
|
|
433
|
+
groupStatusMessageV2: {
|
|
434
|
+
message: waMsgContent.message || waMsgContent
|
|
435
|
+
}
|
|
470
436
|
}
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
437
|
+
};
|
|
438
|
+
return await this.relayMessage(jid, msg.message, {
|
|
439
|
+
messageId: this.bail.generateMessageID()
|
|
440
|
+
});
|
|
441
|
+
} catch (err) {
|
|
442
|
+
console.error("handleGroupStory error:", err);
|
|
443
|
+
throw err;
|
|
444
|
+
}
|
|
477
445
|
}
|
|
478
446
|
}
|
|
479
447
|
|
|
480
|
-
module.exports =
|
|
448
|
+
module.exports = hbmodsofc;
|