zaileys 4.4.0 → 4.5.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/dist/index.cjs +20 -15
- package/dist/index.d.cts +86 -1
- package/dist/index.d.ts +86 -1
- package/dist/index.mjs +20 -15
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -289,6 +289,14 @@ type MessageStoreListOptions = {
|
|
|
289
289
|
limit?: number;
|
|
290
290
|
before?: number;
|
|
291
291
|
};
|
|
292
|
+
type PruneOptions = {
|
|
293
|
+
/** Delete messages whose `messageTimestamp` is strictly older than this epoch value, in **seconds** (matching stored `messageTimestamp`). */
|
|
294
|
+
olderThan?: number;
|
|
295
|
+
/** Keep only the newest N messages per chat. */
|
|
296
|
+
maxPerChat?: number;
|
|
297
|
+
/** Restrict pruning to chats whose jid passes this predicate. */
|
|
298
|
+
chatFilter?: (jid: string) => boolean;
|
|
299
|
+
};
|
|
292
300
|
type ScheduledJobRecord = {
|
|
293
301
|
id: string;
|
|
294
302
|
fireAt: number;
|
|
@@ -321,6 +329,8 @@ interface MessageStore {
|
|
|
321
329
|
saveScheduledJob?(job: ScheduledJobRecord): Promise<void>;
|
|
322
330
|
listScheduledJobs?(): Promise<ScheduledJobRecord[]>;
|
|
323
331
|
deleteScheduledJob?(id: string): Promise<void>;
|
|
332
|
+
deleteMessage?(key: WAMessageKey): Promise<void>;
|
|
333
|
+
pruneMessages?(opts: PruneOptions): Promise<number>;
|
|
324
334
|
}
|
|
325
335
|
|
|
326
336
|
type DeleteOptions = {
|
|
@@ -1163,6 +1173,7 @@ declare class CommandRegistry {
|
|
|
1163
1173
|
def: CommandDefinition;
|
|
1164
1174
|
args: string[];
|
|
1165
1175
|
} | undefined;
|
|
1176
|
+
unregister(spec: string): void;
|
|
1166
1177
|
list(): CommandDefinition[];
|
|
1167
1178
|
}
|
|
1168
1179
|
|
|
@@ -1189,6 +1200,35 @@ interface AuthStoreBundle {
|
|
|
1189
1200
|
readonly signal: AuthStore;
|
|
1190
1201
|
}
|
|
1191
1202
|
|
|
1203
|
+
type AutoDeleteOptions = {
|
|
1204
|
+
maxAgeMs?: number;
|
|
1205
|
+
maxPerChat?: number;
|
|
1206
|
+
intervalMs?: number;
|
|
1207
|
+
chats?: 'all' | ((jid: string) => boolean);
|
|
1208
|
+
};
|
|
1209
|
+
declare function genericPrune(store: MessageStore, opts: PruneOptions): Promise<number>;
|
|
1210
|
+
declare class AutoDeleteSweeper {
|
|
1211
|
+
private readonly store;
|
|
1212
|
+
private readonly options;
|
|
1213
|
+
private readonly logger;
|
|
1214
|
+
private readonly now;
|
|
1215
|
+
private timer;
|
|
1216
|
+
private running;
|
|
1217
|
+
private warnedUnsupported;
|
|
1218
|
+
private disabled;
|
|
1219
|
+
constructor(deps: {
|
|
1220
|
+
store: MessageStore;
|
|
1221
|
+
options: AutoDeleteOptions;
|
|
1222
|
+
logger?: Logger;
|
|
1223
|
+
now?: () => number;
|
|
1224
|
+
});
|
|
1225
|
+
private get active();
|
|
1226
|
+
private buildPruneOptions;
|
|
1227
|
+
runOnce(): Promise<number>;
|
|
1228
|
+
start(): void;
|
|
1229
|
+
stop(): void;
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1192
1232
|
type WAPresence = 'unavailable' | 'available' | 'composing' | 'recording' | 'paused';
|
|
1193
1233
|
interface AutomationSocketLike {
|
|
1194
1234
|
sendPresenceUpdate(type: WAPresence, toJid?: string): Promise<void>;
|
|
@@ -1262,6 +1302,29 @@ declare function isRateLimited(reason: DisconnectReasonDomain): boolean;
|
|
|
1262
1302
|
declare function shouldClearAuth(reason: DisconnectReasonDomain): boolean;
|
|
1263
1303
|
declare function shouldReconnect(reason: DisconnectReasonDomain): boolean;
|
|
1264
1304
|
|
|
1305
|
+
interface PluginContext {
|
|
1306
|
+
client: Client;
|
|
1307
|
+
logger: Logger | undefined;
|
|
1308
|
+
pluginDir: string;
|
|
1309
|
+
command(spec: string, handler: CommandHandler): void;
|
|
1310
|
+
use(middleware: Middleware): void;
|
|
1311
|
+
on<E extends keyof ClientEventMap>(event: E, handler: (payload: ClientEventMap[E]) => void): () => void;
|
|
1312
|
+
once<E extends keyof ClientEventMap>(event: E, handler: (payload: ClientEventMap[E]) => void): () => void;
|
|
1313
|
+
}
|
|
1314
|
+
interface Plugin {
|
|
1315
|
+
name: string;
|
|
1316
|
+
setup(ctx: PluginContext): void | (() => void) | Promise<void | (() => void)>;
|
|
1317
|
+
onUnload?(): void | Promise<void>;
|
|
1318
|
+
}
|
|
1319
|
+
type PluginsOptions = {
|
|
1320
|
+
dir?: string;
|
|
1321
|
+
watch?: boolean;
|
|
1322
|
+
pattern?: RegExp;
|
|
1323
|
+
ignore?: RegExp;
|
|
1324
|
+
onError?: (err: unknown, file: string) => void;
|
|
1325
|
+
};
|
|
1326
|
+
declare const definePlugin: (plugin: Plugin) => Plugin;
|
|
1327
|
+
|
|
1265
1328
|
type ConnectionState = 'idle' | 'connecting' | 'qr-pending' | 'pairing-pending' | 'connected' | 'reconnecting' | 'disconnecting' | 'disconnected';
|
|
1266
1329
|
type ConnectionAuthType = 'qr' | 'pairing';
|
|
1267
1330
|
interface Logger {
|
|
@@ -1304,6 +1367,10 @@ interface ClientOptions {
|
|
|
1304
1367
|
presence?: PresenceThrottleOptions;
|
|
1305
1368
|
/** Max scheduled messages dispatched per second, smoothing backlog bursts. Default `1`; `0` disables. */
|
|
1306
1369
|
scheduleRateLimitPerSec?: number;
|
|
1370
|
+
/** Periodically prune old messages from the store. Enabled by default with a 1-month `maxAgeMs`; pass `false` to disable or override any field. */
|
|
1371
|
+
autoDelete?: AutoDeleteOptions | false;
|
|
1372
|
+
/** Load and manage plugins from a directory. */
|
|
1373
|
+
plugins?: PluginsOptions;
|
|
1307
1374
|
}
|
|
1308
1375
|
type ConnectionEventMap = {
|
|
1309
1376
|
connect: {
|
|
@@ -1569,6 +1636,11 @@ declare class Client extends TypedEventEmitter<ClientEventMap> {
|
|
|
1569
1636
|
private commandDispatcher;
|
|
1570
1637
|
private _presence?;
|
|
1571
1638
|
private _scheduler?;
|
|
1639
|
+
private readonly autoDeleteOptions;
|
|
1640
|
+
private autoDeleteSweeper;
|
|
1641
|
+
private readonly pluginsOptions;
|
|
1642
|
+
private pluginRegistry;
|
|
1643
|
+
private pluginLoader;
|
|
1572
1644
|
private waVersion?;
|
|
1573
1645
|
private versionWarming?;
|
|
1574
1646
|
constructor(options?: ClientOptions);
|
|
@@ -1595,7 +1667,9 @@ declare class Client extends TypedEventEmitter<ClientEventMap> {
|
|
|
1595
1667
|
disconnect(): Promise<void>;
|
|
1596
1668
|
logout(): Promise<void>;
|
|
1597
1669
|
command(spec: string, handler: CommandHandler): this;
|
|
1670
|
+
unregisterCommand(spec: string): this;
|
|
1598
1671
|
use(middleware: Middleware): this;
|
|
1672
|
+
unuse(middleware: Middleware): this;
|
|
1599
1673
|
private attachCommandsIfReady;
|
|
1600
1674
|
private buildCommandContext;
|
|
1601
1675
|
private detachCommands;
|
|
@@ -1767,6 +1841,8 @@ declare class MemoryMessageStore implements MessageStore {
|
|
|
1767
1841
|
savePresence(jid: string, presence: PresenceData): Promise<void>;
|
|
1768
1842
|
getPresence(jid: string): Promise<PresenceData | undefined>;
|
|
1769
1843
|
bind(socket: BaileysSocketLike): void;
|
|
1844
|
+
deleteMessage(key: WAMessageKey): Promise<void>;
|
|
1845
|
+
pruneMessages(opts: PruneOptions): Promise<number>;
|
|
1770
1846
|
clear(): Promise<void>;
|
|
1771
1847
|
close(): Promise<void>;
|
|
1772
1848
|
private assertOpen;
|
|
@@ -1798,6 +1874,8 @@ declare class SqliteMessageStore implements MessageStore {
|
|
|
1798
1874
|
listContacts(): Promise<Contact[]>;
|
|
1799
1875
|
savePresence(jid: string, presence: PresenceData): Promise<void>;
|
|
1800
1876
|
getPresence(jid: string): Promise<PresenceData | undefined>;
|
|
1877
|
+
deleteMessage(key: WAMessageKey): Promise<void>;
|
|
1878
|
+
pruneMessages(opts: PruneOptions): Promise<number>;
|
|
1801
1879
|
bind(socket: BaileysSocketLike): void;
|
|
1802
1880
|
clear(): Promise<void>;
|
|
1803
1881
|
close(): Promise<void>;
|
|
@@ -1836,6 +1914,8 @@ declare class PostgresMessageStore implements MessageStore {
|
|
|
1836
1914
|
listContacts(): Promise<Contact[]>;
|
|
1837
1915
|
savePresence(jid: string, presence: PresenceData): Promise<void>;
|
|
1838
1916
|
getPresence(jid: string): Promise<PresenceData | undefined>;
|
|
1917
|
+
deleteMessage(key: WAMessageKey): Promise<void>;
|
|
1918
|
+
pruneMessages(opts: PruneOptions): Promise<number>;
|
|
1839
1919
|
bind(socket: BaileysSocketLike): void;
|
|
1840
1920
|
clear(): Promise<void>;
|
|
1841
1921
|
close(): Promise<void>;
|
|
@@ -1872,6 +1952,9 @@ declare class RedisMessageStore implements MessageStore {
|
|
|
1872
1952
|
bind(socket: BaileysSocketLike): void;
|
|
1873
1953
|
clear(): Promise<void>;
|
|
1874
1954
|
close(): Promise<void>;
|
|
1955
|
+
deleteMessage(key: WAMessageKey): Promise<void>;
|
|
1956
|
+
pruneMessages(opts: PruneOptions): Promise<number>;
|
|
1957
|
+
private jidFromIndexKey;
|
|
1875
1958
|
private msgIndexKey;
|
|
1876
1959
|
private msgDataKey;
|
|
1877
1960
|
private chatsKey;
|
|
@@ -1908,6 +1991,8 @@ declare class ConvexMessageStore implements MessageStore {
|
|
|
1908
1991
|
saveScheduledJob(job: ScheduledJobRecord): Promise<void>;
|
|
1909
1992
|
listScheduledJobs(): Promise<ScheduledJobRecord[]>;
|
|
1910
1993
|
deleteScheduledJob(id: string): Promise<void>;
|
|
1994
|
+
deleteMessage(key: WAMessageKey): Promise<void>;
|
|
1995
|
+
pruneMessages(opts: PruneOptions): Promise<number>;
|
|
1911
1996
|
bind(socket: BaileysSocketLike): void;
|
|
1912
1997
|
clear(): Promise<void>;
|
|
1913
1998
|
close(): Promise<void>;
|
|
@@ -2171,4 +2256,4 @@ declare class Media {
|
|
|
2171
2256
|
toBuffer(): Promise<Buffer>;
|
|
2172
2257
|
}
|
|
2173
2258
|
|
|
2174
|
-
export { type AddressButton, type AlbumItem, type AudioOptions, AudioProcessor, type AudioType, type AuthAttemptBlockReason, type AuthAttemptDecision, type AuthCredsStore, type AuthGuard, type AuthGuardOptions, type AuthStore, type AuthStoreBundle, type AuthStoreKey, type AuthStoreValue, type AutomationErrorCode, type AutomationSocketLike, type BaileysSocket, type BaileysSocketLike, type BottomSheetOptions, type BroadcastDeps, type BroadcastOptions, type BroadcastResult, BufferConverter, type BuildContextInput, type BuilderContext, type BuilderErrorCode, type BuilderSocketLike, type BuilderState, BusinessModule, type ButtonClickPayload, type ButtonDef, type CacheableAuthStoreOptions, type CallBase, type CallButton, type CallPayload, type CancelReminderButton, ChatModule, type ChatType, type CitationConfig, type CitationPredicates, Client, type ClientEventMap, type ClientEventName, type ClientOptions, type CommandContext, type CommandDefinition, type CommandErrorCode, type CommandHandler, type CommandPrefix, CommandRegistry, CommunityModule, type ConnectionAuthType, type ConnectionEventHandler, type ConnectionEventMap, type ConnectionEventName, type ConnectionState, type ConnectionStateMachine, ContactModule, type ContextMedia, ConvexAuthStore, type ConvexAuthStoreOptions, ConvexMessageStore, type ConvexMessageStoreOptions, type CopyButton, type CreateLoggerOptions, type DeleteOptions, type DeletePayload, type DisconnectReasonDomain, type DispatcherDeps, type DispatcherHandle, type DocumentOptions, DocumentProcessor, type DomainErrorCode, type DomainSocketLike, EditBuilder, type EditPayload, type EventOptions, FFMPEG_CONSTANTS, type FFmpegConfig, FFmpegProcessor, FileAuthStore, type FileAuthStoreOptions, type FileExtension, FileManager, type GroupInviteOptions, type GroupJoinPayload, type GroupLeavePayload, GroupModule, type GroupParticipantInfo, type GroupUpdatePayload, type HistorySyncPayload, type ImageOptions, ImageProcessor, type InboundEventMap, type InboundEventName, type InteractiveButton, type LIDMapping, type LIDMappingUpdatePayload, type LimitedPayload, type LimitedTimeOfferOptions, type LinkedGroup, type ListOptions, type ListSection$1 as ListSection, type ListSelectPayload, type LoadMediaOptions, type LoadedMedia, type LocationOptions, type LocationRequestButton, type Logger, type LoggerLevel, Media, type MediaDescriptor, type MediaDownloadResult, type MediaInput, type MediaKind, type MediaSource, type MemberTagPayload, MemoryAuthStore, MemoryMessageStore, type MentionAllContext, type MentionContext, MessageBuilder, type MessageContext, type MessageStore, type MessageStoreListOptions, type Middleware, MimeValidator, NewsletterModule, type NewsletterPayload, type OperationCategory, type OperationGuard, type OperationGuardClock, type OperationGuardOptions, type PairingFlow, type PairingFlowOptions, type PairingFlowResult, type ParsedArgs, type ParticipantUpdateResult, type PinOptions, type PollOptions, type PollVotePayload, PostgresAuthStore, type PostgresAuthStoreOptions, PostgresMessageStore, type PostgresMessageStoreOptions, type PresenceClock, PresenceModule, type PresencePayload, type PresenceThrottleOptions, type PrivacyConfig, PrivacyModule, type PrivacySettings, type ProductOptions, ProfileModule, type QuotedRef, RateLimiter, type RateLimiterClock, type RateLimiterOptions, type ReactionPayload, type ReconnectDecision, type ReconnectOptions, type ReconnectStrategy, type ReconnectStrategyDeps, RedisAuthStore, type RedisAuthStoreOptions, RedisMessageStore, type RedisMessageStoreOptions, type ReminderButton, type ReplyButton, type ResolvedCommand, type RetryPolicy, SELF_ONLY_PROTOCOL_TYPES, type ScheduleHandle, type ScheduledContentSnapshot, type ScheduledJob, type ScheduledJobRecord, Scheduler, type SchedulerDeps, type SchedulerTimer, type SelfOnlyProtocolType, type SenderDevice, type SenderInfo, SqliteAuthStore, type SqliteAuthStoreOptions, SqliteMessageStore, type SqliteMessageStoreOptions, type StateTransitionListener, type StickerMetadataType, type StickerOptions, StickerProcessor, type StickerShapeType, type StoreErrorCode, TaskQueue, type TaskQueueClock, type TaskQueueOptions, type TemplateOptions, type TextOptions, TypedEventEmitter, type TypedEventEmitterOptions, type UpsertPayload, type UrlButton, type UsernameResolveSocketLike, type VideoNoteOptions, type VideoOptions, VideoProcessor, type WAPresence, ZaileysAutomationError, ZaileysBuilderError, ZaileysCommandError, ZaileysDomainError, type ZaileysLogger, ZaileysStoreError, adoptLogger, attachCommandDispatcher, buildMessageContext, chunk, computeStaticId, computeUniqueId, createAuthGuard, createConnectionStateMachine, createLogger, createOperationGuard, createPairingFlow, createReconnectStrategy, deleteMessage, detectFileType, detectMimeFromBuffer, dropSpoofedSelfOnly, epochSecondsToMs, extractLinks, ffmpegTransform, forwardMessage, generateId, initializeFFmpeg, isFatalDisconnect, isJid, isLidJid, isPnJid, isRateLimited, jidToPhone, loadMedia, makeCacheableAuthStore, mapDisconnectReason, extractJid as normalizeJid, normalizePhoneNumber, parseCommand, phoneToJid, pinMessage, printQrToTerminal, reactToMessage, renderQrInTerminal, resolveUsername, runBroadcast, runMiddleware, senderDeviceOf, shouldClearAuth, shouldReconnect, signalKeyStoreFromAuthStore, validateE164 };
|
|
2259
|
+
export { type AddressButton, type AlbumItem, type AudioOptions, AudioProcessor, type AudioType, type AuthAttemptBlockReason, type AuthAttemptDecision, type AuthCredsStore, type AuthGuard, type AuthGuardOptions, type AuthStore, type AuthStoreBundle, type AuthStoreKey, type AuthStoreValue, type AutoDeleteOptions, AutoDeleteSweeper, type AutomationErrorCode, type AutomationSocketLike, type BaileysSocket, type BaileysSocketLike, type BottomSheetOptions, type BroadcastDeps, type BroadcastOptions, type BroadcastResult, BufferConverter, type BuildContextInput, type BuilderContext, type BuilderErrorCode, type BuilderSocketLike, type BuilderState, BusinessModule, type ButtonClickPayload, type ButtonDef, type CacheableAuthStoreOptions, type CallBase, type CallButton, type CallPayload, type CancelReminderButton, ChatModule, type ChatType, type CitationConfig, type CitationPredicates, Client, type ClientEventMap, type ClientEventName, type ClientOptions, type CommandContext, type CommandDefinition, type CommandErrorCode, type CommandHandler, type CommandPrefix, CommandRegistry, CommunityModule, type ConnectionAuthType, type ConnectionEventHandler, type ConnectionEventMap, type ConnectionEventName, type ConnectionState, type ConnectionStateMachine, ContactModule, type ContextMedia, ConvexAuthStore, type ConvexAuthStoreOptions, ConvexMessageStore, type ConvexMessageStoreOptions, type CopyButton, type CreateLoggerOptions, type DeleteOptions, type DeletePayload, type DisconnectReasonDomain, type DispatcherDeps, type DispatcherHandle, type DocumentOptions, DocumentProcessor, type DomainErrorCode, type DomainSocketLike, EditBuilder, type EditPayload, type EventOptions, FFMPEG_CONSTANTS, type FFmpegConfig, FFmpegProcessor, FileAuthStore, type FileAuthStoreOptions, type FileExtension, FileManager, type GroupInviteOptions, type GroupJoinPayload, type GroupLeavePayload, GroupModule, type GroupParticipantInfo, type GroupUpdatePayload, type HistorySyncPayload, type ImageOptions, ImageProcessor, type InboundEventMap, type InboundEventName, type InteractiveButton, type LIDMapping, type LIDMappingUpdatePayload, type LimitedPayload, type LimitedTimeOfferOptions, type LinkedGroup, type ListOptions, type ListSection$1 as ListSection, type ListSelectPayload, type LoadMediaOptions, type LoadedMedia, type LocationOptions, type LocationRequestButton, type Logger, type LoggerLevel, Media, type MediaDescriptor, type MediaDownloadResult, type MediaInput, type MediaKind, type MediaSource, type MemberTagPayload, MemoryAuthStore, MemoryMessageStore, type MentionAllContext, type MentionContext, MessageBuilder, type MessageContext, type MessageStore, type MessageStoreListOptions, type Middleware, MimeValidator, NewsletterModule, type NewsletterPayload, type OperationCategory, type OperationGuard, type OperationGuardClock, type OperationGuardOptions, type PairingFlow, type PairingFlowOptions, type PairingFlowResult, type ParsedArgs, type ParticipantUpdateResult, type PinOptions, type Plugin, type PluginContext, type PluginsOptions, type PollOptions, type PollVotePayload, PostgresAuthStore, type PostgresAuthStoreOptions, PostgresMessageStore, type PostgresMessageStoreOptions, type PresenceClock, PresenceModule, type PresencePayload, type PresenceThrottleOptions, type PrivacyConfig, PrivacyModule, type PrivacySettings, type ProductOptions, ProfileModule, type PruneOptions, type QuotedRef, RateLimiter, type RateLimiterClock, type RateLimiterOptions, type ReactionPayload, type ReconnectDecision, type ReconnectOptions, type ReconnectStrategy, type ReconnectStrategyDeps, RedisAuthStore, type RedisAuthStoreOptions, RedisMessageStore, type RedisMessageStoreOptions, type ReminderButton, type ReplyButton, type ResolvedCommand, type RetryPolicy, SELF_ONLY_PROTOCOL_TYPES, type ScheduleHandle, type ScheduledContentSnapshot, type ScheduledJob, type ScheduledJobRecord, Scheduler, type SchedulerDeps, type SchedulerTimer, type SelfOnlyProtocolType, type SenderDevice, type SenderInfo, SqliteAuthStore, type SqliteAuthStoreOptions, SqliteMessageStore, type SqliteMessageStoreOptions, type StateTransitionListener, type StickerMetadataType, type StickerOptions, StickerProcessor, type StickerShapeType, type StoreErrorCode, TaskQueue, type TaskQueueClock, type TaskQueueOptions, type TemplateOptions, type TextOptions, TypedEventEmitter, type TypedEventEmitterOptions, type UpsertPayload, type UrlButton, type UsernameResolveSocketLike, type VideoNoteOptions, type VideoOptions, VideoProcessor, type WAPresence, ZaileysAutomationError, ZaileysBuilderError, ZaileysCommandError, ZaileysDomainError, type ZaileysLogger, ZaileysStoreError, adoptLogger, attachCommandDispatcher, buildMessageContext, chunk, computeStaticId, computeUniqueId, createAuthGuard, createConnectionStateMachine, createLogger, createOperationGuard, createPairingFlow, createReconnectStrategy, definePlugin, deleteMessage, detectFileType, detectMimeFromBuffer, dropSpoofedSelfOnly, epochSecondsToMs, extractLinks, ffmpegTransform, forwardMessage, generateId, genericPrune, initializeFFmpeg, isFatalDisconnect, isJid, isLidJid, isPnJid, isRateLimited, jidToPhone, loadMedia, makeCacheableAuthStore, mapDisconnectReason, extractJid as normalizeJid, normalizePhoneNumber, parseCommand, phoneToJid, pinMessage, printQrToTerminal, reactToMessage, renderQrInTerminal, resolveUsername, runBroadcast, runMiddleware, senderDeviceOf, shouldClearAuth, shouldReconnect, signalKeyStoreFromAuthStore, validateE164 };
|
package/dist/index.d.ts
CHANGED
|
@@ -289,6 +289,14 @@ type MessageStoreListOptions = {
|
|
|
289
289
|
limit?: number;
|
|
290
290
|
before?: number;
|
|
291
291
|
};
|
|
292
|
+
type PruneOptions = {
|
|
293
|
+
/** Delete messages whose `messageTimestamp` is strictly older than this epoch value, in **seconds** (matching stored `messageTimestamp`). */
|
|
294
|
+
olderThan?: number;
|
|
295
|
+
/** Keep only the newest N messages per chat. */
|
|
296
|
+
maxPerChat?: number;
|
|
297
|
+
/** Restrict pruning to chats whose jid passes this predicate. */
|
|
298
|
+
chatFilter?: (jid: string) => boolean;
|
|
299
|
+
};
|
|
292
300
|
type ScheduledJobRecord = {
|
|
293
301
|
id: string;
|
|
294
302
|
fireAt: number;
|
|
@@ -321,6 +329,8 @@ interface MessageStore {
|
|
|
321
329
|
saveScheduledJob?(job: ScheduledJobRecord): Promise<void>;
|
|
322
330
|
listScheduledJobs?(): Promise<ScheduledJobRecord[]>;
|
|
323
331
|
deleteScheduledJob?(id: string): Promise<void>;
|
|
332
|
+
deleteMessage?(key: WAMessageKey): Promise<void>;
|
|
333
|
+
pruneMessages?(opts: PruneOptions): Promise<number>;
|
|
324
334
|
}
|
|
325
335
|
|
|
326
336
|
type DeleteOptions = {
|
|
@@ -1163,6 +1173,7 @@ declare class CommandRegistry {
|
|
|
1163
1173
|
def: CommandDefinition;
|
|
1164
1174
|
args: string[];
|
|
1165
1175
|
} | undefined;
|
|
1176
|
+
unregister(spec: string): void;
|
|
1166
1177
|
list(): CommandDefinition[];
|
|
1167
1178
|
}
|
|
1168
1179
|
|
|
@@ -1189,6 +1200,35 @@ interface AuthStoreBundle {
|
|
|
1189
1200
|
readonly signal: AuthStore;
|
|
1190
1201
|
}
|
|
1191
1202
|
|
|
1203
|
+
type AutoDeleteOptions = {
|
|
1204
|
+
maxAgeMs?: number;
|
|
1205
|
+
maxPerChat?: number;
|
|
1206
|
+
intervalMs?: number;
|
|
1207
|
+
chats?: 'all' | ((jid: string) => boolean);
|
|
1208
|
+
};
|
|
1209
|
+
declare function genericPrune(store: MessageStore, opts: PruneOptions): Promise<number>;
|
|
1210
|
+
declare class AutoDeleteSweeper {
|
|
1211
|
+
private readonly store;
|
|
1212
|
+
private readonly options;
|
|
1213
|
+
private readonly logger;
|
|
1214
|
+
private readonly now;
|
|
1215
|
+
private timer;
|
|
1216
|
+
private running;
|
|
1217
|
+
private warnedUnsupported;
|
|
1218
|
+
private disabled;
|
|
1219
|
+
constructor(deps: {
|
|
1220
|
+
store: MessageStore;
|
|
1221
|
+
options: AutoDeleteOptions;
|
|
1222
|
+
logger?: Logger;
|
|
1223
|
+
now?: () => number;
|
|
1224
|
+
});
|
|
1225
|
+
private get active();
|
|
1226
|
+
private buildPruneOptions;
|
|
1227
|
+
runOnce(): Promise<number>;
|
|
1228
|
+
start(): void;
|
|
1229
|
+
stop(): void;
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1192
1232
|
type WAPresence = 'unavailable' | 'available' | 'composing' | 'recording' | 'paused';
|
|
1193
1233
|
interface AutomationSocketLike {
|
|
1194
1234
|
sendPresenceUpdate(type: WAPresence, toJid?: string): Promise<void>;
|
|
@@ -1262,6 +1302,29 @@ declare function isRateLimited(reason: DisconnectReasonDomain): boolean;
|
|
|
1262
1302
|
declare function shouldClearAuth(reason: DisconnectReasonDomain): boolean;
|
|
1263
1303
|
declare function shouldReconnect(reason: DisconnectReasonDomain): boolean;
|
|
1264
1304
|
|
|
1305
|
+
interface PluginContext {
|
|
1306
|
+
client: Client;
|
|
1307
|
+
logger: Logger | undefined;
|
|
1308
|
+
pluginDir: string;
|
|
1309
|
+
command(spec: string, handler: CommandHandler): void;
|
|
1310
|
+
use(middleware: Middleware): void;
|
|
1311
|
+
on<E extends keyof ClientEventMap>(event: E, handler: (payload: ClientEventMap[E]) => void): () => void;
|
|
1312
|
+
once<E extends keyof ClientEventMap>(event: E, handler: (payload: ClientEventMap[E]) => void): () => void;
|
|
1313
|
+
}
|
|
1314
|
+
interface Plugin {
|
|
1315
|
+
name: string;
|
|
1316
|
+
setup(ctx: PluginContext): void | (() => void) | Promise<void | (() => void)>;
|
|
1317
|
+
onUnload?(): void | Promise<void>;
|
|
1318
|
+
}
|
|
1319
|
+
type PluginsOptions = {
|
|
1320
|
+
dir?: string;
|
|
1321
|
+
watch?: boolean;
|
|
1322
|
+
pattern?: RegExp;
|
|
1323
|
+
ignore?: RegExp;
|
|
1324
|
+
onError?: (err: unknown, file: string) => void;
|
|
1325
|
+
};
|
|
1326
|
+
declare const definePlugin: (plugin: Plugin) => Plugin;
|
|
1327
|
+
|
|
1265
1328
|
type ConnectionState = 'idle' | 'connecting' | 'qr-pending' | 'pairing-pending' | 'connected' | 'reconnecting' | 'disconnecting' | 'disconnected';
|
|
1266
1329
|
type ConnectionAuthType = 'qr' | 'pairing';
|
|
1267
1330
|
interface Logger {
|
|
@@ -1304,6 +1367,10 @@ interface ClientOptions {
|
|
|
1304
1367
|
presence?: PresenceThrottleOptions;
|
|
1305
1368
|
/** Max scheduled messages dispatched per second, smoothing backlog bursts. Default `1`; `0` disables. */
|
|
1306
1369
|
scheduleRateLimitPerSec?: number;
|
|
1370
|
+
/** Periodically prune old messages from the store. Enabled by default with a 1-month `maxAgeMs`; pass `false` to disable or override any field. */
|
|
1371
|
+
autoDelete?: AutoDeleteOptions | false;
|
|
1372
|
+
/** Load and manage plugins from a directory. */
|
|
1373
|
+
plugins?: PluginsOptions;
|
|
1307
1374
|
}
|
|
1308
1375
|
type ConnectionEventMap = {
|
|
1309
1376
|
connect: {
|
|
@@ -1569,6 +1636,11 @@ declare class Client extends TypedEventEmitter<ClientEventMap> {
|
|
|
1569
1636
|
private commandDispatcher;
|
|
1570
1637
|
private _presence?;
|
|
1571
1638
|
private _scheduler?;
|
|
1639
|
+
private readonly autoDeleteOptions;
|
|
1640
|
+
private autoDeleteSweeper;
|
|
1641
|
+
private readonly pluginsOptions;
|
|
1642
|
+
private pluginRegistry;
|
|
1643
|
+
private pluginLoader;
|
|
1572
1644
|
private waVersion?;
|
|
1573
1645
|
private versionWarming?;
|
|
1574
1646
|
constructor(options?: ClientOptions);
|
|
@@ -1595,7 +1667,9 @@ declare class Client extends TypedEventEmitter<ClientEventMap> {
|
|
|
1595
1667
|
disconnect(): Promise<void>;
|
|
1596
1668
|
logout(): Promise<void>;
|
|
1597
1669
|
command(spec: string, handler: CommandHandler): this;
|
|
1670
|
+
unregisterCommand(spec: string): this;
|
|
1598
1671
|
use(middleware: Middleware): this;
|
|
1672
|
+
unuse(middleware: Middleware): this;
|
|
1599
1673
|
private attachCommandsIfReady;
|
|
1600
1674
|
private buildCommandContext;
|
|
1601
1675
|
private detachCommands;
|
|
@@ -1767,6 +1841,8 @@ declare class MemoryMessageStore implements MessageStore {
|
|
|
1767
1841
|
savePresence(jid: string, presence: PresenceData): Promise<void>;
|
|
1768
1842
|
getPresence(jid: string): Promise<PresenceData | undefined>;
|
|
1769
1843
|
bind(socket: BaileysSocketLike): void;
|
|
1844
|
+
deleteMessage(key: WAMessageKey): Promise<void>;
|
|
1845
|
+
pruneMessages(opts: PruneOptions): Promise<number>;
|
|
1770
1846
|
clear(): Promise<void>;
|
|
1771
1847
|
close(): Promise<void>;
|
|
1772
1848
|
private assertOpen;
|
|
@@ -1798,6 +1874,8 @@ declare class SqliteMessageStore implements MessageStore {
|
|
|
1798
1874
|
listContacts(): Promise<Contact[]>;
|
|
1799
1875
|
savePresence(jid: string, presence: PresenceData): Promise<void>;
|
|
1800
1876
|
getPresence(jid: string): Promise<PresenceData | undefined>;
|
|
1877
|
+
deleteMessage(key: WAMessageKey): Promise<void>;
|
|
1878
|
+
pruneMessages(opts: PruneOptions): Promise<number>;
|
|
1801
1879
|
bind(socket: BaileysSocketLike): void;
|
|
1802
1880
|
clear(): Promise<void>;
|
|
1803
1881
|
close(): Promise<void>;
|
|
@@ -1836,6 +1914,8 @@ declare class PostgresMessageStore implements MessageStore {
|
|
|
1836
1914
|
listContacts(): Promise<Contact[]>;
|
|
1837
1915
|
savePresence(jid: string, presence: PresenceData): Promise<void>;
|
|
1838
1916
|
getPresence(jid: string): Promise<PresenceData | undefined>;
|
|
1917
|
+
deleteMessage(key: WAMessageKey): Promise<void>;
|
|
1918
|
+
pruneMessages(opts: PruneOptions): Promise<number>;
|
|
1839
1919
|
bind(socket: BaileysSocketLike): void;
|
|
1840
1920
|
clear(): Promise<void>;
|
|
1841
1921
|
close(): Promise<void>;
|
|
@@ -1872,6 +1952,9 @@ declare class RedisMessageStore implements MessageStore {
|
|
|
1872
1952
|
bind(socket: BaileysSocketLike): void;
|
|
1873
1953
|
clear(): Promise<void>;
|
|
1874
1954
|
close(): Promise<void>;
|
|
1955
|
+
deleteMessage(key: WAMessageKey): Promise<void>;
|
|
1956
|
+
pruneMessages(opts: PruneOptions): Promise<number>;
|
|
1957
|
+
private jidFromIndexKey;
|
|
1875
1958
|
private msgIndexKey;
|
|
1876
1959
|
private msgDataKey;
|
|
1877
1960
|
private chatsKey;
|
|
@@ -1908,6 +1991,8 @@ declare class ConvexMessageStore implements MessageStore {
|
|
|
1908
1991
|
saveScheduledJob(job: ScheduledJobRecord): Promise<void>;
|
|
1909
1992
|
listScheduledJobs(): Promise<ScheduledJobRecord[]>;
|
|
1910
1993
|
deleteScheduledJob(id: string): Promise<void>;
|
|
1994
|
+
deleteMessage(key: WAMessageKey): Promise<void>;
|
|
1995
|
+
pruneMessages(opts: PruneOptions): Promise<number>;
|
|
1911
1996
|
bind(socket: BaileysSocketLike): void;
|
|
1912
1997
|
clear(): Promise<void>;
|
|
1913
1998
|
close(): Promise<void>;
|
|
@@ -2171,4 +2256,4 @@ declare class Media {
|
|
|
2171
2256
|
toBuffer(): Promise<Buffer>;
|
|
2172
2257
|
}
|
|
2173
2258
|
|
|
2174
|
-
export { type AddressButton, type AlbumItem, type AudioOptions, AudioProcessor, type AudioType, type AuthAttemptBlockReason, type AuthAttemptDecision, type AuthCredsStore, type AuthGuard, type AuthGuardOptions, type AuthStore, type AuthStoreBundle, type AuthStoreKey, type AuthStoreValue, type AutomationErrorCode, type AutomationSocketLike, type BaileysSocket, type BaileysSocketLike, type BottomSheetOptions, type BroadcastDeps, type BroadcastOptions, type BroadcastResult, BufferConverter, type BuildContextInput, type BuilderContext, type BuilderErrorCode, type BuilderSocketLike, type BuilderState, BusinessModule, type ButtonClickPayload, type ButtonDef, type CacheableAuthStoreOptions, type CallBase, type CallButton, type CallPayload, type CancelReminderButton, ChatModule, type ChatType, type CitationConfig, type CitationPredicates, Client, type ClientEventMap, type ClientEventName, type ClientOptions, type CommandContext, type CommandDefinition, type CommandErrorCode, type CommandHandler, type CommandPrefix, CommandRegistry, CommunityModule, type ConnectionAuthType, type ConnectionEventHandler, type ConnectionEventMap, type ConnectionEventName, type ConnectionState, type ConnectionStateMachine, ContactModule, type ContextMedia, ConvexAuthStore, type ConvexAuthStoreOptions, ConvexMessageStore, type ConvexMessageStoreOptions, type CopyButton, type CreateLoggerOptions, type DeleteOptions, type DeletePayload, type DisconnectReasonDomain, type DispatcherDeps, type DispatcherHandle, type DocumentOptions, DocumentProcessor, type DomainErrorCode, type DomainSocketLike, EditBuilder, type EditPayload, type EventOptions, FFMPEG_CONSTANTS, type FFmpegConfig, FFmpegProcessor, FileAuthStore, type FileAuthStoreOptions, type FileExtension, FileManager, type GroupInviteOptions, type GroupJoinPayload, type GroupLeavePayload, GroupModule, type GroupParticipantInfo, type GroupUpdatePayload, type HistorySyncPayload, type ImageOptions, ImageProcessor, type InboundEventMap, type InboundEventName, type InteractiveButton, type LIDMapping, type LIDMappingUpdatePayload, type LimitedPayload, type LimitedTimeOfferOptions, type LinkedGroup, type ListOptions, type ListSection$1 as ListSection, type ListSelectPayload, type LoadMediaOptions, type LoadedMedia, type LocationOptions, type LocationRequestButton, type Logger, type LoggerLevel, Media, type MediaDescriptor, type MediaDownloadResult, type MediaInput, type MediaKind, type MediaSource, type MemberTagPayload, MemoryAuthStore, MemoryMessageStore, type MentionAllContext, type MentionContext, MessageBuilder, type MessageContext, type MessageStore, type MessageStoreListOptions, type Middleware, MimeValidator, NewsletterModule, type NewsletterPayload, type OperationCategory, type OperationGuard, type OperationGuardClock, type OperationGuardOptions, type PairingFlow, type PairingFlowOptions, type PairingFlowResult, type ParsedArgs, type ParticipantUpdateResult, type PinOptions, type PollOptions, type PollVotePayload, PostgresAuthStore, type PostgresAuthStoreOptions, PostgresMessageStore, type PostgresMessageStoreOptions, type PresenceClock, PresenceModule, type PresencePayload, type PresenceThrottleOptions, type PrivacyConfig, PrivacyModule, type PrivacySettings, type ProductOptions, ProfileModule, type QuotedRef, RateLimiter, type RateLimiterClock, type RateLimiterOptions, type ReactionPayload, type ReconnectDecision, type ReconnectOptions, type ReconnectStrategy, type ReconnectStrategyDeps, RedisAuthStore, type RedisAuthStoreOptions, RedisMessageStore, type RedisMessageStoreOptions, type ReminderButton, type ReplyButton, type ResolvedCommand, type RetryPolicy, SELF_ONLY_PROTOCOL_TYPES, type ScheduleHandle, type ScheduledContentSnapshot, type ScheduledJob, type ScheduledJobRecord, Scheduler, type SchedulerDeps, type SchedulerTimer, type SelfOnlyProtocolType, type SenderDevice, type SenderInfo, SqliteAuthStore, type SqliteAuthStoreOptions, SqliteMessageStore, type SqliteMessageStoreOptions, type StateTransitionListener, type StickerMetadataType, type StickerOptions, StickerProcessor, type StickerShapeType, type StoreErrorCode, TaskQueue, type TaskQueueClock, type TaskQueueOptions, type TemplateOptions, type TextOptions, TypedEventEmitter, type TypedEventEmitterOptions, type UpsertPayload, type UrlButton, type UsernameResolveSocketLike, type VideoNoteOptions, type VideoOptions, VideoProcessor, type WAPresence, ZaileysAutomationError, ZaileysBuilderError, ZaileysCommandError, ZaileysDomainError, type ZaileysLogger, ZaileysStoreError, adoptLogger, attachCommandDispatcher, buildMessageContext, chunk, computeStaticId, computeUniqueId, createAuthGuard, createConnectionStateMachine, createLogger, createOperationGuard, createPairingFlow, createReconnectStrategy, deleteMessage, detectFileType, detectMimeFromBuffer, dropSpoofedSelfOnly, epochSecondsToMs, extractLinks, ffmpegTransform, forwardMessage, generateId, initializeFFmpeg, isFatalDisconnect, isJid, isLidJid, isPnJid, isRateLimited, jidToPhone, loadMedia, makeCacheableAuthStore, mapDisconnectReason, extractJid as normalizeJid, normalizePhoneNumber, parseCommand, phoneToJid, pinMessage, printQrToTerminal, reactToMessage, renderQrInTerminal, resolveUsername, runBroadcast, runMiddleware, senderDeviceOf, shouldClearAuth, shouldReconnect, signalKeyStoreFromAuthStore, validateE164 };
|
|
2259
|
+
export { type AddressButton, type AlbumItem, type AudioOptions, AudioProcessor, type AudioType, type AuthAttemptBlockReason, type AuthAttemptDecision, type AuthCredsStore, type AuthGuard, type AuthGuardOptions, type AuthStore, type AuthStoreBundle, type AuthStoreKey, type AuthStoreValue, type AutoDeleteOptions, AutoDeleteSweeper, type AutomationErrorCode, type AutomationSocketLike, type BaileysSocket, type BaileysSocketLike, type BottomSheetOptions, type BroadcastDeps, type BroadcastOptions, type BroadcastResult, BufferConverter, type BuildContextInput, type BuilderContext, type BuilderErrorCode, type BuilderSocketLike, type BuilderState, BusinessModule, type ButtonClickPayload, type ButtonDef, type CacheableAuthStoreOptions, type CallBase, type CallButton, type CallPayload, type CancelReminderButton, ChatModule, type ChatType, type CitationConfig, type CitationPredicates, Client, type ClientEventMap, type ClientEventName, type ClientOptions, type CommandContext, type CommandDefinition, type CommandErrorCode, type CommandHandler, type CommandPrefix, CommandRegistry, CommunityModule, type ConnectionAuthType, type ConnectionEventHandler, type ConnectionEventMap, type ConnectionEventName, type ConnectionState, type ConnectionStateMachine, ContactModule, type ContextMedia, ConvexAuthStore, type ConvexAuthStoreOptions, ConvexMessageStore, type ConvexMessageStoreOptions, type CopyButton, type CreateLoggerOptions, type DeleteOptions, type DeletePayload, type DisconnectReasonDomain, type DispatcherDeps, type DispatcherHandle, type DocumentOptions, DocumentProcessor, type DomainErrorCode, type DomainSocketLike, EditBuilder, type EditPayload, type EventOptions, FFMPEG_CONSTANTS, type FFmpegConfig, FFmpegProcessor, FileAuthStore, type FileAuthStoreOptions, type FileExtension, FileManager, type GroupInviteOptions, type GroupJoinPayload, type GroupLeavePayload, GroupModule, type GroupParticipantInfo, type GroupUpdatePayload, type HistorySyncPayload, type ImageOptions, ImageProcessor, type InboundEventMap, type InboundEventName, type InteractiveButton, type LIDMapping, type LIDMappingUpdatePayload, type LimitedPayload, type LimitedTimeOfferOptions, type LinkedGroup, type ListOptions, type ListSection$1 as ListSection, type ListSelectPayload, type LoadMediaOptions, type LoadedMedia, type LocationOptions, type LocationRequestButton, type Logger, type LoggerLevel, Media, type MediaDescriptor, type MediaDownloadResult, type MediaInput, type MediaKind, type MediaSource, type MemberTagPayload, MemoryAuthStore, MemoryMessageStore, type MentionAllContext, type MentionContext, MessageBuilder, type MessageContext, type MessageStore, type MessageStoreListOptions, type Middleware, MimeValidator, NewsletterModule, type NewsletterPayload, type OperationCategory, type OperationGuard, type OperationGuardClock, type OperationGuardOptions, type PairingFlow, type PairingFlowOptions, type PairingFlowResult, type ParsedArgs, type ParticipantUpdateResult, type PinOptions, type Plugin, type PluginContext, type PluginsOptions, type PollOptions, type PollVotePayload, PostgresAuthStore, type PostgresAuthStoreOptions, PostgresMessageStore, type PostgresMessageStoreOptions, type PresenceClock, PresenceModule, type PresencePayload, type PresenceThrottleOptions, type PrivacyConfig, PrivacyModule, type PrivacySettings, type ProductOptions, ProfileModule, type PruneOptions, type QuotedRef, RateLimiter, type RateLimiterClock, type RateLimiterOptions, type ReactionPayload, type ReconnectDecision, type ReconnectOptions, type ReconnectStrategy, type ReconnectStrategyDeps, RedisAuthStore, type RedisAuthStoreOptions, RedisMessageStore, type RedisMessageStoreOptions, type ReminderButton, type ReplyButton, type ResolvedCommand, type RetryPolicy, SELF_ONLY_PROTOCOL_TYPES, type ScheduleHandle, type ScheduledContentSnapshot, type ScheduledJob, type ScheduledJobRecord, Scheduler, type SchedulerDeps, type SchedulerTimer, type SelfOnlyProtocolType, type SenderDevice, type SenderInfo, SqliteAuthStore, type SqliteAuthStoreOptions, SqliteMessageStore, type SqliteMessageStoreOptions, type StateTransitionListener, type StickerMetadataType, type StickerOptions, StickerProcessor, type StickerShapeType, type StoreErrorCode, TaskQueue, type TaskQueueClock, type TaskQueueOptions, type TemplateOptions, type TextOptions, TypedEventEmitter, type TypedEventEmitterOptions, type UpsertPayload, type UrlButton, type UsernameResolveSocketLike, type VideoNoteOptions, type VideoOptions, VideoProcessor, type WAPresence, ZaileysAutomationError, ZaileysBuilderError, ZaileysCommandError, ZaileysDomainError, type ZaileysLogger, ZaileysStoreError, adoptLogger, attachCommandDispatcher, buildMessageContext, chunk, computeStaticId, computeUniqueId, createAuthGuard, createConnectionStateMachine, createLogger, createOperationGuard, createPairingFlow, createReconnectStrategy, definePlugin, deleteMessage, detectFileType, detectMimeFromBuffer, dropSpoofedSelfOnly, epochSecondsToMs, extractLinks, ffmpegTransform, forwardMessage, generateId, genericPrune, initializeFFmpeg, isFatalDisconnect, isJid, isLidJid, isPnJid, isRateLimited, jidToPhone, loadMedia, makeCacheableAuthStore, mapDisconnectReason, extractJid as normalizeJid, normalizePhoneNumber, parseCommand, phoneToJid, pinMessage, printQrToTerminal, reactToMessage, renderQrInTerminal, resolveUsername, runBroadcast, runMiddleware, senderDeviceOf, shouldClearAuth, shouldReconnect, signalKeyStoreFromAuthStore, validateE164 };
|