zaileys 4.7.1 → 4.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/dist/auth/adapters/convex.d.ts +9 -0
- package/dist/auth/adapters/file.d.ts +16 -0
- package/dist/auth/adapters/index.d.ts +6 -0
- package/dist/auth/adapters/memory.d.ts +9 -0
- package/dist/auth/adapters/postgres.d.ts +20 -0
- package/dist/auth/adapters/redis.d.ts +27 -0
- package/dist/auth/adapters/sqlite.d.ts +19 -0
- package/dist/auth/cache.d.ts +11 -0
- package/dist/auth/index.d.ts +3 -0
- package/dist/auth/types.d.ts +21 -0
- package/dist/automation/auto-delete.d.ts +30 -0
- package/dist/automation/broadcast.d.ts +10 -0
- package/dist/automation/errors.d.ts +8 -0
- package/dist/automation/index.d.ts +11 -0
- package/dist/automation/operation-guard.d.ts +20 -0
- package/dist/automation/presence.d.ts +28 -0
- package/dist/automation/queue.d.ts +18 -0
- package/dist/automation/rate-limiter.d.ts +18 -0
- package/dist/automation/schedule.d.ts +45 -0
- package/dist/automation/types.d.ts +31 -0
- package/dist/builder/album.d.ts +4 -0
- package/dist/builder/builder.d.ts +59 -0
- package/dist/builder/content/airich.d.ts +80 -0
- package/dist/builder/content/audio.d.ts +9 -0
- package/dist/builder/content/buttons.d.ts +30 -0
- package/dist/builder/content/carousel.d.ts +19 -0
- package/dist/builder/content/contact.d.ts +13 -0
- package/dist/builder/content/document.d.ts +9 -0
- package/dist/builder/content/event.d.ts +3 -0
- package/dist/builder/content/group-invite.d.ts +3 -0
- package/dist/builder/content/image.d.ts +8 -0
- package/dist/builder/content/list.d.ts +14 -0
- package/dist/builder/content/location.d.ts +11 -0
- package/dist/builder/content/markdown.d.ts +2 -0
- package/dist/builder/content/poll.d.ts +10 -0
- package/dist/builder/content/product.d.ts +3 -0
- package/dist/builder/content/sticker.d.ts +7 -0
- package/dist/builder/content/template.d.ts +3 -0
- package/dist/builder/content/text.d.ts +4 -0
- package/dist/builder/content/video.d.ts +10 -0
- package/dist/builder/edit-builder.d.ts +15 -0
- package/dist/builder/errors.d.ts +8 -0
- package/dist/builder/index.d.ts +6 -0
- package/dist/builder/media-loader.d.ts +11 -0
- package/dist/builder/mutations.d.ts +14 -0
- package/dist/builder/state.d.ts +15 -0
- package/dist/builder/types.d.ts +164 -0
- package/dist/builder/username-resolve.d.ts +8 -0
- package/dist/client/client.d.ts +160 -0
- package/dist/client/event-emitter.d.ts +19 -0
- package/dist/client/index.d.ts +3 -0
- package/dist/client/types.d.ts +119 -0
- package/dist/cloud/errors.d.ts +14 -0
- package/dist/cloud/graph-client.d.ts +15 -0
- package/dist/cloud/index.d.ts +6 -0
- package/dist/cloud/media.d.ts +15 -0
- package/dist/cloud/module.d.ts +147 -0
- package/dist/cloud/translate/inbound.d.ts +119 -0
- package/dist/cloud/translate/interactive.d.ts +2 -0
- package/dist/cloud/translate/outbound.d.ts +21 -0
- package/dist/cloud/transport.d.ts +51 -0
- package/dist/cloud/types.d.ts +17 -0
- package/dist/cloud/webhook.d.ts +11 -0
- package/dist/command/dispatcher.d.ts +23 -0
- package/dist/command/errors.d.ts +8 -0
- package/dist/command/index.d.ts +7 -0
- package/dist/command/middleware.d.ts +2 -0
- package/dist/command/parser.d.ts +2 -0
- package/dist/command/registry.d.ts +13 -0
- package/dist/command/types.d.ts +30 -0
- package/dist/connection/auth-adapter.d.ts +4 -0
- package/dist/connection/auth-guard.d.ts +37 -0
- package/dist/connection/disconnect-reason.d.ts +6 -0
- package/dist/connection/index.d.ts +7 -0
- package/dist/connection/pairing-flow.d.ts +16 -0
- package/dist/connection/qr-terminal.d.ts +2 -0
- package/dist/connection/reconnect.d.ts +15 -0
- package/dist/connection/state-machine.d.ts +9 -0
- package/dist/connection/status-log.d.ts +25 -0
- package/dist/domain/business.d.ts +19 -0
- package/dist/domain/chat.d.ts +27 -0
- package/dist/domain/community.d.ts +28 -0
- package/dist/domain/contact.d.ts +21 -0
- package/dist/domain/errors.d.ts +8 -0
- package/dist/domain/group.d.ts +35 -0
- package/dist/domain/index.d.ts +11 -0
- package/dist/domain/newsletter.d.ts +35 -0
- package/dist/domain/privacy.d.ts +15 -0
- package/dist/domain/profile.d.ts +14 -0
- package/dist/domain/socket-like.d.ts +117 -0
- package/dist/domain/types.d.ts +24 -0
- package/dist/events/context.d.ts +238 -0
- package/dist/events/decoders/_media-download.d.ts +8 -0
- package/dist/events/decoders/_shared.d.ts +26 -0
- package/dist/events/decoders/calls.d.ts +11 -0
- package/dist/events/decoders/groups.d.ts +36 -0
- package/dist/events/decoders/interactive.d.ts +9 -0
- package/dist/events/decoders/lifecycle.d.ts +69 -0
- package/dist/events/decoders/messages.d.ts +30 -0
- package/dist/events/decoders/mutations.d.ts +24 -0
- package/dist/events/guards.d.ts +9 -0
- package/dist/events/index.d.ts +4 -0
- package/dist/events/pipeline.d.ts +37 -0
- package/dist/events/types.d.ts +187 -0
- package/dist/index.cjs +20 -15
- package/dist/index.d.ts +15 -2264
- package/dist/index.mjs +20 -15
- package/dist/media/ffmpeg/audio.d.ts +12 -0
- package/dist/media/ffmpeg/core.d.ts +67 -0
- package/dist/media/ffmpeg/document.d.ts +10 -0
- package/dist/media/ffmpeg/image.d.ts +7 -0
- package/dist/media/ffmpeg/index.d.ts +7 -0
- package/dist/media/ffmpeg/sticker.d.ts +14 -0
- package/dist/media/ffmpeg/transform.d.ts +2 -0
- package/dist/media/ffmpeg/video.d.ts +6 -0
- package/dist/media/index.d.ts +2 -0
- package/dist/media/media.d.ts +39 -0
- package/dist/plugin/index.d.ts +5 -0
- package/dist/plugin/loader.d.ts +30 -0
- package/dist/plugin/registry.d.ts +24 -0
- package/dist/plugin/types.d.ts +25 -0
- package/dist/store/adapters/convex.d.ts +33 -0
- package/dist/store/adapters/index.d.ts +5 -0
- package/dist/store/adapters/memory.d.ts +31 -0
- package/dist/store/adapters/postgres.d.ts +40 -0
- package/dist/store/adapters/redis.d.ts +49 -0
- package/dist/store/adapters/sqlite.d.ts +36 -0
- package/dist/store/index.d.ts +2 -0
- package/dist/store/types.d.ts +48 -0
- package/dist/transport/index.d.ts +1 -0
- package/dist/transport/types.d.ts +18 -0
- package/dist/types/convex.d.ts +35 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/lid-mapping.d.ts +5 -0
- package/dist/types/optional-clients.d.ts +69 -0
- package/dist/types/store-error.d.ts +8 -0
- package/dist/utils/array.d.ts +1 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/jid.d.ts +6 -0
- package/dist/utils/logger.d.ts +10 -0
- package/package.json +7 -7
- 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,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,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,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,160 @@
|
|
|
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, ProviderKind } from './types.js';
|
|
11
|
+
import { CloudModule } from '../cloud/module.js';
|
|
12
|
+
import { type WebhookHandler } from '../cloud/webhook.js';
|
|
13
|
+
export declare class Client extends TypedEventEmitter<ClientEventMap> {
|
|
14
|
+
readonly sessionId: string;
|
|
15
|
+
auth: AuthStoreBundle;
|
|
16
|
+
readonly store: MessageStore;
|
|
17
|
+
private readonly logger;
|
|
18
|
+
private readonly authType;
|
|
19
|
+
private readonly phoneNumber;
|
|
20
|
+
private readonly cacheSignal;
|
|
21
|
+
private readonly qrTerminal;
|
|
22
|
+
private readonly statusLog;
|
|
23
|
+
private readonly reconnectOptions;
|
|
24
|
+
private readonly baileysExtra;
|
|
25
|
+
private readonly machine;
|
|
26
|
+
private reconnectStrategy;
|
|
27
|
+
private readonly authGuard;
|
|
28
|
+
private readonly operationGuard;
|
|
29
|
+
private readonly presenceThrottle;
|
|
30
|
+
private readonly scheduleLimiter;
|
|
31
|
+
private authExhausted;
|
|
32
|
+
private _socket;
|
|
33
|
+
private reconnectTimer;
|
|
34
|
+
private listenerCleanup;
|
|
35
|
+
private inboundHandle;
|
|
36
|
+
private connectResolve;
|
|
37
|
+
private connectReject;
|
|
38
|
+
private pairingRequested;
|
|
39
|
+
private cachedSignalWrap;
|
|
40
|
+
private creds;
|
|
41
|
+
private credsLoadedAtConnect;
|
|
42
|
+
private openedThisRun;
|
|
43
|
+
private credsHintShown;
|
|
44
|
+
private postOpenLogoutRetries;
|
|
45
|
+
private disconnectEmittedFor;
|
|
46
|
+
private connectAttemptSeq;
|
|
47
|
+
private pendingDisconnectReason;
|
|
48
|
+
private readonly usernameCache;
|
|
49
|
+
private _group?;
|
|
50
|
+
private _privacy?;
|
|
51
|
+
private _newsletter?;
|
|
52
|
+
private _community?;
|
|
53
|
+
private _profile?;
|
|
54
|
+
private _chat?;
|
|
55
|
+
private _contact?;
|
|
56
|
+
private _business?;
|
|
57
|
+
private commandRegistry?;
|
|
58
|
+
private readonly commandMiddleware;
|
|
59
|
+
private readonly commandPrefixes;
|
|
60
|
+
private readonly citationConfig;
|
|
61
|
+
private readonly ignoreMe;
|
|
62
|
+
private commandDispatcher;
|
|
63
|
+
private _presence?;
|
|
64
|
+
private _scheduler?;
|
|
65
|
+
private readonly autoDeleteOptions;
|
|
66
|
+
private autoDeleteSweeper;
|
|
67
|
+
private readonly pluginsOptions;
|
|
68
|
+
private pluginRegistry;
|
|
69
|
+
private pluginLoader;
|
|
70
|
+
private waVersion?;
|
|
71
|
+
private versionWarming?;
|
|
72
|
+
private readonly _provider;
|
|
73
|
+
private readonly cloudOptions;
|
|
74
|
+
private cloudTransport;
|
|
75
|
+
private cloudRuntimeReady;
|
|
76
|
+
private _cloudModule;
|
|
77
|
+
constructor(options?: ClientOptions);
|
|
78
|
+
private warmVersion;
|
|
79
|
+
private emitAutoConnectError;
|
|
80
|
+
private logStatus;
|
|
81
|
+
private resolveMe;
|
|
82
|
+
get provider(): ProviderKind;
|
|
83
|
+
get state(): ConnectionState;
|
|
84
|
+
get socket(): BaileysSocket | undefined;
|
|
85
|
+
/** Web-only surfaces fail loud on the cloud provider instead of dying deeper with a vague error. */
|
|
86
|
+
private assertWebProvider;
|
|
87
|
+
get group(): GroupModule;
|
|
88
|
+
get privacy(): PrivacyModule;
|
|
89
|
+
get newsletter(): NewsletterModule;
|
|
90
|
+
get community(): CommunityModule;
|
|
91
|
+
get profile(): ProfileModule;
|
|
92
|
+
get chat(): ChatModule;
|
|
93
|
+
get contact(): ContactModule;
|
|
94
|
+
get business(): BusinessModule;
|
|
95
|
+
get presence(): PresenceModule;
|
|
96
|
+
broadcast(jids: string[], build: (b: MessageBuilder<'init'>) => MessageBuilder<'content-set'>, options?: BroadcastOptions): Promise<BroadcastResult>;
|
|
97
|
+
scheduleAt(date: Date, build: (b: MessageBuilder<'init'>) => MessageBuilder<'content-set'>): Promise<ScheduleHandle>;
|
|
98
|
+
private ensureScheduler;
|
|
99
|
+
private dispatchSnapshot;
|
|
100
|
+
connect(): Promise<void>;
|
|
101
|
+
/** Create the cloud transport + attach the inbound pipeline exactly once — independent of connect(). */
|
|
102
|
+
private ensureCloudRuntime;
|
|
103
|
+
private connectCloud;
|
|
104
|
+
private attachCloudPipeline;
|
|
105
|
+
/**
|
|
106
|
+
* Framework-agnostic Meta webhook endpoint (cloud provider only): handles the GET
|
|
107
|
+
* verification challenge and signed POST deliveries, then feeds events into the client.
|
|
108
|
+
*/
|
|
109
|
+
webhook(): WebhookHandler;
|
|
110
|
+
private disconnectCloud;
|
|
111
|
+
disconnect(): Promise<void>;
|
|
112
|
+
logout(): Promise<void>;
|
|
113
|
+
command(spec: string, handler: CommandHandler): this;
|
|
114
|
+
unregisterCommand(spec: string): this;
|
|
115
|
+
use(middleware: Middleware): this;
|
|
116
|
+
unuse(middleware: Middleware): this;
|
|
117
|
+
private attachCommandsIfReady;
|
|
118
|
+
private buildCommandContext;
|
|
119
|
+
private detachCommands;
|
|
120
|
+
send(to: string): MessageBuilder<'init'>;
|
|
121
|
+
edit(key: WAMessageKey): EditBuilder;
|
|
122
|
+
delete(key: WAMessageKey, opts?: DeleteOptions): Promise<void>;
|
|
123
|
+
react(key: WAMessageKey, emoji: string): Promise<WAMessageKey>;
|
|
124
|
+
/** Cloud provider only: management surface (templates, profile, flows, blocklist, qr, analytics, phone). */
|
|
125
|
+
get cloud(): CloudModule;
|
|
126
|
+
/** Cloud provider only: send an approved Meta message template by name + language. */
|
|
127
|
+
sendTemplate(to: string, name: string, languageCode: string, components?: Array<Record<string, unknown>>): Promise<WAMessageKey>;
|
|
128
|
+
/** Cloud provider only: mark an inbound message read (optionally showing a typing indicator). */
|
|
129
|
+
markRead(messageId: string, opts?: {
|
|
130
|
+
typing?: boolean;
|
|
131
|
+
}): Promise<void>;
|
|
132
|
+
forward(key: WAMessageKey, to: string): Promise<WAMessageKey>;
|
|
133
|
+
pin(key: WAMessageKey, opts?: PinOptions): Promise<WAMessageKey>;
|
|
134
|
+
unpin(key: WAMessageKey): Promise<WAMessageKey>;
|
|
135
|
+
setDisappearing(to: string, seconds: number): Promise<void>;
|
|
136
|
+
private resolveRecipient;
|
|
137
|
+
private requireSocket;
|
|
138
|
+
/** Messaging seam: baileys socket or the cloud transport, whichever the provider dictates. */
|
|
139
|
+
private requireBuilderSocket;
|
|
140
|
+
private attachEmitterLogger;
|
|
141
|
+
private wireSocket;
|
|
142
|
+
private handleConnectionUpdate;
|
|
143
|
+
private handleQrUpdate;
|
|
144
|
+
private handleAuthExhausted;
|
|
145
|
+
private handleOpen;
|
|
146
|
+
private resolveMessageForResend;
|
|
147
|
+
private lidMapping;
|
|
148
|
+
/** Resolve a `@lid` JID to its phone-number JID (uses WhatsApp's LID mapping; may hit the network). */
|
|
149
|
+
lidToPn(lid: string): Promise<string | null>;
|
|
150
|
+
/** Resolve a phone-number JID to its `@lid` JID (uses WhatsApp's LID mapping; may hit the network). */
|
|
151
|
+
pnToLid(pn: string): Promise<string | null>;
|
|
152
|
+
/**
|
|
153
|
+
* Download media bytes for a message stored in the message store (by key).
|
|
154
|
+
* Tries both `fromMe` variants. `null` when the message is unknown or carries no media.
|
|
155
|
+
*/
|
|
156
|
+
downloadMedia(key: WAMessageKey): Promise<MediaDownloadResult | null>;
|
|
157
|
+
private lookupQuoted;
|
|
158
|
+
private handleClose;
|
|
159
|
+
private rejectPendingConnect;
|
|
160
|
+
}
|
|
@@ -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,119 @@
|
|
|
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
|
+
import type { CloudOptions } from '../cloud/types.js';
|
|
13
|
+
import type { CloudFlowResponseEvent, CloudOrderEvent, CloudStatusEvent, CloudTemplateStatusEvent } from '../cloud/translate/inbound.js';
|
|
14
|
+
export type ProviderKind = 'baileys' | 'cloud';
|
|
15
|
+
export type ConnectionState = 'idle' | 'connecting' | 'qr-pending' | 'pairing-pending' | 'connected' | 'reconnecting' | 'disconnecting' | 'disconnected';
|
|
16
|
+
export type ConnectionAuthType = 'qr' | 'pairing';
|
|
17
|
+
export interface Logger {
|
|
18
|
+
debug(...args: unknown[]): void;
|
|
19
|
+
info(...args: unknown[]): void;
|
|
20
|
+
warn(...args: unknown[]): void;
|
|
21
|
+
error(...args: unknown[]): void;
|
|
22
|
+
fatal(...args: unknown[]): void;
|
|
23
|
+
}
|
|
24
|
+
export interface ReconnectOptions {
|
|
25
|
+
enabled?: boolean;
|
|
26
|
+
maxAttempts?: number;
|
|
27
|
+
initialDelayMs?: number;
|
|
28
|
+
maxDelayMs?: number;
|
|
29
|
+
jitterFactor?: number;
|
|
30
|
+
/** Fixed backoff applied when the disconnect reason is `rate-limited` (429). Default `300000`. */
|
|
31
|
+
rateLimitedDelayMs?: number;
|
|
32
|
+
}
|
|
33
|
+
export interface ClientOptions {
|
|
34
|
+
/** Message transport: baileys (WhatsApp Web, default) or the official Meta Cloud API. */
|
|
35
|
+
provider?: ProviderKind;
|
|
36
|
+
/** Cloud API credentials/config — required when `provider: 'cloud'`. */
|
|
37
|
+
cloud?: CloudOptions;
|
|
38
|
+
sessionId?: string;
|
|
39
|
+
auth?: AuthStoreBundle;
|
|
40
|
+
store?: MessageStore;
|
|
41
|
+
authType?: ConnectionAuthType;
|
|
42
|
+
phoneNumber?: string;
|
|
43
|
+
logger?: Logger;
|
|
44
|
+
cacheSignal?: boolean;
|
|
45
|
+
reconnect?: ReconnectOptions;
|
|
46
|
+
qrTerminal?: boolean;
|
|
47
|
+
baileys?: Partial<UserFacingSocketConfig>;
|
|
48
|
+
autoConnect?: boolean;
|
|
49
|
+
statusLog?: boolean;
|
|
50
|
+
commandPrefix?: string | string[];
|
|
51
|
+
citation?: CitationConfig;
|
|
52
|
+
ignoreMe?: boolean;
|
|
53
|
+
/** Bounds QR/pairing regeneration to avoid spam restriction. ON by default; `{ enabled: false }` to opt out. */
|
|
54
|
+
authGuard?: AuthGuardOptions;
|
|
55
|
+
/** Spaces out sensitive group/community/newsletter operations. ON by default; `{ enabled: false }` to opt out. */
|
|
56
|
+
operationGuard?: OperationGuardOptions;
|
|
57
|
+
/** Drops duplicate presence (typing/recording/online) updates within a window. ON by default. */
|
|
58
|
+
presence?: PresenceThrottleOptions;
|
|
59
|
+
/** Max scheduled messages dispatched per second, smoothing backlog bursts. Default `1`; `0` disables. */
|
|
60
|
+
scheduleRateLimitPerSec?: number;
|
|
61
|
+
/** Periodically prune old messages from the store. Enabled by default with a 1-month `maxAgeMs`; pass `false` to disable or override any field. */
|
|
62
|
+
autoDelete?: AutoDeleteOptions | false;
|
|
63
|
+
/** Load and manage plugins from a directory. */
|
|
64
|
+
plugins?: PluginsOptions;
|
|
65
|
+
}
|
|
66
|
+
export type ConnectionEventMap = {
|
|
67
|
+
connect: {
|
|
68
|
+
sessionId: string;
|
|
69
|
+
me: {
|
|
70
|
+
id: string;
|
|
71
|
+
lid?: string;
|
|
72
|
+
name?: string;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
disconnect: {
|
|
76
|
+
sessionId: string;
|
|
77
|
+
reason: DisconnectReasonDomain;
|
|
78
|
+
willReconnect: boolean;
|
|
79
|
+
};
|
|
80
|
+
qr: {
|
|
81
|
+
sessionId: string;
|
|
82
|
+
qrString: string;
|
|
83
|
+
expiresAt: number;
|
|
84
|
+
};
|
|
85
|
+
'pairing-code': {
|
|
86
|
+
sessionId: string;
|
|
87
|
+
code: string;
|
|
88
|
+
expiresAt: number;
|
|
89
|
+
};
|
|
90
|
+
reconnecting: {
|
|
91
|
+
sessionId: string;
|
|
92
|
+
attempt: number;
|
|
93
|
+
delayMs: number;
|
|
94
|
+
reason: DisconnectReasonDomain;
|
|
95
|
+
};
|
|
96
|
+
'auth-exhausted': {
|
|
97
|
+
sessionId: string;
|
|
98
|
+
kind: ConnectionAuthType;
|
|
99
|
+
attempts: number;
|
|
100
|
+
max: number;
|
|
101
|
+
};
|
|
102
|
+
error: {
|
|
103
|
+
sessionId: string;
|
|
104
|
+
error: Error;
|
|
105
|
+
};
|
|
106
|
+
/** Cloud provider: delivery lifecycle of outbound messages (sent/delivered/read/failed). */
|
|
107
|
+
'message-status': CloudStatusEvent;
|
|
108
|
+
/** Cloud provider: template review lifecycle (APPROVED/REJECTED/PAUSED...). */
|
|
109
|
+
'template-status': CloudTemplateStatusEvent;
|
|
110
|
+
/** Cloud provider: WhatsApp Flow completion (nfm_reply) with parsed response payload. */
|
|
111
|
+
'flow-response': CloudFlowResponseEvent;
|
|
112
|
+
/** Cloud provider: catalog order placed by the customer. */
|
|
113
|
+
order: CloudOrderEvent;
|
|
114
|
+
};
|
|
115
|
+
export type ConnectionEventName = keyof ConnectionEventMap;
|
|
116
|
+
export type ConnectionEventHandler<E extends ConnectionEventName> = (payload: ConnectionEventMap[E]) => void;
|
|
117
|
+
export type ClientEventMap = ConnectionEventMap & InboundEventMap;
|
|
118
|
+
export type ClientEventName = keyof ClientEventMap;
|
|
119
|
+
export type BaileysSocket = WASocket;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type CloudErrorCode = 'CONFIG' | 'AUTH' | 'REQUEST_FAILED' | 'RATE_LIMITED' | 'NOT_IMPLEMENTED';
|
|
2
|
+
/** Thrown when a WhatsApp-Web-only surface is used on the official Cloud API provider. */
|
|
3
|
+
export declare class ZaileysProviderError extends Error {
|
|
4
|
+
readonly code = "UNSUPPORTED_ON_CLOUD";
|
|
5
|
+
readonly feature: string;
|
|
6
|
+
constructor(feature: string);
|
|
7
|
+
}
|
|
8
|
+
export declare class ZaileysCloudError extends Error {
|
|
9
|
+
readonly code: CloudErrorCode;
|
|
10
|
+
readonly cause?: unknown;
|
|
11
|
+
constructor(code: CloudErrorCode, message: string, options?: {
|
|
12
|
+
cause?: unknown;
|
|
13
|
+
});
|
|
14
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CloudOptions } from './types.js';
|
|
2
|
+
/** Pinned default Graph API version — override via CloudOptions.apiVersion. */
|
|
3
|
+
export declare const DEFAULT_GRAPH_VERSION = "v23.0";
|
|
4
|
+
export declare const DEFAULT_GRAPH_BASE_URL = "https://graph.facebook.com";
|
|
5
|
+
export interface GraphClientDeps {
|
|
6
|
+
delay?: (ms: number) => Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export interface GraphClient {
|
|
9
|
+
get<T>(path: string): Promise<T>;
|
|
10
|
+
post<T>(path: string, body: unknown): Promise<T>;
|
|
11
|
+
postForm<T>(path: string, form: FormData): Promise<T>;
|
|
12
|
+
delete<T = unknown>(path: string, body?: unknown): Promise<T>;
|
|
13
|
+
url(path: string): string;
|
|
14
|
+
}
|
|
15
|
+
export declare function createGraphClient(options: CloudOptions, deps?: GraphClientDeps): GraphClient;
|