@areumtecnologia/wasockets 2.0.0 → 2.3.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/README.md +1987 -1649
- package/lib/Client/Builders/Buttons.js +127 -0
- package/lib/Client/Builders/EventBuilder.js +122 -0
- package/lib/Client/Builders/InteractiveMessage.js +150 -0
- package/lib/Client/Builders/Lists.js +78 -0
- package/lib/Client/Builders/PollBuilder.js +84 -0
- package/lib/Client/Builders/index.js +21 -0
- package/lib/Client/Constants.js +54 -0
- package/lib/Client/Context/CallContext.js +96 -0
- package/lib/Client/Context/MediaObject.js +155 -0
- package/lib/Client/Context/MessageContext.js +146 -0
- package/lib/Client/Modules/BusinessManager.js +155 -0
- package/lib/Client/Modules/ChannelManager.js +144 -0
- package/lib/Client/Modules/ChatManager.js +113 -0
- package/lib/Client/Modules/CommunityManager.js +136 -0
- package/lib/Client/Modules/GroupManager.js +194 -0
- package/lib/Client/Modules/LabelManager.js +123 -0
- package/lib/Client/Modules/MessageManager.js +198 -0
- package/lib/Client/Modules/PresenceManager.js +68 -0
- package/lib/Client/Modules/PrivacyManager.js +98 -0
- package/lib/Client/Modules/ProfileManager.js +92 -0
- package/lib/Client/Modules/UserManager.js +92 -0
- package/lib/Client/Modules/VoipManager.js +117 -0
- package/lib/Client/Modules/index.js +29 -0
- package/lib/Client/Normalizers/EventNormalizer.js +82 -0
- package/lib/Client/Normalizers/JidNormalizer.js +93 -0
- package/lib/Client/Normalizers/MessageNormalizer.js +134 -0
- package/lib/Client/WaClient.js +438 -0
- package/lib/Client/index.d.ts +464 -0
- package/lib/Client/index.js +76 -0
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/connection.js +14 -1
- package/lib/Socket/index.js +51 -48
- package/lib/Socket/messages-recv.js +74 -13
- package/lib/Socket/messages-send.js +50 -25
- package/lib/Socket/socket.js +13 -0
- package/lib/Socket/voip.js +123 -0
- package/lib/Store/make-cache-manager-store.js +14 -5
- package/lib/Types/index.d.ts +4 -0
- package/lib/Utils/auth-utils.js +16 -1
- package/lib/Utils/browser-utils.js +6 -2
- package/lib/Utils/generics.js +47 -8
- package/lib/Utils/index.d.ts +1 -0
- package/lib/Utils/messages-media.js +44 -21
- package/lib/Utils/pre-key-manager.js +16 -1
- package/lib/Utils/validate-connection.js +10 -11
- package/lib/VoIP/VoIPCrypto.js +150 -0
- package/lib/VoIP/VoIPManager.js +469 -0
- package/lib/VoIP/VoIPMediaEngine.js +224 -0
- package/lib/VoIP/VoIPProtocol.js +354 -0
- package/lib/VoIP/VoIPRelayTransport.js +173 -0
- package/lib/VoIP/VoIPSession.js +314 -0
- package/lib/VoIP/assets/wasm/loader.js +5 -0
- package/lib/VoIP/assets/wasm/whatsapp.wasm +0 -0
- package/lib/VoIP/assets/wasm/worker-modules.js +305 -0
- package/lib/VoIP/engine/audio-feeder.d.mts +15 -0
- package/lib/VoIP/engine/audio-feeder.mjs +243 -0
- package/lib/VoIP/engine/index.d.mts +91 -0
- package/lib/VoIP/engine/index.mjs +1683 -0
- package/lib/VoIP/engine/relay-transport.d.mts +43 -0
- package/lib/VoIP/engine/relay-transport.mjs +607 -0
- package/lib/VoIP/engine/signaling.d.mts +44 -0
- package/lib/VoIP/engine/signaling.mjs +893 -0
- package/lib/VoIP/engine/types.d.mts +183 -0
- package/lib/VoIP/engine/types.mjs +17 -0
- package/lib/VoIP/engine/wasm-engine.d.mts +103 -0
- package/lib/VoIP/engine/wasm-engine.mjs +1397 -0
- package/lib/VoIP/engine/worker-bootstrap.mjs +1049 -0
- package/lib/VoIP/index.js +51 -0
- package/lib/VoIP/utils/audio.d.ts +28 -0
- package/lib/VoIP/utils/audio.js +148 -0
- package/lib/WABinary/generic-utils.js +22 -6
- package/lib/index.d.ts +382 -274
- package/lib/index.js +5 -0
- package/package.json +51 -49
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
import { EventEmitter } from 'events'
|
|
2
|
+
import { Readable } from 'stream'
|
|
3
|
+
import { AuthenticationState, proto, AnyMessageContent, MiscMessageGenerationOptions, GroupMetadata } from '../Types'
|
|
4
|
+
|
|
5
|
+
export declare const Events: {
|
|
6
|
+
readonly STATUS_CHANGE: 'status.change'
|
|
7
|
+
readonly QR_CODE: 'qr'
|
|
8
|
+
readonly PAIRING_CODE: 'pairing.code'
|
|
9
|
+
readonly CONNECTED: 'connected'
|
|
10
|
+
readonly DISCONNECTED: 'disconnected'
|
|
11
|
+
readonly LOGGED_OUT: 'logged.out'
|
|
12
|
+
readonly MESSAGE_RECEIVED: 'message.received'
|
|
13
|
+
readonly MESSAGE_SENT: 'message.sent'
|
|
14
|
+
readonly MESSAGE_UPDATE: 'message.update'
|
|
15
|
+
readonly MESSAGE_DELETE: 'message.delete'
|
|
16
|
+
readonly PRESENCE_UPDATE: 'presence.update'
|
|
17
|
+
readonly CONTACTS_UPSERT: 'contacts.upsert'
|
|
18
|
+
readonly CALL_INCOMING: 'call.incoming'
|
|
19
|
+
readonly CALL_STATUS: 'call.status'
|
|
20
|
+
readonly GROUP_PARTICIPANTS_UPDATE: 'group.participants.update'
|
|
21
|
+
readonly ERROR: 'error'
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type EventNames = typeof Events[keyof typeof Events]
|
|
25
|
+
|
|
26
|
+
export declare const ConnectionStatus: {
|
|
27
|
+
readonly IDLE: 'idle'
|
|
28
|
+
readonly INITIALIZING: 'initializing'
|
|
29
|
+
readonly CONNECTING: 'connecting'
|
|
30
|
+
readonly QR_READY: 'qr_ready'
|
|
31
|
+
readonly PAIRING_READY: 'pairing_ready'
|
|
32
|
+
readonly CONNECTED: 'connected'
|
|
33
|
+
readonly RECONNECTING: 'reconnecting'
|
|
34
|
+
readonly LOGGED_OUT: 'logged_out'
|
|
35
|
+
readonly DISCONNECTED: 'disconnected'
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type ConnectionStatusType = typeof ConnectionStatus[keyof typeof ConnectionStatus]
|
|
39
|
+
|
|
40
|
+
export interface WaClientOptions {
|
|
41
|
+
sessionName?: string
|
|
42
|
+
dataPath?: string
|
|
43
|
+
auth?: { state: AuthenticationState; saveCreds: () => Promise<void> }
|
|
44
|
+
phoneNumber?: string
|
|
45
|
+
printQRInTerminal?: boolean
|
|
46
|
+
restartOnClose?: boolean
|
|
47
|
+
maxReconnectAttempts?: number
|
|
48
|
+
syncFullHistory?: boolean
|
|
49
|
+
markOnlineOnConnect?: boolean
|
|
50
|
+
socketOptions?: Record<string, any>
|
|
51
|
+
logger?: any
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export declare class MediaObject {
|
|
55
|
+
mediaNode: any
|
|
56
|
+
rawType: string
|
|
57
|
+
mediaType: string
|
|
58
|
+
mimetype: string
|
|
59
|
+
fileLength: number
|
|
60
|
+
fileName: string
|
|
61
|
+
seconds: number
|
|
62
|
+
isVoice: boolean
|
|
63
|
+
isAnimated: boolean
|
|
64
|
+
extension: string
|
|
65
|
+
|
|
66
|
+
constructor(mediaNode: any, canonicalType: string)
|
|
67
|
+
|
|
68
|
+
toStream(options?: any): Promise<Readable>
|
|
69
|
+
toBuffer(options?: any): Promise<Buffer>
|
|
70
|
+
save(destinationPath: string, options?: any): Promise<string>
|
|
71
|
+
toBase64(options?: any): Promise<string>
|
|
72
|
+
toDataUri(options?: any): Promise<string>
|
|
73
|
+
toSharp(options?: any): Promise<any>
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export declare class CallContext {
|
|
77
|
+
client: WaClient
|
|
78
|
+
raw: any
|
|
79
|
+
id: string
|
|
80
|
+
from: string
|
|
81
|
+
fromNumber: string
|
|
82
|
+
isVideo: boolean
|
|
83
|
+
status: string
|
|
84
|
+
startTime: number
|
|
85
|
+
instance: any | null
|
|
86
|
+
|
|
87
|
+
constructor(client: WaClient, callData: any, activeCallInstance?: any)
|
|
88
|
+
|
|
89
|
+
accept(options?: { isVideo?: boolean; durationMs?: number; audioSource?: any }): Promise<any>
|
|
90
|
+
reject(reason?: number | string): Promise<void>
|
|
91
|
+
hangup(): Promise<void>
|
|
92
|
+
playAudio(audioPathOrBuffer: string | Buffer): Promise<any>
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface QuotedMessageContext {
|
|
96
|
+
id: string
|
|
97
|
+
sender: string
|
|
98
|
+
senderNumber: string
|
|
99
|
+
type: string
|
|
100
|
+
body: string
|
|
101
|
+
raw: proto.IMessage
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export declare class MessageContext {
|
|
105
|
+
client: WaClient
|
|
106
|
+
raw: proto.IWebMessageInfo
|
|
107
|
+
id: string
|
|
108
|
+
chatId: string
|
|
109
|
+
isFromMe: boolean
|
|
110
|
+
isGroup: boolean
|
|
111
|
+
isChannel: boolean
|
|
112
|
+
isBroadcast: boolean
|
|
113
|
+
sender: string
|
|
114
|
+
senderNumber: string
|
|
115
|
+
senderName: string
|
|
116
|
+
type: string
|
|
117
|
+
body: string
|
|
118
|
+
mediaNode: any | null
|
|
119
|
+
hasMedia: boolean
|
|
120
|
+
media: MediaObject | null
|
|
121
|
+
timestamp: number
|
|
122
|
+
contextInfo: proto.IContextInfo | null
|
|
123
|
+
mentionedJids: string[]
|
|
124
|
+
quoted: QuotedMessageContext | null
|
|
125
|
+
|
|
126
|
+
constructor(client: WaClient, rawMessage: proto.IWebMessageInfo)
|
|
127
|
+
|
|
128
|
+
reply(content: string | AnyMessageContent, options?: MiscMessageGenerationOptions): Promise<proto.WebMessageInfo | undefined>
|
|
129
|
+
react(emoji: string): Promise<proto.WebMessageInfo | undefined>
|
|
130
|
+
removeReaction(): Promise<proto.WebMessageInfo | undefined>
|
|
131
|
+
delete(): Promise<proto.WebMessageInfo | undefined>
|
|
132
|
+
markRead(): Promise<void>
|
|
133
|
+
forward(targetJid: string, options?: MiscMessageGenerationOptions): Promise<proto.WebMessageInfo | undefined>
|
|
134
|
+
pin(durationInSeconds?: number): Promise<any>
|
|
135
|
+
unpin(): Promise<any>
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export declare class QuickReplyButton {
|
|
139
|
+
displayText: string
|
|
140
|
+
id: string
|
|
141
|
+
constructor(displayText: string, id?: string)
|
|
142
|
+
build(): { name: string; buttonParamsJson: string }
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export declare class UrlButton {
|
|
146
|
+
displayText: string
|
|
147
|
+
url: string
|
|
148
|
+
merchantUrl?: string
|
|
149
|
+
constructor(displayText: string, url: string, merchantUrl?: string)
|
|
150
|
+
build(): { name: string; buttonParamsJson: string }
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export declare class CopyCodeButton {
|
|
154
|
+
displayText: string
|
|
155
|
+
copyCode: string
|
|
156
|
+
id?: string
|
|
157
|
+
constructor(displayText: string, copyCode: string, id?: string)
|
|
158
|
+
build(): { name: string; buttonParamsJson: string }
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export declare class CallButton {
|
|
162
|
+
displayText: string
|
|
163
|
+
phoneNumber: string
|
|
164
|
+
constructor(displayText: string, phoneNumber: string)
|
|
165
|
+
build(): { name: string; buttonParamsJson: string }
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export declare class PixButton {
|
|
169
|
+
displayText: string
|
|
170
|
+
pixKey: string
|
|
171
|
+
keyType: string
|
|
172
|
+
merchantName: string
|
|
173
|
+
constructor(displayText: string, pixKey: string, keyType?: 'CPF' | 'EMAIL' | 'PHONE' | 'EVP' | string, merchantName?: string)
|
|
174
|
+
build(): { name: string; buttonParamsJson: string }
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export declare class ListRow {
|
|
178
|
+
title: string
|
|
179
|
+
description: string
|
|
180
|
+
rowId: string
|
|
181
|
+
constructor(title: string, description?: string, rowId?: string)
|
|
182
|
+
build(): { title: string; description: string; rowId: string }
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export declare class ListSection {
|
|
186
|
+
title: string
|
|
187
|
+
rows: (ListRow | any)[]
|
|
188
|
+
constructor(title: string, rows?: ListRow[])
|
|
189
|
+
addRow(titleOrRow: string | ListRow, description?: string, rowId?: string): this
|
|
190
|
+
build(): { title: string; rows: any[] }
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export declare class ListButton {
|
|
194
|
+
buttonText: string
|
|
195
|
+
sections: (ListSection | any)[]
|
|
196
|
+
constructor(buttonText: string, sections?: ListSection[])
|
|
197
|
+
addSection(titleOrSection: string | ListSection, rows?: ListRow[]): this
|
|
198
|
+
build(): { buttonText: string; sections: any[] }
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export declare class InteractiveMessage {
|
|
202
|
+
setTitle(title: string): this
|
|
203
|
+
setSubtitle(subtitle: string): this
|
|
204
|
+
setText(text: string): this
|
|
205
|
+
setFooter(footer: string): this
|
|
206
|
+
setHeaderImage(image: string | Buffer | { url: string }): this
|
|
207
|
+
setHeaderVideo(video: string | Buffer | { url: string }): this
|
|
208
|
+
addButton(button: any): this
|
|
209
|
+
addButtons(buttons: any[]): this
|
|
210
|
+
build(): any
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export declare class PollBuilder {
|
|
214
|
+
setName(name: string): this
|
|
215
|
+
addOption(option: string): this
|
|
216
|
+
addOptions(options: string[]): this
|
|
217
|
+
setSelectableCount(count: number): this
|
|
218
|
+
build(): { poll: { name: string; values: string[]; selectableCount: number } }
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export declare class EventBuilder {
|
|
222
|
+
setName(name: string): this
|
|
223
|
+
setDescription(description: string): this
|
|
224
|
+
setStartDate(date: Date | number): this
|
|
225
|
+
setEndDate(date: Date | number): this
|
|
226
|
+
setLocation(name: string, degreesLatitude?: number, degreesLongitude?: number): this
|
|
227
|
+
setCall(callType?: 'voice' | 'video' | 1 | 2): this
|
|
228
|
+
build(): { event: any }
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export declare class MessageManager {
|
|
232
|
+
constructor(client: WaClient)
|
|
233
|
+
sendText(jid: string, text: string, options?: any): Promise<proto.WebMessageInfo | undefined>
|
|
234
|
+
sendMedia(jid: string, type: 'image' | 'video' | 'audio' | 'document' | 'sticker', content: any, options?: any): Promise<proto.WebMessageInfo | undefined>
|
|
235
|
+
sendAlbum(jid: string, items: any[], options?: any): Promise<proto.WebMessageInfo | undefined>
|
|
236
|
+
sendVoice(jid: string, audioSource: any, options?: any): Promise<proto.WebMessageInfo | undefined>
|
|
237
|
+
sendContact(jid: string, name: string, phoneNumber: string, options?: any): Promise<proto.WebMessageInfo | undefined>
|
|
238
|
+
sendLocation(jid: string, coords: { latitude: number; longitude: number; name?: string; address?: string; live?: boolean }, options?: any): Promise<proto.WebMessageInfo | undefined>
|
|
239
|
+
forward(targetJid: string, message: any, options?: any): Promise<proto.WebMessageInfo | undefined>
|
|
240
|
+
delete(jid: string, messageKey: proto.IMessageKey): Promise<proto.WebMessageInfo | undefined>
|
|
241
|
+
edit(jid: string, messageKey: proto.IMessageKey, newText: string): Promise<proto.WebMessageInfo | undefined>
|
|
242
|
+
pin(jid: string, messageKey: proto.IMessageKey, durationSeconds?: number): Promise<any>
|
|
243
|
+
unpin(jid: string, messageKey: proto.IMessageKey): Promise<any>
|
|
244
|
+
react(jid: string, messageKey: proto.IMessageKey, emoji: string): Promise<proto.WebMessageInfo | undefined>
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export declare class GroupManager {
|
|
248
|
+
constructor(client: WaClient)
|
|
249
|
+
create(subject: string, participants: string[]): Promise<GroupMetadata>
|
|
250
|
+
getMetadata(groupJid: string): Promise<GroupMetadata>
|
|
251
|
+
addMembers(groupJid: string, participants: string[]): Promise<any>
|
|
252
|
+
removeMembers(groupJid: string, participants: string[]): Promise<any>
|
|
253
|
+
promote(groupJid: string, participants: string[]): Promise<any>
|
|
254
|
+
demote(groupJid: string, participants: string[]): Promise<any>
|
|
255
|
+
getInviteCode(groupJid: string): Promise<string>
|
|
256
|
+
revokeInviteCode(groupJid: string): Promise<string>
|
|
257
|
+
joinWithCode(inviteCode: string): Promise<string>
|
|
258
|
+
setSubject(groupJid: string, subject: string): Promise<void>
|
|
259
|
+
setDescription(groupJid: string, description: string): Promise<void>
|
|
260
|
+
setAnnounceOnly(groupJid: string, announceOnly?: boolean): Promise<void>
|
|
261
|
+
setLocked(groupJid: string, locked?: boolean): Promise<void>
|
|
262
|
+
mentionAll(groupJid: string, textOrContent: string | any, options?: any): Promise<proto.WebMessageInfo | undefined>
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export declare class ChannelManager {
|
|
266
|
+
constructor(client: WaClient)
|
|
267
|
+
create(name: string, description?: string): Promise<any>
|
|
268
|
+
getMetadata(channelJidOrInvite: string): Promise<any>
|
|
269
|
+
subscribe(channelJid: string): Promise<any>
|
|
270
|
+
unsubscribe(channelJid: string): Promise<any>
|
|
271
|
+
mute(channelJid: string): Promise<any>
|
|
272
|
+
unmute(channelJid: string): Promise<any>
|
|
273
|
+
listSubscribed(): Promise<any[]>
|
|
274
|
+
fetchMessages(channelJid: string, count?: number, sinceTimestamp?: number): Promise<proto.WebMessageInfo[]>
|
|
275
|
+
fetchReactions(channelJid: string, messageServerId: string): Promise<any>
|
|
276
|
+
setName(channelJid: string, name: string): Promise<any>
|
|
277
|
+
setDescription(channelJid: string, description: string): Promise<any>
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export declare class PresenceManager {
|
|
281
|
+
constructor(client: WaClient)
|
|
282
|
+
startTyping(jid: string): { stop: () => Promise<void> }
|
|
283
|
+
startRecording(jid: string): { stop: () => Promise<void> }
|
|
284
|
+
setOnline(): Promise<void>
|
|
285
|
+
setOffline(): Promise<void>
|
|
286
|
+
subscribe(jid: string): Promise<void>
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
export declare class ProfileManager {
|
|
290
|
+
constructor(client: WaClient)
|
|
291
|
+
updateName(name: string): Promise<void>
|
|
292
|
+
updateAbout(aboutText: string): Promise<void>
|
|
293
|
+
getAbout(jid?: string): Promise<any>
|
|
294
|
+
updatePicture(jidOrSelf: string, imageSource: any): Promise<void>
|
|
295
|
+
removePicture(jidOrSelf?: string): Promise<void>
|
|
296
|
+
getPictureUrl(jid: string, highRes?: boolean): Promise<string | null>
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export declare class PrivacyManager {
|
|
300
|
+
constructor(client: WaClient)
|
|
301
|
+
block(jid: string): Promise<void>
|
|
302
|
+
unblock(jid: string): Promise<void>
|
|
303
|
+
getBlocklist(): Promise<string[]>
|
|
304
|
+
setLastSeen(privacy: 'all' | 'contacts' | 'contact_blacklist' | 'none'): Promise<void>
|
|
305
|
+
setOnline(privacy: 'all' | 'match_last_seen'): Promise<void>
|
|
306
|
+
setProfilePicture(privacy: 'all' | 'contacts' | 'contact_blacklist' | 'none'): Promise<void>
|
|
307
|
+
setAbout(privacy: 'all' | 'contacts' | 'contact_blacklist' | 'none'): Promise<void>
|
|
308
|
+
setReadReceipts(enabled: boolean): Promise<void>
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
export declare class UserManager {
|
|
312
|
+
constructor(client: WaClient)
|
|
313
|
+
isOnWhatsApp(phoneOrJid: string): Promise<{ exists: boolean; jid: string } | null>
|
|
314
|
+
resolveJid(jidOrPhone: string, fetchIfMissing?: boolean): Promise<string>
|
|
315
|
+
getPnForLid(lidJid: string, fetchIfMissing?: boolean): Promise<string | null>
|
|
316
|
+
getLidForPn(pnJid: string, fetchIfMissing?: boolean): Promise<string | null>
|
|
317
|
+
getBusinessProfile(jid: string): Promise<any>
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export declare class ChatManager {
|
|
321
|
+
constructor(client: WaClient)
|
|
322
|
+
pin(jid: string): Promise<void>
|
|
323
|
+
unpin(jid: string): Promise<void>
|
|
324
|
+
mute(jid: string, durationMs?: number): Promise<void>
|
|
325
|
+
unmute(jid: string): Promise<void>
|
|
326
|
+
archive(jid: string): Promise<void>
|
|
327
|
+
unarchive(jid: string): Promise<void>
|
|
328
|
+
setFavorite(jid: string, isFavorite?: boolean): Promise<void>
|
|
329
|
+
setChatNote(jid: string, note: string): Promise<void>
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
export declare class VoipManager {
|
|
333
|
+
constructor(client: WaClient)
|
|
334
|
+
call(phoneNumber: string, options?: any): Promise<CallContext>
|
|
335
|
+
callVideo(phoneNumber: string, options?: any): Promise<CallContext>
|
|
336
|
+
get activeCall(): CallContext | null
|
|
337
|
+
clearActiveCall(): void
|
|
338
|
+
acceptCall(callId: string, from: string, options?: any): Promise<any>
|
|
339
|
+
rejectCall(callId: string, from: string, reason?: number | string): Promise<void>
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
export declare class BusinessManager {
|
|
343
|
+
constructor(client: WaClient)
|
|
344
|
+
createProduct(product: {
|
|
345
|
+
name: string
|
|
346
|
+
description?: string
|
|
347
|
+
price: number
|
|
348
|
+
currency?: string
|
|
349
|
+
images?: (string | Buffer)[]
|
|
350
|
+
retailerId?: string
|
|
351
|
+
url?: string
|
|
352
|
+
isHidden?: boolean
|
|
353
|
+
}): Promise<any>
|
|
354
|
+
updateProduct(productId: string, update: any): Promise<any>
|
|
355
|
+
deleteProduct(productIds: string | string[]): Promise<{ deleted: number }>
|
|
356
|
+
getProduct(productId: string, merchantJid?: string): Promise<any>
|
|
357
|
+
getCatalog(options?: { jid?: string; limit?: number; cursor?: string }): Promise<any>
|
|
358
|
+
getCollections(merchantJid?: string, limit?: number): Promise<any>
|
|
359
|
+
getOrderDetails(orderId: string, orderToken: string): Promise<any>
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
export declare class CommunityManager {
|
|
363
|
+
constructor(client: WaClient)
|
|
364
|
+
create(subject: string, description?: string): Promise<any>
|
|
365
|
+
getMetadata(communityJid: string): Promise<any>
|
|
366
|
+
createSubgroup(communityJid: string, subject: string, participants?: string[]): Promise<any>
|
|
367
|
+
linkSubgroup(communityJid: string, groupJid: string): Promise<any>
|
|
368
|
+
unlinkSubgroup(communityJid: string, groupJid: string): Promise<any>
|
|
369
|
+
getSubgroups(communityJid: string): Promise<any>
|
|
370
|
+
leave(communityJid: string): Promise<any>
|
|
371
|
+
setName(communityJid: string, subject: string): Promise<any>
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
export declare class LabelManager {
|
|
375
|
+
constructor(client: WaClient)
|
|
376
|
+
create(name: string, color?: number, predefinedId?: number): Promise<any>
|
|
377
|
+
update(id: string, name: string, color?: number, predefinedId?: number): Promise<any>
|
|
378
|
+
delete(id: string): Promise<any>
|
|
379
|
+
addChat(jid: string, labelId: string): Promise<any>
|
|
380
|
+
removeChat(jid: string, labelId: string): Promise<any>
|
|
381
|
+
addMessage(jid: string, messageId: string, labelId: string): Promise<any>
|
|
382
|
+
removeMessage(jid: string, messageId: string, labelId: string): Promise<any>
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
export declare class JidNormalizer {
|
|
386
|
+
static toJid(input: string): string
|
|
387
|
+
static toPhoneNumber(jid: string): string
|
|
388
|
+
static isGroup(jid: string): boolean
|
|
389
|
+
static isNewsletter(jid: string): boolean
|
|
390
|
+
static isLid(jid: string): boolean
|
|
391
|
+
static isUser(jid: string): boolean
|
|
392
|
+
static isStatusBroadcast(jid: string): boolean
|
|
393
|
+
static isBroadcast(jid: string): boolean
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
export declare class MessageNormalizer {
|
|
397
|
+
static unwrapMessage(rawMessageContent: any): any
|
|
398
|
+
static extractType(messageContent: any): string
|
|
399
|
+
static extractBody(messageContent: any): string
|
|
400
|
+
static extractMediaNode(messageContent: any): any | null
|
|
401
|
+
static extractContextInfo(messageContent: any): proto.IContextInfo | null
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
export declare class WaClient extends EventEmitter {
|
|
405
|
+
options: WaClientOptions
|
|
406
|
+
status: ConnectionStatusType
|
|
407
|
+
sock: any
|
|
408
|
+
authState: AuthenticationState | null
|
|
409
|
+
saveCreds: (() => Promise<void>) | null
|
|
410
|
+
reconnectAttempts: number
|
|
411
|
+
|
|
412
|
+
// Specialized Domain Managers
|
|
413
|
+
messages: MessageManager
|
|
414
|
+
groups: GroupManager
|
|
415
|
+
channels: ChannelManager
|
|
416
|
+
presence: PresenceManager
|
|
417
|
+
profile: ProfileManager
|
|
418
|
+
privacy: PrivacyManager
|
|
419
|
+
users: UserManager
|
|
420
|
+
chat: ChatManager
|
|
421
|
+
voip: VoipManager
|
|
422
|
+
business: BusinessManager
|
|
423
|
+
communities: CommunityManager
|
|
424
|
+
labels: LabelManager
|
|
425
|
+
|
|
426
|
+
constructor(options?: WaClientOptions)
|
|
427
|
+
|
|
428
|
+
connect(): Promise<this>
|
|
429
|
+
disconnect(): Promise<void>
|
|
430
|
+
logout(): Promise<void>
|
|
431
|
+
|
|
432
|
+
sendMessage(jid: string, content: AnyMessageContent, options?: MiscMessageGenerationOptions): Promise<proto.WebMessageInfo | undefined>
|
|
433
|
+
sendInteractive(jid: string, interactiveOrBuilder: InteractiveMessage | any, options?: MiscMessageGenerationOptions): Promise<proto.WebMessageInfo | undefined>
|
|
434
|
+
sendPoll(jid: string, pollOrBuilder: PollBuilder | any, options?: MiscMessageGenerationOptions): Promise<proto.WebMessageInfo | undefined>
|
|
435
|
+
sendEvent(jid: string, eventOrBuilder: EventBuilder | any, options?: MiscMessageGenerationOptions): Promise<proto.WebMessageInfo | undefined>
|
|
436
|
+
|
|
437
|
+
startTyping(jid: string): { stop: () => Promise<void> }
|
|
438
|
+
startRecording(jid: string): { stop: () => Promise<void> }
|
|
439
|
+
isOnWhatsApp(jidOrNumber: string): Promise<{ exists: boolean; jid: string } | null>
|
|
440
|
+
|
|
441
|
+
get user(): { id: string; name?: string } | null
|
|
442
|
+
get isConnected(): boolean
|
|
443
|
+
get rawSocket(): any
|
|
444
|
+
|
|
445
|
+
on(event: 'status.change', listener: (status: { current: ConnectionStatusType; previous: ConnectionStatusType }) => void): this
|
|
446
|
+
on(event: 'qr', listener: (data: { qr: string }) => void): this
|
|
447
|
+
on(event: 'pairing.code', listener: (data: { code: string }) => void): this
|
|
448
|
+
on(event: 'connected', listener: (data: { user: any }) => void): this
|
|
449
|
+
on(event: 'disconnected', listener: (data: { error?: any; willReconnect: boolean; attempt?: number; delayMs?: number }) => void): this
|
|
450
|
+
on(event: 'logged.out', listener: (data: { error?: any }) => void): this
|
|
451
|
+
on(event: 'call.incoming', listener: (call: CallContext) => void): this
|
|
452
|
+
on(event: 'call.status', listener: (calls: any[]) => void): this
|
|
453
|
+
on(event: 'message.received', listener: (ctx: MessageContext, raw: proto.IWebMessageInfo) => void): this
|
|
454
|
+
on(event: 'message.sent', listener: (ctx: MessageContext, raw: proto.IWebMessageInfo) => void): this
|
|
455
|
+
on(event: 'message.update', listener: (updates: any[]) => void): this
|
|
456
|
+
on(event: 'message.delete', listener: (item: any) => void): this
|
|
457
|
+
on(event: 'presence.update', listener: (presence: any) => void): this
|
|
458
|
+
on(event: 'contacts.upsert', listener: (contacts: any[]) => void): this
|
|
459
|
+
on(event: 'group.participants.update', listener: (update: any) => void): this
|
|
460
|
+
on(event: 'error', listener: (error: any) => void): this
|
|
461
|
+
on(event: string | symbol, listener: (...args: any[]) => void): this
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
export default WaClient
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
|
+
|
|
5
|
+
const { WaClient } = require("./WaClient")
|
|
6
|
+
const { Events, ConnectionStatus } = require("./Constants")
|
|
7
|
+
const { MessageContext } = require("./Context/MessageContext")
|
|
8
|
+
const { MediaObject } = require("./Context/MediaObject")
|
|
9
|
+
const { CallContext } = require("./Context/CallContext")
|
|
10
|
+
const { JidNormalizer } = require("./Normalizers/JidNormalizer")
|
|
11
|
+
const { MessageNormalizer } = require("./Normalizers/MessageNormalizer")
|
|
12
|
+
const {
|
|
13
|
+
InteractiveMessage,
|
|
14
|
+
QuickReplyButton,
|
|
15
|
+
UrlButton,
|
|
16
|
+
CopyCodeButton,
|
|
17
|
+
CallButton,
|
|
18
|
+
PixButton,
|
|
19
|
+
ListButton,
|
|
20
|
+
ListSection,
|
|
21
|
+
ListRow,
|
|
22
|
+
PollBuilder,
|
|
23
|
+
EventBuilder
|
|
24
|
+
} = require("./Builders")
|
|
25
|
+
const {
|
|
26
|
+
MessageManager,
|
|
27
|
+
GroupManager,
|
|
28
|
+
ChannelManager,
|
|
29
|
+
PresenceManager,
|
|
30
|
+
ProfileManager,
|
|
31
|
+
PrivacyManager,
|
|
32
|
+
UserManager,
|
|
33
|
+
ChatManager,
|
|
34
|
+
VoipManager,
|
|
35
|
+
BusinessManager,
|
|
36
|
+
CommunityManager,
|
|
37
|
+
LabelManager
|
|
38
|
+
} = require("./Modules")
|
|
39
|
+
|
|
40
|
+
exports.WaClient = WaClient
|
|
41
|
+
exports.Events = Events
|
|
42
|
+
exports.ConnectionStatus = ConnectionStatus
|
|
43
|
+
exports.MessageContext = MessageContext
|
|
44
|
+
exports.MediaObject = MediaObject
|
|
45
|
+
exports.CallContext = CallContext
|
|
46
|
+
exports.JidNormalizer = JidNormalizer
|
|
47
|
+
exports.MessageNormalizer = MessageNormalizer
|
|
48
|
+
|
|
49
|
+
// Builders
|
|
50
|
+
exports.InteractiveMessage = InteractiveMessage
|
|
51
|
+
exports.QuickReplyButton = QuickReplyButton
|
|
52
|
+
exports.UrlButton = UrlButton
|
|
53
|
+
exports.CopyCodeButton = CopyCodeButton
|
|
54
|
+
exports.CallButton = CallButton
|
|
55
|
+
exports.PixButton = PixButton
|
|
56
|
+
exports.ListButton = ListButton
|
|
57
|
+
exports.ListSection = ListSection
|
|
58
|
+
exports.ListRow = ListRow
|
|
59
|
+
exports.PollBuilder = PollBuilder
|
|
60
|
+
exports.EventBuilder = EventBuilder
|
|
61
|
+
|
|
62
|
+
// Domain Managers
|
|
63
|
+
exports.MessageManager = MessageManager
|
|
64
|
+
exports.GroupManager = GroupManager
|
|
65
|
+
exports.ChannelManager = ChannelManager
|
|
66
|
+
exports.PresenceManager = PresenceManager
|
|
67
|
+
exports.ProfileManager = ProfileManager
|
|
68
|
+
exports.PrivacyManager = PrivacyManager
|
|
69
|
+
exports.UserManager = UserManager
|
|
70
|
+
exports.ChatManager = ChatManager
|
|
71
|
+
exports.VoipManager = VoipManager
|
|
72
|
+
exports.BusinessManager = BusinessManager
|
|
73
|
+
exports.CommunityManager = CommunityManager
|
|
74
|
+
exports.LabelManager = LabelManager
|
|
75
|
+
|
|
76
|
+
exports.default = WaClient
|
|
@@ -7,6 +7,19 @@ const { default: logger } = require("../Utils/logger")
|
|
|
7
7
|
const { makeLibSignalRepository } = require("../Signal/libsignal")
|
|
8
8
|
const { version } = require("./baileys-version.json")
|
|
9
9
|
|
|
10
|
+
let defaultWaVersion = version
|
|
11
|
+
try {
|
|
12
|
+
const pkg = require("../../package.json")
|
|
13
|
+
if (typeof pkg.whatsappVersion === 'string') {
|
|
14
|
+
const parts = pkg.whatsappVersion.split('.').map(Number)
|
|
15
|
+
if (parts.length === 3 && parts.every(n => !isNaN(n))) {
|
|
16
|
+
defaultWaVersion = parts
|
|
17
|
+
}
|
|
18
|
+
} else if (Array.isArray(pkg.whatsappVersion) && pkg.whatsappVersion.length === 3) {
|
|
19
|
+
defaultWaVersion = pkg.whatsappVersion.map(Number)
|
|
20
|
+
}
|
|
21
|
+
} catch {}
|
|
22
|
+
|
|
10
23
|
const createGroupMetadataCache = (ttlMs = 300000, maxSize = 250) => {
|
|
11
24
|
const cache = new Map()
|
|
12
25
|
|
|
@@ -35,7 +48,7 @@ const createGroupMetadataCache = (ttlMs = 300000, maxSize = 250) => {
|
|
|
35
48
|
}
|
|
36
49
|
|
|
37
50
|
const DEFAULT_CONNECTION_CONFIG = {
|
|
38
|
-
version,
|
|
51
|
+
version: defaultWaVersion,
|
|
39
52
|
browser: Browsers.windows('Chrome'),
|
|
40
53
|
waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
|
|
41
54
|
connectTimeoutMs: 20000,
|
package/lib/Socket/index.js
CHANGED
|
@@ -1,48 +1,51 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
|
-
|
|
5
|
-
const { DEFAULT_CONNECTION_CONFIG, createGroupMetadataCache } = require("../Defaults/connection")
|
|
6
|
-
const { makeCommunitiesSocket } = require("./community")
|
|
7
|
-
const { PluginManager } = require("../Plugins")
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
//
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
sock.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
|
+
|
|
5
|
+
const { DEFAULT_CONNECTION_CONFIG, createGroupMetadataCache } = require("../Defaults/connection")
|
|
6
|
+
const { makeCommunitiesSocket } = require("./community")
|
|
7
|
+
const { PluginManager } = require("../Plugins")
|
|
8
|
+
const { makeVoipSocket } = require("./voip")
|
|
9
|
+
|
|
10
|
+
// export the last socket layer
|
|
11
|
+
const makeWASocket = (config = {}) => {
|
|
12
|
+
const newConfig = {
|
|
13
|
+
...DEFAULT_CONNECTION_CONFIG,
|
|
14
|
+
...config
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// If the user hasn't provided their own history sync function,
|
|
18
|
+
// let's create a default one that respects the syncFullHistory flag.
|
|
19
|
+
if (config.shouldSyncHistoryMessage === undefined) {
|
|
20
|
+
newConfig.shouldSyncHistoryMessage = () => !!newConfig.syncFullHistory
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (!config.cachedGroupMetadata && newConfig.enableGroupCache) {
|
|
24
|
+
newConfig.cachedGroupMetadata = createGroupMetadataCache()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const baseSock = makeCommunitiesSocket(newConfig)
|
|
28
|
+
const sock = makeVoipSocket(newConfig, baseSock)
|
|
29
|
+
const pluginManager = new PluginManager(sock)
|
|
30
|
+
|
|
31
|
+
sock.plugins = pluginManager
|
|
32
|
+
sock.use = (plugin, options) => {
|
|
33
|
+
pluginManager.use(plugin, options)
|
|
34
|
+
return sock
|
|
35
|
+
}
|
|
36
|
+
sock.registerMiddleware = (hook, fn) => pluginManager.registerMiddleware(hook, fn)
|
|
37
|
+
sock.hasPlugin = (name) => pluginManager.hasPlugin(name)
|
|
38
|
+
sock.listPlugins = () => pluginManager.listPlugins()
|
|
39
|
+
|
|
40
|
+
// Auto-install plugins passed in configuration
|
|
41
|
+
if (Array.isArray(config.plugins)) {
|
|
42
|
+
for (const p of config.plugins) {
|
|
43
|
+
sock.use(p)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return sock
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
exports.default = makeWASocket
|
|
51
|
+
exports.makeWASocket = makeWASocket
|