zaileys 4.7.1 → 4.7.2

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.
Files changed (130) hide show
  1. package/README.md +5 -0
  2. package/dist/auth/adapters/convex.d.ts +9 -0
  3. package/dist/auth/adapters/file.d.ts +16 -0
  4. package/dist/auth/adapters/index.d.ts +6 -0
  5. package/dist/auth/adapters/memory.d.ts +9 -0
  6. package/dist/auth/adapters/postgres.d.ts +20 -0
  7. package/dist/auth/adapters/redis.d.ts +27 -0
  8. package/dist/auth/adapters/sqlite.d.ts +19 -0
  9. package/dist/auth/cache.d.ts +11 -0
  10. package/dist/auth/index.d.ts +3 -0
  11. package/dist/auth/types.d.ts +21 -0
  12. package/dist/automation/auto-delete.d.ts +30 -0
  13. package/dist/automation/broadcast.d.ts +10 -0
  14. package/dist/automation/errors.d.ts +8 -0
  15. package/dist/automation/index.d.ts +11 -0
  16. package/dist/automation/operation-guard.d.ts +20 -0
  17. package/dist/automation/presence.d.ts +28 -0
  18. package/dist/automation/queue.d.ts +18 -0
  19. package/dist/automation/rate-limiter.d.ts +18 -0
  20. package/dist/automation/schedule.d.ts +45 -0
  21. package/dist/automation/types.d.ts +31 -0
  22. package/dist/builder/album.d.ts +4 -0
  23. package/dist/builder/builder.d.ts +59 -0
  24. package/dist/builder/content/airich.d.ts +80 -0
  25. package/dist/builder/content/audio.d.ts +9 -0
  26. package/dist/builder/content/buttons.d.ts +30 -0
  27. package/dist/builder/content/carousel.d.ts +19 -0
  28. package/dist/builder/content/contact.d.ts +13 -0
  29. package/dist/builder/content/document.d.ts +9 -0
  30. package/dist/builder/content/event.d.ts +3 -0
  31. package/dist/builder/content/group-invite.d.ts +3 -0
  32. package/dist/builder/content/image.d.ts +8 -0
  33. package/dist/builder/content/list.d.ts +14 -0
  34. package/dist/builder/content/location.d.ts +11 -0
  35. package/dist/builder/content/markdown.d.ts +2 -0
  36. package/dist/builder/content/poll.d.ts +10 -0
  37. package/dist/builder/content/product.d.ts +3 -0
  38. package/dist/builder/content/sticker.d.ts +7 -0
  39. package/dist/builder/content/template.d.ts +3 -0
  40. package/dist/builder/content/text.d.ts +4 -0
  41. package/dist/builder/content/video.d.ts +10 -0
  42. package/dist/builder/edit-builder.d.ts +15 -0
  43. package/dist/builder/errors.d.ts +8 -0
  44. package/dist/builder/index.d.ts +6 -0
  45. package/dist/builder/media-loader.d.ts +11 -0
  46. package/dist/builder/mutations.d.ts +14 -0
  47. package/dist/builder/state.d.ts +15 -0
  48. package/dist/builder/types.d.ts +164 -0
  49. package/dist/builder/username-resolve.d.ts +8 -0
  50. package/dist/client/client.d.ts +130 -0
  51. package/dist/client/event-emitter.d.ts +19 -0
  52. package/dist/client/index.d.ts +3 -0
  53. package/dist/client/types.d.ts +104 -0
  54. package/dist/command/dispatcher.d.ts +23 -0
  55. package/dist/command/errors.d.ts +8 -0
  56. package/dist/command/index.d.ts +7 -0
  57. package/dist/command/middleware.d.ts +2 -0
  58. package/dist/command/parser.d.ts +2 -0
  59. package/dist/command/registry.d.ts +13 -0
  60. package/dist/command/types.d.ts +30 -0
  61. package/dist/connection/auth-adapter.d.ts +4 -0
  62. package/dist/connection/auth-guard.d.ts +37 -0
  63. package/dist/connection/disconnect-reason.d.ts +6 -0
  64. package/dist/connection/index.d.ts +7 -0
  65. package/dist/connection/pairing-flow.d.ts +16 -0
  66. package/dist/connection/qr-terminal.d.ts +2 -0
  67. package/dist/connection/reconnect.d.ts +15 -0
  68. package/dist/connection/state-machine.d.ts +9 -0
  69. package/dist/connection/status-log.d.ts +25 -0
  70. package/dist/domain/business.d.ts +19 -0
  71. package/dist/domain/chat.d.ts +27 -0
  72. package/dist/domain/community.d.ts +28 -0
  73. package/dist/domain/contact.d.ts +21 -0
  74. package/dist/domain/errors.d.ts +8 -0
  75. package/dist/domain/group.d.ts +35 -0
  76. package/dist/domain/index.d.ts +11 -0
  77. package/dist/domain/newsletter.d.ts +35 -0
  78. package/dist/domain/privacy.d.ts +15 -0
  79. package/dist/domain/profile.d.ts +14 -0
  80. package/dist/domain/socket-like.d.ts +117 -0
  81. package/dist/domain/types.d.ts +24 -0
  82. package/dist/events/context.d.ts +238 -0
  83. package/dist/events/decoders/_media-download.d.ts +8 -0
  84. package/dist/events/decoders/_shared.d.ts +26 -0
  85. package/dist/events/decoders/calls.d.ts +11 -0
  86. package/dist/events/decoders/groups.d.ts +36 -0
  87. package/dist/events/decoders/interactive.d.ts +9 -0
  88. package/dist/events/decoders/lifecycle.d.ts +69 -0
  89. package/dist/events/decoders/messages.d.ts +30 -0
  90. package/dist/events/decoders/mutations.d.ts +24 -0
  91. package/dist/events/guards.d.ts +9 -0
  92. package/dist/events/index.d.ts +4 -0
  93. package/dist/events/pipeline.d.ts +37 -0
  94. package/dist/events/types.d.ts +187 -0
  95. package/dist/index.cjs +7 -7
  96. package/dist/index.d.ts +14 -2264
  97. package/dist/index.mjs +7 -7
  98. package/dist/media/ffmpeg/audio.d.ts +12 -0
  99. package/dist/media/ffmpeg/core.d.ts +67 -0
  100. package/dist/media/ffmpeg/document.d.ts +10 -0
  101. package/dist/media/ffmpeg/image.d.ts +7 -0
  102. package/dist/media/ffmpeg/index.d.ts +7 -0
  103. package/dist/media/ffmpeg/sticker.d.ts +14 -0
  104. package/dist/media/ffmpeg/transform.d.ts +2 -0
  105. package/dist/media/ffmpeg/video.d.ts +6 -0
  106. package/dist/media/index.d.ts +2 -0
  107. package/dist/media/media.d.ts +39 -0
  108. package/dist/plugin/index.d.ts +5 -0
  109. package/dist/plugin/loader.d.ts +30 -0
  110. package/dist/plugin/registry.d.ts +24 -0
  111. package/dist/plugin/types.d.ts +25 -0
  112. package/dist/store/adapters/convex.d.ts +33 -0
  113. package/dist/store/adapters/index.d.ts +5 -0
  114. package/dist/store/adapters/memory.d.ts +31 -0
  115. package/dist/store/adapters/postgres.d.ts +40 -0
  116. package/dist/store/adapters/redis.d.ts +49 -0
  117. package/dist/store/adapters/sqlite.d.ts +36 -0
  118. package/dist/store/index.d.ts +2 -0
  119. package/dist/store/types.d.ts +48 -0
  120. package/dist/types/convex.d.ts +35 -0
  121. package/dist/types/index.d.ts +4 -0
  122. package/dist/types/lid-mapping.d.ts +5 -0
  123. package/dist/types/optional-clients.d.ts +69 -0
  124. package/dist/types/store-error.d.ts +8 -0
  125. package/dist/utils/array.d.ts +1 -0
  126. package/dist/utils/index.d.ts +5 -0
  127. package/dist/utils/jid.d.ts +6 -0
  128. package/dist/utils/logger.d.ts +10 -0
  129. package/package.json +5 -7
  130. package/dist/index.d.cts +0 -2264
