@whanext/core 0.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/CHANGELOG.md +35 -0
- package/CONTRIBUTING.md +36 -0
- package/LICENSE +21 -0
- package/README.md +507 -0
- package/SECURITY.md +16 -0
- package/dist/index.d.ts +500 -0
- package/dist/index.js +1988 -0
- package/dist/index.js.map +1 -0
- package/package.json +71 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
interface CacheStore {
|
|
2
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
3
|
+
set<T>(key: string, value: T, ttlMs?: number): Promise<void>;
|
|
4
|
+
delete(key: string): Promise<void>;
|
|
5
|
+
clear(): Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
interface CacheOptions {
|
|
8
|
+
store?: CacheStore;
|
|
9
|
+
groupTtlMs?: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface UserData {
|
|
13
|
+
id: string;
|
|
14
|
+
identities?: readonly string[];
|
|
15
|
+
jid?: string;
|
|
16
|
+
lid?: string;
|
|
17
|
+
phoneNumber?: string;
|
|
18
|
+
name?: string;
|
|
19
|
+
}
|
|
20
|
+
declare class User {
|
|
21
|
+
readonly id: string;
|
|
22
|
+
readonly identities: string[];
|
|
23
|
+
readonly jid: string | undefined;
|
|
24
|
+
readonly lid: string | undefined;
|
|
25
|
+
readonly phoneNumber: string | undefined;
|
|
26
|
+
readonly name: string | undefined;
|
|
27
|
+
constructor(data: UserData);
|
|
28
|
+
get mentionId(): string;
|
|
29
|
+
get mention(): string;
|
|
30
|
+
get phone(): string | undefined;
|
|
31
|
+
get username(): string;
|
|
32
|
+
get displayName(): string;
|
|
33
|
+
matches(identity: string | User): boolean;
|
|
34
|
+
toJSON(): UserData;
|
|
35
|
+
static fromIdentities(identities: readonly string[]): User;
|
|
36
|
+
static fromPhoneNumber(phoneNumber: string): User;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
interface ArgumentOptions {
|
|
40
|
+
optional?: boolean;
|
|
41
|
+
}
|
|
42
|
+
declare class ArgsParser {
|
|
43
|
+
#private;
|
|
44
|
+
constructor(values: readonly string[]);
|
|
45
|
+
get remaining(): number;
|
|
46
|
+
peek(): string | undefined;
|
|
47
|
+
skip(count?: number): this;
|
|
48
|
+
string(name?: string, options?: ArgumentOptions): string | undefined;
|
|
49
|
+
number(name?: string, options?: ArgumentOptions): number | undefined;
|
|
50
|
+
boolean(name?: string, options?: ArgumentOptions): boolean | undefined;
|
|
51
|
+
enum<const Values extends readonly string[]>(values: Values, name?: string, options?: ArgumentOptions): Values[number] | undefined;
|
|
52
|
+
user(name?: string): User;
|
|
53
|
+
user(name: string, options: {
|
|
54
|
+
optional: true;
|
|
55
|
+
}): User | undefined;
|
|
56
|
+
duration(name?: string, options?: ArgumentOptions): number | undefined;
|
|
57
|
+
rest(): string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface MessageKey {
|
|
61
|
+
id: string;
|
|
62
|
+
chatId: string;
|
|
63
|
+
fromMe: boolean;
|
|
64
|
+
participantId?: string;
|
|
65
|
+
}
|
|
66
|
+
type MediaKind = 'image' | 'video' | 'audio' | 'document' | 'sticker';
|
|
67
|
+
interface MessageMedia {
|
|
68
|
+
kind: MediaKind;
|
|
69
|
+
mimetype?: string;
|
|
70
|
+
fileName?: string;
|
|
71
|
+
seconds?: number;
|
|
72
|
+
viewOnce: boolean;
|
|
73
|
+
}
|
|
74
|
+
interface QuotedMessage {
|
|
75
|
+
key: MessageKey;
|
|
76
|
+
text?: string;
|
|
77
|
+
senderId?: string;
|
|
78
|
+
sender?: User;
|
|
79
|
+
hasMedia: boolean;
|
|
80
|
+
}
|
|
81
|
+
interface Message {
|
|
82
|
+
id: string;
|
|
83
|
+
jid: string;
|
|
84
|
+
lid?: string;
|
|
85
|
+
chatId: string;
|
|
86
|
+
senderId: string;
|
|
87
|
+
senderIds: string[];
|
|
88
|
+
senderJid?: string;
|
|
89
|
+
senderLid?: string;
|
|
90
|
+
sender: User;
|
|
91
|
+
keys: MessageKey;
|
|
92
|
+
text?: string;
|
|
93
|
+
caption?: string;
|
|
94
|
+
mentions: string[];
|
|
95
|
+
mentionedUsers: User[];
|
|
96
|
+
timestamp: Date;
|
|
97
|
+
isGroup: boolean;
|
|
98
|
+
isReply: boolean;
|
|
99
|
+
isViewOnce: boolean;
|
|
100
|
+
hasMedia: boolean;
|
|
101
|
+
media?: MessageMedia;
|
|
102
|
+
quoted?: QuotedMessage;
|
|
103
|
+
}
|
|
104
|
+
interface SentMessage {
|
|
105
|
+
id: string;
|
|
106
|
+
chatId: string;
|
|
107
|
+
keys: MessageKey;
|
|
108
|
+
timestamp: Date;
|
|
109
|
+
}
|
|
110
|
+
type MediaSource = Uint8Array | {
|
|
111
|
+
url: string;
|
|
112
|
+
} | {
|
|
113
|
+
path: string;
|
|
114
|
+
};
|
|
115
|
+
type MentionTarget = string | User;
|
|
116
|
+
interface TextContent {
|
|
117
|
+
text: string;
|
|
118
|
+
mentions?: MentionTarget[];
|
|
119
|
+
}
|
|
120
|
+
interface ImageContent {
|
|
121
|
+
image: MediaSource;
|
|
122
|
+
caption?: string;
|
|
123
|
+
mentions?: MentionTarget[];
|
|
124
|
+
viewOnce?: boolean;
|
|
125
|
+
}
|
|
126
|
+
interface VideoContent {
|
|
127
|
+
video: MediaSource;
|
|
128
|
+
caption?: string;
|
|
129
|
+
mentions?: MentionTarget[];
|
|
130
|
+
viewOnce?: boolean;
|
|
131
|
+
gif?: boolean;
|
|
132
|
+
}
|
|
133
|
+
interface AudioContent {
|
|
134
|
+
audio: MediaSource;
|
|
135
|
+
mimetype?: string;
|
|
136
|
+
voice?: boolean;
|
|
137
|
+
}
|
|
138
|
+
type MessageContent = TextContent | ImageContent | VideoContent | AudioContent;
|
|
139
|
+
|
|
140
|
+
interface CommandDefinition {
|
|
141
|
+
name: string;
|
|
142
|
+
description: string;
|
|
143
|
+
aliases?: readonly string[];
|
|
144
|
+
onlyGroup?: boolean;
|
|
145
|
+
onlyPrivate?: boolean;
|
|
146
|
+
onlyAdmin?: boolean;
|
|
147
|
+
botMustBeAdmin?: boolean;
|
|
148
|
+
execute(message: Message, args: ArgsParser): void | Promise<void>;
|
|
149
|
+
}
|
|
150
|
+
declare function defineCommand<const Command extends CommandDefinition>(command: Command): Command;
|
|
151
|
+
|
|
152
|
+
type WhaNextErrorCode = 'AUTH_INVALID_PHONE' | 'AUTH_EXPIRED' | 'CONNECTION_CLOSED' | 'CONNECTION_FAILED' | 'GROUP_NOT_FOUND' | 'MEMBER_NOT_FOUND' | 'BOT_NOT_ADMIN' | 'MESSAGE_NOT_FOUND' | 'MUTE_DISABLED' | 'STORAGE_ERROR' | 'ARGUMENT_MISSING' | 'ARGUMENT_INVALID' | 'COMMAND_NOT_ALLOWED' | 'PROVIDER_ERROR' | 'UNKNOWN_ERROR';
|
|
153
|
+
interface WhaNextErrorOptions {
|
|
154
|
+
cause?: unknown;
|
|
155
|
+
context?: Readonly<Record<string, unknown>>;
|
|
156
|
+
recoverable?: boolean;
|
|
157
|
+
}
|
|
158
|
+
declare class WhaNextError extends Error {
|
|
159
|
+
readonly code: WhaNextErrorCode;
|
|
160
|
+
readonly context: Readonly<Record<string, unknown>>;
|
|
161
|
+
readonly recoverable: boolean;
|
|
162
|
+
constructor(code: WhaNextErrorCode, message: string, options?: WhaNextErrorOptions);
|
|
163
|
+
}
|
|
164
|
+
declare function toWhaNextError(error: unknown, context?: Readonly<Record<string, unknown>>): WhaNextError;
|
|
165
|
+
|
|
166
|
+
type GroupAccess = 'open' | 'closed';
|
|
167
|
+
type GroupRole = 'member' | 'admin' | 'owner';
|
|
168
|
+
type GroupAddressingMode = 'lid' | 'pn';
|
|
169
|
+
interface GroupParticipant {
|
|
170
|
+
id: string;
|
|
171
|
+
lid?: string;
|
|
172
|
+
phoneNumber?: string;
|
|
173
|
+
role: GroupRole;
|
|
174
|
+
}
|
|
175
|
+
interface GroupSnapshot {
|
|
176
|
+
id: string;
|
|
177
|
+
subject: string;
|
|
178
|
+
access: GroupAccess;
|
|
179
|
+
addressingMode: GroupAddressingMode;
|
|
180
|
+
participants: GroupParticipant[];
|
|
181
|
+
fetchedAt: Date;
|
|
182
|
+
}
|
|
183
|
+
type ChangeResult<State extends string> = {
|
|
184
|
+
ok: true;
|
|
185
|
+
changed: true;
|
|
186
|
+
state: State;
|
|
187
|
+
} | {
|
|
188
|
+
ok: true;
|
|
189
|
+
changed: false;
|
|
190
|
+
state: State;
|
|
191
|
+
};
|
|
192
|
+
interface InviteResult {
|
|
193
|
+
ok: true;
|
|
194
|
+
url: string;
|
|
195
|
+
code: string;
|
|
196
|
+
}
|
|
197
|
+
type MemberAction = 'removed' | 'promoted' | 'demoted';
|
|
198
|
+
type MemberActionState = MemberAction | 'already_removed' | 'already_admin' | 'not_admin' | 'not_in_group';
|
|
199
|
+
|
|
200
|
+
type ConnectionState = 'idle' | 'connecting' | 'connected' | 'reconnecting' | 'closed';
|
|
201
|
+
type PresenceState = 'typing' | 'recording' | 'paused';
|
|
202
|
+
type ParticipantAction = 'remove' | 'promote' | 'demote';
|
|
203
|
+
interface ParticipantUpdateResult {
|
|
204
|
+
success: boolean;
|
|
205
|
+
status: string;
|
|
206
|
+
memberId?: string;
|
|
207
|
+
}
|
|
208
|
+
interface ConnectionUpdate {
|
|
209
|
+
state: ConnectionState;
|
|
210
|
+
attempt?: number;
|
|
211
|
+
error?: Error;
|
|
212
|
+
}
|
|
213
|
+
interface ProviderEvents {
|
|
214
|
+
message: Message;
|
|
215
|
+
connection: ConnectionUpdate;
|
|
216
|
+
groupChanged: {
|
|
217
|
+
groupId: string;
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
type Unsubscribe = () => void;
|
|
221
|
+
interface WhatsAppProvider {
|
|
222
|
+
connect(): Promise<void>;
|
|
223
|
+
disconnect(): Promise<void>;
|
|
224
|
+
getCurrentUserIds(): string[];
|
|
225
|
+
requestPairingCode(phone: string): Promise<string>;
|
|
226
|
+
on<Event extends keyof ProviderEvents>(event: Event, listener: (payload: ProviderEvents[Event]) => void | Promise<void>): Unsubscribe;
|
|
227
|
+
sendMessage(chatId: string, content: MessageContent, replyTo?: MessageKey): Promise<SentMessage>;
|
|
228
|
+
editMessage(key: MessageKey, content: string): Promise<SentMessage>;
|
|
229
|
+
deleteMessage(key: MessageKey): Promise<void>;
|
|
230
|
+
getGroup(groupId: string): Promise<GroupSnapshot>;
|
|
231
|
+
setGroupAccess(groupId: string, access: GroupAccess): Promise<void>;
|
|
232
|
+
getGroupInviteCode(groupId: string): Promise<string>;
|
|
233
|
+
revokeGroupInvite(groupId: string): Promise<string>;
|
|
234
|
+
setMessagePin(groupId: string, key: MessageKey, pinned: boolean): Promise<void>;
|
|
235
|
+
updateParticipant(groupId: string, memberId: string, action: ParticipantAction): Promise<ParticipantUpdateResult>;
|
|
236
|
+
setPresence(chatId: string, state: PresenceState): Promise<void>;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
declare class GroupService {
|
|
240
|
+
#private;
|
|
241
|
+
constructor(provider: WhatsAppProvider, cache: CacheStore, ttlMs?: number);
|
|
242
|
+
open(groupId: string): Promise<ChangeResult<'open' | 'already_open'>>;
|
|
243
|
+
close(groupId: string): Promise<ChangeResult<'closed' | 'already_closed'>>;
|
|
244
|
+
invite(groupId: string): Promise<InviteResult>;
|
|
245
|
+
revokeInvite(groupId: string): Promise<InviteResult>;
|
|
246
|
+
pin(groupId: string, key: MessageKey): Promise<ChangeResult<'pinned'>>;
|
|
247
|
+
unpin(groupId: string, key: MessageKey): Promise<ChangeResult<'unpinned'>>;
|
|
248
|
+
metadata(groupId: string, refresh?: boolean): Promise<GroupSnapshot>;
|
|
249
|
+
isAdmin(groupId: string, memberIds: string | readonly string[]): Promise<boolean>;
|
|
250
|
+
isCurrentUserAdmin(groupId: string): Promise<boolean>;
|
|
251
|
+
resolveUser(groupId: string, user: User): Promise<User>;
|
|
252
|
+
invalidate(groupId: string): Promise<void>;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
interface RouterOptions {
|
|
256
|
+
prefix?: string;
|
|
257
|
+
onError?: (error: WhaNextError, message: Message) => void | Promise<void>;
|
|
258
|
+
}
|
|
259
|
+
declare class CommandRouter {
|
|
260
|
+
#private;
|
|
261
|
+
constructor(group: GroupService, options?: RouterOptions);
|
|
262
|
+
command(definition: CommandDefinition): this;
|
|
263
|
+
dispatch(message: Message): Promise<boolean>;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent';
|
|
267
|
+
type LogFormat = 'pretty' | 'json';
|
|
268
|
+
type LogContext = Readonly<Record<string, unknown>>;
|
|
269
|
+
interface LogEntry {
|
|
270
|
+
timestamp: string;
|
|
271
|
+
level: Exclude<LogLevel, 'silent'>;
|
|
272
|
+
scope: string;
|
|
273
|
+
message: string;
|
|
274
|
+
context: LogContext;
|
|
275
|
+
}
|
|
276
|
+
type LogWriter = (entry: LogEntry) => unknown;
|
|
277
|
+
interface LoggerOptions {
|
|
278
|
+
level?: LogLevel;
|
|
279
|
+
format?: LogFormat;
|
|
280
|
+
writer?: LogWriter;
|
|
281
|
+
scope?: string;
|
|
282
|
+
redact?: readonly string[];
|
|
283
|
+
}
|
|
284
|
+
type LoggerConfig = LogLevel | LoggerOptions;
|
|
285
|
+
declare class Logger {
|
|
286
|
+
#private;
|
|
287
|
+
constructor(config?: LoggerConfig);
|
|
288
|
+
get level(): LogLevel;
|
|
289
|
+
setLevel(level: LogLevel): this;
|
|
290
|
+
isEnabled(level: Exclude<LogLevel, 'silent'>): boolean;
|
|
291
|
+
child(scope: string): Logger;
|
|
292
|
+
debug(message: string, context?: LogContext): void;
|
|
293
|
+
info(message: string, context?: LogContext): void;
|
|
294
|
+
warn(message: string, context?: LogContext): void;
|
|
295
|
+
error(message: string, context?: LogContext): void;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
interface StoredMute {
|
|
299
|
+
key: string;
|
|
300
|
+
groupId: string;
|
|
301
|
+
user: UserData;
|
|
302
|
+
identities: string[];
|
|
303
|
+
createdAt: number;
|
|
304
|
+
expiresAt: number | null;
|
|
305
|
+
}
|
|
306
|
+
interface MuteStore {
|
|
307
|
+
upsert(mute: StoredMute): void | Promise<void>;
|
|
308
|
+
find(groupId: string, identities: readonly string[]): StoredMute | undefined | Promise<StoredMute | undefined>;
|
|
309
|
+
delete(groupId: string, identities: readonly string[]): boolean | Promise<boolean>;
|
|
310
|
+
purgeExpired(now: number): number | Promise<number>;
|
|
311
|
+
close?(): void | Promise<void>;
|
|
312
|
+
}
|
|
313
|
+
interface MuteOptions {
|
|
314
|
+
enabled?: boolean;
|
|
315
|
+
store?: MuteStore;
|
|
316
|
+
database?: string;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
interface AddMuteOptions {
|
|
320
|
+
durationMs?: number;
|
|
321
|
+
}
|
|
322
|
+
interface MuteRecord {
|
|
323
|
+
groupId: string;
|
|
324
|
+
user: User;
|
|
325
|
+
createdAt: Date;
|
|
326
|
+
expiresAt: Date | null;
|
|
327
|
+
}
|
|
328
|
+
type AddMuteResult = {
|
|
329
|
+
ok: true;
|
|
330
|
+
changed: true;
|
|
331
|
+
state: 'muted' | 'updated';
|
|
332
|
+
record: MuteRecord;
|
|
333
|
+
} | {
|
|
334
|
+
ok: true;
|
|
335
|
+
changed: false;
|
|
336
|
+
state: 'already_muted';
|
|
337
|
+
record: MuteRecord;
|
|
338
|
+
};
|
|
339
|
+
type RemoveMuteResult = {
|
|
340
|
+
ok: true;
|
|
341
|
+
changed: true;
|
|
342
|
+
state: 'unmuted';
|
|
343
|
+
} | {
|
|
344
|
+
ok: true;
|
|
345
|
+
changed: false;
|
|
346
|
+
state: 'already_unmuted';
|
|
347
|
+
};
|
|
348
|
+
type MuteChangeResult = AddMuteResult | RemoveMuteResult;
|
|
349
|
+
interface MuteEnforcement {
|
|
350
|
+
message: Message;
|
|
351
|
+
record: MuteRecord;
|
|
352
|
+
}
|
|
353
|
+
declare class MuteService {
|
|
354
|
+
#private;
|
|
355
|
+
constructor(provider: WhatsAppProvider, store?: MuteStore);
|
|
356
|
+
get enabled(): boolean;
|
|
357
|
+
add(groupId: string, user: User, options?: AddMuteOptions): Promise<AddMuteResult>;
|
|
358
|
+
remove(groupId: string, user: User): Promise<RemoveMuteResult>;
|
|
359
|
+
get(groupId: string, user: User): Promise<MuteRecord | undefined>;
|
|
360
|
+
isMuted(groupId: string, user: User): Promise<boolean>;
|
|
361
|
+
enforce(message: Message): Promise<MuteEnforcement | undefined>;
|
|
362
|
+
purgeExpired(): Promise<number>;
|
|
363
|
+
close(): Promise<void>;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
declare class ChatService {
|
|
367
|
+
#private;
|
|
368
|
+
constructor(provider: WhatsAppProvider);
|
|
369
|
+
typing(chatId: string): Promise<void>;
|
|
370
|
+
recording(chatId: string): Promise<void>;
|
|
371
|
+
stop(chatId: string): Promise<void>;
|
|
372
|
+
stopTyping(chatId: string): Promise<void>;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
declare class MediaService {
|
|
376
|
+
#private;
|
|
377
|
+
constructor(provider: WhatsAppProvider);
|
|
378
|
+
image(chatId: string, content: ImageContent): Promise<SentMessage>;
|
|
379
|
+
video(chatId: string, content: VideoContent): Promise<SentMessage>;
|
|
380
|
+
audio(chatId: string, content: AudioContent): Promise<SentMessage>;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
declare class MemberService {
|
|
384
|
+
#private;
|
|
385
|
+
constructor(provider: WhatsAppProvider, group: GroupService);
|
|
386
|
+
remove(groupId: string, member: string | User): Promise<ChangeResult<MemberActionState>>;
|
|
387
|
+
promote(groupId: string, member: string | User): Promise<ChangeResult<MemberActionState>>;
|
|
388
|
+
demote(groupId: string, member: string | User): Promise<ChangeResult<MemberActionState>>;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
declare class MessageService {
|
|
392
|
+
#private;
|
|
393
|
+
constructor(provider: WhatsAppProvider);
|
|
394
|
+
send(chatId: string, content: MessageContent): Promise<SentMessage>;
|
|
395
|
+
reply(message: Message, content: MessageContent): Promise<SentMessage>;
|
|
396
|
+
edit(message: Message | SentMessage | MessageKey, text: string): Promise<SentMessage>;
|
|
397
|
+
delete(message: Message | SentMessage | MessageKey): Promise<void>;
|
|
398
|
+
text(chatId: string, text: string, mentions?: MentionTarget[]): Promise<SentMessage>;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
declare class UserService {
|
|
402
|
+
#private;
|
|
403
|
+
constructor(group: GroupService);
|
|
404
|
+
resolve(message: Message, args: ArgsParser): Promise<User>;
|
|
405
|
+
from(identity: string): User;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
interface AppEvents {
|
|
409
|
+
message: Message;
|
|
410
|
+
connection: ConnectionUpdate;
|
|
411
|
+
error: WhaNextError;
|
|
412
|
+
mute: MuteEnforcement;
|
|
413
|
+
}
|
|
414
|
+
interface LoginOptions {
|
|
415
|
+
onCode?: (code: string) => void | Promise<void>;
|
|
416
|
+
timeoutMs?: number;
|
|
417
|
+
}
|
|
418
|
+
type AppHealthStatus = 'idle' | 'starting' | 'ready' | 'stopped';
|
|
419
|
+
interface AppHealth {
|
|
420
|
+
status: AppHealthStatus;
|
|
421
|
+
state: ConnectionUpdate['state'];
|
|
422
|
+
ready: boolean;
|
|
423
|
+
uptimeMs: number;
|
|
424
|
+
timestamp: Date;
|
|
425
|
+
muteEnabled: boolean;
|
|
426
|
+
logLevel: LogLevel;
|
|
427
|
+
}
|
|
428
|
+
interface WhaNextAppOptions {
|
|
429
|
+
phone?: string;
|
|
430
|
+
prefix?: string;
|
|
431
|
+
cache?: CacheOptions;
|
|
432
|
+
logger?: LoggerConfig;
|
|
433
|
+
mute?: MuteOptions;
|
|
434
|
+
router?: Omit<RouterOptions, 'prefix'>;
|
|
435
|
+
}
|
|
436
|
+
declare class WhaNextApp {
|
|
437
|
+
#private;
|
|
438
|
+
readonly message: MessageService;
|
|
439
|
+
readonly media: MediaService;
|
|
440
|
+
readonly group: GroupService;
|
|
441
|
+
readonly member: MemberService;
|
|
442
|
+
readonly chat: ChatService;
|
|
443
|
+
readonly user: UserService;
|
|
444
|
+
readonly mute: MuteService;
|
|
445
|
+
readonly logger: Logger;
|
|
446
|
+
constructor(provider: WhatsAppProvider, options?: WhaNextAppOptions, logger?: Logger);
|
|
447
|
+
get state(): ConnectionUpdate['state'];
|
|
448
|
+
get isReady(): boolean;
|
|
449
|
+
health(): AppHealth;
|
|
450
|
+
router(): CommandRouter;
|
|
451
|
+
on<Event extends keyof AppEvents>(event: Event, listener: (payload: AppEvents[Event]) => void | Promise<void>): () => void;
|
|
452
|
+
login(options?: LoginOptions): Promise<void>;
|
|
453
|
+
disconnect(): Promise<void>;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
declare enum Browser {
|
|
457
|
+
Windows = "windows",
|
|
458
|
+
MacOS = "macos",
|
|
459
|
+
Ubuntu = "ubuntu"
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
interface ReconnectOptions {
|
|
463
|
+
enabled?: boolean;
|
|
464
|
+
maxAttempts?: number;
|
|
465
|
+
initialDelayMs?: number;
|
|
466
|
+
maxDelayMs?: number;
|
|
467
|
+
}
|
|
468
|
+
interface CreateOptions {
|
|
469
|
+
phone?: string;
|
|
470
|
+
browser?: Browser;
|
|
471
|
+
auth?: string;
|
|
472
|
+
prefix?: string;
|
|
473
|
+
cache?: CacheOptions;
|
|
474
|
+
logger?: LoggerConfig;
|
|
475
|
+
mute?: MuteOptions;
|
|
476
|
+
router?: Omit<RouterOptions, 'prefix'>;
|
|
477
|
+
reconnect?: ReconnectOptions;
|
|
478
|
+
provider?: WhatsAppProvider;
|
|
479
|
+
}
|
|
480
|
+
declare function create(options?: CreateOptions): Promise<WhaNextApp>;
|
|
481
|
+
|
|
482
|
+
declare class MemoryCache implements CacheStore {
|
|
483
|
+
#private;
|
|
484
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
485
|
+
set<T>(key: string, value: T, ttlMs?: number): Promise<void>;
|
|
486
|
+
delete(key: string): Promise<void>;
|
|
487
|
+
clear(): Promise<void>;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
declare class SqliteMuteStore implements MuteStore {
|
|
491
|
+
#private;
|
|
492
|
+
constructor(path?: string);
|
|
493
|
+
upsert(mute: StoredMute): void;
|
|
494
|
+
find(groupId: string, identities: readonly string[]): StoredMute | undefined;
|
|
495
|
+
delete(groupId: string, identities: readonly string[]): boolean;
|
|
496
|
+
purgeExpired(now: number): number;
|
|
497
|
+
close(): void;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
export { type AddMuteOptions, type AddMuteResult, type AppEvents, type AppHealth, type AppHealthStatus, ArgsParser, type AudioContent, Browser, type CacheOptions, type CacheStore, type ChangeResult, type CommandDefinition, CommandRouter, type ConnectionState, type ConnectionUpdate, type CreateOptions, type GroupAccess, type GroupAddressingMode, type GroupParticipant, type GroupRole, type GroupSnapshot, type ImageContent, type InviteResult, type LogContext, type LogEntry, type LogFormat, type LogLevel, type LogWriter, Logger, type LoggerConfig, type LoggerOptions, type LoginOptions, type MediaKind, type MediaSource, type MemberActionState, MemoryCache, type MentionTarget, type Message, type MessageContent, type MessageKey, type MessageMedia, type MuteChangeResult, type MuteEnforcement, type MuteOptions, type MuteRecord, MuteService, type MuteStore, type ParticipantUpdateResult, type PresenceState, type QuotedMessage, type ReconnectOptions, type RemoveMuteResult, type RouterOptions, type SentMessage, SqliteMuteStore, type StoredMute, type TextContent, User, type UserData, type VideoContent, WhaNextApp, WhaNextError, type WhaNextErrorCode, type WhatsAppProvider, create, defineCommand, toWhaNextError };
|