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,6 @@
|
|
|
1
|
+
export { ZaileysCloudError, ZaileysProviderError, type CloudErrorCode } from './errors.js';
|
|
2
|
+
export { validateCloudOptions, type CloudOptions } from './types.js';
|
|
3
|
+
export { CloudTransport, DEFAULT_GRAPH_VERSION } from './transport.js';
|
|
4
|
+
export { CloudModule, type CloudTemplate, type CloudBusinessProfile, type FlowSendOptions } from './module.js';
|
|
5
|
+
export { createWebhookHandler, type WebhookHandler, type WebhookHandlerOptions } from './webhook.js';
|
|
6
|
+
export type { CloudFlowResponseEvent, CloudMessageStatus, CloudOrderEvent, CloudStatusEvent, CloudTemplateStatusEvent, } from './translate/inbound.js';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AnyMessageContent } from 'baileys';
|
|
2
|
+
import type { GraphClient } from './graph-client.js';
|
|
3
|
+
export type CloudMediaKind = 'image' | 'video' | 'audio' | 'document' | 'sticker';
|
|
4
|
+
export interface OutboundMedia {
|
|
5
|
+
kind: CloudMediaKind;
|
|
6
|
+
buffer: Buffer;
|
|
7
|
+
caption?: string;
|
|
8
|
+
fileName?: string;
|
|
9
|
+
mimetype?: string;
|
|
10
|
+
}
|
|
11
|
+
/** Detect a builder media content (`{ image: Buffer, caption? }` etc.); null when not media. */
|
|
12
|
+
export declare function outboundMediaOf(content: AnyMessageContent): OutboundMedia | null;
|
|
13
|
+
/** Upload bytes to the Cloud media endpoint; returns the media id to reference in sends. */
|
|
14
|
+
export declare function uploadMedia(graph: GraphClient, phoneNumberId: string, media: OutboundMedia): Promise<string>;
|
|
15
|
+
export declare function mediaMessageBody(media: OutboundMedia, mediaId: string): Record<string, unknown>;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import type { WAMessageKey } from 'baileys';
|
|
2
|
+
import type { CloudTransport } from './transport.js';
|
|
3
|
+
import type { CloudOptions } from './types.js';
|
|
4
|
+
export interface FlowSendOptions {
|
|
5
|
+
flowId?: string;
|
|
6
|
+
flowName?: string;
|
|
7
|
+
cta: string;
|
|
8
|
+
bodyText: string;
|
|
9
|
+
headerText?: string;
|
|
10
|
+
footerText?: string;
|
|
11
|
+
screen: string;
|
|
12
|
+
flowToken?: string;
|
|
13
|
+
data?: Record<string, unknown>;
|
|
14
|
+
mode?: 'draft' | 'published';
|
|
15
|
+
action?: 'navigate' | 'data_exchange';
|
|
16
|
+
}
|
|
17
|
+
export interface CloudTemplate {
|
|
18
|
+
id: string;
|
|
19
|
+
name: string;
|
|
20
|
+
status: string;
|
|
21
|
+
category?: string;
|
|
22
|
+
language?: string;
|
|
23
|
+
components?: Array<Record<string, unknown>>;
|
|
24
|
+
}
|
|
25
|
+
export interface CloudBusinessProfile {
|
|
26
|
+
about?: string;
|
|
27
|
+
address?: string;
|
|
28
|
+
description?: string;
|
|
29
|
+
email?: string;
|
|
30
|
+
websites?: string[];
|
|
31
|
+
vertical?: string;
|
|
32
|
+
messaging_product?: string;
|
|
33
|
+
}
|
|
34
|
+
/** Cloud-only management surface: templates, profile, flows, commerce, blocklist, qr, analytics, phone. */
|
|
35
|
+
export declare class CloudModule {
|
|
36
|
+
private readonly graph;
|
|
37
|
+
private readonly options;
|
|
38
|
+
private readonly getTransport;
|
|
39
|
+
constructor(options: CloudOptions, getTransport: () => CloudTransport);
|
|
40
|
+
private requireWaba;
|
|
41
|
+
/** This sender's phone-number node: display number, verified name, quality rating, throughput. */
|
|
42
|
+
info(): Promise<Record<string, unknown>>;
|
|
43
|
+
/** All phone numbers registered under the WhatsApp Business Account. */
|
|
44
|
+
phoneNumbers(): Promise<Array<Record<string, unknown>>>;
|
|
45
|
+
/** Request the user's shipping address (interactive address_message; ID/BR only per Meta). */
|
|
46
|
+
sendAddressRequest(to: string, opts: {
|
|
47
|
+
bodyText: string;
|
|
48
|
+
countryIso: string;
|
|
49
|
+
values?: Record<string, unknown>;
|
|
50
|
+
}): Promise<WAMessageKey>;
|
|
51
|
+
readonly commerce: {
|
|
52
|
+
catalogs: () => Promise<Array<{
|
|
53
|
+
id: string;
|
|
54
|
+
name: string;
|
|
55
|
+
}>>;
|
|
56
|
+
products: (catalogId: string, limit?: number) => Promise<Array<{
|
|
57
|
+
id: string;
|
|
58
|
+
retailer_id: string;
|
|
59
|
+
name: string;
|
|
60
|
+
price?: string;
|
|
61
|
+
availability?: string;
|
|
62
|
+
}>>;
|
|
63
|
+
sendProduct: (to: string, opts: {
|
|
64
|
+
catalogId: string;
|
|
65
|
+
retailerId: string;
|
|
66
|
+
bodyText?: string;
|
|
67
|
+
footerText?: string;
|
|
68
|
+
}) => Promise<WAMessageKey>;
|
|
69
|
+
sendProductList: (to: string, opts: {
|
|
70
|
+
catalogId: string;
|
|
71
|
+
headerText: string;
|
|
72
|
+
bodyText: string;
|
|
73
|
+
footerText?: string;
|
|
74
|
+
sections: Array<{
|
|
75
|
+
title: string;
|
|
76
|
+
productIds: string[];
|
|
77
|
+
}>;
|
|
78
|
+
}) => Promise<WAMessageKey>;
|
|
79
|
+
};
|
|
80
|
+
readonly templates: {
|
|
81
|
+
list: (params?: {
|
|
82
|
+
status?: string;
|
|
83
|
+
limit?: number;
|
|
84
|
+
}) => Promise<CloudTemplate[]>;
|
|
85
|
+
get: (idOrName: string) => Promise<CloudTemplate | null>;
|
|
86
|
+
create: (template: {
|
|
87
|
+
name: string;
|
|
88
|
+
category: 'MARKETING' | 'UTILITY' | 'AUTHENTICATION';
|
|
89
|
+
language: string;
|
|
90
|
+
components: Array<Record<string, unknown>>;
|
|
91
|
+
}) => Promise<{
|
|
92
|
+
id: string;
|
|
93
|
+
status: string;
|
|
94
|
+
}>;
|
|
95
|
+
delete: (name: string, id?: string) => Promise<void>;
|
|
96
|
+
};
|
|
97
|
+
readonly profile: {
|
|
98
|
+
get: () => Promise<CloudBusinessProfile>;
|
|
99
|
+
update: (fields: CloudBusinessProfile) => Promise<void>;
|
|
100
|
+
};
|
|
101
|
+
readonly flows: {
|
|
102
|
+
list: () => Promise<Array<{
|
|
103
|
+
id: string;
|
|
104
|
+
name: string;
|
|
105
|
+
status: string;
|
|
106
|
+
}>>;
|
|
107
|
+
send: (to: string, opts: FlowSendOptions) => Promise<WAMessageKey>;
|
|
108
|
+
};
|
|
109
|
+
readonly blocklist: {
|
|
110
|
+
add: (numbers: string[]) => Promise<void>;
|
|
111
|
+
remove: (numbers: string[]) => Promise<void>;
|
|
112
|
+
list: () => Promise<Array<{
|
|
113
|
+
wa_id: string;
|
|
114
|
+
}>>;
|
|
115
|
+
};
|
|
116
|
+
readonly qr: {
|
|
117
|
+
create: (prefilledMessage: string, imageFormat?: 'SVG' | 'PNG') => Promise<{
|
|
118
|
+
code: string;
|
|
119
|
+
prefilled_message: string;
|
|
120
|
+
qr_image_url?: string;
|
|
121
|
+
}>;
|
|
122
|
+
list: () => Promise<Array<{
|
|
123
|
+
code: string;
|
|
124
|
+
prefilled_message: string;
|
|
125
|
+
}>>;
|
|
126
|
+
delete: (code: string) => Promise<void>;
|
|
127
|
+
};
|
|
128
|
+
readonly analytics: {
|
|
129
|
+
conversations: (params: {
|
|
130
|
+
start: number;
|
|
131
|
+
end: number;
|
|
132
|
+
granularity?: 'HALF_HOUR' | 'DAILY' | 'MONTHLY';
|
|
133
|
+
}) => Promise<unknown>;
|
|
134
|
+
messages: (params: {
|
|
135
|
+
start: number;
|
|
136
|
+
end: number;
|
|
137
|
+
granularity?: 'HALF_HOUR' | 'DAY' | 'MONTH';
|
|
138
|
+
}) => Promise<unknown>;
|
|
139
|
+
};
|
|
140
|
+
readonly phone: {
|
|
141
|
+
/** Registers the number for Cloud API messaging. Touches live registration — use with care. */
|
|
142
|
+
register: (pin: string) => Promise<void>;
|
|
143
|
+
deregister: () => Promise<void>;
|
|
144
|
+
requestCode: (method: 'SMS' | 'VOICE', language?: string) => Promise<void>;
|
|
145
|
+
verifyCode: (code: string) => Promise<void>;
|
|
146
|
+
};
|
|
147
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { WAMessage } from 'baileys';
|
|
2
|
+
export interface CloudInboundMedia {
|
|
3
|
+
id?: string;
|
|
4
|
+
mime_type?: string;
|
|
5
|
+
sha256?: string;
|
|
6
|
+
caption?: string;
|
|
7
|
+
filename?: string;
|
|
8
|
+
voice?: boolean;
|
|
9
|
+
animated?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface CloudWebhookMessage {
|
|
12
|
+
from?: string;
|
|
13
|
+
id?: string;
|
|
14
|
+
timestamp?: string;
|
|
15
|
+
type?: string;
|
|
16
|
+
text?: {
|
|
17
|
+
body?: string;
|
|
18
|
+
};
|
|
19
|
+
image?: CloudInboundMedia;
|
|
20
|
+
video?: CloudInboundMedia;
|
|
21
|
+
audio?: CloudInboundMedia;
|
|
22
|
+
document?: CloudInboundMedia;
|
|
23
|
+
sticker?: CloudInboundMedia;
|
|
24
|
+
[key: string]: unknown;
|
|
25
|
+
}
|
|
26
|
+
export interface CloudWebhookValue {
|
|
27
|
+
messaging_product?: string;
|
|
28
|
+
metadata?: {
|
|
29
|
+
display_phone_number?: string;
|
|
30
|
+
phone_number_id?: string;
|
|
31
|
+
};
|
|
32
|
+
contacts?: Array<{
|
|
33
|
+
profile?: {
|
|
34
|
+
name?: string;
|
|
35
|
+
};
|
|
36
|
+
wa_id?: string;
|
|
37
|
+
}>;
|
|
38
|
+
messages?: CloudWebhookMessage[];
|
|
39
|
+
statuses?: Array<Record<string, unknown>>;
|
|
40
|
+
}
|
|
41
|
+
export interface CloudWebhookPayload {
|
|
42
|
+
object?: string;
|
|
43
|
+
entry?: Array<{
|
|
44
|
+
id?: string;
|
|
45
|
+
changes?: Array<{
|
|
46
|
+
value?: CloudWebhookValue;
|
|
47
|
+
field?: string;
|
|
48
|
+
}>;
|
|
49
|
+
}>;
|
|
50
|
+
}
|
|
51
|
+
export interface CloudTemplateStatusEvent {
|
|
52
|
+
event: string;
|
|
53
|
+
id: string;
|
|
54
|
+
name: string;
|
|
55
|
+
language?: string;
|
|
56
|
+
reason?: string;
|
|
57
|
+
}
|
|
58
|
+
export type CloudMessageStatus = 'sent' | 'delivered' | 'read' | 'failed';
|
|
59
|
+
export interface CloudStatusEvent {
|
|
60
|
+
id: string;
|
|
61
|
+
status: CloudMessageStatus;
|
|
62
|
+
recipientId: string;
|
|
63
|
+
timestamp: number;
|
|
64
|
+
conversationId?: string;
|
|
65
|
+
error?: {
|
|
66
|
+
code?: number;
|
|
67
|
+
title?: string;
|
|
68
|
+
message?: string;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export interface CloudFlowResponseEvent {
|
|
72
|
+
id: string;
|
|
73
|
+
name: string;
|
|
74
|
+
body?: string;
|
|
75
|
+
response: Record<string, unknown>;
|
|
76
|
+
senderId: string;
|
|
77
|
+
senderName?: string;
|
|
78
|
+
timestamp: number;
|
|
79
|
+
}
|
|
80
|
+
export interface CloudOrderEvent {
|
|
81
|
+
id: string;
|
|
82
|
+
catalogId: string;
|
|
83
|
+
text?: string;
|
|
84
|
+
items: Array<{
|
|
85
|
+
productRetailerId: string;
|
|
86
|
+
quantity: number;
|
|
87
|
+
price: number;
|
|
88
|
+
currency: string;
|
|
89
|
+
}>;
|
|
90
|
+
senderId: string;
|
|
91
|
+
senderName?: string;
|
|
92
|
+
timestamp: number;
|
|
93
|
+
}
|
|
94
|
+
export interface CloudReactionItem {
|
|
95
|
+
key: {
|
|
96
|
+
id: string;
|
|
97
|
+
remoteJid: string;
|
|
98
|
+
fromMe: boolean;
|
|
99
|
+
};
|
|
100
|
+
reaction: {
|
|
101
|
+
key: {
|
|
102
|
+
id: string;
|
|
103
|
+
remoteJid: string;
|
|
104
|
+
fromMe: boolean;
|
|
105
|
+
};
|
|
106
|
+
text: string;
|
|
107
|
+
senderTimestampMs: number;
|
|
108
|
+
};
|
|
109
|
+
pushName?: string;
|
|
110
|
+
}
|
|
111
|
+
/** Flatten a Meta webhook delivery into baileys-shaped events the existing pipeline can decode. */
|
|
112
|
+
export declare function translateInbound(payload: CloudWebhookPayload): {
|
|
113
|
+
messages: WAMessage[];
|
|
114
|
+
reactions: CloudReactionItem[];
|
|
115
|
+
statuses: CloudStatusEvent[];
|
|
116
|
+
templateStatuses: CloudTemplateStatusEvent[];
|
|
117
|
+
flowResponses: CloudFlowResponseEvent[];
|
|
118
|
+
orders: CloudOrderEvent[];
|
|
119
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AnyMessageContent, MiscMessageGenerationOptions, WAMessage } from 'baileys';
|
|
2
|
+
export interface GraphMessagePayload {
|
|
3
|
+
messaging_product: 'whatsapp';
|
|
4
|
+
recipient_type: 'individual';
|
|
5
|
+
to: string;
|
|
6
|
+
type: string;
|
|
7
|
+
context?: {
|
|
8
|
+
message_id: string;
|
|
9
|
+
};
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
}
|
|
12
|
+
/** Graph `to` is a bare number — strip any jid server suffix. */
|
|
13
|
+
export declare const toGraphRecipient: (to: string) => string;
|
|
14
|
+
export declare const toJid: (recipient: string) => string;
|
|
15
|
+
export declare const basePayload: (to: string, type: string, options?: MiscMessageGenerationOptions) => GraphMessagePayload;
|
|
16
|
+
/** Translate baileys-style outbound content to a Graph payload; null = not translatable yet. */
|
|
17
|
+
export declare function translateOutbound(to: string, content: AnyMessageContent, options?: MiscMessageGenerationOptions): GraphMessagePayload | null;
|
|
18
|
+
/** Minimal vcard extraction (FN/N + TELs) — Graph requires formatted_name plus one name part. */
|
|
19
|
+
export declare function vcardToGraphContact(vcard: string): Record<string, unknown> | null;
|
|
20
|
+
/** Minimal baileys-shaped WAMessage so recordSent/store/reply keep working on cloud. */
|
|
21
|
+
export declare function synthesizeSentMessage(wamid: string, to: string, content: AnyMessageContent, timestampMs: number): WAMessage;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import type { AnyMessageContent, MiscMessageGenerationOptions, WAMessage } from 'baileys';
|
|
3
|
+
import type { Transport } from '../transport/types.js';
|
|
4
|
+
import type { CloudOptions } from './types.js';
|
|
5
|
+
import { DEFAULT_GRAPH_BASE_URL, DEFAULT_GRAPH_VERSION } from './graph-client.js';
|
|
6
|
+
export { DEFAULT_GRAPH_BASE_URL, DEFAULT_GRAPH_VERSION };
|
|
7
|
+
export interface CloudMe {
|
|
8
|
+
id: string;
|
|
9
|
+
name?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare class CloudTransport implements Transport {
|
|
12
|
+
readonly ev: EventEmitter<[never]>;
|
|
13
|
+
readonly user: {
|
|
14
|
+
id: string;
|
|
15
|
+
};
|
|
16
|
+
private readonly options;
|
|
17
|
+
private readonly graph;
|
|
18
|
+
constructor(options: CloudOptions);
|
|
19
|
+
get apiVersion(): string;
|
|
20
|
+
get baseUrl(): string;
|
|
21
|
+
url(path: string): string;
|
|
22
|
+
/** Health check: token+phoneNumberId must resolve the phone-number node. No retry — a bad token never heals. */
|
|
23
|
+
connect(): Promise<CloudMe>;
|
|
24
|
+
disconnect(): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Relay seam used by the builder for interactive sends (buttons/list/cta). Translates the
|
|
27
|
+
* proto to a Graph interactive payload. Returns the builder's messageId per contract, but
|
|
28
|
+
* the store records the real wamid via the upsert emit.
|
|
29
|
+
*/
|
|
30
|
+
relayMessage: (jid: string, message: unknown, options: {
|
|
31
|
+
messageId: string;
|
|
32
|
+
additionalNodes?: unknown[];
|
|
33
|
+
}) => Promise<string>;
|
|
34
|
+
/** Post a raw interactive object to /messages; shared by flows/commerce/address sends. */
|
|
35
|
+
sendInteractive(to: string, interactive: Record<string, unknown>): Promise<WAMessage>;
|
|
36
|
+
/** Send an approved Meta message template (Cloud-only; templates are managed in Business Manager). */
|
|
37
|
+
sendTemplate(to: string, name: string, languageCode: string, components?: Array<Record<string, unknown>>): Promise<WAMessage>;
|
|
38
|
+
/** Mark an inbound message read; optionally show a typing indicator alongside. */
|
|
39
|
+
markRead(messageId: string, opts?: {
|
|
40
|
+
typing?: boolean;
|
|
41
|
+
}): Promise<void>;
|
|
42
|
+
/** Resolve a Meta media id to bytes: GET /{mediaId} -> short-lived CDN url -> authorized fetch. */
|
|
43
|
+
downloadMedia(mediaId: string): Promise<{
|
|
44
|
+
buffer: Buffer;
|
|
45
|
+
mime: string;
|
|
46
|
+
size: number;
|
|
47
|
+
} | null>;
|
|
48
|
+
/** Feed a verified webhook payload into the shared event pipeline. */
|
|
49
|
+
ingest(payload: unknown): void;
|
|
50
|
+
sendMessage(jid: string, content: AnyMessageContent, options?: MiscMessageGenerationOptions): Promise<WAMessage | undefined>;
|
|
51
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface CloudOptions {
|
|
2
|
+
/** Permanent or system-user access token for the WhatsApp Business app. */
|
|
3
|
+
accessToken: string;
|
|
4
|
+
/** Sender phone-number id (not the phone number itself). */
|
|
5
|
+
phoneNumberId: string;
|
|
6
|
+
/** WhatsApp Business Account id — optional, needed only for account-level ops. */
|
|
7
|
+
wabaId?: string;
|
|
8
|
+
/** Token echoed back on the webhook GET verification challenge. */
|
|
9
|
+
verifyToken?: string;
|
|
10
|
+
/** Meta app secret; enables X-Hub-Signature-256 verification of webhook POSTs. */
|
|
11
|
+
appSecret?: string;
|
|
12
|
+
/** Graph API version, e.g. 'v23.0'. Defaults to the pinned stable version. */
|
|
13
|
+
apiVersion?: string;
|
|
14
|
+
/** Override the Graph API origin (tests / proxies). */
|
|
15
|
+
baseUrl?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function validateCloudOptions(cloud: CloudOptions | undefined): CloudOptions;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type WebhookHandler = (req: Request) => Promise<Response>;
|
|
2
|
+
export interface WebhookHandlerOptions {
|
|
3
|
+
verifyToken?: string;
|
|
4
|
+
appSecret?: string;
|
|
5
|
+
onPayload: (payload: unknown) => void;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Framework-agnostic Meta webhook endpoint: handles the GET verification challenge and
|
|
9
|
+
* signed POST deliveries. Mount it on any server that speaks Web Request/Response.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createWebhookHandler(options: WebhookHandlerOptions): WebhookHandler;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Logger } from '../client/types.js';
|
|
2
|
+
import type { MessageContext } from '../events/context.js';
|
|
3
|
+
import type { CommandRegistry } from './registry.js';
|
|
4
|
+
import type { CommandContext, Middleware } from './types.js';
|
|
5
|
+
export interface ResolvedCommand {
|
|
6
|
+
command: string;
|
|
7
|
+
args: string[];
|
|
8
|
+
flags: Record<string, string | boolean>;
|
|
9
|
+
json: unknown;
|
|
10
|
+
raw: string;
|
|
11
|
+
}
|
|
12
|
+
export interface DispatcherDeps {
|
|
13
|
+
registry: CommandRegistry;
|
|
14
|
+
middleware: Middleware[];
|
|
15
|
+
prefixes: string[];
|
|
16
|
+
onText: (handler: (msg: MessageContext) => void) => () => void;
|
|
17
|
+
buildContext: (resolved: ResolvedCommand, msg: MessageContext) => CommandContext;
|
|
18
|
+
logger: Logger;
|
|
19
|
+
}
|
|
20
|
+
export interface DispatcherHandle {
|
|
21
|
+
detach(): void;
|
|
22
|
+
}
|
|
23
|
+
export declare function attachCommandDispatcher(deps: DispatcherDeps): DispatcherHandle;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type CommandErrorCode = 'DUPLICATE_COMMAND' | 'INVALID_COMMAND_NAME' | 'HANDLER_ERROR' | 'MIDDLEWARE_ERROR' | 'NO_SENT_MESSAGE' | 'NOT_CONNECTED';
|
|
2
|
+
export declare class ZaileysCommandError extends Error {
|
|
3
|
+
readonly code: CommandErrorCode;
|
|
4
|
+
readonly cause?: unknown;
|
|
5
|
+
constructor(code: CommandErrorCode, message: string, options?: {
|
|
6
|
+
cause?: unknown;
|
|
7
|
+
});
|
|
8
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './types.js';
|
|
2
|
+
export * from './errors.js';
|
|
3
|
+
export { parseCommand } from './parser.js';
|
|
4
|
+
export { CommandRegistry } from './registry.js';
|
|
5
|
+
export { runMiddleware } from './middleware.js';
|
|
6
|
+
export { attachCommandDispatcher } from './dispatcher.js';
|
|
7
|
+
export type { DispatcherDeps, DispatcherHandle, ResolvedCommand } from './dispatcher.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CommandDefinition, CommandHandler, ParsedArgs } from './types.js';
|
|
2
|
+
export declare class CommandRegistry {
|
|
3
|
+
private readonly paths;
|
|
4
|
+
private readonly defs;
|
|
5
|
+
private maxDepth;
|
|
6
|
+
register(spec: string, handler: CommandHandler): void;
|
|
7
|
+
resolve(parsed: ParsedArgs): {
|
|
8
|
+
def: CommandDefinition;
|
|
9
|
+
args: string[];
|
|
10
|
+
} | undefined;
|
|
11
|
+
unregister(spec: string): void;
|
|
12
|
+
list(): CommandDefinition[];
|
|
13
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { WAMessageKey } from 'baileys';
|
|
2
|
+
import type { MessageContext } from '../events/context.js';
|
|
3
|
+
import type { TextOptions } from '../builder/builder.js';
|
|
4
|
+
export type CommandPrefix = string | string[];
|
|
5
|
+
export interface ParsedArgs {
|
|
6
|
+
matched: boolean;
|
|
7
|
+
name?: string;
|
|
8
|
+
args: string[];
|
|
9
|
+
flags: Record<string, string | boolean>;
|
|
10
|
+
json: unknown;
|
|
11
|
+
raw: string;
|
|
12
|
+
}
|
|
13
|
+
export interface CommandContext extends MessageContext {
|
|
14
|
+
raw: string;
|
|
15
|
+
command: string;
|
|
16
|
+
args: string[];
|
|
17
|
+
flags: Record<string, string | boolean>;
|
|
18
|
+
json: unknown;
|
|
19
|
+
reply(content: string, opts?: TextOptions): Promise<WAMessageKey>;
|
|
20
|
+
react(emoji: string): Promise<WAMessageKey>;
|
|
21
|
+
edit(content: string): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
export type CommandHandler = (ctx: CommandContext) => Promise<void> | void;
|
|
24
|
+
export type Middleware = (ctx: CommandContext, next: () => Promise<void>) => Promise<void> | void;
|
|
25
|
+
export interface CommandDefinition {
|
|
26
|
+
name: string;
|
|
27
|
+
aliases: string[];
|
|
28
|
+
parts: string[];
|
|
29
|
+
handler: CommandHandler;
|
|
30
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ConnectionAuthType } from '../client/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Bounds QR and pairing-code regeneration across a client's lifetime to avoid
|
|
4
|
+
* tripping WhatsApp's spam/automation restriction. Each reconnect creates a fresh
|
|
5
|
+
* socket which re-emits a QR or requests a new pairing code; without a budget and
|
|
6
|
+
* cooldown this loops unbounded and gets the account restricted.
|
|
7
|
+
*/
|
|
8
|
+
export interface AuthGuardOptions {
|
|
9
|
+
/** Master switch. When `false` the guard never blocks (legacy behaviour). Default `true`. */
|
|
10
|
+
enabled?: boolean;
|
|
11
|
+
/** Total QR codes emitted before the guard stops and signals exhaustion. Default `5`. */
|
|
12
|
+
maxQrAttempts?: number;
|
|
13
|
+
/** Total pairing-code requests before the guard stops and signals exhaustion. Default `3`. */
|
|
14
|
+
maxPairingAttempts?: number;
|
|
15
|
+
/** Base cooldown between pairing-code requests; escalates per attempt. Default `60000`. */
|
|
16
|
+
pairingCooldownMs?: number;
|
|
17
|
+
}
|
|
18
|
+
export type AuthAttemptBlockReason = 'budget-exhausted' | 'cooldown';
|
|
19
|
+
export interface AuthAttemptDecision {
|
|
20
|
+
allowed: boolean;
|
|
21
|
+
reason?: AuthAttemptBlockReason;
|
|
22
|
+
waitMs: number;
|
|
23
|
+
attempts: number;
|
|
24
|
+
max: number;
|
|
25
|
+
}
|
|
26
|
+
export interface AuthGuard {
|
|
27
|
+
/** Decide whether a new auth attempt of `kind` is permitted at time `now` (does not mutate). */
|
|
28
|
+
evaluate(kind: ConnectionAuthType, now: number): AuthAttemptDecision;
|
|
29
|
+
/** Record that an attempt of `kind` was actually issued at time `now`. */
|
|
30
|
+
record(kind: ConnectionAuthType, now: number): void;
|
|
31
|
+
/** Clear all counters and cooldowns (call on a successful connection or manual restart). */
|
|
32
|
+
reset(): void;
|
|
33
|
+
readonly enabled: boolean;
|
|
34
|
+
readonly qrAttempts: number;
|
|
35
|
+
readonly pairingAttempts: number;
|
|
36
|
+
}
|
|
37
|
+
export declare function createAuthGuard(options?: AuthGuardOptions): AuthGuard;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type DisconnectReasonDomain = 'logged-out' | 'connection-replaced' | 'forbidden' | 'restart-required' | 'bad-session' | 'connection-closed' | 'connection-lost' | 'multi-device-mismatch' | 'unavailable-service' | 'rate-limited' | 'unknown';
|
|
2
|
+
export declare function mapDisconnectReason(code: number | undefined): DisconnectReasonDomain;
|
|
3
|
+
export declare function isFatalDisconnect(reason: DisconnectReasonDomain): boolean;
|
|
4
|
+
export declare function isRateLimited(reason: DisconnectReasonDomain): boolean;
|
|
5
|
+
export declare function shouldClearAuth(reason: DisconnectReasonDomain): boolean;
|
|
6
|
+
export declare function shouldReconnect(reason: DisconnectReasonDomain): boolean;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { BaileysSocket } from '../client/types.js';
|
|
2
|
+
export interface PairingFlowOptions {
|
|
3
|
+
phoneNumber: string;
|
|
4
|
+
ttlMs?: number;
|
|
5
|
+
}
|
|
6
|
+
export interface PairingFlowResult {
|
|
7
|
+
code: string;
|
|
8
|
+
expiresAt: number;
|
|
9
|
+
}
|
|
10
|
+
export interface PairingFlow {
|
|
11
|
+
readonly phoneNumber: string;
|
|
12
|
+
requestCode(socket: Pick<BaileysSocket, 'requestPairingCode'>): Promise<PairingFlowResult>;
|
|
13
|
+
}
|
|
14
|
+
export declare function normalizePhoneNumber(raw: string): string;
|
|
15
|
+
export declare function validateE164(raw: string): string;
|
|
16
|
+
export declare function createPairingFlow(options: PairingFlowOptions): PairingFlow;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ReconnectOptions } from '../client/types.js';
|
|
2
|
+
import { type DisconnectReasonDomain } from './disconnect-reason.js';
|
|
3
|
+
export interface ReconnectDecision {
|
|
4
|
+
attempt: number;
|
|
5
|
+
delayMs: number;
|
|
6
|
+
}
|
|
7
|
+
export interface ReconnectStrategy {
|
|
8
|
+
next(reason: DisconnectReasonDomain): ReconnectDecision | null;
|
|
9
|
+
reset(): void;
|
|
10
|
+
readonly attempts: number;
|
|
11
|
+
}
|
|
12
|
+
export interface ReconnectStrategyDeps {
|
|
13
|
+
random?: () => number;
|
|
14
|
+
}
|
|
15
|
+
export declare function createReconnectStrategy(options?: ReconnectOptions, deps?: ReconnectStrategyDeps): ReconnectStrategy;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ConnectionState } from '../client/types.js';
|
|
2
|
+
export type StateTransitionListener = (prev: ConnectionState, next: ConnectionState) => void;
|
|
3
|
+
export interface ConnectionStateMachine {
|
|
4
|
+
readonly state: ConnectionState;
|
|
5
|
+
canTransition(next: ConnectionState): boolean;
|
|
6
|
+
transition(next: ConnectionState): void;
|
|
7
|
+
onChange(listener: StateTransitionListener): () => void;
|
|
8
|
+
}
|
|
9
|
+
export declare function createConnectionStateMachine(initial?: ConnectionState): ConnectionStateMachine;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { DisconnectReasonDomain } from './disconnect-reason.js';
|
|
2
|
+
export type StatusEvent = {
|
|
3
|
+
kind: 'connecting';
|
|
4
|
+
sessionId: string;
|
|
5
|
+
} | {
|
|
6
|
+
kind: 'qr';
|
|
7
|
+
} | {
|
|
8
|
+
kind: 'pairing-code';
|
|
9
|
+
code: string;
|
|
10
|
+
} | {
|
|
11
|
+
kind: 'connected';
|
|
12
|
+
id: string;
|
|
13
|
+
} | {
|
|
14
|
+
kind: 'reconnecting';
|
|
15
|
+
attempt: number;
|
|
16
|
+
delayMs: number;
|
|
17
|
+
reason: DisconnectReasonDomain;
|
|
18
|
+
invalidCredsSuspected: boolean;
|
|
19
|
+
} | {
|
|
20
|
+
kind: 'disconnect';
|
|
21
|
+
reason: DisconnectReasonDomain;
|
|
22
|
+
willReconnect: boolean;
|
|
23
|
+
};
|
|
24
|
+
export declare function formatConnectionStatus(event: StatusEvent): string | null;
|
|
25
|
+
export declare function suppressLibsignalNoise(): void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { DomainSocketLike } from './socket-like.js';
|
|
2
|
+
export declare class BusinessModule {
|
|
3
|
+
private readonly getSocket;
|
|
4
|
+
constructor(getSocket: () => DomainSocketLike | undefined);
|
|
5
|
+
protected requireSocket(): DomainSocketLike;
|
|
6
|
+
profile(jid: string): Promise<unknown>;
|
|
7
|
+
catalog(opts?: {
|
|
8
|
+
jid?: string;
|
|
9
|
+
limit?: number;
|
|
10
|
+
cursor?: string;
|
|
11
|
+
}): Promise<unknown>;
|
|
12
|
+
collections(jid?: string, limit?: number): Promise<unknown>;
|
|
13
|
+
orderDetails(orderId: string, tokenBase64: string): Promise<unknown>;
|
|
14
|
+
createProduct(create: Record<string, unknown>): Promise<unknown>;
|
|
15
|
+
updateProduct(productId: string, update: Record<string, unknown>): Promise<unknown>;
|
|
16
|
+
deleteProduct(...productIds: string[]): Promise<{
|
|
17
|
+
deleted: number;
|
|
18
|
+
}>;
|
|
19
|
+
}
|