@goldenqueen/bai 1.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/WAProto/GenerateStatics.sh +4 -0
- package/WAProto/WAProto.proto +4775 -0
- package/WAProto/index.d.ts +55057 -0
- package/WAProto/index.js +169661 -0
- package/WAProto/index.ts.ts +53473 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +51 -0
- package/lib/Defaults/index.js +106 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.d.ts +14 -0
- package/lib/Signal/Group/group-session-builder.js +64 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +96 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +57 -0
- package/lib/Signal/Group/keyhelper.d.ts +10 -0
- package/lib/Signal/Group/keyhelper.js +55 -0
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +34 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +69 -0
- package/lib/Signal/Group/sender-key-name.d.ts +17 -0
- package/lib/Signal/Group/sender-key-name.js +51 -0
- package/lib/Signal/Group/sender-key-record.d.ts +30 -0
- package/lib/Signal/Group/sender-key-record.js +53 -0
- package/lib/Signal/Group/sender-key-state.d.ts +38 -0
- package/lib/Signal/Group/sender-key-state.js +99 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/lib/Signal/Group/sender-message-key.js +29 -0
- package/lib/Signal/libsignal.d.ts +3 -0
- package/lib/Signal/libsignal.js +174 -0
- package/lib/Socket/Client/index.d.ts +2 -0
- package/lib/Socket/Client/index.js +18 -0
- package/lib/Socket/Client/types.d.ts +16 -0
- package/lib/Socket/Client/types.js +13 -0
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.js +111 -0
- package/lib/Socket/business.d.ts +172 -0
- package/lib/Socket/business.js +260 -0
- package/lib/Socket/chats.d.ts +82 -0
- package/lib/Socket/chats.js +871 -0
- package/lib/Socket/groups.d.ts +124 -0
- package/lib/Socket/groups.js +332 -0
- package/lib/Socket/index.d.ts +172 -0
- package/lib/Socket/index.js +10 -0
- package/lib/Socket/messages-recv.d.ts +161 -0
- package/lib/Socket/messages-recv.js +1054 -0
- package/lib/Socket/messages-send.d.ts +151 -0
- package/lib/Socket/messages-send.js +925 -0
- package/lib/Socket/newsletter.d.ts +136 -0
- package/lib/Socket/newsletter.js +250 -0
- package/lib/Socket/setup.js +433 -0
- package/lib/Socket/setup.ts +219 -0
- package/lib/Socket/socket.d.ts +43 -0
- package/lib/Socket/socket.js +654 -0
- package/lib/Socket/usync.d.ts +36 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/index.d.ts +2 -0
- package/lib/Store/index.js +8 -0
- package/lib/Store/make-in-memory-store.d.ts +118 -0
- package/lib/Store/make-in-memory-store.js +439 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.js +81 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.d.ts +103 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Call.d.ts +13 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.d.ts +109 -0
- package/lib/Types/Chat.js +4 -0
- package/lib/Types/Contact.d.ts +23 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.d.ts +199 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.d.ts +64 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.d.ts +35 -0
- package/lib/Types/Label.js +27 -0
- package/lib/Types/LabelAssociation.d.ts +29 -0
- package/lib/Types/LabelAssociation.js +9 -0
- package/lib/Types/Message.d.ts +400 -0
- package/lib/Types/Message.js +7 -0
- package/lib/Types/Newsletter.d.ts +79 -0
- package/lib/Types/Newsletter.js +18 -0
- package/lib/Types/Product.d.ts +78 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.d.ts +57 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.d.ts +119 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.d.ts +27 -0
- package/lib/Types/State.js +2 -0
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.d.ts +64 -0
- package/lib/Types/index.js +42 -0
- package/lib/Utils/auth-utils.d.ts +18 -0
- package/lib/Utils/auth-utils.js +199 -0
- package/lib/Utils/baileys-event-stream.d.ts +16 -0
- package/lib/Utils/baileys-event-stream.js +63 -0
- package/lib/Utils/business.d.ts +22 -0
- package/lib/Utils/business.js +234 -0
- package/lib/Utils/chat-utils.d.ts +70 -0
- package/lib/Utils/chat-utils.js +730 -0
- package/lib/Utils/crypto.d.ts +40 -0
- package/lib/Utils/crypto.js +193 -0
- package/lib/Utils/decode-wa-message.d.ts +35 -0
- package/lib/Utils/decode-wa-message.js +207 -0
- package/lib/Utils/event-buffer.d.ts +35 -0
- package/lib/Utils/event-buffer.js +518 -0
- package/lib/Utils/generics.d.ts +89 -0
- package/lib/Utils/generics.js +441 -0
- package/lib/Utils/history.d.ts +19 -0
- package/lib/Utils/history.js +94 -0
- package/lib/Utils/index.d.ts +17 -0
- package/lib/Utils/index.js +33 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +126 -0
- package/lib/Utils/logger.d.ts +11 -0
- package/lib/Utils/logger.js +7 -0
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/lt-hash.js +51 -0
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/make-mutex.js +43 -0
- package/lib/Utils/messages-media.d.ts +113 -0
- package/lib/Utils/messages-media.js +736 -0
- package/lib/Utils/messages.d.ts +75 -0
- package/lib/Utils/messages.js +1012 -0
- package/lib/Utils/noise-handler.d.ts +19 -0
- package/lib/Utils/noise-handler.js +150 -0
- package/lib/Utils/process-message.d.ts +42 -0
- package/lib/Utils/process-message.js +404 -0
- package/lib/Utils/signal.d.ts +33 -0
- package/lib/Utils/signal.js +153 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
- package/lib/Utils/use-multi-file-auth-state.js +125 -0
- package/lib/Utils/validate-connection.d.ts +10 -0
- package/lib/Utils/validate-connection.js +173 -0
- package/lib/WABinary/constants.d.ts +27 -0
- package/lib/WABinary/constants.js +1303 -0
- package/lib/WABinary/decode.d.ts +6 -0
- package/lib/WABinary/decode.js +265 -0
- package/lib/WABinary/encode.d.ts +2 -0
- package/lib/WABinary/encode.js +250 -0
- package/lib/WABinary/generic-utils.d.ts +14 -0
- package/lib/WABinary/generic-utils.js +110 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/index.js +21 -0
- package/lib/WABinary/jid-utils.d.ts +37 -0
- package/lib/WABinary/jid-utils.js +85 -0
- package/lib/WABinary/jid-utils.js.bak +83 -0
- package/lib/WABinary/types.d.ts +18 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.d.ts +8 -0
- package/lib/WAM/BinaryInfo.js +13 -0
- package/lib/WAM/constants.d.ts +38 -0
- package/lib/WAM/constants.js +15350 -0
- package/lib/WAM/encode.d.ts +2 -0
- package/lib/WAM/encode.js +155 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAM/index.js +19 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
- package/lib/WAUSync/Protocols/index.d.ts +4 -0
- package/lib/WAUSync/Protocols/index.js +20 -0
- package/lib/WAUSync/USyncQuery.d.ts +28 -0
- package/lib/WAUSync/USyncQuery.js +89 -0
- package/lib/WAUSync/USyncUser.d.ts +12 -0
- package/lib/WAUSync/USyncUser.js +26 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +19 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.js +45 -0
- package/package.json +112 -0
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
const WAProto = require('../../WAProto').proto;
|
|
2
|
+
const crypto = require('crypto');
|
|
3
|
+
|
|
4
|
+
class NotForrAll {
|
|
5
|
+
constructor(utils, waUploadToServer, relayMessageFn) {
|
|
6
|
+
this.utils = utils;
|
|
7
|
+
this.relayMessage = relayMessageFn
|
|
8
|
+
this.waUploadToServer = waUploadToServer;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
detectType(content) {
|
|
12
|
+
if (content.requestPaymentMessage) return 'PAYMENT';
|
|
13
|
+
if (content.productMessage) return 'PRODUCT';
|
|
14
|
+
if (content.interactiveMessage) return 'INTERACTIVE';
|
|
15
|
+
if (content.albumMessage) return 'ALBUM';
|
|
16
|
+
if (content.eventMessage) return 'EVENT';
|
|
17
|
+
if (content.pollResultMessage) return 'POLL_RESULT'
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async handlePayment(content, quoted) {
|
|
22
|
+
const data = content.requestPaymentMessage;
|
|
23
|
+
let notes = {};
|
|
24
|
+
|
|
25
|
+
if (data.sticker?.stickerMessage) {
|
|
26
|
+
notes = {
|
|
27
|
+
stickerMessage: {
|
|
28
|
+
...data.sticker.stickerMessage,
|
|
29
|
+
contextInfo: {
|
|
30
|
+
stanzaId: quoted?.key?.id,
|
|
31
|
+
participant: quoted?.key?.participant || content.sender,
|
|
32
|
+
quotedMessage: quoted?.message
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
} else if (data.note) {
|
|
37
|
+
notes = {
|
|
38
|
+
extendedTextMessage: {
|
|
39
|
+
text: data.note,
|
|
40
|
+
contextInfo: {
|
|
41
|
+
stanzaId: quoted?.key?.id,
|
|
42
|
+
participant: quoted?.key?.participant || content.sender,
|
|
43
|
+
quotedMessage: quoted?.message
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
requestPaymentMessage: WAProto.Message.RequestPaymentMessage.fromObject({
|
|
51
|
+
expiryTimestamp: data.expiry || 0,
|
|
52
|
+
amount1000: data.amount || 0,
|
|
53
|
+
currencyCodeIso4217: data.currency || "IDR",
|
|
54
|
+
requestFrom: data.from || "0@s.whatsapp.net",
|
|
55
|
+
noteMessage: notes,
|
|
56
|
+
background: data.background ?? {
|
|
57
|
+
id: "DEFAULT",
|
|
58
|
+
placeholderArgb: 0xFFF0F0F0
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async handleProduct(content, jid, quoted) {
|
|
65
|
+
const {
|
|
66
|
+
title,
|
|
67
|
+
description,
|
|
68
|
+
thumbnail,
|
|
69
|
+
productId,
|
|
70
|
+
retailerId,
|
|
71
|
+
url,
|
|
72
|
+
body = "",
|
|
73
|
+
footer = "",
|
|
74
|
+
buttons = [],
|
|
75
|
+
} = content.productMessage;
|
|
76
|
+
|
|
77
|
+
let productImage;
|
|
78
|
+
|
|
79
|
+
if (Buffer.isBuffer(thumbnail)) {
|
|
80
|
+
const { imageMessage } = await this.utils.generateWAMessageContent(
|
|
81
|
+
{ image: thumbnail },
|
|
82
|
+
{ upload: this.waUploadToServer }
|
|
83
|
+
);
|
|
84
|
+
productImage = imageMessage;
|
|
85
|
+
} else if (typeof thumbnail === 'object' && thumbnail.url) {
|
|
86
|
+
const { imageMessage } = await this.utils.generateWAMessageContent(
|
|
87
|
+
{ image: { url: thumbnail.url }},
|
|
88
|
+
{ upload: this.waUploadToServer }
|
|
89
|
+
);
|
|
90
|
+
productImage = imageMessage;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
viewOnceMessage: {
|
|
95
|
+
message: {
|
|
96
|
+
interactiveMessage: {
|
|
97
|
+
body: { text: body },
|
|
98
|
+
footer: { text: footer },
|
|
99
|
+
header: {
|
|
100
|
+
title,
|
|
101
|
+
hasMediaAttachment: true,
|
|
102
|
+
productMessage: {
|
|
103
|
+
product: {
|
|
104
|
+
productImage,
|
|
105
|
+
productId,
|
|
106
|
+
title,
|
|
107
|
+
description,
|
|
108
|
+
retailerId,
|
|
109
|
+
url,
|
|
110
|
+
productImageCount: 1
|
|
111
|
+
},
|
|
112
|
+
businessOwnerJid: "0@s.whatsapp.net"
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
nativeFlowMessage: { buttons }
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async handleInteractive(content, jid, quoted) {
|
|
123
|
+
const {
|
|
124
|
+
title,
|
|
125
|
+
footer,
|
|
126
|
+
thumbnail,
|
|
127
|
+
image,
|
|
128
|
+
video,
|
|
129
|
+
document,
|
|
130
|
+
mimetype,
|
|
131
|
+
fileName,
|
|
132
|
+
jpegThumbnail,
|
|
133
|
+
contextInfo,
|
|
134
|
+
externalAdReply,
|
|
135
|
+
buttons = [],
|
|
136
|
+
nativeFlowMessage
|
|
137
|
+
} = content.interactiveMessage;
|
|
138
|
+
|
|
139
|
+
let media = null;
|
|
140
|
+
let mediaType = null;
|
|
141
|
+
|
|
142
|
+
if (thumbnail) {
|
|
143
|
+
media = await this.utils.prepareWAMessageMedia(
|
|
144
|
+
{ image: { url: thumbnail } },
|
|
145
|
+
{ upload: this.waUploadToServer }
|
|
146
|
+
);
|
|
147
|
+
mediaType = 'image';
|
|
148
|
+
} else if (image) {
|
|
149
|
+
if (typeof image === 'object' && image.url) {
|
|
150
|
+
media = await this.utils.prepareWAMessageMedia(
|
|
151
|
+
{ image: { url: image.url } },
|
|
152
|
+
{ upload: this.waUploadToServer }
|
|
153
|
+
);
|
|
154
|
+
} else {
|
|
155
|
+
media = await this.utils.prepareWAMessageMedia(
|
|
156
|
+
{ image: image },
|
|
157
|
+
{ upload: this.waUploadToServer }
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
mediaType = 'image';
|
|
161
|
+
} else if (video) {
|
|
162
|
+
if (typeof video === 'object' && video.url) {
|
|
163
|
+
media = await this.utils.prepareWAMessageMedia(
|
|
164
|
+
{ video: { url: video.url } },
|
|
165
|
+
{ upload: this.waUploadToServer }
|
|
166
|
+
);
|
|
167
|
+
} else {
|
|
168
|
+
media = await this.utils.prepareWAMessageMedia(
|
|
169
|
+
{ video: video },
|
|
170
|
+
{ upload: this.waUploadToServer }
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
mediaType = 'video';
|
|
174
|
+
} else if (document) {
|
|
175
|
+
let documentPayload = { document: document };
|
|
176
|
+
|
|
177
|
+
if (jpegThumbnail) {
|
|
178
|
+
if (typeof jpegThumbnail === 'object' && jpegThumbnail.url) {
|
|
179
|
+
documentPayload.jpegThumbnail = { url: jpegThumbnail.url };
|
|
180
|
+
} else {
|
|
181
|
+
documentPayload.jpegThumbnail = jpegThumbnail;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
media = await this.utils.prepareWAMessageMedia(
|
|
186
|
+
documentPayload,
|
|
187
|
+
{ upload: this.waUploadToServer }
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
if (fileName) {
|
|
191
|
+
media.documentMessage.fileName = fileName;
|
|
192
|
+
}
|
|
193
|
+
if (mimetype) {
|
|
194
|
+
media.documentMessage.mimetype = mimetype;
|
|
195
|
+
}
|
|
196
|
+
mediaType = 'document';
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
let interactiveMessage = {
|
|
200
|
+
body: { text: title || "" },
|
|
201
|
+
footer: { text: footer || "" }
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
if (buttons && buttons.length > 0) {
|
|
205
|
+
interactiveMessage.nativeFlowMessage = {
|
|
206
|
+
buttons: buttons
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
if (nativeFlowMessage) {
|
|
210
|
+
interactiveMessage.nativeFlowMessage = {
|
|
211
|
+
...interactiveMessage.nativeFlowMessage,
|
|
212
|
+
...nativeFlowMessage
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
} else if (nativeFlowMessage) {
|
|
216
|
+
interactiveMessage.nativeFlowMessage = nativeFlowMessage;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (media) {
|
|
220
|
+
interactiveMessage.header = {
|
|
221
|
+
title: "",
|
|
222
|
+
hasMediaAttachment: true,
|
|
223
|
+
...media
|
|
224
|
+
};
|
|
225
|
+
} else {
|
|
226
|
+
interactiveMessage.header = {
|
|
227
|
+
title: "",
|
|
228
|
+
hasMediaAttachment: false
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
let finalContextInfo = {};
|
|
233
|
+
|
|
234
|
+
if (contextInfo) {
|
|
235
|
+
finalContextInfo = {
|
|
236
|
+
mentionedJid: contextInfo.mentionedJid || [],
|
|
237
|
+
forwardingScore: contextInfo.forwardingScore || 0,
|
|
238
|
+
isForwarded: contextInfo.isForwarded || false,
|
|
239
|
+
...contextInfo
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (externalAdReply) {
|
|
244
|
+
finalContextInfo.externalAdReply = {
|
|
245
|
+
title: externalAdReply.title || "",
|
|
246
|
+
body: externalAdReply.body || "",
|
|
247
|
+
mediaType: externalAdReply.mediaType || 1,
|
|
248
|
+
thumbnailUrl: externalAdReply.thumbnailUrl || "",
|
|
249
|
+
mediaUrl: externalAdReply.mediaUrl || "",
|
|
250
|
+
sourceUrl: externalAdReply.sourceUrl || "",
|
|
251
|
+
showAdAttribution: externalAdReply.showAdAttribution || false,
|
|
252
|
+
renderLargerThumbnail: externalAdReply.renderLargerThumbnail || false,
|
|
253
|
+
...externalAdReply
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (Object.keys(finalContextInfo).length > 0) {
|
|
258
|
+
interactiveMessage.contextInfo = finalContextInfo;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return {
|
|
262
|
+
interactiveMessage: interactiveMessage
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
async handleAlbum(content, jid, quoted) {
|
|
267
|
+
const array = content.albumMessage;
|
|
268
|
+
const album = await this.utils.generateWAMessageFromContent(jid, {
|
|
269
|
+
messageContextInfo: {
|
|
270
|
+
messageSecret: crypto.randomBytes(32),
|
|
271
|
+
},
|
|
272
|
+
albumMessage: {
|
|
273
|
+
expectedImageCount: array.filter((a) => a.hasOwnProperty("image")).length,
|
|
274
|
+
expectedVideoCount: array.filter((a) => a.hasOwnProperty("video")).length,
|
|
275
|
+
},
|
|
276
|
+
}, {
|
|
277
|
+
userJid: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net',
|
|
278
|
+
quoted,
|
|
279
|
+
upload: this.waUploadToServer
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
await this.relayMessage(jid, album.message, {
|
|
283
|
+
messageId: album.key.id,
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
for (let content of array) {
|
|
287
|
+
const img = await this.utils.generateWAMessage(jid, content, {
|
|
288
|
+
upload: this.waUploadToServer,
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
img.message.messageContextInfo = {
|
|
292
|
+
messageSecret: crypto.randomBytes(32),
|
|
293
|
+
messageAssociation: {
|
|
294
|
+
associationType: 1,
|
|
295
|
+
parentMessageKey: album.key,
|
|
296
|
+
},
|
|
297
|
+
participant: "0@s.whatsapp.net",
|
|
298
|
+
remoteJid: "status@broadcast",
|
|
299
|
+
forwardingScore: 99999,
|
|
300
|
+
isForwarded: true,
|
|
301
|
+
mentionedJid: [jid],
|
|
302
|
+
starred: true,
|
|
303
|
+
labels: ["Y", "Important"],
|
|
304
|
+
isHighlighted: true,
|
|
305
|
+
businessMessageForwardInfo: {
|
|
306
|
+
businessOwnerJid: jid,
|
|
307
|
+
},
|
|
308
|
+
dataSharingContext: {
|
|
309
|
+
showMmDisclosure: true,
|
|
310
|
+
},
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
img.message.forwardedNewsletterMessageInfo = {
|
|
314
|
+
newsletterJid: "0@newsletter",
|
|
315
|
+
serverMessageId: 1,
|
|
316
|
+
newsletterName: `WhatsApp`,
|
|
317
|
+
contentType: 1,
|
|
318
|
+
timestamp: new Date().toISOString(),
|
|
319
|
+
senderName: "NotForrAll",
|
|
320
|
+
content: "Text Message",
|
|
321
|
+
priority: "high",
|
|
322
|
+
status: "sent",
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
img.message.disappearingMode = {
|
|
326
|
+
initiator: 3,
|
|
327
|
+
trigger: 4,
|
|
328
|
+
initiatorDeviceJid: jid,
|
|
329
|
+
initiatedByExternalService: true,
|
|
330
|
+
initiatedByUserDevice: true,
|
|
331
|
+
initiatedBySystem: true,
|
|
332
|
+
initiatedByServer: true,
|
|
333
|
+
initiatedByAdmin: true,
|
|
334
|
+
initiatedByUser: true,
|
|
335
|
+
initiatedByApp: true,
|
|
336
|
+
initiatedByBot: true,
|
|
337
|
+
initiatedByMe: true,
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
await this.relayMessage(jid, img.message, {
|
|
341
|
+
messageId: img.key.id,
|
|
342
|
+
quoted: {
|
|
343
|
+
key: {
|
|
344
|
+
remoteJid: album.key.remoteJid,
|
|
345
|
+
id: album.key.id,
|
|
346
|
+
fromMe: true,
|
|
347
|
+
participant: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net',
|
|
348
|
+
},
|
|
349
|
+
message: album.message,
|
|
350
|
+
},
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
return album;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
async handleEvent(content, jid, quoted) {
|
|
357
|
+
const eventData = content.eventMessage;
|
|
358
|
+
|
|
359
|
+
const msg = await this.utils.generateWAMessageFromContent(jid, {
|
|
360
|
+
viewOnceMessage: {
|
|
361
|
+
message: {
|
|
362
|
+
messageContextInfo: {
|
|
363
|
+
deviceListMetadata: {},
|
|
364
|
+
deviceListMetadataVersion: 2,
|
|
365
|
+
messageSecret: crypto.randomBytes(32),
|
|
366
|
+
supportPayload: JSON.stringify({
|
|
367
|
+
version: 2,
|
|
368
|
+
is_ai_message: true,
|
|
369
|
+
should_show_system_message: true,
|
|
370
|
+
ticket_id: crypto.randomBytes(16).toString('hex')
|
|
371
|
+
})
|
|
372
|
+
},
|
|
373
|
+
eventMessage: {
|
|
374
|
+
contextInfo: {
|
|
375
|
+
mentionedJid: [jid],
|
|
376
|
+
participant: jid,
|
|
377
|
+
remoteJid: "status@broadcast",
|
|
378
|
+
forwardedNewsletterMessageInfo: {
|
|
379
|
+
newsletterName: "Yaoii — Baileys",
|
|
380
|
+
newsletterJid: "120363374309117436@newsletter",
|
|
381
|
+
serverMessageId: 1
|
|
382
|
+
}
|
|
383
|
+
},
|
|
384
|
+
isCanceled: eventData.isCanceled || false,
|
|
385
|
+
name: eventData.name,
|
|
386
|
+
description: eventData.description,
|
|
387
|
+
location: eventData.location || {
|
|
388
|
+
degreesLatitude: 0,
|
|
389
|
+
degreesLongitude: 0,
|
|
390
|
+
name: "Location"
|
|
391
|
+
},
|
|
392
|
+
joinLink: eventData.joinLink || '',
|
|
393
|
+
startTime: typeof eventData.startTime === 'string' ? parseInt(eventData.startTime) : eventData.startTime || Date.now(),
|
|
394
|
+
endTime: typeof eventData.endTime === 'string' ? parseInt(eventData.endTime) : eventData.endTime || Date.now() + 3600000,
|
|
395
|
+
extraGuestsAllowed: eventData.extraGuestsAllowed !== false
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}, { quoted });
|
|
400
|
+
|
|
401
|
+
await this.relayMessage(jid, msg.message, {
|
|
402
|
+
messageId: msg.key.id
|
|
403
|
+
});
|
|
404
|
+
return msg;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
async handlePollResult(content, jid, quoted) {
|
|
408
|
+
const pollData = content.pollResultMessage;
|
|
409
|
+
|
|
410
|
+
const msg = await this.utils.generateWAMessageFromContent(jid, {
|
|
411
|
+
pollResultSnapshotMessage: {
|
|
412
|
+
name: pollData.name,
|
|
413
|
+
pollVotes: pollData.pollVotes.map(vote => ({
|
|
414
|
+
optionName: vote.optionName,
|
|
415
|
+
optionVoteCount: typeof vote.optionVoteCount === 'number'
|
|
416
|
+
? vote.optionVoteCount.toString()
|
|
417
|
+
: vote.optionVoteCount
|
|
418
|
+
}))
|
|
419
|
+
}
|
|
420
|
+
}, {
|
|
421
|
+
userJid: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net',
|
|
422
|
+
quoted
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
await this.relayMessage(jid, msg.message, {
|
|
426
|
+
messageId: msg.key.id
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
return msg;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
module.exports = NotForrAll;
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
// setup.d.ts
|
|
2
|
+
import { proto } from '../../WAProto';
|
|
3
|
+
|
|
4
|
+
declare namespace NotForrAll {
|
|
5
|
+
interface MediaUploadOptions {
|
|
6
|
+
fileEncSha256?: Buffer;
|
|
7
|
+
mediaType?: string;
|
|
8
|
+
newsletter?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
type WAMediaUploadFunction = (
|
|
12
|
+
stream: Buffer | NodeJS.ReadableStream,
|
|
13
|
+
options?: MediaUploadOptions
|
|
14
|
+
) => Promise<{ url: string; directPath: string }>;
|
|
15
|
+
|
|
16
|
+
interface WAMessageContentGenerationOptions {
|
|
17
|
+
upload?: WAMediaUploadFunction;
|
|
18
|
+
mediaCache?: any;
|
|
19
|
+
options?: any;
|
|
20
|
+
logger?: any;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface StickerMessage {
|
|
24
|
+
url: string;
|
|
25
|
+
fileSha256: Buffer | string;
|
|
26
|
+
fileEncSha256: Buffer | string;
|
|
27
|
+
mediaKey: Buffer | string;
|
|
28
|
+
mimetype: string;
|
|
29
|
+
directPath: string;
|
|
30
|
+
fileLength: number | string;
|
|
31
|
+
mediaKeyTimestamp: number | string;
|
|
32
|
+
isAnimated?: boolean;
|
|
33
|
+
stickerSentTs?: number | string;
|
|
34
|
+
isAvatar?: boolean;
|
|
35
|
+
isAiSticker?: boolean;
|
|
36
|
+
isLottie?: boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
interface PaymentMessage {
|
|
40
|
+
amount: number;
|
|
41
|
+
currency?: string;
|
|
42
|
+
from?: string;
|
|
43
|
+
expiry?: number;
|
|
44
|
+
sticker?: { stickerMessage: StickerMessage };
|
|
45
|
+
note?: string;
|
|
46
|
+
background?: {
|
|
47
|
+
id?: string;
|
|
48
|
+
fileLength?: string;
|
|
49
|
+
width?: number;
|
|
50
|
+
height?: number;
|
|
51
|
+
mimetype?: string;
|
|
52
|
+
placeholderArgb?: number;
|
|
53
|
+
textArgb?: number;
|
|
54
|
+
subtextArgb?: number;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
interface ProductMessage {
|
|
59
|
+
title: string;
|
|
60
|
+
description: string;
|
|
61
|
+
thumbnail: Buffer | { url: string };
|
|
62
|
+
productId: string;
|
|
63
|
+
retailerId: string;
|
|
64
|
+
url: string;
|
|
65
|
+
body?: string;
|
|
66
|
+
footer?: string;
|
|
67
|
+
buttons?: proto.Message.InteractiveMessage.INativeFlowButton[];
|
|
68
|
+
priceAmount1000?: number | null;
|
|
69
|
+
currencyCode?: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
interface InteractiveMessage {
|
|
73
|
+
title: string;
|
|
74
|
+
footer?: string;
|
|
75
|
+
thumbnail?: string;
|
|
76
|
+
image?: string | Buffer | { url: string };
|
|
77
|
+
video?: string | Buffer | { url: string };
|
|
78
|
+
document?: Buffer;
|
|
79
|
+
mimetype?: string;
|
|
80
|
+
fileName?: string;
|
|
81
|
+
jpegThumbnail?: Buffer; // Hanya Buffer saja
|
|
82
|
+
contextInfo?: {
|
|
83
|
+
mentionedJid?: string[];
|
|
84
|
+
forwardingScore?: number;
|
|
85
|
+
isForwarded?: boolean;
|
|
86
|
+
externalAdReply?: {
|
|
87
|
+
title?: string;
|
|
88
|
+
body?: string;
|
|
89
|
+
mediaType?: number;
|
|
90
|
+
thumbnailUrl?: string;
|
|
91
|
+
mediaUrl?: string;
|
|
92
|
+
sourceUrl?: string;
|
|
93
|
+
showAdAttribution?: boolean;
|
|
94
|
+
renderLargerThumbnail?: boolean;
|
|
95
|
+
[key: string]: any;
|
|
96
|
+
};
|
|
97
|
+
[key: string]: any;
|
|
98
|
+
};
|
|
99
|
+
externalAdReply?: {
|
|
100
|
+
title?: string;
|
|
101
|
+
body?: string;
|
|
102
|
+
mediaType?: number;
|
|
103
|
+
thumbnailUrl?: string;
|
|
104
|
+
mediaUrl?: string;
|
|
105
|
+
sourceUrl?: string;
|
|
106
|
+
showAdAttribution?: boolean;
|
|
107
|
+
renderLargerThumbnail?: boolean;
|
|
108
|
+
[key: string]: any;
|
|
109
|
+
};
|
|
110
|
+
buttons?: proto.Message.InteractiveMessage.INativeFlowButton[];
|
|
111
|
+
nativeFlowMessage?: {
|
|
112
|
+
messageParamsJson?: string;
|
|
113
|
+
buttons?: proto.Message.InteractiveMessage.INativeFlowButton[];
|
|
114
|
+
[key: string]: any;
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
interface AlbumItem {
|
|
119
|
+
image?: { url: string; caption?: string };
|
|
120
|
+
video?: { url: string; caption?: string };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
interface EventMessageLocation {
|
|
124
|
+
degreesLatitude: number;
|
|
125
|
+
degreesLongitude: number;
|
|
126
|
+
name: string;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
interface EventMessage {
|
|
130
|
+
isCanceled?: boolean;
|
|
131
|
+
name: string;
|
|
132
|
+
description: string;
|
|
133
|
+
location?: EventMessageLocation;
|
|
134
|
+
joinLink?: string;
|
|
135
|
+
startTime?: string | number;
|
|
136
|
+
endTime?: string | number;
|
|
137
|
+
extraGuestsAllowed?: boolean;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
interface PollVote {
|
|
141
|
+
optionName: string;
|
|
142
|
+
optionVoteCount: string | number;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
interface PollResultMessage {
|
|
146
|
+
name: string;
|
|
147
|
+
pollVotes: PollVote[];
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
interface MessageContent {
|
|
151
|
+
requestPaymentMessage?: PaymentMessage;
|
|
152
|
+
productMessage?: ProductMessage;
|
|
153
|
+
interactiveMessage?: InteractiveMessage;
|
|
154
|
+
albumMessage?: AlbumItem[];
|
|
155
|
+
eventMessage?: EventMessage;
|
|
156
|
+
pollResultMessage?: PollResultMessage;
|
|
157
|
+
sender?: string;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
interface MessageOptions {
|
|
161
|
+
quoted?: proto.IWebMessageInfo;
|
|
162
|
+
filter?: boolean;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
interface Utils {
|
|
166
|
+
prepareWAMessageMedia: (media: any, options: WAMessageContentGenerationOptions) => Promise<any>;
|
|
167
|
+
generateWAMessageContent: (content: any, options: WAMessageContentGenerationOptions) => Promise<any>;
|
|
168
|
+
generateWAMessageFromContent: (jid: string, content: any, options?: any) => Promise<any>;
|
|
169
|
+
generateWAMessage: (jid: string, content: any, options?: any) => Promise<any>;
|
|
170
|
+
generateMessageID: () => string;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
declare class NotForrAll {
|
|
175
|
+
constructor(
|
|
176
|
+
utils: NotForrAll.Utils,
|
|
177
|
+
waUploadToServer: NotForrAll.WAMediaUploadFunction,
|
|
178
|
+
relayMessageFn?: (jid: string, content: any, options?: any) => Promise<any>
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
detectType(content: NotForrAll.MessageContent): 'PAYMENT' | 'PRODUCT' | 'INTERACTIVE' | 'ALBUM' | 'EVENT' | 'POLL_RESULT' | null;
|
|
182
|
+
|
|
183
|
+
handlePayment(
|
|
184
|
+
content: { requestPaymentMessage: NotForrAll.PaymentMessage },
|
|
185
|
+
quoted?: proto.IWebMessageInfo
|
|
186
|
+
): Promise<{ requestPaymentMessage: proto.Message.RequestPaymentMessage }>;
|
|
187
|
+
|
|
188
|
+
handleProduct(
|
|
189
|
+
content: { productMessage: NotForrAll.ProductMessage },
|
|
190
|
+
jid: string,
|
|
191
|
+
quoted?: proto.IWebMessageInfo
|
|
192
|
+
): Promise<{ viewOnceMessage: proto.Message.ViewOnceMessage }>;
|
|
193
|
+
|
|
194
|
+
handleInteractive(
|
|
195
|
+
content: { interactiveMessage: NotForrAll.InteractiveMessage },
|
|
196
|
+
jid: string,
|
|
197
|
+
quoted?: proto.IWebMessageInfo
|
|
198
|
+
): Promise<{ interactiveMessage: proto.Message.InteractiveMessage }>;
|
|
199
|
+
|
|
200
|
+
handleAlbum(
|
|
201
|
+
content: { albumMessage: NotForrAll.AlbumItem[] },
|
|
202
|
+
jid: string,
|
|
203
|
+
quoted?: proto.IWebMessageInfo
|
|
204
|
+
): Promise<any>;
|
|
205
|
+
|
|
206
|
+
handleEvent(
|
|
207
|
+
content: { eventMessage: NotForrAll.EventMessage },
|
|
208
|
+
jid: string,
|
|
209
|
+
quoted?: proto.IWebMessageInfo
|
|
210
|
+
): Promise<any>;
|
|
211
|
+
|
|
212
|
+
handlePollResult(
|
|
213
|
+
content: { pollResultMessage: NotForrAll.PollResultMessage },
|
|
214
|
+
jid: string,
|
|
215
|
+
quoted?: proto.IWebMessageInfo
|
|
216
|
+
): Promise<any>;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export = NotForrAll;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
import { SocketConfig } from '../Types';
|
|
3
|
+
import { BinaryNode } from '../WABinary';
|
|
4
|
+
import { WebSocketClient } from './Client';
|
|
5
|
+
/**
|
|
6
|
+
* Connects to WA servers and performs:
|
|
7
|
+
* - simple queries (no retry mechanism, wait for connection establishment)
|
|
8
|
+
* - listen to messages and emit events
|
|
9
|
+
* - query phone connection
|
|
10
|
+
*/
|
|
11
|
+
export declare const makeSocket: (config: SocketConfig) => {
|
|
12
|
+
type: "md";
|
|
13
|
+
ws: WebSocketClient;
|
|
14
|
+
ev: import("../Types").BaileysEventEmitter & {
|
|
15
|
+
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
|
|
16
|
+
buffer(): void;
|
|
17
|
+
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
|
|
18
|
+
flush(force?: boolean): boolean;
|
|
19
|
+
isBuffering(): boolean;
|
|
20
|
+
};
|
|
21
|
+
authState: {
|
|
22
|
+
creds: import("../Types").AuthenticationCreds;
|
|
23
|
+
keys: import("../Types").SignalKeyStoreWithTransaction;
|
|
24
|
+
};
|
|
25
|
+
signalRepository: import("../Types").SignalRepository;
|
|
26
|
+
readonly user: import("../Types").Contact | undefined;
|
|
27
|
+
generateMessageTag: () => string;
|
|
28
|
+
query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
|
|
29
|
+
waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
|
|
30
|
+
waitForSocketOpen: () => Promise<void>;
|
|
31
|
+
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
|
32
|
+
sendNode: (frame: BinaryNode) => Promise<void>;
|
|
33
|
+
logout: (msg?: string) => Promise<void>;
|
|
34
|
+
end: (error: Error | undefined) => void;
|
|
35
|
+
onUnexpectedError: (err: Error | Boom, msg: string) => void;
|
|
36
|
+
uploadPreKeys: (count?: number) => Promise<void>;
|
|
37
|
+
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
38
|
+
requestPairingCode: (phoneNumber: any, pairKey?: string) => Promise<string>;
|
|
39
|
+
/** Waits for the connection to WA to reach a state */
|
|
40
|
+
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
|
41
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
|
|
42
|
+
};
|
|
43
|
+
export type Socket = ReturnType<typeof makeSocket>;
|