@vinzsocket/baileys 3.3.2 → 3.3.13
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 +21 -0
- package/README.md +1337 -2685
- package/WAProto/WAProto.proto +916 -360
- package/WAProto/fix-imports.js +18 -22
- package/WAProto/index.d.ts +0 -14015
- package/WAProto/index.js +80576 -45941
- package/lib/Defaults/index.d.ts +14 -15
- package/lib/Defaults/index.d.ts.map +1 -1
- package/lib/Defaults/index.js +109 -98
- package/lib/Defaults/index.js.map +1 -1
- package/lib/Signal/Group/group_cipher.js.map +1 -1
- package/lib/Signal/Group/keyhelper.d.ts.map +1 -1
- package/lib/Signal/Group/keyhelper.js.map +1 -1
- package/lib/Signal/Group/sender-chain-key.js.map +1 -1
- package/lib/Signal/Group/sender-key-message.js.map +1 -1
- package/lib/Signal/Group/sender-message-key.js.map +1 -1
- package/lib/Signal/libsignal.d.ts.map +1 -1
- package/lib/Signal/libsignal.js +17 -45
- package/lib/Signal/libsignal.js.map +1 -1
- package/lib/Signal/lid-mapping.d.ts +0 -4
- package/lib/Signal/lid-mapping.d.ts.map +1 -1
- package/lib/Signal/lid-mapping.js +0 -6
- package/lib/Signal/lid-mapping.js.map +1 -1
- package/lib/Socket/business.d.ts +532 -213
- package/lib/Socket/business.d.ts.map +1 -1
- package/lib/Socket/business.js +401 -358
- package/lib/Socket/chats.d.ts +2 -15
- package/lib/Socket/chats.d.ts.map +1 -1
- package/lib/Socket/chats.js +40 -247
- package/lib/Socket/chats.js.map +1 -1
- package/lib/Socket/communities.d.ts +641 -269
- package/lib/Socket/communities.d.ts.map +1 -1
- package/lib/Socket/dugong.d.ts +127 -315
- package/lib/Socket/dugong.d.ts.map +1 -0
- package/lib/Socket/dugong.js +749 -653
- package/lib/Socket/dugong.js.map +1 -0
- package/lib/Socket/groups.d.ts +2 -13
- package/lib/Socket/groups.d.ts.map +1 -1
- package/lib/Socket/groups.js +1 -21
- package/lib/Socket/groups.js.map +1 -1
- package/lib/Socket/index.d.ts +631 -256
- package/lib/Socket/index.d.ts.map +1 -1
- package/lib/Socket/index.js +12 -9
- package/lib/Socket/index.js.map +1 -1
- package/lib/Socket/messages-recv.d.ts +58 -23
- package/lib/Socket/messages-recv.d.ts.map +1 -1
- package/lib/Socket/messages-recv.js +181 -645
- package/lib/Socket/messages-recv.js.map +1 -1
- package/lib/Socket/messages-send.d.ts +575 -201
- package/lib/Socket/messages-send.d.ts.map +1 -1
- package/lib/Socket/messages-send.js +1552 -1185
- package/lib/Socket/messages-send.js.map +1 -1
- package/lib/Socket/mex.d.ts.map +1 -1
- package/lib/Socket/mex.js +8 -2
- package/lib/Socket/mex.js.map +1 -1
- package/lib/Socket/newsletter.d.ts +18 -11
- package/lib/Socket/newsletter.d.ts.map +1 -1
- package/lib/Socket/newsletter.js +440 -165
- package/lib/Socket/newsletter.js.map +1 -1
- package/lib/Socket/socket.d.ts +2 -6
- package/lib/Socket/socket.d.ts.map +1 -1
- package/lib/Socket/socket.js +25 -59
- package/lib/Socket/socket.js.map +1 -1
- package/lib/Types/Auth.d.ts +0 -1
- package/lib/Types/Auth.d.ts.map +1 -1
- package/lib/Types/Bussines.d.ts +34 -22
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Call.d.ts.map +1 -1
- package/lib/Types/Chat.d.ts +0 -1
- package/lib/Types/Chat.d.ts.map +1 -1
- package/lib/Types/Contact.d.ts +0 -2
- package/lib/Types/Contact.d.ts.map +1 -1
- package/lib/Types/Events.d.ts +1 -20
- package/lib/Types/Events.d.ts.map +1 -1
- package/lib/Types/GroupMetadata.d.ts +1 -4
- package/lib/Types/GroupMetadata.d.ts.map +1 -1
- package/lib/Types/Message.d.ts +348 -294
- package/lib/Types/Message.d.ts.map +1 -1
- package/lib/Types/Message.js.map +1 -1
- package/lib/Types/Newsletter.d.ts.map +1 -0
- package/lib/Types/Newsletter.js.map +1 -0
- package/lib/Types/Signal.d.ts +1 -12
- package/lib/Types/Signal.d.ts.map +1 -1
- package/lib/Types/Socket.d.ts +148 -126
- package/lib/Types/Socket.d.ts.map +1 -1
- package/lib/Types/State.d.ts +0 -58
- package/lib/Types/State.d.ts.map +1 -1
- package/lib/Types/State.js +0 -43
- package/lib/Types/State.js.map +1 -1
- package/lib/Types/index.d.ts +52 -52
- package/lib/Types/index.d.ts.map +1 -1
- package/lib/Types/index.js +30 -23
- package/lib/Types/index.js.map +1 -1
- package/lib/Utils/auth-utils.d.ts +0 -5
- package/lib/Utils/auth-utils.d.ts.map +1 -1
- package/lib/Utils/auth-utils.js +0 -12
- package/lib/Utils/auth-utils.js.map +1 -1
- package/lib/Utils/browser-utils.js +0 -1
- package/lib/Utils/chat-utils.d.ts +4 -34
- package/lib/Utils/chat-utils.d.ts.map +1 -1
- package/lib/Utils/chat-utils.js +20 -80
- package/lib/Utils/chat-utils.js.map +1 -1
- package/lib/Utils/crypto.d.ts +12 -12
- package/lib/Utils/crypto.d.ts.map +1 -1
- package/lib/Utils/crypto.js.map +1 -1
- package/lib/Utils/decode-wa-message.d.ts +0 -18
- package/lib/Utils/decode-wa-message.d.ts.map +1 -1
- package/lib/Utils/decode-wa-message.js +0 -34
- package/lib/Utils/decode-wa-message.js.map +1 -1
- package/lib/Utils/event-buffer.d.ts +0 -2
- package/lib/Utils/event-buffer.d.ts.map +1 -1
- package/lib/Utils/event-buffer.js +1 -49
- package/lib/Utils/event-buffer.js.map +1 -1
- package/lib/Utils/generics.d.ts +2 -2
- package/lib/Utils/generics.d.ts.map +1 -1
- package/lib/Utils/generics.js +1 -10
- package/lib/Utils/generics.js.map +1 -1
- package/lib/Utils/history.d.ts +0 -2
- package/lib/Utils/history.d.ts.map +1 -1
- package/lib/Utils/history.js +9 -12
- package/lib/Utils/history.js.map +1 -1
- package/lib/Utils/identity-change-handler.d.ts +0 -7
- package/lib/Utils/identity-change-handler.d.ts.map +1 -1
- package/lib/Utils/identity-change-handler.js +0 -1
- package/lib/Utils/identity-change-handler.js.map +1 -1
- package/lib/Utils/index.d.ts +23 -23
- package/lib/Utils/index.d.ts.map +1 -1
- package/lib/Utils/index.js +1 -4
- package/lib/Utils/index.js.map +1 -1
- package/lib/Utils/link-preview.js +2 -2
- package/lib/Utils/link-preview.js.map +1 -1
- package/lib/Utils/logger.d.ts +2 -1
- package/lib/Utils/logger.d.ts.map +1 -1
- package/lib/Utils/message-retry-manager.d.ts +0 -5
- package/lib/Utils/message-retry-manager.d.ts.map +1 -1
- package/lib/Utils/message-retry-manager.js +0 -40
- package/lib/Utils/message-retry-manager.js.map +1 -1
- package/lib/Utils/messages-media.d.ts +13 -16
- package/lib/Utils/messages-media.d.ts.map +1 -1
- package/lib/Utils/messages-media.js +79 -85
- package/lib/Utils/messages-media.js.map +1 -1
- package/lib/Utils/messages.d.ts +6 -16
- package/lib/Utils/messages.d.ts.map +1 -1
- package/lib/Utils/messages.js +1160 -1021
- package/lib/Utils/messages.js.map +1 -1
- package/lib/Utils/noise-handler.d.ts +1 -1
- package/lib/Utils/process-message.d.ts.map +1 -1
- package/lib/Utils/process-message.js +1 -103
- package/lib/Utils/process-message.js.map +1 -1
- package/lib/Utils/rich-messages.d.ts.map +1 -0
- package/lib/Utils/rich-messages.js.map +1 -0
- package/lib/Utils/signal.d.ts +0 -13
- package/lib/Utils/signal.d.ts.map +1 -1
- package/lib/Utils/signal.js +0 -42
- package/lib/Utils/signal.js.map +1 -1
- package/lib/Utils/sync-action-utils.d.ts.map +1 -1
- package/lib/Utils/sync-action-utils.js +0 -1
- package/lib/Utils/sync-action-utils.js.map +1 -1
- package/lib/Utils/tc-token-utils.d.ts +1 -26
- package/lib/Utils/tc-token-utils.d.ts.map +1 -1
- package/lib/Utils/tc-token-utils.js +5 -151
- package/lib/Utils/tc-token-utils.js.map +1 -1
- package/lib/Utils/validate-connection.d.ts.map +1 -1
- package/lib/Utils/validate-connection.js +2 -12
- package/lib/Utils/validate-connection.js.map +1 -1
- package/lib/VoIP/audio-feeder.js +8 -0
- package/lib/VoIP/relay-transport.js +15 -1
- package/lib/VoIP/worker-bootstrap.js +14 -2
- package/lib/WABinary/decode.d.ts +1 -1
- package/lib/WABinary/decode.d.ts.map +1 -1
- package/lib/WABinary/generic-utils.d.ts +3 -1
- package/lib/WABinary/generic-utils.d.ts.map +1 -1
- package/lib/WABinary/generic-utils.js +78 -0
- package/lib/WABinary/generic-utils.js.map +1 -1
- package/lib/WAM/encode.d.ts +1 -1
- package/lib/WAM/encode.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +3 -26
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -1
- package/lib/WAUSync/Protocols/index.d.ts +0 -1
- package/lib/WAUSync/Protocols/index.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/index.js +0 -1
- package/lib/WAUSync/Protocols/index.js.map +1 -1
- package/lib/WAUSync/USyncQuery.d.ts +0 -1
- package/lib/WAUSync/USyncQuery.d.ts.map +1 -1
- package/lib/WAUSync/USyncQuery.js +2 -6
- package/lib/WAUSync/USyncQuery.js.map +1 -1
- package/lib/WAUSync/USyncUser.d.ts +0 -4
- package/lib/WAUSync/USyncUser.d.ts.map +1 -1
- package/lib/WAUSync/USyncUser.js +0 -8
- package/lib/WAUSync/USyncUser.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/package.json +24 -91
- package/engine-requirements.js +0 -27
- package/lib/Types/Mex.d.ts +0 -141
- package/lib/Types/Mex.d.ts.map +0 -1
- package/lib/Types/Mex.js +0 -37
- package/lib/Types/Mex.js.map +0 -1
- package/lib/Utils/companion-reg-client-utils.d.ts +0 -17
- package/lib/Utils/companion-reg-client-utils.d.ts.map +0 -1
- package/lib/Utils/companion-reg-client-utils.js +0 -35
- package/lib/Utils/companion-reg-client-utils.js.map +0 -1
- package/lib/Utils/mention.d.ts +0 -14
- package/lib/Utils/mention.js +0 -138
- package/lib/Utils/story-card.js +0 -107
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +0 -25
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +0 -1
package/lib/Socket/dugong.js
CHANGED
|
@@ -1,672 +1,768 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
|
|
1
|
+
import crypto from "crypto";
|
|
2
|
+
import { proto } from "../../WAProto/index.js";
|
|
3
|
+
import {
|
|
4
|
+
delay,
|
|
5
|
+
generateMessageID,
|
|
6
|
+
generateWAMessage,
|
|
7
|
+
generateWAMessageContent,
|
|
8
|
+
generateWAMessageFromContent,
|
|
9
|
+
getUrlFromDirectPath,
|
|
10
|
+
normalizeMessageContent,
|
|
11
|
+
prepareWAMessageMedia,
|
|
12
|
+
} from "../Utils/index.js";
|
|
13
|
+
import {
|
|
14
|
+
isJidGroup,
|
|
15
|
+
isPnUser,
|
|
16
|
+
jidNormalizedUser,
|
|
17
|
+
STORIES_JID,
|
|
18
|
+
} from "../WABinary/index.js";
|
|
19
|
+
export class Dugong {
|
|
20
|
+
constructor(waUploadToServer, relayMessageFn, config, sock) {
|
|
21
|
+
this.relayMessage = relayMessageFn;
|
|
22
|
+
this.waUploadToServer = waUploadToServer;
|
|
23
|
+
this.config = config;
|
|
24
|
+
this.sock = sock;
|
|
25
|
+
}
|
|
26
|
+
detectType(content) {
|
|
27
|
+
if (content.requestPaymentMessage) return "PAYMENT";
|
|
28
|
+
if (content.productMessage) return "PRODUCT";
|
|
29
|
+
if (content.interactiveButtons) return "INTERACTIVE_BUTTONS";
|
|
30
|
+
if (content.interactiveMessage?.carouselMessage) return "CAROUSEL";
|
|
31
|
+
if (content.interactiveMessage) return "INTERACTIVE";
|
|
32
|
+
if (content.albumMessage || content.album) return "ALBUM";
|
|
33
|
+
if (content.eventMessage) return "EVENT";
|
|
34
|
+
if (content.pollResultMessage) return "POLL_RESULT";
|
|
35
|
+
if (content.groupStatusMessage) return "GROUP_STORY";
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
async handlePayment(content, quoted) {
|
|
39
|
+
const data = content.requestPaymentMessage;
|
|
40
|
+
let notes = {};
|
|
41
|
+
if (data.sticker?.stickerMessage) {
|
|
42
|
+
notes = {
|
|
43
|
+
stickerMessage: {
|
|
44
|
+
...data.sticker.stickerMessage,
|
|
45
|
+
contextInfo: {
|
|
46
|
+
stanzaId: quoted?.key?.id,
|
|
47
|
+
participant: quoted?.key?.participant || content.sender,
|
|
48
|
+
quotedMessage: quoted?.message,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
} else if (data.note) {
|
|
53
|
+
notes = {
|
|
54
|
+
extendedTextMessage: {
|
|
55
|
+
text: data.note,
|
|
56
|
+
contextInfo: {
|
|
57
|
+
stanzaId: quoted?.key?.id,
|
|
58
|
+
participant: quoted?.key?.participant || content.sender,
|
|
59
|
+
quotedMessage: quoted?.message,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
requestPaymentMessage: proto.Message.RequestPaymentMessage.fromObject({
|
|
66
|
+
expiryTimestamp: data.expiry || 0,
|
|
67
|
+
amount1000: data.amount || 0,
|
|
68
|
+
currencyCodeIso4217: data.currency || "IDR",
|
|
69
|
+
requestFrom: data.from || "0@s.whatsapp.net",
|
|
70
|
+
noteMessage: notes,
|
|
71
|
+
background: data.background ?? {
|
|
72
|
+
id: "DEFAULT",
|
|
73
|
+
placeholderArgb: 0xfff0f0f0,
|
|
74
|
+
},
|
|
75
|
+
}),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
async handleProduct(content, _jid, _quoted) {
|
|
79
|
+
const {
|
|
80
|
+
title,
|
|
81
|
+
description,
|
|
82
|
+
thumbnail,
|
|
83
|
+
productId,
|
|
84
|
+
retailerId,
|
|
85
|
+
url,
|
|
86
|
+
body = "",
|
|
87
|
+
footer = "",
|
|
88
|
+
buttons = [],
|
|
89
|
+
priceAmount1000 = null,
|
|
90
|
+
currencyCode = "IDR",
|
|
91
|
+
} = content.productMessage;
|
|
92
|
+
let productImage;
|
|
93
|
+
if (Buffer.isBuffer(thumbnail)) {
|
|
94
|
+
const { imageMessage } = await generateWAMessageContent(
|
|
95
|
+
{ image: thumbnail },
|
|
96
|
+
{ upload: this.waUploadToServer },
|
|
97
|
+
);
|
|
98
|
+
productImage = imageMessage;
|
|
99
|
+
} else if (typeof thumbnail === "object" && thumbnail.url) {
|
|
100
|
+
const { imageMessage } = await generateWAMessageContent(
|
|
101
|
+
{ image: { url: thumbnail.url } },
|
|
102
|
+
{ upload: this.waUploadToServer },
|
|
103
|
+
);
|
|
104
|
+
productImage = imageMessage;
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
viewOnceMessage: {
|
|
108
|
+
message: {
|
|
109
|
+
interactiveMessage: {
|
|
110
|
+
body: { text: body },
|
|
111
|
+
footer: { text: footer },
|
|
112
|
+
header: {
|
|
113
|
+
title,
|
|
114
|
+
hasMediaAttachment: true,
|
|
115
|
+
productMessage: {
|
|
116
|
+
product: {
|
|
117
|
+
productImage,
|
|
118
|
+
productId,
|
|
119
|
+
title,
|
|
120
|
+
description,
|
|
121
|
+
currencyCode,
|
|
122
|
+
priceAmount1000,
|
|
123
|
+
retailerId,
|
|
124
|
+
url,
|
|
125
|
+
productImageCount: 1,
|
|
126
|
+
},
|
|
127
|
+
businessOwnerJid: "0@s.whatsapp.net",
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
nativeFlowMessage: { buttons },
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
async handleInteractive(content, _jid, _quoted) {
|
|
137
|
+
const {
|
|
138
|
+
title,
|
|
139
|
+
footer,
|
|
140
|
+
thumbnail,
|
|
141
|
+
image,
|
|
142
|
+
video,
|
|
143
|
+
document,
|
|
144
|
+
mimetype,
|
|
145
|
+
fileName,
|
|
146
|
+
jpegThumbnail,
|
|
147
|
+
contextInfo,
|
|
148
|
+
externalAdReply,
|
|
149
|
+
buttons = [],
|
|
150
|
+
nativeFlowMessage,
|
|
151
|
+
header,
|
|
152
|
+
} = content.interactiveMessage;
|
|
153
|
+
let media = null;
|
|
154
|
+
let _mediaType = null;
|
|
155
|
+
if (thumbnail) {
|
|
156
|
+
media = await prepareWAMessageMedia(
|
|
157
|
+
{ image: { url: thumbnail } },
|
|
158
|
+
{ upload: this.waUploadToServer },
|
|
159
|
+
);
|
|
160
|
+
_mediaType = "image";
|
|
161
|
+
} else if (image) {
|
|
162
|
+
const src =
|
|
163
|
+
typeof image === "object" && image.url
|
|
164
|
+
? { image: { url: image.url } }
|
|
165
|
+
: { image };
|
|
166
|
+
media = await prepareWAMessageMedia(src, {
|
|
167
|
+
upload: this.waUploadToServer,
|
|
168
|
+
});
|
|
169
|
+
_mediaType = "image";
|
|
170
|
+
} else if (video) {
|
|
171
|
+
const src =
|
|
172
|
+
typeof video === "object" && video.url
|
|
173
|
+
? { video: { url: video.url } }
|
|
174
|
+
: { video };
|
|
175
|
+
media = await prepareWAMessageMedia(src, {
|
|
176
|
+
upload: this.waUploadToServer,
|
|
177
|
+
});
|
|
178
|
+
_mediaType = "video";
|
|
179
|
+
} else if (document) {
|
|
180
|
+
const docPayload = { document };
|
|
181
|
+
if (jpegThumbnail) {
|
|
182
|
+
docPayload.jpegThumbnail =
|
|
183
|
+
typeof jpegThumbnail === "object" && jpegThumbnail.url
|
|
184
|
+
? { url: jpegThumbnail.url }
|
|
185
|
+
: jpegThumbnail;
|
|
186
|
+
}
|
|
187
|
+
media = await prepareWAMessageMedia(docPayload, {
|
|
188
|
+
upload: this.waUploadToServer,
|
|
189
|
+
});
|
|
190
|
+
if (fileName) media.documentMessage.fileName = fileName;
|
|
191
|
+
if (mimetype) media.documentMessage.mimetype = mimetype;
|
|
192
|
+
_mediaType = "document";
|
|
130
193
|
}
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
this.bail = {
|
|
142
|
-
generateWAMessageContent: this.utils.generateWAMessageContent,
|
|
143
|
-
generateMessageID: this.utils.generateMessageID,
|
|
144
|
-
getContentType: (msg) => Object.keys(msg.message || {})[0]
|
|
194
|
+
const interactiveMessage = {
|
|
195
|
+
body: { text: title || "" },
|
|
196
|
+
footer: { text: footer || "" },
|
|
197
|
+
};
|
|
198
|
+
if (buttons && buttons.length > 0) {
|
|
199
|
+
interactiveMessage.nativeFlowMessage = { buttons };
|
|
200
|
+
if (nativeFlowMessage) {
|
|
201
|
+
interactiveMessage.nativeFlowMessage = {
|
|
202
|
+
...interactiveMessage.nativeFlowMessage,
|
|
203
|
+
...nativeFlowMessage,
|
|
145
204
|
};
|
|
205
|
+
}
|
|
206
|
+
} else if (nativeFlowMessage) {
|
|
207
|
+
interactiveMessage.nativeFlowMessage = nativeFlowMessage;
|
|
208
|
+
}
|
|
209
|
+
if (media) {
|
|
210
|
+
interactiveMessage.header = {
|
|
211
|
+
title: header || "",
|
|
212
|
+
hasMediaAttachment: true,
|
|
213
|
+
...media,
|
|
214
|
+
};
|
|
215
|
+
} else {
|
|
216
|
+
interactiveMessage.header = {
|
|
217
|
+
title: header || "",
|
|
218
|
+
hasMediaAttachment: false,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
const finalContextInfo = {};
|
|
222
|
+
if (contextInfo) {
|
|
223
|
+
Object.assign(finalContextInfo, {
|
|
224
|
+
mentionedJid: contextInfo.mentionedJid || [],
|
|
225
|
+
forwardingScore: contextInfo.forwardingScore || 0,
|
|
226
|
+
isForwarded: contextInfo.isForwarded || false,
|
|
227
|
+
...contextInfo,
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
if (externalAdReply) {
|
|
231
|
+
finalContextInfo.externalAdReply = {
|
|
232
|
+
title: externalAdReply.title || "",
|
|
233
|
+
body: externalAdReply.body || "",
|
|
234
|
+
mediaType: externalAdReply.mediaType || 1,
|
|
235
|
+
thumbnailUrl: externalAdReply.thumbnailUrl || "",
|
|
236
|
+
mediaUrl: externalAdReply.mediaUrl || "",
|
|
237
|
+
sourceUrl: externalAdReply.sourceUrl || "",
|
|
238
|
+
showAdAttribution: externalAdReply.showAdAttribution || false,
|
|
239
|
+
renderLargerThumbnail: externalAdReply.renderLargerThumbnail || false,
|
|
240
|
+
...externalAdReply,
|
|
241
|
+
};
|
|
146
242
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
if (content.requestPaymentMessage) return 'PAYMENT';
|
|
150
|
-
if (content.productMessage) return 'PRODUCT';
|
|
151
|
-
if (content.interactiveMessage) return 'INTERACTIVE';
|
|
152
|
-
if (content.albumMessage) return 'ALBUM';
|
|
153
|
-
if (content.eventMessage) return 'EVENT';
|
|
154
|
-
if (content.pollResultMessage) return 'POLL_RESULT';
|
|
155
|
-
if (content.groupStatusMessage) return 'GROUP_STORY';
|
|
156
|
-
if (content.nestedListMessage) return 'NESTED_LIST';
|
|
157
|
-
if (content.multiSelectMessage) return 'MULTI_SELECT';
|
|
158
|
-
return null;
|
|
243
|
+
if (Object.keys(finalContextInfo).length > 0) {
|
|
244
|
+
interactiveMessage.contextInfo = finalContextInfo;
|
|
159
245
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
246
|
+
return { interactiveMessage };
|
|
247
|
+
}
|
|
248
|
+
async handleInteractiveButtons(content, _jid, _quoted) {
|
|
249
|
+
const {
|
|
250
|
+
text,
|
|
251
|
+
caption,
|
|
252
|
+
title,
|
|
253
|
+
subtitle,
|
|
254
|
+
footer,
|
|
255
|
+
interactiveButtons,
|
|
256
|
+
hasMediaAttachment,
|
|
257
|
+
image,
|
|
258
|
+
video,
|
|
259
|
+
document,
|
|
260
|
+
mimetype,
|
|
261
|
+
jpegThumbnail,
|
|
262
|
+
location,
|
|
263
|
+
product,
|
|
264
|
+
businessOwnerJid,
|
|
265
|
+
} = content;
|
|
266
|
+
const bodyText = text || caption || "";
|
|
267
|
+
const buttons = interactiveButtons.map((btn) => ({
|
|
268
|
+
name: btn.name,
|
|
269
|
+
buttonParamsJson:
|
|
270
|
+
typeof btn.buttonParamsJson === "string"
|
|
271
|
+
? btn.buttonParamsJson
|
|
272
|
+
: JSON.stringify(btn.buttonParamsJson),
|
|
273
|
+
}));
|
|
274
|
+
let headerContent = {};
|
|
275
|
+
let mediaAttached =
|
|
276
|
+
typeof hasMediaAttachment === "boolean" ? hasMediaAttachment : false;
|
|
277
|
+
if (image) {
|
|
278
|
+
const src =
|
|
279
|
+
typeof image === "object" && image.url
|
|
280
|
+
? { image: { url: image.url } }
|
|
281
|
+
: { image };
|
|
282
|
+
const uploaded = await prepareWAMessageMedia(src, {
|
|
283
|
+
upload: this.waUploadToServer,
|
|
284
|
+
});
|
|
285
|
+
headerContent = { ...uploaded };
|
|
286
|
+
mediaAttached =
|
|
287
|
+
typeof hasMediaAttachment === "boolean" ? hasMediaAttachment : true;
|
|
288
|
+
} else if (video) {
|
|
289
|
+
const src =
|
|
290
|
+
typeof video === "object" && video.url
|
|
291
|
+
? { video: { url: video.url } }
|
|
292
|
+
: { video };
|
|
293
|
+
const uploaded = await prepareWAMessageMedia(src, {
|
|
294
|
+
upload: this.waUploadToServer,
|
|
295
|
+
});
|
|
296
|
+
headerContent = { ...uploaded };
|
|
297
|
+
mediaAttached =
|
|
298
|
+
typeof hasMediaAttachment === "boolean" ? hasMediaAttachment : true;
|
|
299
|
+
} else if (document) {
|
|
300
|
+
const docPayload =
|
|
301
|
+
typeof document === "object" && document.url
|
|
302
|
+
? { document: { url: document.url } }
|
|
303
|
+
: { document };
|
|
304
|
+
if (mimetype) docPayload.mimetype = mimetype;
|
|
305
|
+
const uploaded = await prepareWAMessageMedia(docPayload, {
|
|
306
|
+
upload: this.waUploadToServer,
|
|
307
|
+
});
|
|
308
|
+
if (jpegThumbnail) {
|
|
309
|
+
uploaded.documentMessage.jpegThumbnail =
|
|
310
|
+
typeof jpegThumbnail === "string"
|
|
311
|
+
? Buffer.from(jpegThumbnail, "base64")
|
|
312
|
+
: jpegThumbnail;
|
|
313
|
+
}
|
|
314
|
+
headerContent = { ...uploaded };
|
|
315
|
+
mediaAttached =
|
|
316
|
+
typeof hasMediaAttachment === "boolean" ? hasMediaAttachment : true;
|
|
317
|
+
} else if (location) {
|
|
318
|
+
headerContent = {
|
|
319
|
+
locationMessage: {
|
|
320
|
+
degreesLatitude:
|
|
321
|
+
location.degressLatitude || location.degreesLatitude || 0,
|
|
322
|
+
degreesLongitude:
|
|
323
|
+
location.degressLongitude || location.degreesLongitude || 0,
|
|
324
|
+
name: location.name || "",
|
|
325
|
+
},
|
|
326
|
+
};
|
|
327
|
+
mediaAttached =
|
|
328
|
+
typeof hasMediaAttachment === "boolean" ? hasMediaAttachment : true;
|
|
329
|
+
} else if (product) {
|
|
330
|
+
let productImage;
|
|
331
|
+
if (product.productImage) {
|
|
332
|
+
const imgSrc =
|
|
333
|
+
typeof product.productImage === "object" && product.productImage.url
|
|
334
|
+
? { image: { url: product.productImage.url } }
|
|
335
|
+
: { image: product.productImage };
|
|
336
|
+
const uploaded = await prepareWAMessageMedia(imgSrc, {
|
|
337
|
+
upload: this.waUploadToServer,
|
|
338
|
+
});
|
|
339
|
+
productImage = uploaded.imageMessage;
|
|
340
|
+
}
|
|
341
|
+
headerContent = {
|
|
342
|
+
productMessage: {
|
|
343
|
+
product: {
|
|
344
|
+
productImage,
|
|
345
|
+
productId: product.productId,
|
|
346
|
+
title: product.title,
|
|
347
|
+
description: product.description,
|
|
348
|
+
currencyCode: product.currencyCode || "IDR",
|
|
349
|
+
priceAmount1000: product.priceAmount1000,
|
|
350
|
+
retailerId: product.retailerId,
|
|
351
|
+
url: product.url,
|
|
352
|
+
productImageCount: product.productImageCount || 1,
|
|
353
|
+
},
|
|
354
|
+
businessOwnerJid: businessOwnerJid || "0@s.whatsapp.net",
|
|
355
|
+
},
|
|
356
|
+
};
|
|
357
|
+
mediaAttached =
|
|
358
|
+
typeof hasMediaAttachment === "boolean" ? hasMediaAttachment : true;
|
|
359
|
+
}
|
|
360
|
+
const interactiveMessage = {
|
|
361
|
+
body: { text: bodyText },
|
|
362
|
+
footer: { text: footer || "" },
|
|
363
|
+
header: {
|
|
364
|
+
title: title || "",
|
|
365
|
+
subtitle: subtitle || "",
|
|
366
|
+
hasMediaAttachment: mediaAttached,
|
|
367
|
+
...headerContent,
|
|
368
|
+
},
|
|
369
|
+
nativeFlowMessage: { buttons },
|
|
370
|
+
};
|
|
371
|
+
return {
|
|
372
|
+
viewOnceMessage: {
|
|
373
|
+
message: {
|
|
374
|
+
messageContextInfo: {
|
|
375
|
+
deviceListMetadata: {},
|
|
376
|
+
deviceListMetadataVersion: 2,
|
|
377
|
+
messageSecret: crypto.randomBytes(32),
|
|
378
|
+
},
|
|
379
|
+
interactiveMessage,
|
|
380
|
+
},
|
|
381
|
+
},
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
async handleCarousel(content, _jid, _quoted) {
|
|
385
|
+
const { interactiveMessage } = content;
|
|
386
|
+
const { body, footer, header, carouselMessage, contextInfo } =
|
|
387
|
+
interactiveMessage;
|
|
388
|
+
const processedCards = [];
|
|
389
|
+
for (const card of carouselMessage.cards) {
|
|
390
|
+
const cardMsg = {
|
|
391
|
+
body: card.body || { text: "" },
|
|
392
|
+
footer: card.footer || { text: "" },
|
|
393
|
+
header: {
|
|
394
|
+
title: card.header?.title || "",
|
|
395
|
+
hasMediaAttachment: false,
|
|
396
|
+
},
|
|
397
|
+
};
|
|
398
|
+
if (card.nativeFlowMessage) {
|
|
399
|
+
cardMsg.nativeFlowMessage = card.nativeFlowMessage;
|
|
400
|
+
}
|
|
401
|
+
if (
|
|
402
|
+
card.header?.imageMessage ||
|
|
403
|
+
card.header?.videoMessage ||
|
|
404
|
+
card.header?.documentMessage
|
|
405
|
+
) {
|
|
406
|
+
let headerContent = {};
|
|
407
|
+
let mediaAttached = true;
|
|
408
|
+
if (card.header.imageMessage) {
|
|
409
|
+
const url = card.header.imageMessage.url || card.header.imageMessage;
|
|
410
|
+
const src =
|
|
411
|
+
typeof url === "string" ? { image: { url } } : { image: url };
|
|
412
|
+
const uploaded = await prepareWAMessageMedia(src, {
|
|
413
|
+
upload: this.waUploadToServer,
|
|
414
|
+
});
|
|
415
|
+
headerContent = { ...uploaded };
|
|
416
|
+
} else if (card.header.videoMessage) {
|
|
417
|
+
const url = card.header.videoMessage.url || card.header.videoMessage;
|
|
418
|
+
const src =
|
|
419
|
+
typeof url === "string" ? { video: { url } } : { video: url };
|
|
420
|
+
const uploaded = await prepareWAMessageMedia(src, {
|
|
421
|
+
upload: this.waUploadToServer,
|
|
422
|
+
});
|
|
423
|
+
headerContent = { ...uploaded };
|
|
424
|
+
} else if (card.header.documentMessage) {
|
|
425
|
+
const url =
|
|
426
|
+
card.header.documentMessage.url || card.header.documentMessage;
|
|
427
|
+
const src =
|
|
428
|
+
typeof url === "string" ? { document: { url } } : { document: url };
|
|
429
|
+
const uploaded = await prepareWAMessageMedia(src, {
|
|
430
|
+
upload: this.waUploadToServer,
|
|
431
|
+
});
|
|
432
|
+
headerContent = { ...uploaded };
|
|
168
433
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
noteMessage: notes, background: data.background ?? { id: 'DEFAULT', placeholderArgb: 0xFFF0F0F0 }
|
|
174
|
-
})
|
|
434
|
+
cardMsg.header = {
|
|
435
|
+
title: card.header?.title || "",
|
|
436
|
+
hasMediaAttachment: mediaAttached,
|
|
437
|
+
...headerContent,
|
|
175
438
|
};
|
|
439
|
+
}
|
|
440
|
+
processedCards.push(cardMsg);
|
|
176
441
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
442
|
+
const interactiveMsg = {
|
|
443
|
+
body: body || { text: "" },
|
|
444
|
+
footer: footer || { text: "" },
|
|
445
|
+
header: header || { title: "", hasMediaAttachment: false },
|
|
446
|
+
carouselMessage: {
|
|
447
|
+
cards: processedCards,
|
|
448
|
+
messageVersion: carouselMessage.messageVersion || 1,
|
|
449
|
+
carouselCardType: carouselMessage.carouselCardType ?? 1,
|
|
450
|
+
},
|
|
451
|
+
};
|
|
452
|
+
if (contextInfo) {
|
|
453
|
+
interactiveMsg.contextInfo = contextInfo;
|
|
189
454
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
455
|
+
return {
|
|
456
|
+
viewOnceMessage: {
|
|
457
|
+
message: {
|
|
458
|
+
messageContextInfo: {
|
|
459
|
+
deviceListMetadata: {},
|
|
460
|
+
deviceListMetadataVersion: 2,
|
|
461
|
+
messageSecret: crypto.randomBytes(32),
|
|
462
|
+
},
|
|
463
|
+
interactiveMessage: interactiveMsg,
|
|
464
|
+
},
|
|
465
|
+
},
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
async handleAlbum(content, jid, quoted) {
|
|
469
|
+
const array = content.albumMessage || content.album;
|
|
470
|
+
const ctxInfo = content.contextInfo || {};
|
|
471
|
+
const album = await generateWAMessageFromContent(
|
|
472
|
+
jid,
|
|
473
|
+
{
|
|
474
|
+
messageContextInfo: {
|
|
475
|
+
messageSecret: crypto.randomBytes(32),
|
|
476
|
+
},
|
|
477
|
+
albumMessage: {
|
|
478
|
+
expectedImageCount: array.filter((a) => "image" in a).length,
|
|
479
|
+
expectedVideoCount: array.filter((a) => "video" in a).length,
|
|
480
|
+
},
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
userJid: jidNormalizedUser(this.sock.authState?.creds?.me?.id || ""),
|
|
484
|
+
quoted,
|
|
485
|
+
upload: this.waUploadToServer,
|
|
486
|
+
},
|
|
487
|
+
);
|
|
488
|
+
await this.relayMessage(jid, album.message, {
|
|
489
|
+
messageId: album.key.id,
|
|
490
|
+
});
|
|
491
|
+
for (let item of array) {
|
|
492
|
+
if (ctxInfo && Object.keys(ctxInfo).length > 0 && !item.contextInfo) {
|
|
493
|
+
item = { ...item, contextInfo: ctxInfo };
|
|
494
|
+
}
|
|
495
|
+
const img = await generateWAMessage(jid, item, {
|
|
496
|
+
upload: this.waUploadToServer,
|
|
497
|
+
userJid: jidNormalizedUser(this.sock.authState?.creds?.me?.id || ""),
|
|
498
|
+
});
|
|
499
|
+
img.message.messageContextInfo = {
|
|
500
|
+
messageSecret: crypto.randomBytes(32),
|
|
501
|
+
messageAssociation: {
|
|
502
|
+
associationType: 1,
|
|
503
|
+
parentMessageKey: album.key,
|
|
504
|
+
},
|
|
505
|
+
};
|
|
506
|
+
await this.relayMessage(jid, img.message, {
|
|
507
|
+
messageId: img.key.id,
|
|
508
|
+
});
|
|
215
509
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
510
|
+
return album;
|
|
511
|
+
}
|
|
512
|
+
async handleEvent(content, jid, quoted) {
|
|
513
|
+
const eventData = content.eventMessage;
|
|
514
|
+
const msg = await generateWAMessageFromContent(
|
|
515
|
+
jid,
|
|
516
|
+
{
|
|
517
|
+
viewOnceMessage: {
|
|
518
|
+
message: {
|
|
519
|
+
messageContextInfo: {
|
|
520
|
+
deviceListMetadata: {},
|
|
521
|
+
deviceListMetadataVersion: 2,
|
|
522
|
+
messageSecret: crypto.randomBytes(32),
|
|
523
|
+
},
|
|
524
|
+
eventMessage: {
|
|
525
|
+
isCanceled: eventData.isCanceled || false,
|
|
526
|
+
name: eventData.name,
|
|
527
|
+
description: eventData.description,
|
|
528
|
+
location: eventData.location || {
|
|
529
|
+
degreesLatitude: 0,
|
|
530
|
+
degreesLongitude: 0,
|
|
531
|
+
name: "Location",
|
|
532
|
+
},
|
|
533
|
+
joinLink: eventData.joinLink || "",
|
|
534
|
+
startTime:
|
|
535
|
+
typeof eventData.startTime === "string"
|
|
536
|
+
? parseInt(eventData.startTime)
|
|
537
|
+
: eventData.startTime || Date.now(),
|
|
538
|
+
endTime:
|
|
539
|
+
typeof eventData.endTime === "string"
|
|
540
|
+
? parseInt(eventData.endTime)
|
|
541
|
+
: eventData.endTime || Date.now() + 3600000,
|
|
542
|
+
extraGuestsAllowed: eventData.extraGuestsAllowed !== false,
|
|
543
|
+
},
|
|
544
|
+
},
|
|
545
|
+
},
|
|
546
|
+
},
|
|
547
|
+
{
|
|
548
|
+
quoted,
|
|
549
|
+
userJid: jidNormalizedUser(this.sock.authState?.creds?.me?.id || ""),
|
|
550
|
+
},
|
|
551
|
+
);
|
|
552
|
+
await this.relayMessage(jid, msg.message, {
|
|
553
|
+
messageId: msg.key.id,
|
|
554
|
+
});
|
|
555
|
+
return msg;
|
|
556
|
+
}
|
|
557
|
+
async handlePollResult(content, jid, quoted) {
|
|
558
|
+
const pollData = content.pollResultMessage;
|
|
559
|
+
const msg = await generateWAMessageFromContent(
|
|
560
|
+
jid,
|
|
561
|
+
{
|
|
562
|
+
pollResultSnapshotMessage: {
|
|
563
|
+
name: pollData.name,
|
|
564
|
+
pollVotes: pollData.pollVotes.map((vote) => ({
|
|
565
|
+
optionName: vote.optionName,
|
|
566
|
+
optionVoteCount:
|
|
567
|
+
typeof vote.optionVoteCount === "number"
|
|
568
|
+
? vote.optionVoteCount.toString()
|
|
569
|
+
: vote.optionVoteCount,
|
|
570
|
+
})),
|
|
571
|
+
},
|
|
572
|
+
},
|
|
573
|
+
{
|
|
574
|
+
quoted,
|
|
575
|
+
userJid: jidNormalizedUser(this.sock.authState?.creds?.me?.id || ""),
|
|
576
|
+
},
|
|
577
|
+
);
|
|
578
|
+
await this.relayMessage(jid, msg.message, {
|
|
579
|
+
messageId: msg.key.id,
|
|
580
|
+
});
|
|
581
|
+
return msg;
|
|
582
|
+
}
|
|
583
|
+
async handleGroupStory(content, jid, _quoted, options = {}) {
|
|
584
|
+
const storyData = content.groupStatusMessage;
|
|
585
|
+
let waMsgContent;
|
|
586
|
+
if (storyData.message) {
|
|
587
|
+
waMsgContent = storyData;
|
|
588
|
+
} else {
|
|
589
|
+
waMsgContent = await generateWAMessageContent(storyData, {
|
|
590
|
+
upload: this.waUploadToServer,
|
|
591
|
+
});
|
|
237
592
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
* ]
|
|
256
|
-
* }
|
|
257
|
-
* })
|
|
258
|
-
*/
|
|
259
|
-
async handleNestedList(content, jid, quoted) {
|
|
260
|
-
const payload = buildNestedListMessage(content.nestedListMessage);
|
|
261
|
-
return await this.utils.generateWAMessageFromContent(jid, {
|
|
262
|
-
viewOnceMessage: { message: { messageContextInfo: { deviceListMetadata: {}, deviceListMetadataVersion: 2 }, ...payload } }
|
|
263
|
-
}, { quoted });
|
|
593
|
+
const innerMsg = waMsgContent.message || waMsgContent;
|
|
594
|
+
const msgKey = Object.keys(innerMsg).find(
|
|
595
|
+
(k) => innerMsg[k] && typeof innerMsg[k] === "object",
|
|
596
|
+
);
|
|
597
|
+
if (msgKey) {
|
|
598
|
+
innerMsg[msgKey].contextInfo = innerMsg[msgKey].contextInfo || {};
|
|
599
|
+
innerMsg[msgKey].contextInfo.isGroupStatus = true;
|
|
600
|
+
if (!innerMsg[msgKey].contextInfo.statusSourceType) {
|
|
601
|
+
if (innerMsg.imageMessage)
|
|
602
|
+
innerMsg[msgKey].contextInfo.statusSourceType = 0;
|
|
603
|
+
else if (innerMsg.videoMessage)
|
|
604
|
+
innerMsg[msgKey].contextInfo.statusSourceType = 1;
|
|
605
|
+
else if (innerMsg.audioMessage)
|
|
606
|
+
innerMsg[msgKey].contextInfo.statusSourceType = 3;
|
|
607
|
+
else if (innerMsg.extendedTextMessage)
|
|
608
|
+
innerMsg[msgKey].contextInfo.statusSourceType = 4;
|
|
609
|
+
}
|
|
264
610
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
611
|
+
const finalMsg = {
|
|
612
|
+
groupStatusMessageV2: {
|
|
613
|
+
message: innerMsg,
|
|
614
|
+
},
|
|
615
|
+
};
|
|
616
|
+
return await this.relayMessage(jid, finalMsg, {
|
|
617
|
+
messageId: generateMessageID(),
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
async sendStatusWhatsApp(content, jids = []) {
|
|
621
|
+
const userJid = jidNormalizedUser(this.sock.authState.creds.me.id);
|
|
622
|
+
const allUsers = new Set();
|
|
623
|
+
allUsers.add(userJid);
|
|
624
|
+
for (const id of jids) {
|
|
625
|
+
if (isJidGroup(id)) {
|
|
626
|
+
try {
|
|
627
|
+
const metadata = await this.sock.groupMetadata(id);
|
|
628
|
+
metadata.participants.forEach((p) =>
|
|
629
|
+
allUsers.add(jidNormalizedUser(p.id)),
|
|
630
|
+
);
|
|
631
|
+
} catch (error) {
|
|
632
|
+
this.config.logger.error(
|
|
633
|
+
`Error getting metadata for group ${id}: ${error}`,
|
|
634
|
+
);
|
|
280
635
|
}
|
|
281
|
-
|
|
636
|
+
} else if (isPnUser(id)) {
|
|
637
|
+
allUsers.add(jidNormalizedUser(id));
|
|
638
|
+
}
|
|
282
639
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
640
|
+
const uniqueUsers = Array.from(allUsers);
|
|
641
|
+
const getRandomHexColor = () =>
|
|
642
|
+
"#" +
|
|
643
|
+
Math.floor(Math.random() * 16777215)
|
|
644
|
+
.toString(16)
|
|
645
|
+
.padStart(6, "0");
|
|
646
|
+
const isMedia = content.image || content.video || content.audio;
|
|
647
|
+
const isAudio = !!content.audio;
|
|
648
|
+
const messageContent = { ...content };
|
|
649
|
+
if (isMedia && !isAudio) {
|
|
650
|
+
if (messageContent.text) {
|
|
651
|
+
messageContent.caption = messageContent.text;
|
|
652
|
+
delete messageContent.text;
|
|
653
|
+
}
|
|
654
|
+
delete messageContent.ptt;
|
|
655
|
+
delete messageContent.font;
|
|
656
|
+
delete messageContent.backgroundColor;
|
|
657
|
+
delete messageContent.textColor;
|
|
291
658
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
}, { userJid: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net', quoted });
|
|
298
|
-
await this.relayMessage(jid, msg.message, { messageId: msg.key.id });
|
|
299
|
-
return msg;
|
|
659
|
+
if (isAudio) {
|
|
660
|
+
delete messageContent.text;
|
|
661
|
+
delete messageContent.caption;
|
|
662
|
+
delete messageContent.font;
|
|
663
|
+
delete messageContent.textColor;
|
|
300
664
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
};
|
|
379
|
-
const additionalNodes = buildNodes ? buildNodes(jid, wrapped) : [];
|
|
380
|
-
return await this.relayMessage(jid, wrapped, {
|
|
381
|
-
messageId: this.bail.generateMessageID(),
|
|
382
|
-
additionalNodes
|
|
383
|
-
});
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
// Mode 3: generate dari media/teks
|
|
387
|
-
let innerMessage = {};
|
|
388
|
-
// PATCH: normalize mentions (terima nomor polos, bukan cuma JID lengkap — biar konsisten
|
|
389
|
-
// sama handleInteractive) dan sisipkan quoted-reply (stanzaId/participant/quotedMessage).
|
|
390
|
-
// Sebelumnya dua-duanya "keisi" secara visual tapi diam-diam gak ke-apply: s.mentions gak
|
|
391
|
-
// pernah dilewatin ke normalizeMentions(), dan param quoted malah belum ada sama sekali di
|
|
392
|
-
// signature function ini padahal messages-send.js (swgc & case 'GROUP_STORY') udah ngoper dia.
|
|
393
|
-
const normalizedMentions = normalizeMentions(s.mentions);
|
|
394
|
-
const quoteCtx = quoted?.key
|
|
395
|
-
? {
|
|
396
|
-
stanzaId: quoted.key.id,
|
|
397
|
-
participant: quoted.key.participant || quoted.key.remoteJid,
|
|
398
|
-
quotedMessage: quoted.message
|
|
399
|
-
}
|
|
400
|
-
: {};
|
|
401
|
-
const mentionCtx = (normalizedMentions.length || Object.keys(quoteCtx).length)
|
|
402
|
-
? { contextInfo: { ...quoteCtx, ...(normalizedMentions.length ? { mentionedJid: normalizedMentions } : {}) } }
|
|
403
|
-
: {};
|
|
404
|
-
|
|
405
|
-
if (s.text || (!s.image && !s.video && !s.gif && !s.audio && !s.sticker && !s.document)) {
|
|
406
|
-
// Teks
|
|
407
|
-
innerMessage = {
|
|
408
|
-
extendedTextMessage: {
|
|
409
|
-
text: s.text || s.caption || '',
|
|
410
|
-
...(typeof s.backgroundColor !== 'undefined' ? { backgroundArgb: s.backgroundColor } : {}),
|
|
411
|
-
...(typeof s.textArgb !== 'undefined' ? { textArgb: s.textArgb } : {}),
|
|
412
|
-
...(typeof s.font !== 'undefined' ? { font: s.font } : {}),
|
|
413
|
-
...mentionCtx
|
|
414
|
-
}
|
|
415
|
-
};
|
|
416
|
-
} else if (s.image) {
|
|
417
|
-
const media = await this.utils.prepareWAMessageMedia(
|
|
418
|
-
{ image: s.image },
|
|
419
|
-
{ upload: this.waUploadToServer }
|
|
420
|
-
);
|
|
421
|
-
if (s.caption) media.imageMessage.caption = s.caption;
|
|
422
|
-
if (mentionCtx.contextInfo) media.imageMessage.contextInfo = { ...media.imageMessage.contextInfo, ...mentionCtx.contextInfo };
|
|
423
|
-
innerMessage = media;
|
|
424
|
-
} else if (s.card) {
|
|
425
|
-
// Mode: canvas-rendered story card (gradient + title/body/footer text),
|
|
426
|
-
// see lib/Utils/story-card.js. `s.card` accepts the same options as
|
|
427
|
-
// renderStoryCard() — e.g. { title, body, footer, gradient, direction }.
|
|
428
|
-
const cardBuffer = await this.utils.renderStoryCard(s.card);
|
|
429
|
-
const media = await this.utils.prepareWAMessageMedia(
|
|
430
|
-
{ image: cardBuffer },
|
|
431
|
-
{ upload: this.waUploadToServer }
|
|
432
|
-
);
|
|
433
|
-
if (s.caption) media.imageMessage.caption = s.caption;
|
|
434
|
-
if (mentionCtx.contextInfo) media.imageMessage.contextInfo = { ...media.imageMessage.contextInfo, ...mentionCtx.contextInfo };
|
|
435
|
-
innerMessage = media;
|
|
436
|
-
} else if (s.gif) {
|
|
437
|
-
// Shorthand: { gif: Buffer | { url }, caption? } — dikirim sebagai video looping,
|
|
438
|
-
// sama seperti representasi GIF asli WhatsApp.
|
|
439
|
-
const media = await this.utils.prepareWAMessageMedia(
|
|
440
|
-
{ video: s.gif },
|
|
441
|
-
{ upload: this.waUploadToServer }
|
|
442
|
-
);
|
|
443
|
-
if (s.caption) media.videoMessage.caption = s.caption;
|
|
444
|
-
media.videoMessage.gifPlayback = true;
|
|
445
|
-
if (mentionCtx.contextInfo) media.videoMessage.contextInfo = { ...media.videoMessage.contextInfo, ...mentionCtx.contextInfo };
|
|
446
|
-
innerMessage = media;
|
|
447
|
-
} else if (s.video) {
|
|
448
|
-
const media = await this.utils.prepareWAMessageMedia(
|
|
449
|
-
{ video: s.video },
|
|
450
|
-
{ upload: this.waUploadToServer }
|
|
451
|
-
);
|
|
452
|
-
if (s.caption) media.videoMessage.caption = s.caption;
|
|
453
|
-
if (s.gifPlayback) media.videoMessage.gifPlayback = true;
|
|
454
|
-
if (s.seconds) media.videoMessage.seconds = s.seconds;
|
|
455
|
-
if (mentionCtx.contextInfo) media.videoMessage.contextInfo = { ...media.videoMessage.contextInfo, ...mentionCtx.contextInfo };
|
|
456
|
-
innerMessage = media;
|
|
457
|
-
} else if (s.audio) {
|
|
458
|
-
const media = await this.utils.prepareWAMessageMedia(
|
|
459
|
-
{
|
|
460
|
-
audio: s.audio,
|
|
461
|
-
ptt: s.ptt !== false,
|
|
462
|
-
...(s.seconds ? { seconds: s.seconds } : {}),
|
|
463
|
-
...(s.mimetype ? { mimetype: s.mimetype } : {})
|
|
464
|
-
},
|
|
465
|
-
{
|
|
466
|
-
upload: this.waUploadToServer,
|
|
467
|
-
// NOTE: backgroundColor harus lewat `options` (argumen ke-2), bukan payload
|
|
468
|
-
// media — prepareWAMessageMedia() cuma hitung backgroundArgb untuk ptt audio
|
|
469
|
-
// kalau options.backgroundColor keisi. Sebelumnya gak pernah diteruskan di sini,
|
|
470
|
-
// jadi backgroundColor pada audio story selalu diam-diam diabaikan.
|
|
471
|
-
...(typeof s.backgroundColor !== 'undefined' ? { backgroundColor: s.backgroundColor } : {})
|
|
472
|
-
}
|
|
473
|
-
);
|
|
474
|
-
if (mentionCtx.contextInfo) media.audioMessage.contextInfo = { ...media.audioMessage.contextInfo, ...mentionCtx.contextInfo };
|
|
475
|
-
innerMessage = media;
|
|
476
|
-
} else if (s.sticker) {
|
|
477
|
-
const media = await this.utils.prepareWAMessageMedia(
|
|
478
|
-
{ sticker: s.sticker },
|
|
479
|
-
{ upload: this.waUploadToServer }
|
|
480
|
-
);
|
|
481
|
-
if (mentionCtx.contextInfo) media.stickerMessage.contextInfo = { ...media.stickerMessage.contextInfo, ...mentionCtx.contextInfo };
|
|
482
|
-
innerMessage = media;
|
|
483
|
-
} else if (s.document) {
|
|
484
|
-
const media = await this.utils.prepareWAMessageMedia(
|
|
485
|
-
{
|
|
486
|
-
document: s.document,
|
|
487
|
-
mimetype: s.mimetype || 'application/octet-stream',
|
|
488
|
-
fileName: s.fileName || 'file'
|
|
489
|
-
},
|
|
490
|
-
{ upload: this.waUploadToServer }
|
|
491
|
-
);
|
|
492
|
-
if (s.caption && media.documentMessage) media.documentMessage.caption = s.caption;
|
|
493
|
-
if (s.fileName && media.documentMessage) media.documentMessage.fileName = s.fileName;
|
|
494
|
-
if (mentionCtx.contextInfo && media.documentMessage) media.documentMessage.contextInfo = { ...media.documentMessage.contextInfo, ...mentionCtx.contextInfo };
|
|
495
|
-
innerMessage = media;
|
|
496
|
-
} else {
|
|
497
|
-
innerMessage = await this.bail.generateWAMessageContent(s, { upload: this.waUploadToServer });
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
// PATCH V4 (diambil dari Ourin Baileys, kebukti jalan lewat testing user —
|
|
501
|
-
// lihat CHANGELOG): WA butuh contextInfo.isGroupStatus + statusSourceType di
|
|
502
|
-
// level pesan supaya klien nge-render sebagai ring status, bukan cuma nampil
|
|
503
|
-
// sebagai pesan grup biasa. additionalNodes <meta is_vsn2> di bawah TETAP
|
|
504
|
-
// dipertahankan (gak ada bukti itu bikin masalah), tapi contextInfo ini yang
|
|
505
|
-
// di implementasi Ourin kebukti jadi kunci utamanya — dan itu diverifikasi
|
|
506
|
-
// jalan buat foto & video langsung dari testing user, bukan cuma teori.
|
|
507
|
-
const statusMsgKey = Object.keys(innerMessage).find(
|
|
508
|
-
(k) => innerMessage[k] && typeof innerMessage[k] === 'object'
|
|
509
|
-
);
|
|
510
|
-
if (statusMsgKey) {
|
|
511
|
-
innerMessage[statusMsgKey].contextInfo = innerMessage[statusMsgKey].contextInfo || {};
|
|
512
|
-
innerMessage[statusMsgKey].contextInfo.isGroupStatus = true;
|
|
513
|
-
if (typeof innerMessage[statusMsgKey].contextInfo.statusSourceType === 'undefined') {
|
|
514
|
-
// Nilai ini persis enum StatusSourceType resmi di WAProto.proto:
|
|
515
|
-
// IMAGE=0, VIDEO=1, GIF=2, AUDIO=3, TEXT=4, MUSIC_STANDALONE=5.
|
|
516
|
-
// Implementasi Ourin sendiri cuma isi image/video/audio/text (gif ikut
|
|
517
|
-
// video); di sini gif dipisah ke nilai 2 miliknya sendiri karena memang
|
|
518
|
-
// ada di enum resminya. sticker & document SENGAJA gak diisi — gak ada
|
|
519
|
-
// nilai enum yang cocok buat keduanya (kemungkinan besar memang gak
|
|
520
|
-
// didukung sebagai tipe status asli oleh WhatsApp), sama seperti
|
|
521
|
-
// implementasi Ourin yang jadi rujukan di sini.
|
|
522
|
-
if (s.image || s.card) innerMessage[statusMsgKey].contextInfo.statusSourceType = 0;
|
|
523
|
-
else if (s.gif) innerMessage[statusMsgKey].contextInfo.statusSourceType = 2;
|
|
524
|
-
else if (s.video) innerMessage[statusMsgKey].contextInfo.statusSourceType = 1;
|
|
525
|
-
else if (s.audio) innerMessage[statusMsgKey].contextInfo.statusSourceType = 3;
|
|
526
|
-
else if (statusMsgKey === 'extendedTextMessage') innerMessage[statusMsgKey].contextInfo.statusSourceType = 4;
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
// Wrap dengan messageContextInfo + messageSecret — WAJIB supaya konten bisa ditampilkan
|
|
531
|
-
const wrapped = {
|
|
532
|
-
groupStatusMessageV2: {
|
|
533
|
-
message: {
|
|
534
|
-
messageContextInfo: {
|
|
535
|
-
messageSecret: secret,
|
|
536
|
-
deviceListMetadata: {},
|
|
537
|
-
deviceListMetadataVersion: 2
|
|
538
|
-
},
|
|
539
|
-
...innerMessage
|
|
540
|
-
}
|
|
541
|
-
}
|
|
665
|
+
const font = !isMedia
|
|
666
|
+
? content.font || Math.floor(Math.random() * 9)
|
|
667
|
+
: undefined;
|
|
668
|
+
const textColor = !isMedia
|
|
669
|
+
? content.textColor || getRandomHexColor()
|
|
670
|
+
: undefined;
|
|
671
|
+
const backgroundColor =
|
|
672
|
+
!isMedia || isAudio
|
|
673
|
+
? content.backgroundColor || getRandomHexColor()
|
|
674
|
+
: undefined;
|
|
675
|
+
const ptt = isAudio
|
|
676
|
+
? typeof content.ptt === "boolean"
|
|
677
|
+
? content.ptt
|
|
678
|
+
: true
|
|
679
|
+
: undefined;
|
|
680
|
+
const { getUrlInfo } = await import("../Utils/link-preview.js");
|
|
681
|
+
const msg = await generateWAMessage(STORIES_JID, messageContent, {
|
|
682
|
+
logger: this.config.logger,
|
|
683
|
+
userJid,
|
|
684
|
+
getUrlInfo: (text) =>
|
|
685
|
+
getUrlInfo(text, {
|
|
686
|
+
thumbnailWidth: this.config.linkPreviewImageThumbnailWidth,
|
|
687
|
+
fetchOpts: { timeout: 3000, ...(this.config.options || {}) },
|
|
688
|
+
logger: this.config.logger,
|
|
689
|
+
uploadImage: this.config.generateHighQualityLinkPreview
|
|
690
|
+
? this.waUploadToServer
|
|
691
|
+
: undefined,
|
|
692
|
+
}),
|
|
693
|
+
upload: this.waUploadToServer,
|
|
694
|
+
mediaCache: this.config.mediaCache,
|
|
695
|
+
options: this.config.options,
|
|
696
|
+
font,
|
|
697
|
+
textColor,
|
|
698
|
+
backgroundColor,
|
|
699
|
+
ptt,
|
|
700
|
+
});
|
|
701
|
+
await this.relayMessage(STORIES_JID, msg.message, {
|
|
702
|
+
messageId: msg.key.id,
|
|
703
|
+
statusJidList: uniqueUsers,
|
|
704
|
+
additionalNodes: [
|
|
705
|
+
{
|
|
706
|
+
tag: "meta",
|
|
707
|
+
attrs: {},
|
|
708
|
+
content: [
|
|
709
|
+
{
|
|
710
|
+
tag: "mentioned_users",
|
|
711
|
+
attrs: {},
|
|
712
|
+
content: jids.map((jid) => ({
|
|
713
|
+
tag: "to",
|
|
714
|
+
attrs: { jid: jidNormalizedUser(jid) },
|
|
715
|
+
})),
|
|
716
|
+
},
|
|
717
|
+
],
|
|
718
|
+
},
|
|
719
|
+
],
|
|
720
|
+
});
|
|
721
|
+
for (const id of jids) {
|
|
722
|
+
try {
|
|
723
|
+
const normalizedId = jidNormalizedUser(id);
|
|
724
|
+
const isPrivate = isPnUser(normalizedId);
|
|
725
|
+
const type = isPrivate
|
|
726
|
+
? "statusMentionMessage"
|
|
727
|
+
: "groupStatusMentionMessage";
|
|
728
|
+
const protocolMessage = {
|
|
729
|
+
[type]: {
|
|
730
|
+
message: {
|
|
731
|
+
protocolMessage: {
|
|
732
|
+
key: msg.key,
|
|
733
|
+
type: 25,
|
|
734
|
+
},
|
|
735
|
+
},
|
|
736
|
+
},
|
|
737
|
+
messageContextInfo: {
|
|
738
|
+
messageSecret: crypto.randomBytes(32),
|
|
739
|
+
},
|
|
542
740
|
};
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
* jids: campuran nomor pribadi & JID grup — kalau grup, semua member-nya
|
|
562
|
-
* otomatis ditambahkan ke daftar penerima status (statusJidList) dan
|
|
563
|
-
* masing-masing dikirimi status-mention.
|
|
564
|
-
*/
|
|
565
|
-
async sendStatusWhatsApp(content, jids = []) {
|
|
566
|
-
const { authState, groupMetadata, logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, httpRequestOptions, mediaCache, getUrlInfo } = this.utils;
|
|
567
|
-
const userJid = jidNormalizedUser(authState.creds.me.id);
|
|
568
|
-
const allUsers = new Set([userJid]);
|
|
569
|
-
for (const id of jids) {
|
|
570
|
-
if (isJidGroup(id)) {
|
|
571
|
-
try {
|
|
572
|
-
const metadata = await groupMetadata(id);
|
|
573
|
-
metadata.participants.forEach(p => allUsers.add(jidNormalizedUser(p.id)));
|
|
574
|
-
}
|
|
575
|
-
catch (error) {
|
|
576
|
-
logger?.error(`Error getting metadata for group ${id}: ${error}`);
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
else if (isPnUser(id)) {
|
|
580
|
-
allUsers.add(jidNormalizedUser(id));
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
const uniqueUsers = Array.from(allUsers);
|
|
584
|
-
const getRandomHexColor = () => '#' + Math.floor(Math.random() * 16777215).toString(16).padStart(6, '0');
|
|
585
|
-
const isMedia = !!(content.image || content.video || content.audio);
|
|
586
|
-
const isAudio = !!content.audio;
|
|
587
|
-
const messageContent = { ...content };
|
|
588
|
-
if (isMedia && !isAudio) {
|
|
589
|
-
if (messageContent.text) {
|
|
590
|
-
messageContent.caption = messageContent.text;
|
|
591
|
-
delete messageContent.text;
|
|
592
|
-
}
|
|
593
|
-
delete messageContent.ptt;
|
|
594
|
-
delete messageContent.font;
|
|
595
|
-
delete messageContent.backgroundColor;
|
|
596
|
-
delete messageContent.textColor;
|
|
597
|
-
}
|
|
598
|
-
if (isAudio) {
|
|
599
|
-
delete messageContent.text;
|
|
600
|
-
delete messageContent.caption;
|
|
601
|
-
delete messageContent.font;
|
|
602
|
-
delete messageContent.textColor;
|
|
603
|
-
}
|
|
604
|
-
const font = !isMedia ? (content.font ?? Math.floor(Math.random() * 9)) : undefined;
|
|
605
|
-
const textColor = !isMedia ? (content.textColor || getRandomHexColor()) : undefined;
|
|
606
|
-
const backgroundColor = (!isMedia || isAudio) ? (content.backgroundColor || getRandomHexColor()) : undefined;
|
|
607
|
-
const ptt = isAudio ? (typeof content.ptt === 'boolean' ? content.ptt : true) : undefined;
|
|
608
|
-
const msg = await this.utils.generateWAMessage(STORIES_JID, messageContent, {
|
|
609
|
-
logger,
|
|
610
|
-
userJid,
|
|
611
|
-
getUrlInfo: (text) => getUrlInfo(text, {
|
|
612
|
-
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
613
|
-
fetchOpts: { timeout: 3000, ...(httpRequestOptions || {}) },
|
|
614
|
-
logger,
|
|
615
|
-
uploadImage: generateHighQualityLinkPreview ? this.waUploadToServer : undefined
|
|
616
|
-
}),
|
|
617
|
-
upload: this.waUploadToServer,
|
|
618
|
-
mediaCache,
|
|
619
|
-
options: httpRequestOptions,
|
|
620
|
-
font,
|
|
621
|
-
textColor,
|
|
622
|
-
backgroundColor,
|
|
623
|
-
ptt
|
|
624
|
-
});
|
|
625
|
-
await this.relayMessage(STORIES_JID, msg.message, {
|
|
626
|
-
messageId: msg.key.id,
|
|
627
|
-
statusJidList: uniqueUsers,
|
|
628
|
-
additionalNodes: [
|
|
629
|
-
{
|
|
630
|
-
tag: 'meta',
|
|
631
|
-
attrs: {},
|
|
632
|
-
content: [
|
|
633
|
-
{
|
|
634
|
-
tag: 'mentioned_users',
|
|
635
|
-
attrs: {},
|
|
636
|
-
content: jids.map(jid => ({ tag: 'to', attrs: { jid: jidNormalizedUser(jid) } }))
|
|
637
|
-
}
|
|
638
|
-
]
|
|
639
|
-
}
|
|
640
|
-
]
|
|
741
|
+
const statusMsg = await generateWAMessageFromContent(
|
|
742
|
+
normalizedId,
|
|
743
|
+
protocolMessage,
|
|
744
|
+
{
|
|
745
|
+
userJid: jidNormalizedUser(
|
|
746
|
+
this.sock.authState?.creds?.me?.id || "",
|
|
747
|
+
),
|
|
748
|
+
},
|
|
749
|
+
);
|
|
750
|
+
await this.relayMessage(normalizedId, statusMsg.message, {
|
|
751
|
+
additionalNodes: [
|
|
752
|
+
{
|
|
753
|
+
tag: "meta",
|
|
754
|
+
attrs: isPrivate
|
|
755
|
+
? { is_status_mention: "true" }
|
|
756
|
+
: { is_group_status_mention: "true" },
|
|
757
|
+
},
|
|
758
|
+
],
|
|
641
759
|
});
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
const type = isPrivate ? 'statusMentionMessage' : 'groupStatusMentionMessage';
|
|
647
|
-
const protocolMessage = {
|
|
648
|
-
[type]: { message: { protocolMessage: { key: msg.key, type: 25 } } },
|
|
649
|
-
messageContextInfo: { messageSecret: randomBytes(32) }
|
|
650
|
-
};
|
|
651
|
-
const statusMsg = await this.utils.generateWAMessageFromContent(normalizedId, protocolMessage, {
|
|
652
|
-
userJid: jidNormalizedUser(authState?.creds?.me?.id || '')
|
|
653
|
-
});
|
|
654
|
-
await this.relayMessage(normalizedId, statusMsg.message, {
|
|
655
|
-
additionalNodes: [
|
|
656
|
-
{
|
|
657
|
-
tag: 'meta',
|
|
658
|
-
attrs: isPrivate ? { is_status_mention: 'true' } : { is_group_status_mention: 'true' }
|
|
659
|
-
}
|
|
660
|
-
]
|
|
661
|
-
});
|
|
662
|
-
await delay(2000);
|
|
663
|
-
}
|
|
664
|
-
catch (error) {
|
|
665
|
-
logger?.error(`Error sending to ${id}: ${error}`);
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
return msg;
|
|
760
|
+
await delay(2000);
|
|
761
|
+
} catch (error) {
|
|
762
|
+
this.config.logger.error(`Error sending to ${id}: ${error}`);
|
|
763
|
+
}
|
|
669
764
|
}
|
|
765
|
+
return msg;
|
|
766
|
+
}
|
|
670
767
|
}
|
|
671
|
-
|
|
672
|
-
export default ExtendedMessageBuilder;
|
|
768
|
+
//# sourceMappingURL=dugong.js.map
|