@@ -0,0 +1,14 @@
1
+ import { type AnyMessageContent } from 'baileys';
2
+ import type { ListOptions } from '../types.js';
3
+ export type ListContentRow = {
4
+ header: string;
5
+ title: string;
6
+ description: string;
7
+ id: string;
8
+ };
9
+ export type ListContentSection = {
10
+ title: string;
11
+ highlight_label: string;
12
+ rows: ListContentRow[];
13
+ };
14
+ export declare const buildListContent: (opts: ListOptions) => AnyMessageContent;
@@ -0,0 +1,11 @@
1
+ import type { AnyMessageContent } from 'baileys';
2
+ import type { LocationOptions } from '../types.js';
3
+ export type LocationContent = {
4
+ location: {
5
+ degreesLatitude: number;
6
+ degreesLongitude: number;
7
+ name?: string;
8
+ address?: string;
9
+ };
10
+ };
11
+ export declare const buildLocationContent: (lat: number, lon: number, opts?: LocationOptions) => AnyMessageContent;
@@ -0,0 +1,2 @@
1
+ import type { AIRichPart } from './airich.js';
2
+ export declare const parseRichMarkdown: (md: string) => AIRichPart[];
@@ -0,0 +1,10 @@
1
+ import type { AnyMessageContent } from 'baileys';
2
+ import type { PollOptions } from '../types.js';
3
+ export type PollContent = {
4
+ poll: {
5
+ name: string;
6
+ values: string[];
7
+ selectableCount: number;
8
+ };
9
+ };
10
+ export declare const buildPollContent: (question: string, options: string[], opts?: PollOptions) => AnyMessageContent;
@@ -0,0 +1,3 @@
1
+ import type { AnyMessageContent } from 'baileys';
2
+ import type { ProductOptions } from '../types.js';
3
+ export declare const buildProductContent: (opts: ProductOptions) => Promise<AnyMessageContent>;
@@ -0,0 +1,7 @@
1
+ import type { AnyMessageContent } from 'baileys';
2
+ import type { MediaSource, StickerOptions } from '../types.js';
3
+ export type StickerContent = {
4
+ sticker: Buffer;
5
+ isAnimated?: boolean;
6
+ };
7
+ export declare const buildStickerContent: (src: MediaSource, opts?: StickerOptions) => Promise<AnyMessageContent>;
@@ -0,0 +1,3 @@
1
+ import type { AnyMessageContent } from 'baileys';
2
+ import type { TemplateOptions } from '../types.js';
3
+ export declare const buildTemplateContent: (opts: TemplateOptions) => AnyMessageContent;
@@ -0,0 +1,4 @@
1
+ export type TextContent = {
2
+ text: string;
3
+ };
4
+ export declare const buildTextContent: (text: string) => TextContent;
@@ -0,0 +1,10 @@
1
+ import type { AnyMessageContent } from 'baileys';
2
+ import type { MediaSource, VideoOptions } from '../types.js';
3
+ export type VideoContent = {
4
+ video: Buffer;
5
+ caption?: string;
6
+ gifPlayback?: boolean;
7
+ viewOnce?: boolean;
8
+ ptv?: boolean;
9
+ };
10
+ export declare const buildVideoContent: (src: MediaSource, opts?: VideoOptions) => Promise<AnyMessageContent>;
@@ -0,0 +1,15 @@
1
+ import type { WAMessageKey } from 'baileys';
2
+ import type { BuilderSocketLike } from './builder.js';
3
+ import type { ImageOptions, MediaSource, VideoOptions } from './types.js';
4
+ export declare class EditBuilder {
5
+ private readonly socket;
6
+ private readonly key;
7
+ private content;
8
+ private pendingContent;
9
+ constructor(socket: BuilderSocketLike, key: WAMessageKey);
10
+ text(content: string): this;
11
+ image(src: MediaSource, opts?: ImageOptions): this;
12
+ video(src: MediaSource, opts?: VideoOptions): this;
13
+ then<T = WAMessageKey>(onResolved: (key: WAMessageKey) => T, onRejected?: (err: unknown) => T | PromiseLike<T>): Promise<T>;
14
+ private send;
15
+ }
@@ -0,0 +1,8 @@
1
+ export type BuilderErrorCode = 'MEDIA_LOAD_FAILED' | 'INVALID_RECIPIENT' | 'USERNAME_NOT_FOUND' | 'EMPTY_CONTENT' | 'INVALID_OPTIONS' | 'SEND_FAILED' | 'MESSAGE_NOT_FOUND';
2
+ export declare class ZaileysBuilderError extends Error {
3
+ readonly code: BuilderErrorCode;
4
+ readonly cause?: unknown;
5
+ constructor(code: BuilderErrorCode, message: string, options?: {
6
+ cause?: unknown;
7
+ });
8
+ }
@@ -0,0 +1,6 @@
1
+ export * from './types.js';
2
+ export * from './errors.js';
3
+ export { MessageBuilder, type BuilderSocketLike, type TextOptions } from './builder.js';
4
+ export { EditBuilder } from './edit-builder.js';
5
+ export { deleteMessage, reactToMessage, forwardMessage, pinMessage, type DeleteOptions, type PinOptions, } from './mutations.js';
6
+ export { isJid, resolveUsername, type UsernameResolveSocketLike, } from './username-resolve.js';
@@ -0,0 +1,11 @@
1
+ import type { MediaSource } from './types.js';
2
+ export type LoadedMedia = {
3
+ buffer: Buffer;
4
+ mime: string;
5
+ size: number;
6
+ };
7
+ export type LoadMediaOptions = {
8
+ timeoutMs?: number;
9
+ };
10
+ export declare const detectMimeFromBuffer: (buffer: Buffer) => Promise<string>;
11
+ export declare const loadMedia: (src: MediaSource, options?: LoadMediaOptions) => Promise<LoadedMedia>;
@@ -0,0 +1,14 @@
1
+ import type { WAMessageKey } from 'baileys';
2
+ import type { MessageStore } from '../store/types.js';
3
+ import type { BuilderSocketLike } from './builder.js';
4
+ export type DeleteOptions = {
5
+ forEveryone?: boolean;
6
+ };
7
+ export type PinOptions = {
8
+ /** Pin duration in seconds (WhatsApp offers 86400 / 604800 / 2592000). Defaults to 24h. */
9
+ duration?: number;
10
+ };
11
+ export declare const deleteMessage: (socket: BuilderSocketLike, key: WAMessageKey, opts?: DeleteOptions) => Promise<void>;
12
+ export declare const reactToMessage: (socket: BuilderSocketLike, key: WAMessageKey, emoji: string) => Promise<WAMessageKey>;
13
+ export declare const forwardMessage: (socket: BuilderSocketLike, store: Pick<MessageStore, 'getMessage'>, key: WAMessageKey, to: string) => Promise<WAMessageKey>;
14
+ export declare const pinMessage: (socket: BuilderSocketLike, key: WAMessageKey, pin: boolean, opts?: PinOptions) => Promise<WAMessageKey>;
@@ -0,0 +1,15 @@
1
+ import type { AnyMessageContent, WAMessage, WAMessageKey } from 'baileys';
2
+ import type { AlbumItem } from './types.js';
3
+ export type BuilderInternalState = {
4
+ recipient: string;
5
+ content?: AnyMessageContent;
6
+ pendingContent?: Promise<AnyMessageContent>;
7
+ albumItems?: AlbumItem[];
8
+ quoted?: WAMessage | WAMessageKey;
9
+ mentions?: string[];
10
+ mentionAll?: boolean;
11
+ disappearingSeconds?: number;
12
+ resolveRecipient?: (raw: string) => Promise<string>;
13
+ recordSent?: (message: WAMessage) => void;
14
+ };
15
+ export declare const createInternalState: (recipient: string, resolveRecipient?: (raw: string) => Promise<string>, recordSent?: (message: WAMessage) => void) => BuilderInternalState;
@@ -0,0 +1,164 @@
1
+ import type { WAMessage, WAMessageKey } from 'baileys';
2
+ export type BuilderState = 'init' | 'content-set';
3
+ export type MediaSource = string | Buffer | URL;
4
+ export type ImageOptions = {
5
+ caption?: string;
6
+ viewOnce?: boolean;
7
+ };
8
+ export type VideoOptions = {
9
+ caption?: string;
10
+ gifPlayback?: boolean;
11
+ viewOnce?: boolean;
12
+ /** Send as a round video note (PTV). */
13
+ ptv?: boolean;
14
+ };
15
+ export type VideoNoteOptions = {
16
+ viewOnce?: boolean;
17
+ };
18
+ export type AudioOptions = {
19
+ ptt?: boolean;
20
+ seconds?: number;
21
+ };
22
+ export type DocumentOptions = {
23
+ fileName: string;
24
+ mimetype?: string;
25
+ caption?: string;
26
+ };
27
+ export type StickerOptions = {
28
+ animated?: boolean;
29
+ };
30
+ export type AlbumItem = {
31
+ type: 'image' | 'video';
32
+ src: MediaSource;
33
+ caption?: string;
34
+ };
35
+ export type ReplyButton = {
36
+ type?: 'reply';
37
+ id: string;
38
+ text: string;
39
+ };
40
+ export type UrlButton = {
41
+ type: 'url';
42
+ text: string;
43
+ url: string;
44
+ webview?: boolean;
45
+ };
46
+ export type CopyButton = {
47
+ type: 'copy';
48
+ text: string;
49
+ code: string;
50
+ };
51
+ export type CallButton = {
52
+ type: 'call';
53
+ text: string;
54
+ phone: string;
55
+ };
56
+ export type ReminderButton = {
57
+ type: 'reminder';
58
+ text: string;
59
+ id?: string;
60
+ };
61
+ export type CancelReminderButton = {
62
+ type: 'cancel-reminder';
63
+ text: string;
64
+ id?: string;
65
+ };
66
+ export type LocationRequestButton = {
67
+ type: 'location';
68
+ text?: string;
69
+ };
70
+ export type AddressButton = {
71
+ type: 'address';
72
+ text: string;
73
+ id?: string;
74
+ };
75
+ export type InteractiveButton = ReplyButton | UrlButton | CopyButton | CallButton | ReminderButton | CancelReminderButton | LocationRequestButton | AddressButton;
76
+ export type BottomSheetOptions = {
77
+ listTitle?: string;
78
+ buttonTitle?: string;
79
+ buttonsLimit?: number;
80
+ dividers?: number[];
81
+ };
82
+ export type LimitedTimeOfferOptions = {
83
+ text?: string;
84
+ url?: string;
85
+ copyCode?: string;
86
+ expiresAt?: number;
87
+ };
88
+ export type ButtonDef = {
89
+ id: string;
90
+ text: string;
91
+ };
92
+ export type ListSection = {
93
+ title: string;
94
+ rows: Array<{
95
+ id: string;
96
+ title: string;
97
+ description?: string;
98
+ }>;
99
+ };
100
+ export type ListOptions = {
101
+ title?: string;
102
+ description?: string;
103
+ buttonText: string;
104
+ footerText?: string;
105
+ sections: ListSection[];
106
+ };
107
+ export type PollOptions = {
108
+ multipleChoice?: boolean;
109
+ };
110
+ export type LocationOptions = {
111
+ name?: string;
112
+ address?: string;
113
+ };
114
+ export type TemplateOptions = {
115
+ header?: string;
116
+ body: string;
117
+ footer?: string;
118
+ buttons: ButtonDef[];
119
+ };
120
+ export type EventOptions = {
121
+ name: string;
122
+ description?: string;
123
+ startAt: Date | number;
124
+ endAt?: Date | number;
125
+ location?: {
126
+ latitude: number;
127
+ longitude: number;
128
+ name?: string;
129
+ address?: string;
130
+ };
131
+ call?: 'audio' | 'video';
132
+ canceled?: boolean;
133
+ };
134
+ export type ProductOptions = {
135
+ image: MediaSource;
136
+ title: string;
137
+ businessOwnerId: string;
138
+ description?: string;
139
+ /** Price in currency units (e.g. 50 = 50.00); mapped to priceAmount1000. */
140
+ price?: number;
141
+ currency?: string;
142
+ productId?: string;
143
+ retailerId?: string;
144
+ url?: string;
145
+ body?: string;
146
+ footer?: string;
147
+ };
148
+ export type GroupInviteOptions = {
149
+ jid: string;
150
+ code: string;
151
+ subject?: string;
152
+ caption?: string;
153
+ /** Unix seconds when the invite expires. Defaults to ~3 days from now. WhatsApp reads this as seconds. */
154
+ expiresAt?: number;
155
+ /** Optional JPEG thumbnail (group avatar) — improves how the card renders. */
156
+ thumbnail?: Buffer;
157
+ };
158
+ export type BuilderContext = {
159
+ recipient: string;
160
+ quoted?: WAMessage | WAMessageKey;
161
+ mentions?: string[];
162
+ mentionAll?: boolean;
163
+ disappearingSeconds?: number;
164
+ };
@@ -0,0 +1,8 @@
1
+ export interface UsernameResolveSocketLike {
2
+ onWhatsApp(...phoneNumber: string[]): Promise<Array<{
3
+ jid: string;
4
+ exists: boolean;
5
+ }> | undefined>;
6
+ }
7
+ export declare const isJid: (value: string) => boolean;
8
+ export declare const resolveUsername: (socket: UsernameResolveSocketLike, username: string, cache: Map<string, string>, inflight?: Map<string, Promise<string>>) => Promise<string>;
@@ -0,0 +1,130 @@
1
+ import { type WAMessageKey } from 'baileys';
2
+ import { EditBuilder, MessageBuilder, type DeleteOptions, type PinOptions } from '../builder/index.js';
3
+ import { CommunityModule, GroupModule, BusinessModule, ChatModule, ContactModule, NewsletterModule, PrivacyModule, ProfileModule } from '../domain/index.js';
4
+ import { type CommandHandler, type Middleware } from '../command/index.js';
5
+ import { PresenceModule, type BroadcastOptions, type BroadcastResult, type ScheduleHandle } from '../automation/index.js';
6
+ import type { MediaDownloadResult } from '../events/types.js';
7
+ import type { AuthStoreBundle } from '../auth/types.js';
8
+ import type { MessageStore } from '../store/types.js';
9
+ import { TypedEventEmitter } from './event-emitter.js';
10
+ import type { BaileysSocket, ClientEventMap, ClientOptions, ConnectionState } from './types.js';
11
+ export declare class Client extends TypedEventEmitter<ClientEventMap> {
12
+ readonly sessionId: string;
13
+ auth: AuthStoreBundle;
14
+ readonly store: MessageStore;
15
+ private readonly logger;
16
+ private readonly authType;
17
+ private readonly phoneNumber;
18
+ private readonly cacheSignal;
19
+ private readonly qrTerminal;
20
+ private readonly statusLog;
21
+ private readonly reconnectOptions;
22
+ private readonly baileysExtra;
23
+ private readonly machine;
24
+ private reconnectStrategy;
25
+ private readonly authGuard;
26
+ private readonly operationGuard;
27
+ private readonly presenceThrottle;
28
+ private readonly scheduleLimiter;
29
+ private authExhausted;
30
+ private _socket;
31
+ private reconnectTimer;
32
+ private listenerCleanup;
33
+ private inboundHandle;
34
+ private connectResolve;
35
+ private connectReject;
36
+ private pairingRequested;
37
+ private cachedSignalWrap;
38
+ private creds;
39
+ private credsLoadedAtConnect;
40
+ private openedThisRun;
41
+ private credsHintShown;
42
+ private postOpenLogoutRetries;
43
+ private disconnectEmittedFor;
44
+ private connectAttemptSeq;
45
+ private pendingDisconnectReason;
46
+ private readonly usernameCache;
47
+ private _group?;
48
+ private _privacy?;
49
+ private _newsletter?;
50
+ private _community?;
51
+ private _profile?;
52
+ private _chat?;
53
+ private _contact?;
54
+ private _business?;
55
+ private commandRegistry?;
56
+ private readonly commandMiddleware;
57
+ private readonly commandPrefixes;
58
+ private readonly citationConfig;
59
+ private readonly ignoreMe;
60
+ private commandDispatcher;
61
+ private _presence?;
62
+ private _scheduler?;
63
+ private readonly autoDeleteOptions;
64
+ private autoDeleteSweeper;
65
+ private readonly pluginsOptions;
66
+ private pluginRegistry;
67
+ private pluginLoader;
68
+ private waVersion?;
69
+ private versionWarming?;
70
+ constructor(options?: ClientOptions);
71
+ private warmVersion;
72
+ private emitAutoConnectError;
73
+ private logStatus;
74
+ private resolveMe;
75
+ get state(): ConnectionState;
76
+ get socket(): BaileysSocket | undefined;
77
+ get group(): GroupModule;
78
+ get privacy(): PrivacyModule;
79
+ get newsletter(): NewsletterModule;
80
+ get community(): CommunityModule;
81
+ get profile(): ProfileModule;
82
+ get chat(): ChatModule;
83
+ get contact(): ContactModule;
84
+ get business(): BusinessModule;
85
+ get presence(): PresenceModule;
86
+ broadcast(jids: string[], build: (b: MessageBuilder<'init'>) => MessageBuilder<'content-set'>, options?: BroadcastOptions): Promise<BroadcastResult>;
87
+ scheduleAt(date: Date, build: (b: MessageBuilder<'init'>) => MessageBuilder<'content-set'>): Promise<ScheduleHandle>;
88
+ private ensureScheduler;
89
+ private dispatchSnapshot;
90
+ connect(): Promise<void>;
91
+ disconnect(): Promise<void>;
92
+ logout(): Promise<void>;
93
+ command(spec: string, handler: CommandHandler): this;
94
+ unregisterCommand(spec: string): this;
95
+ use(middleware: Middleware): this;
96
+ unuse(middleware: Middleware): this;
97
+ private attachCommandsIfReady;
98
+ private buildCommandContext;
99
+ private detachCommands;
100
+ send(to: string): MessageBuilder<'init'>;
101
+ edit(key: WAMessageKey): EditBuilder;
102
+ delete(key: WAMessageKey, opts?: DeleteOptions): Promise<void>;
103
+ react(key: WAMessageKey, emoji: string): Promise<WAMessageKey>;
104
+ forward(key: WAMessageKey, to: string): Promise<WAMessageKey>;
105
+ pin(key: WAMessageKey, opts?: PinOptions): Promise<WAMessageKey>;
106
+ unpin(key: WAMessageKey): Promise<WAMessageKey>;
107
+ setDisappearing(to: string, seconds: number): Promise<void>;
108
+ private resolveRecipient;
109
+ private requireSocket;
110
+ private attachEmitterLogger;
111
+ private wireSocket;
112
+ private handleConnectionUpdate;
113
+ private handleQrUpdate;
114
+ private handleAuthExhausted;
115
+ private handleOpen;
116
+ private resolveMessageForResend;
117
+ private lidMapping;
118
+ /** Resolve a `@lid` JID to its phone-number JID (uses WhatsApp's LID mapping; may hit the network). */
119
+ lidToPn(lid: string): Promise<string | null>;
120
+ /** Resolve a phone-number JID to its `@lid` JID (uses WhatsApp's LID mapping; may hit the network). */
121
+ pnToLid(pn: string): Promise<string | null>;
122
+ /**
123
+ * Download media bytes for a message stored in the message store (by key).
124
+ * Tries both `fromMe` variants. `null` when the message is unknown or carries no media.
125
+ */
126
+ downloadMedia(key: WAMessageKey): Promise<MediaDownloadResult | null>;
127
+ private lookupQuoted;
128
+ private handleClose;
129
+ private rejectPendingConnect;
130
+ }
@@ -0,0 +1,19 @@
1
+ import type { Logger } from './types.js';
2
+ export interface TypedEventEmitterOptions {
3
+ logger?: Logger | undefined;
4
+ }
5
+ export declare class TypedEventEmitter<M extends Record<string, unknown>> {
6
+ private readonly inner;
7
+ protected readonly emitterLogger: Logger | undefined;
8
+ constructor(options?: TypedEventEmitterOptions);
9
+ on<E extends keyof M>(event: E, handler: (payload: M[E]) => void): () => void;
10
+ off<E extends keyof M>(event: E, handler: (payload: M[E]) => void): void;
11
+ emit<E extends keyof M>(event: E, payload: M[E]): void;
12
+ removeAllListeners(event?: keyof M): void;
13
+ listenerCount(event: keyof M): number;
14
+ private wrap;
15
+ private tag;
16
+ private untag;
17
+ private lookup;
18
+ private tagMap;
19
+ }
@@ -0,0 +1,3 @@
1
+ export * from './client.js';
2
+ export * from './event-emitter.js';
3
+ export * from './types.js';
@@ -0,0 +1,104 @@
1
+ import type { UserFacingSocketConfig, WASocket } from 'baileys';
2
+ import type { AuthStoreBundle } from '../auth/types.js';
3
+ import type { AutoDeleteOptions } from '../automation/auto-delete.js';
4
+ import type { OperationGuardOptions } from '../automation/operation-guard.js';
5
+ import type { PresenceThrottleOptions } from '../automation/presence.js';
6
+ import type { AuthGuardOptions } from '../connection/auth-guard.js';
7
+ import type { DisconnectReasonDomain } from '../connection/disconnect-reason.js';
8
+ import type { CitationConfig } from '../events/context.js';
9
+ import type { InboundEventMap } from '../events/types.js';
10
+ import type { MessageStore } from '../store/types.js';
11
+ import type { PluginsOptions } from '../plugin/types.js';
12
+ export type ConnectionState = 'idle' | 'connecting' | 'qr-pending' | 'pairing-pending' | 'connected' | 'reconnecting' | 'disconnecting' | 'disconnected';
13
+ export type ConnectionAuthType = 'qr' | 'pairing';
14
+ export interface Logger {
15
+ debug(...args: unknown[]): void;
16
+ info(...args: unknown[]): void;
17
+ warn(...args: unknown[]): void;
18
+ error(...args: unknown[]): void;
19
+ fatal(...args: unknown[]): void;
20
+ }
21
+ export interface ReconnectOptions {
22
+ enabled?: boolean;
23
+ maxAttempts?: number;
24
+ initialDelayMs?: number;
25
+ maxDelayMs?: number;
26
+ jitterFactor?: number;
27
+ /** Fixed backoff applied when the disconnect reason is `rate-limited` (429). Default `300000`. */
28
+ rateLimitedDelayMs?: number;
29
+ }
30
+ export interface ClientOptions {
31
+ sessionId?: string;
32
+ auth?: AuthStoreBundle;
33
+ store?: MessageStore;
34
+ authType?: ConnectionAuthType;
35
+ phoneNumber?: string;
36
+ logger?: Logger;
37
+ cacheSignal?: boolean;
38
+ reconnect?: ReconnectOptions;
39
+ qrTerminal?: boolean;
40
+ baileys?: Partial<UserFacingSocketConfig>;
41
+ autoConnect?: boolean;
42
+ statusLog?: boolean;
43
+ commandPrefix?: string | string[];
44
+ citation?: CitationConfig;
45
+ ignoreMe?: boolean;
46
+ /** Bounds QR/pairing regeneration to avoid spam restriction. ON by default; `{ enabled: false }` to opt out. */
47
+ authGuard?: AuthGuardOptions;
48
+ /** Spaces out sensitive group/community/newsletter operations. ON by default; `{ enabled: false }` to opt out. */
49
+ operationGuard?: OperationGuardOptions;
50
+ /** Drops duplicate presence (typing/recording/online) updates within a window. ON by default. */
51
+ presence?: PresenceThrottleOptions;
52
+ /** Max scheduled messages dispatched per second, smoothing backlog bursts. Default `1`; `0` disables. */
53
+ scheduleRateLimitPerSec?: number;
54
+ /** Periodically prune old messages from the store. Enabled by default with a 1-month `maxAgeMs`; pass `false` to disable or override any field. */
55
+ autoDelete?: AutoDeleteOptions | false;
56
+ /** Load and manage plugins from a directory. */
57
+ plugins?: PluginsOptions;
58
+ }
59
+ export type ConnectionEventMap = {
60
+ connect: {
61
+ sessionId: string;
62
+ me: {
63
+ id: string;
64
+ lid?: string;
65
+ name?: string;
66
+ };
67
+ };
68
+ disconnect: {
69
+ sessionId: string;
70
+ reason: DisconnectReasonDomain;
71
+ willReconnect: boolean;
72
+ };
73
+ qr: {
74
+ sessionId: string;
75
+ qrString: string;
76
+ expiresAt: number;
77
+ };
78
+ 'pairing-code': {
79
+ sessionId: string;
80
+ code: string;
81
+ expiresAt: number;
82
+ };
83
+ reconnecting: {
84
+ sessionId: string;
85
+ attempt: number;
86
+ delayMs: number;
87
+ reason: DisconnectReasonDomain;
88
+ };
89
+ 'auth-exhausted': {
90
+ sessionId: string;
91
+ kind: ConnectionAuthType;
92
+ attempts: number;
93
+ max: number;
94
+ };
95
+ error: {
96
+ sessionId: string;
97
+ error: Error;
98
+ };
99
+ };
100
+ export type ConnectionEventName = keyof ConnectionEventMap;
101
+ export type ConnectionEventHandler<E extends ConnectionEventName> = (payload: ConnectionEventMap[E]) => void;
102
+ export type ClientEventMap = ConnectionEventMap & InboundEventMap;
103
+ export type ClientEventName = keyof ClientEventMap;
104
+ export type BaileysSocket = WASocket;
@@ -0,0 +1,23 @@
1
+ import type { Logger } from '../client/types.js';
2
+ import type { MessageContext } from '../events/context.js';
3
+ import type { CommandRegistry } from './registry.js';
4
+ import type { CommandContext, Middleware } from './types.js';
5
+ export interface ResolvedCommand {
6
+ command: string;
7
+ args: string[];
8
+ flags: Record<string, string | boolean>;
9
+ json: unknown;
10
+ raw: string;
11
+ }
12
+ export interface DispatcherDeps {
13
+ registry: CommandRegistry;
14
+ middleware: Middleware[];
15
+ prefixes: string[];
16
+ onText: (handler: (msg: MessageContext) => void) => () => void;
17
+ buildContext: (resolved: ResolvedCommand, msg: MessageContext) => CommandContext;
18
+ logger: Logger;
19
+ }
20
+ export interface DispatcherHandle {
21
+ detach(): void;
22
+ }
23
+ export declare function attachCommandDispatcher(deps: DispatcherDeps): DispatcherHandle;
@@ -0,0 +1,8 @@
1
+ export type CommandErrorCode = 'DUPLICATE_COMMAND' | 'INVALID_COMMAND_NAME' | 'HANDLER_ERROR' | 'MIDDLEWARE_ERROR' | 'NO_SENT_MESSAGE' | 'NOT_CONNECTED';
2
+ export declare class ZaileysCommandError extends Error {
3
+ readonly code: CommandErrorCode;
4
+ readonly cause?: unknown;
5
+ constructor(code: CommandErrorCode, message: string, options?: {
6
+ cause?: unknown;
7
+ });
8
+ }
@@ -0,0 +1,7 @@
1
+ export * from './types.js';
2
+ export * from './errors.js';
3
+ export { parseCommand } from './parser.js';
4
+ export { CommandRegistry } from './registry.js';
5
+ export { runMiddleware } from './middleware.js';
6
+ export { attachCommandDispatcher } from './dispatcher.js';
7
+ export type { DispatcherDeps, DispatcherHandle, ResolvedCommand } from './dispatcher.js';
@@ -0,0 +1,2 @@
1
+ import type { CommandContext, Middleware } from './types.js';
2
+ export declare function runMiddleware(chain: Middleware[], ctx: CommandContext, final: () => Promise<void> | void): Promise<void>;
@@ -0,0 +1,2 @@
1
+ import type { ParsedArgs } from './types.js';
2
+ export declare function parseCommand(text: string, prefixes: string[]): ParsedArgs;
@@ -0,0 +1,13 @@
1
+ import type { CommandDefinition, CommandHandler, ParsedArgs } from './types.js';
2
+ export declare class CommandRegistry {
3
+ private readonly paths;
4
+ private readonly defs;
5
+ private maxDepth;
6
+ register(spec: string, handler: CommandHandler): void;
7
+ resolve(parsed: ParsedArgs): {
8
+ def: CommandDefinition;
9
+ args: string[];
10
+ } | undefined;
11
+ unregister(spec: string): void;
12
+ list(): CommandDefinition[];
13
+ }