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
package/README.md CHANGED
@@ -235,6 +235,11 @@ Zaileys ships dual ESM/CJS entry points with type declarations for both module s
235
235
 
236
236
  Package managers: **npm**, **pnpm**, **yarn**, and **bun** are all supported.
237
237
 
238
+ ### Bundling & typecheck troubleshooting
239
+
240
+ - **`bun build` fails with "Browser build cannot import Node.js builtin"** — Zaileys (and baileys underneath) is a Node-only library; bun's bundler defaults to a browser target. Pass the target explicitly: `bun build index.ts --target bun` (or `--target node`).
241
+ - **`tsc` reports errors inside `node_modules` (`ws`, `thread-stream`, `whatsapp-rust-bridge`)** — upstream declaration issues, not yours. Set `"skipLibCheck": true` in your `tsconfig.json`.
242
+
238
243
  ## Documentation
239
244
 
240
245
  - 🌐 [**zeative.github.io/zaileys**](https://zeative.github.io/zaileys/) — full documentation site: guides, API reference, recipes
@@ -0,0 +1,9 @@
1
+ import { type ConvexKvOptions } from '../../types/convex.js';
2
+ import type { AuthCredsStore, AuthStore, AuthStoreBundle } from '../types.js';
3
+ export type ConvexAuthStoreOptions = ConvexKvOptions;
4
+ export declare class ConvexAuthStore implements AuthStoreBundle {
5
+ readonly creds: AuthCredsStore;
6
+ readonly signal: AuthStore;
7
+ private readonly kv;
8
+ constructor(options: ConvexAuthStoreOptions);
9
+ }
@@ -0,0 +1,16 @@
1
+ import type { AuthCredsStore, AuthStore, AuthStoreBundle } from '../types.js';
2
+ export interface FileAuthStoreOptions {
3
+ basePath?: string;
4
+ }
5
+ export declare class FileAuthStore implements AuthStoreBundle {
6
+ private readonly basePath;
7
+ private closed;
8
+ constructor(options?: FileAuthStoreOptions);
9
+ readonly signal: AuthStore;
10
+ readonly creds: AuthCredsStore;
11
+ private credsPath;
12
+ private signalDir;
13
+ private signalPath;
14
+ private atomicWrite;
15
+ private assertOpen;
16
+ }
@@ -0,0 +1,6 @@
1
+ export * from './memory.js';
2
+ export * from './file.js';
3
+ export * from './sqlite.js';
4
+ export * from './postgres.js';
5
+ export * from './redis.js';
6
+ export * from './convex.js';
@@ -0,0 +1,9 @@
1
+ import type { AuthCredsStore, AuthStore, AuthStoreBundle } from '../types.js';
2
+ export declare class MemoryAuthStore implements AuthStoreBundle {
3
+ private credsBlob;
4
+ private readonly signalMap;
5
+ private closed;
6
+ readonly signal: AuthStore;
7
+ readonly creds: AuthCredsStore;
8
+ private assertOpen;
9
+ }
@@ -0,0 +1,20 @@
1
+ import type { PgPoolLike } from '../../types/optional-clients.js';
2
+ import type { AuthCredsStore, AuthStore, AuthStoreBundle } from '../types.js';
3
+ export interface PostgresAuthStoreOptions {
4
+ pool?: PgPoolLike;
5
+ connectionString?: string;
6
+ max?: number;
7
+ }
8
+ export declare class PostgresAuthStore implements AuthStoreBundle {
9
+ private readonly externalPool;
10
+ private readonly connectionString;
11
+ private readonly poolMax;
12
+ private ownedPool;
13
+ private resolvedPool;
14
+ private readyPromise;
15
+ private closed;
16
+ constructor(options: PostgresAuthStoreOptions);
17
+ private ensureReady;
18
+ readonly signal: AuthStore;
19
+ readonly creds: AuthCredsStore;
20
+ }
@@ -0,0 +1,27 @@
1
+ import type { RedisClientLike } from '../../types/optional-clients.js';
2
+ import type { AuthCredsStore, AuthStore, AuthStoreBundle } from '../types.js';
3
+ export interface RedisAuthStoreOptions {
4
+ client?: RedisClientLike;
5
+ url?: string;
6
+ namespace?: string;
7
+ }
8
+ export declare class RedisAuthStore implements AuthStoreBundle {
9
+ private readonly namespace;
10
+ private readonly externalClient;
11
+ private readonly url;
12
+ private ownedClient;
13
+ private ready;
14
+ private closed;
15
+ constructor(options: RedisAuthStoreOptions);
16
+ readonly signal: AuthStore;
17
+ readonly creds: AuthCredsStore;
18
+ private credsKey;
19
+ private signalKey;
20
+ private indexKey;
21
+ private ensureReady;
22
+ private connect;
23
+ private runRead;
24
+ private runWrite;
25
+ private shutdown;
26
+ private assertOpen;
27
+ }
@@ -0,0 +1,19 @@
1
+ import type { AuthCredsStore, AuthStore, AuthStoreBundle } from '../types.js';
2
+ export interface SqliteAuthStoreOptions {
3
+ database: string | Buffer;
4
+ readonly?: boolean;
5
+ }
6
+ export declare class SqliteAuthStore implements AuthStoreBundle {
7
+ private readonly options;
8
+ private db;
9
+ private prepared;
10
+ private readyPromise;
11
+ private closed;
12
+ constructor(options: SqliteAuthStoreOptions);
13
+ readonly creds: AuthCredsStore;
14
+ readonly signal: AuthStore;
15
+ private ensureReady;
16
+ private openAndMigrate;
17
+ private encodeBlob;
18
+ private parseBlob;
19
+ }
@@ -0,0 +1,11 @@
1
+ import type { AuthStoreBundle } from './types.js';
2
+ export interface CacheableAuthStoreOptions {
3
+ logger?: {
4
+ trace?: (msg: unknown) => void;
5
+ debug?: (msg: unknown) => void;
6
+ info?: (msg: unknown) => void;
7
+ warn?: (msg: unknown) => void;
8
+ error?: (msg: unknown) => void;
9
+ };
10
+ }
11
+ export declare function makeCacheableAuthStore(bundle: AuthStoreBundle, options?: CacheableAuthStoreOptions): AuthStoreBundle;
@@ -0,0 +1,3 @@
1
+ export * from './types.js';
2
+ export * from './adapters/index.js';
3
+ export * from './cache.js';
@@ -0,0 +1,21 @@
1
+ import type { AuthenticationCreds, SignalDataSet, SignalDataTypeMap } from 'baileys';
2
+ export type AuthStoreKey = keyof SignalDataTypeMap;
3
+ export type AuthStoreValue<K extends AuthStoreKey> = SignalDataTypeMap[K];
4
+ export interface AuthStore {
5
+ read<K extends AuthStoreKey>(type: K, ids: readonly string[]): Promise<{
6
+ [id: string]: AuthStoreValue<K> | undefined;
7
+ }>;
8
+ write(data: SignalDataSet): Promise<void>;
9
+ delete<K extends AuthStoreKey>(type: K, ids: readonly string[]): Promise<void>;
10
+ clear(): Promise<void>;
11
+ close(): Promise<void>;
12
+ }
13
+ export interface AuthCredsStore {
14
+ readCreds(): Promise<AuthenticationCreds | undefined>;
15
+ writeCreds(creds: AuthenticationCreds): Promise<void>;
16
+ deleteCreds(): Promise<void>;
17
+ }
18
+ export interface AuthStoreBundle {
19
+ readonly creds: AuthCredsStore;
20
+ readonly signal: AuthStore;
21
+ }
@@ -0,0 +1,30 @@
1
+ import type { Logger } from '../client/types.js';
2
+ import type { MessageStore, PruneOptions } from '../store/types.js';
3
+ export type AutoDeleteOptions = {
4
+ maxAgeMs?: number;
5
+ maxPerChat?: number;
6
+ intervalMs?: number;
7
+ chats?: 'all' | ((jid: string) => boolean);
8
+ };
9
+ export declare function genericPrune(store: MessageStore, opts: PruneOptions): Promise<number>;
10
+ export declare class AutoDeleteSweeper {
11
+ private readonly store;
12
+ private readonly options;
13
+ private readonly logger;
14
+ private readonly now;
15
+ private timer;
16
+ private running;
17
+ private warnedUnsupported;
18
+ private disabled;
19
+ constructor(deps: {
20
+ store: MessageStore;
21
+ options: AutoDeleteOptions;
22
+ logger?: Logger;
23
+ now?: () => number;
24
+ });
25
+ private get active();
26
+ private buildPruneOptions;
27
+ runOnce(): Promise<number>;
28
+ start(): void;
29
+ stop(): void;
30
+ }
@@ -0,0 +1,10 @@
1
+ import type { MessageBuilder } from '../builder/builder.js';
2
+ import { RateLimiter } from './rate-limiter.js';
3
+ import type { BroadcastOptions, BroadcastResult } from './types.js';
4
+ export type BroadcastDeps = {
5
+ sendTo: (jid: string) => MessageBuilder<'init'>;
6
+ limiter?: RateLimiter;
7
+ now?: () => number;
8
+ sleep?: (ms: number) => Promise<void>;
9
+ };
10
+ export declare function runBroadcast(jids: string[], build: (b: MessageBuilder<'init'>) => MessageBuilder<'content-set'>, deps: BroadcastDeps, options?: BroadcastOptions): Promise<BroadcastResult>;
@@ -0,0 +1,8 @@
1
+ export type AutomationErrorCode = 'NOT_CONNECTED' | 'RATE_LIMIT_INVALID' | 'TASK_FAILED' | 'SCHEDULE_INVALID' | 'STORE_UNAVAILABLE' | 'PRESENCE_FAILED';
2
+ export declare class ZaileysAutomationError extends Error {
3
+ readonly code: AutomationErrorCode;
4
+ readonly cause?: unknown;
5
+ constructor(code: AutomationErrorCode, message: string, options?: {
6
+ cause?: unknown;
7
+ });
8
+ }
@@ -0,0 +1,11 @@
1
+ export * from './types.js';
2
+ export * from './errors.js';
3
+ export { RateLimiter, type RateLimiterClock } from './rate-limiter.js';
4
+ export { createOperationGuard, type OperationGuard, type OperationGuardOptions, type OperationGuardClock, type OperationCategory, } from './operation-guard.js';
5
+ export { TaskQueue, type TaskQueueClock } from './queue.js';
6
+ export { runBroadcast, type BroadcastDeps } from './broadcast.js';
7
+ export { PresenceModule, type AutomationSocketLike, type WAPresence, type PresenceThrottleOptions, type PresenceClock, } from './presence.js';
8
+ export { Scheduler, type SchedulerDeps, type SchedulerTimer, type ScheduleHandle, type ScheduledContentSnapshot, } from './schedule.js';
9
+ export type { ScheduledJobRecord } from '../store/types.js';
10
+ export { AutoDeleteSweeper, genericPrune } from './auto-delete.js';
11
+ export type { AutoDeleteOptions } from './auto-delete.js';
@@ -0,0 +1,20 @@
1
+ export type OperationGuardClock = {
2
+ now?: () => number;
3
+ sleep?: (ms: number) => Promise<void>;
4
+ };
5
+ /**
6
+ * Per-category minimum-interval throttle for sensitive account operations
7
+ * (group/community/newsletter create, join, member changes). Spacing these out
8
+ * avoids the rapid-fire pattern WhatsApp flags as automated/bulk abuse.
9
+ */
10
+ export type OperationCategory = 'group.create' | 'group.join' | 'group.participants' | 'group.update' | 'community.create' | 'community.join' | 'community.update' | 'newsletter.create' | 'newsletter.follow' | 'newsletter.update';
11
+ export interface OperationGuardOptions {
12
+ /** Master switch. When `false` operations run with no spacing. Default `true`. */
13
+ enabled?: boolean;
14
+ /** Per-category minimum interval in ms, overriding the built-in defaults. */
15
+ intervalsMs?: Partial<Record<OperationCategory, number>>;
16
+ }
17
+ export interface OperationGuard {
18
+ run<T>(category: OperationCategory, op: () => Promise<T>): Promise<T>;
19
+ }
20
+ export declare function createOperationGuard(options?: OperationGuardOptions, clock?: OperationGuardClock): OperationGuard;
@@ -0,0 +1,28 @@
1
+ export type WAPresence = 'unavailable' | 'available' | 'composing' | 'recording' | 'paused';
2
+ export interface AutomationSocketLike {
3
+ sendPresenceUpdate(type: WAPresence, toJid?: string): Promise<void>;
4
+ }
5
+ /** Drops presence updates that repeat the same (type, chat) inside `minIntervalMs`. */
6
+ export interface PresenceThrottleOptions {
7
+ enabled?: boolean;
8
+ minIntervalMs?: number;
9
+ }
10
+ export type PresenceClock = {
11
+ now?: () => number;
12
+ };
13
+ export declare class PresenceModule {
14
+ private readonly getSocket;
15
+ private readonly throttleEnabled;
16
+ private readonly minIntervalMs;
17
+ private readonly now;
18
+ private readonly lastSent;
19
+ constructor(getSocket: () => AutomationSocketLike | undefined, throttle?: PresenceThrottleOptions, clock?: PresenceClock);
20
+ protected requireSocket(): AutomationSocketLike;
21
+ private throttled;
22
+ private update;
23
+ private scheduleClear;
24
+ online(): Promise<void>;
25
+ offline(): Promise<void>;
26
+ typing(jid: string, ms?: number): Promise<void>;
27
+ recording(jid: string, ms?: number): Promise<void>;
28
+ }
@@ -0,0 +1,18 @@
1
+ import type { TaskQueueOptions } from './types.js';
2
+ export type TaskQueueClock = {
3
+ sleep?: (ms: number) => Promise<void>;
4
+ };
5
+ export declare class TaskQueue {
6
+ private readonly concurrency;
7
+ private readonly retry;
8
+ private readonly sleep;
9
+ private readonly pending;
10
+ private active;
11
+ private idleWaiters;
12
+ constructor(options?: TaskQueueOptions, clock?: TaskQueueClock);
13
+ add<T>(task: () => Promise<T>): Promise<T>;
14
+ onIdle(): Promise<void>;
15
+ private pump;
16
+ private settleIdle;
17
+ private execute;
18
+ }
@@ -0,0 +1,18 @@
1
+ import type { RateLimiterOptions } from './types.js';
2
+ export type RateLimiterClock = {
3
+ now?: () => number;
4
+ sleep?: (ms: number) => Promise<void>;
5
+ };
6
+ export declare class RateLimiter {
7
+ private readonly now;
8
+ private readonly sleep;
9
+ private readonly perJidRatePerMs?;
10
+ private readonly perJidCapacity?;
11
+ private readonly global;
12
+ private readonly perJid;
13
+ constructor(options: RateLimiterOptions, clock?: RateLimiterClock);
14
+ acquire(jid?: string): Promise<void>;
15
+ private bucketFor;
16
+ private consume;
17
+ private refill;
18
+ }
@@ -0,0 +1,45 @@
1
+ import type { AnyMessageContent, MiscMessageGenerationOptions } from 'baileys';
2
+ import { MessageBuilder } from '../builder/builder.js';
3
+ import type { MessageStore } from '../store/types.js';
4
+ import type { Logger } from '../client/types.js';
5
+ export type ScheduledContentSnapshot = {
6
+ recipient: string;
7
+ content: AnyMessageContent;
8
+ options?: MiscMessageGenerationOptions;
9
+ };
10
+ export type SchedulerTimer = {
11
+ set: (cb: () => void, ms: number) => unknown;
12
+ clear: (handle: unknown) => void;
13
+ };
14
+ export type SchedulerDeps = {
15
+ store: MessageStore;
16
+ sendSnapshot: (snapshot: ScheduledContentSnapshot) => Promise<void>;
17
+ now?: () => number;
18
+ timer?: SchedulerTimer;
19
+ logger?: Logger;
20
+ acquire?: () => Promise<void>;
21
+ };
22
+ export type ScheduleHandle = {
23
+ id: string;
24
+ cancel(): void;
25
+ };
26
+ export declare class Scheduler {
27
+ private readonly store;
28
+ private readonly sendSnapshot;
29
+ private readonly now;
30
+ private readonly timer;
31
+ private readonly logger;
32
+ private readonly acquire;
33
+ private readonly memory;
34
+ private readonly timers;
35
+ constructor(deps: SchedulerDeps);
36
+ scheduleAt(date: Date, build: (b: MessageBuilder<'init'>) => MessageBuilder<'content-set'>): Promise<ScheduleHandle>;
37
+ loadPending(): Promise<void>;
38
+ dispose(): void;
39
+ private cancel;
40
+ private arm;
41
+ private fire;
42
+ private persist;
43
+ private remove;
44
+ private evaluate;
45
+ }
@@ -0,0 +1,31 @@
1
+ export type RateLimiterOptions = {
2
+ perSec: number;
3
+ perJidPerSec?: number;
4
+ burst?: number;
5
+ };
6
+ export type RetryPolicy = {
7
+ maxRetries: number;
8
+ backoffMs: (attempt: number) => number;
9
+ };
10
+ export type TaskQueueOptions = {
11
+ concurrency?: number;
12
+ retry?: RetryPolicy;
13
+ };
14
+ export type BroadcastOptions = {
15
+ rateLimitPerSec?: number;
16
+ retry?: RetryPolicy;
17
+ onProgress?: (done: number, total: number, jid: string, ok: boolean) => void;
18
+ };
19
+ export type BroadcastResult = {
20
+ sent: string[];
21
+ failed: {
22
+ jid: string;
23
+ error: Error;
24
+ }[];
25
+ };
26
+ export type ScheduledJob = {
27
+ id: string;
28
+ fireAt: number;
29
+ recipient: string;
30
+ payload: unknown;
31
+ };
@@ -0,0 +1,4 @@
1
+ import type { WAMessageKey } from 'baileys';
2
+ import type { BuilderSocketLike } from './builder.js';
3
+ import type { AlbumItem, BuilderContext } from './types.js';
4
+ export declare const sendAlbum: (socket: BuilderSocketLike, recipient: string, items: AlbumItem[], context: BuilderContext) => Promise<WAMessageKey>;
@@ -0,0 +1,59 @@
1
+ import { type AnyMessageContent, type MiscMessageGenerationOptions, type WAMessage, type WAMessageKey } from 'baileys';
2
+ import { type ButtonsContentOptions } from './content/buttons.js';
3
+ import { type CarouselCard } from './content/carousel.js';
4
+ import { type AIRichOptions } from './content/airich.js';
5
+ import { type BuilderInternalState } from './state.js';
6
+ import type { AlbumItem, AudioOptions, BuilderState, ButtonDef, DocumentOptions, EventOptions, GroupInviteOptions, ImageOptions, InteractiveButton, ListOptions, LocationOptions, MediaSource, PollOptions, ProductOptions, StickerOptions, TemplateOptions, VideoNoteOptions, VideoOptions } from './types.js';
7
+ export interface BuilderSocketLike {
8
+ sendMessage(jid: string, content: AnyMessageContent, options?: MiscMessageGenerationOptions): Promise<WAMessage | undefined>;
9
+ relayMessage?(jid: string, message: unknown, options: {
10
+ messageId: string;
11
+ additionalNodes?: unknown[];
12
+ }): Promise<string>;
13
+ chatModify?(mod: unknown, jid: string): Promise<void>;
14
+ user?: {
15
+ id?: string | null;
16
+ } | null;
17
+ waUploadToServer?: unknown;
18
+ }
19
+ export type TextOptions = {
20
+ rich?: boolean;
21
+ } & AIRichOptions;
22
+ export declare class MessageBuilder<State extends BuilderState> {
23
+ protected readonly __state?: State;
24
+ protected readonly socket: BuilderSocketLike;
25
+ protected readonly internal: BuilderInternalState;
26
+ constructor(socket: BuilderSocketLike, internal: BuilderInternalState);
27
+ static create(socket: BuilderSocketLike, recipient: string, resolveRecipient?: (raw: string) => Promise<string>, recordSent?: (message: WAMessage) => void): MessageBuilder<'init'>;
28
+ to(this: MessageBuilder<'init'>, recipient: string): MessageBuilder<'init'>;
29
+ text(this: MessageBuilder<'init'>, content: string, opts?: TextOptions): MessageBuilder<'content-set'>;
30
+ image(this: MessageBuilder<'init'>, src: MediaSource, opts?: ImageOptions): MessageBuilder<'content-set'>;
31
+ videoNote(this: MessageBuilder<'init'>, src: MediaSource, opts?: VideoNoteOptions): MessageBuilder<'content-set'>;
32
+ video(this: MessageBuilder<'init'>, src: MediaSource, opts?: VideoOptions): MessageBuilder<'content-set'>;
33
+ audio(this: MessageBuilder<'init'>, src: MediaSource, opts?: AudioOptions): MessageBuilder<'content-set'>;
34
+ document(this: MessageBuilder<'init'>, src: MediaSource, opts: DocumentOptions): MessageBuilder<'content-set'>;
35
+ sticker(this: MessageBuilder<'init'>, src: MediaSource, opts?: StickerOptions): MessageBuilder<'content-set'>;
36
+ buttons(this: MessageBuilder<'init'>, buttons: Array<ButtonDef | InteractiveButton>, opts?: ButtonsContentOptions): MessageBuilder<'content-set'>;
37
+ carousel(this: MessageBuilder<'init'>, cards: CarouselCard[], opts?: {
38
+ text?: string;
39
+ }): MessageBuilder<'content-set'>;
40
+ list(this: MessageBuilder<'init'>, opts: ListOptions): MessageBuilder<'content-set'>;
41
+ poll(this: MessageBuilder<'init'>, question: string, options: string[], opts?: PollOptions): MessageBuilder<'content-set'>;
42
+ location(this: MessageBuilder<'init'>, lat: number, lon: number, opts?: LocationOptions): MessageBuilder<'content-set'>;
43
+ contact(this: MessageBuilder<'init'>, vcard: string): MessageBuilder<'content-set'>;
44
+ template(this: MessageBuilder<'init'>, opts: TemplateOptions): MessageBuilder<'content-set'>;
45
+ event(this: MessageBuilder<'init'>, opts: EventOptions): MessageBuilder<'content-set'>;
46
+ groupInvite(this: MessageBuilder<'init'>, opts: GroupInviteOptions): MessageBuilder<'content-set'>;
47
+ product(this: MessageBuilder<'init'>, opts: ProductOptions): MessageBuilder<'content-set'>;
48
+ requestPhoneNumber(this: MessageBuilder<'init'>): MessageBuilder<'content-set'>;
49
+ sharePhoneNumber(this: MessageBuilder<'init'>): MessageBuilder<'content-set'>;
50
+ limitSharing(this: MessageBuilder<'init'>, enabled?: boolean): MessageBuilder<'content-set'>;
51
+ album(this: MessageBuilder<'init'>, items: AlbumItem[]): MessageBuilder<'content-set'>;
52
+ reply(quoted: WAMessage | WAMessageKey): MessageBuilder<State>;
53
+ mentions(jids: string[]): MessageBuilder<State>;
54
+ mentionAll(): MessageBuilder<State>;
55
+ disappearing(seconds: number): MessageBuilder<State>;
56
+ then<T = WAMessageKey>(this: MessageBuilder<'content-set'>, onResolved: (key: WAMessageKey) => T, onRejected?: (err: unknown) => T | PromiseLike<T>): Promise<T>;
57
+ private uploadHeaderMedia;
58
+ private sendRelay;
59
+ }
@@ -0,0 +1,80 @@
1
+ import type { AnyMessageContent } from 'baileys';
2
+ export type AIRichPart = {
3
+ type: 'text';
4
+ text: string;
5
+ } | {
6
+ type: 'code';
7
+ language?: string;
8
+ content: string;
9
+ } | {
10
+ type: 'table';
11
+ rows: string[][];
12
+ } | {
13
+ type: 'image';
14
+ url: string | string[];
15
+ } | {
16
+ type: 'video';
17
+ url: string | string[];
18
+ duration?: number;
19
+ } | {
20
+ type: 'product';
21
+ products: AIRichProduct | AIRichProduct[];
22
+ } | {
23
+ type: 'reels';
24
+ reels: AIRichReel | AIRichReel[];
25
+ } | {
26
+ type: 'post';
27
+ posts: AIRichPost | AIRichPost[];
28
+ } | {
29
+ type: 'tip';
30
+ text: string;
31
+ } | {
32
+ type: 'suggest';
33
+ prompts: string | string[];
34
+ };
35
+ export type AIRichProduct = {
36
+ title: string;
37
+ price?: string;
38
+ salePrice?: string;
39
+ brand?: string;
40
+ url?: string;
41
+ image?: string;
42
+ icon?: string;
43
+ };
44
+ export type AIRichReel = {
45
+ username?: string;
46
+ title?: string;
47
+ profileUrl?: string;
48
+ thumbnail?: string;
49
+ url?: string;
50
+ likes?: number;
51
+ shares?: number;
52
+ views?: number;
53
+ source?: string;
54
+ verified?: boolean;
55
+ };
56
+ export type AIRichPost = {
57
+ title?: string;
58
+ subtitle?: string;
59
+ username?: string;
60
+ profileUrl?: string;
61
+ verified?: boolean;
62
+ thumbnail?: string;
63
+ caption?: string;
64
+ likes?: number;
65
+ comments?: number;
66
+ shares?: number;
67
+ url?: string;
68
+ deeplink?: string;
69
+ source?: string;
70
+ footer?: string;
71
+ icon?: string;
72
+ orientation?: string;
73
+ postType?: string;
74
+ };
75
+ export type AIRichOptions = {
76
+ title?: string;
77
+ footer?: string;
78
+ sources?: Array<[profileUrl: string, url: string, text: string]>;
79
+ };
80
+ export declare const buildAIRichContent: (parts: AIRichPart[], opts?: AIRichOptions) => AnyMessageContent;
@@ -0,0 +1,9 @@
1
+ import type { AnyMessageContent } from 'baileys';
2
+ import type { AudioOptions, MediaSource } from '../types.js';
3
+ export type AudioContent = {
4
+ audio: Buffer;
5
+ ptt?: boolean;
6
+ seconds?: number;
7
+ waveform?: Uint8Array;
8
+ };
9
+ export declare const buildAudioContent: (src: MediaSource, opts?: AudioOptions) => Promise<AnyMessageContent>;
@@ -0,0 +1,30 @@
1
+ import { proto, type AnyMessageContent } from 'baileys';
2
+ import type { BottomSheetOptions, ButtonDef, InteractiveButton, LimitedTimeOfferOptions, MediaSource } from '../types.js';
3
+ export declare const RELAY_CONTENT_KEY = "__zaileysRelayMessage";
4
+ export declare const RELAY_MEDIA_KEY = "__zaileysHeaderMedia";
5
+ export type HeaderMedia = {
6
+ kind: 'image' | 'video';
7
+ src: MediaSource;
8
+ };
9
+ export type RelayContent = {
10
+ [RELAY_CONTENT_KEY]: proto.IMessage;
11
+ [RELAY_MEDIA_KEY]?: HeaderMedia;
12
+ };
13
+ export type ButtonsContentOptions = {
14
+ text?: string;
15
+ footer?: string;
16
+ title?: string;
17
+ subtitle?: string;
18
+ image?: MediaSource;
19
+ video?: MediaSource;
20
+ bottomSheet?: BottomSheetOptions;
21
+ limitedTimeOffer?: LimitedTimeOfferOptions;
22
+ };
23
+ type NativeButton = {
24
+ name: string;
25
+ buttonParamsJson: string;
26
+ };
27
+ export declare const buildMessageParamsJson: (opts?: ButtonsContentOptions) => string;
28
+ export declare const buildNativeButtons: (buttons: Array<ButtonDef | InteractiveButton>) => NativeButton[];
29
+ export declare const buildButtonsContent: (buttons: Array<ButtonDef | InteractiveButton>, opts?: ButtonsContentOptions) => AnyMessageContent;
30
+ export {};
@@ -0,0 +1,19 @@
1
+ import { type AnyMessageContent } from 'baileys';
2
+ import type { ButtonDef, InteractiveButton, MediaSource } from '../types.js';
3
+ import { type HeaderMedia } from './buttons.js';
4
+ export declare const RELAY_CARDS_MEDIA_KEY = "__zaileysCardsMedia";
5
+ export type CardMedia = HeaderMedia & {
6
+ index: number;
7
+ };
8
+ export type CarouselCard = {
9
+ title?: string;
10
+ subtitle?: string;
11
+ body?: string;
12
+ footer?: string;
13
+ image?: MediaSource;
14
+ video?: MediaSource;
15
+ buttons?: Array<ButtonDef | InteractiveButton>;
16
+ };
17
+ export declare const buildCarouselContent: (cards: CarouselCard[], opts?: {
18
+ text?: string;
19
+ }) => AnyMessageContent;
@@ -0,0 +1,13 @@
1
+ import type { AnyMessageContent } from 'baileys';
2
+ export type ContactContentOptions = {
3
+ displayName?: string;
4
+ };
5
+ export type ContactContent = {
6
+ contacts: {
7
+ displayName?: string;
8
+ contacts: Array<{
9
+ vcard: string;
10
+ }>;
11
+ };
12
+ };
13
+ export declare const buildContactContent: (vcard: string, opts?: ContactContentOptions) => AnyMessageContent;
@@ -0,0 +1,9 @@
1
+ import type { AnyMessageContent } from 'baileys';
2
+ import type { DocumentOptions, MediaSource } from '../types.js';
3
+ export type DocumentContent = {
4
+ document: Buffer;
5
+ fileName: string;
6
+ mimetype: string;
7
+ caption?: string;
8
+ };
9
+ export declare const buildDocumentContent: (src: MediaSource, opts: DocumentOptions) => Promise<AnyMessageContent>;
@@ -0,0 +1,3 @@
1
+ import type { AnyMessageContent } from 'baileys';
2
+ import type { EventOptions } from '../types.js';
3
+ export declare const buildEventContent: (opts: EventOptions) => AnyMessageContent;
@@ -0,0 +1,3 @@
1
+ import type { AnyMessageContent } from 'baileys';
2
+ import type { GroupInviteOptions } from '../types.js';
3
+ export declare const buildGroupInviteContent: (opts: GroupInviteOptions) => AnyMessageContent;
@@ -0,0 +1,8 @@
1
+ import type { AnyMessageContent } from 'baileys';
2
+ import type { ImageOptions, MediaSource } from '../types.js';
3
+ export type ImageContent = {
4
+ image: Buffer;
5
+ caption?: string;
6
+ viewOnce?: boolean;
7
+ };
8
+ export declare const buildImageContent: (src: MediaSource, opts?: ImageOptions) => Promise<AnyMessageContent>;