@ariaflowagents/messaging-meta 0.8.1
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 +236 -0
- package/dist/graph-api/client.d.ts +125 -0
- package/dist/graph-api/client.d.ts.map +1 -0
- package/dist/graph-api/client.js +204 -0
- package/dist/graph-api/client.js.map +1 -0
- package/dist/graph-api/errors.d.ts +41 -0
- package/dist/graph-api/errors.d.ts.map +1 -0
- package/dist/graph-api/errors.js +72 -0
- package/dist/graph-api/errors.js.map +1 -0
- package/dist/graph-api/index.d.ts +15 -0
- package/dist/graph-api/index.d.ts.map +1 -0
- package/dist/graph-api/index.js +11 -0
- package/dist/graph-api/index.js.map +1 -0
- package/dist/graph-api/rate-limiter.d.ts +90 -0
- package/dist/graph-api/rate-limiter.d.ts.map +1 -0
- package/dist/graph-api/rate-limiter.js +172 -0
- package/dist/graph-api/rate-limiter.js.map +1 -0
- package/dist/graph-api/retry.d.ts +55 -0
- package/dist/graph-api/retry.d.ts.map +1 -0
- package/dist/graph-api/retry.js +103 -0
- package/dist/graph-api/retry.js.map +1 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/instagram/client.d.ts +365 -0
- package/dist/instagram/client.d.ts.map +1 -0
- package/dist/instagram/client.js +857 -0
- package/dist/instagram/client.js.map +1 -0
- package/dist/instagram/format.d.ts +62 -0
- package/dist/instagram/format.d.ts.map +1 -0
- package/dist/instagram/format.js +92 -0
- package/dist/instagram/format.js.map +1 -0
- package/dist/instagram/ice-breakers.d.ts +63 -0
- package/dist/instagram/ice-breakers.d.ts.map +1 -0
- package/dist/instagram/ice-breakers.js +87 -0
- package/dist/instagram/ice-breakers.js.map +1 -0
- package/dist/instagram/index.d.ts +44 -0
- package/dist/instagram/index.d.ts.map +1 -0
- package/dist/instagram/index.js +46 -0
- package/dist/instagram/index.js.map +1 -0
- package/dist/instagram/types.d.ts +188 -0
- package/dist/instagram/types.d.ts.map +1 -0
- package/dist/instagram/types.js +19 -0
- package/dist/instagram/types.js.map +1 -0
- package/dist/messenger/client.d.ts +339 -0
- package/dist/messenger/client.d.ts.map +1 -0
- package/dist/messenger/client.js +782 -0
- package/dist/messenger/client.js.map +1 -0
- package/dist/messenger/format.d.ts +69 -0
- package/dist/messenger/format.d.ts.map +1 -0
- package/dist/messenger/format.js +98 -0
- package/dist/messenger/format.js.map +1 -0
- package/dist/messenger/index.d.ts +34 -0
- package/dist/messenger/index.d.ts.map +1 -0
- package/dist/messenger/index.js +35 -0
- package/dist/messenger/index.js.map +1 -0
- package/dist/messenger/types.d.ts +181 -0
- package/dist/messenger/types.d.ts.map +1 -0
- package/dist/messenger/types.js +10 -0
- package/dist/messenger/types.js.map +1 -0
- package/dist/server.d.ts +31 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +29 -0
- package/dist/server.js.map +1 -0
- package/dist/webhook/index.d.ts +10 -0
- package/dist/webhook/index.d.ts.map +1 -0
- package/dist/webhook/index.js +8 -0
- package/dist/webhook/index.js.map +1 -0
- package/dist/webhook/normalizer.d.ts +169 -0
- package/dist/webhook/normalizer.d.ts.map +1 -0
- package/dist/webhook/normalizer.js +301 -0
- package/dist/webhook/normalizer.js.map +1 -0
- package/dist/webhook/verifier.d.ts +45 -0
- package/dist/webhook/verifier.d.ts.map +1 -0
- package/dist/webhook/verifier.js +62 -0
- package/dist/webhook/verifier.js.map +1 -0
- package/dist/whatsapp/client.d.ts +481 -0
- package/dist/whatsapp/client.d.ts.map +1 -0
- package/dist/whatsapp/client.js +1043 -0
- package/dist/whatsapp/client.js.map +1 -0
- package/dist/whatsapp/flows.d.ts +74 -0
- package/dist/whatsapp/flows.d.ts.map +1 -0
- package/dist/whatsapp/flows.js +77 -0
- package/dist/whatsapp/flows.js.map +1 -0
- package/dist/whatsapp/format.d.ts +78 -0
- package/dist/whatsapp/format.d.ts.map +1 -0
- package/dist/whatsapp/format.js +195 -0
- package/dist/whatsapp/format.js.map +1 -0
- package/dist/whatsapp/index.d.ts +39 -0
- package/dist/whatsapp/index.d.ts.map +1 -0
- package/dist/whatsapp/index.js +42 -0
- package/dist/whatsapp/index.js.map +1 -0
- package/dist/whatsapp/split.d.ts +35 -0
- package/dist/whatsapp/split.d.ts.map +1 -0
- package/dist/whatsapp/split.js +76 -0
- package/dist/whatsapp/split.js.map +1 -0
- package/dist/whatsapp/templates.d.ts +129 -0
- package/dist/whatsapp/templates.d.ts.map +1 -0
- package/dist/whatsapp/templates.js +125 -0
- package/dist/whatsapp/templates.js.map +1 -0
- package/dist/whatsapp/types.d.ts +440 -0
- package/dist/whatsapp/types.d.ts.map +1 -0
- package/dist/whatsapp/types.js +11 -0
- package/dist/whatsapp/types.js.map +1 -0
- package/package.json +31 -0
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module whatsapp/client
|
|
3
|
+
*
|
|
4
|
+
* WhatsApp Cloud API client implementing the {@link PlatformClient} interface
|
|
5
|
+
* from `@ariaflowagents/messaging`.
|
|
6
|
+
*
|
|
7
|
+
* Provides a complete, production-ready integration with Meta's WhatsApp
|
|
8
|
+
* Business Platform including:
|
|
9
|
+
*
|
|
10
|
+
* - Sending text, media, interactive, template, location, and contact messages
|
|
11
|
+
* - Webhook handling with signature verification
|
|
12
|
+
* - Template management (list, create, delete)
|
|
13
|
+
* - Phone number management (register, verify, business profile)
|
|
14
|
+
* - WhatsApp Flows management
|
|
15
|
+
* - Media upload and download
|
|
16
|
+
* - Smart message splitting for the 4096-char limit
|
|
17
|
+
* - WhatsApp-specific format conversion
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { createWhatsAppClient } from '@ariaflowagents/messaging-meta/whatsapp';
|
|
22
|
+
*
|
|
23
|
+
* const client = createWhatsAppClient({
|
|
24
|
+
* accessToken: process.env.WHATSAPP_ACCESS_TOKEN!,
|
|
25
|
+
* appSecret: process.env.META_APP_SECRET!,
|
|
26
|
+
* phoneNumberId: process.env.WHATSAPP_PHONE_NUMBER_ID!,
|
|
27
|
+
* verifyToken: process.env.WHATSAPP_VERIFY_TOKEN!,
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* client.onMessage(async (msg) => {
|
|
31
|
+
* await client.sendText(msg.from.phone!, `Echo: ${msg.text}`);
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
import type { PlatformClient, SendResult, MediaPayload, MediaHandle, MediaDownload, MediaUploadOptions, InteractiveMessage, MessageHandler, StatusHandler, ReactionHandler, FormatConverter } from '@ariaflowagents/messaging';
|
|
36
|
+
import type { NormalizedMessage } from '../webhook/normalizer.js';
|
|
37
|
+
import type { WhatsAppClientConfig, TemplateMessage, TemplateInfo, TemplateDefinition, TextOrTemplateOptions, ListMessage, ButtonMessage, CTAButtonMessage, FlowInteractiveInput, LocationPayload, ContactPayload, BusinessProfile, FlowDefinition, FlowInfo, FlowAssets } from './types.js';
|
|
38
|
+
/** Raw inbound type (the normalised message from the webhook). */
|
|
39
|
+
type WhatsAppInbound = NormalizedMessage;
|
|
40
|
+
/** Raw outbound type (arbitrary JSON payload). */
|
|
41
|
+
type WhatsAppOutbound = Record<string, unknown>;
|
|
42
|
+
/**
|
|
43
|
+
* Create a new {@link WhatsAppClient} instance.
|
|
44
|
+
*
|
|
45
|
+
* This is the recommended entry point. It constructs the client with all
|
|
46
|
+
* internal dependencies wired up (Graph API client, format converter).
|
|
47
|
+
*
|
|
48
|
+
* @param config - WhatsApp client configuration.
|
|
49
|
+
* @returns A fully configured {@link WhatsAppClient}.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* const whatsapp = createWhatsAppClient({
|
|
54
|
+
* accessToken: process.env.WHATSAPP_ACCESS_TOKEN!,
|
|
55
|
+
* appSecret: process.env.META_APP_SECRET!,
|
|
56
|
+
* phoneNumberId: process.env.WHATSAPP_PHONE_NUMBER_ID!,
|
|
57
|
+
* verifyToken: process.env.WHATSAPP_VERIFY_TOKEN!,
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare function createWhatsAppClient(config: WhatsAppClientConfig): WhatsAppClient;
|
|
62
|
+
/**
|
|
63
|
+
* Full-featured WhatsApp Cloud API client.
|
|
64
|
+
*
|
|
65
|
+
* Implements the `PlatformClient` interface from `@ariaflowagents/messaging`
|
|
66
|
+
* so it can be plugged into the messaging adapter layer, while also exposing
|
|
67
|
+
* WhatsApp-specific capabilities (templates, flows, reactions, CTA buttons).
|
|
68
|
+
*
|
|
69
|
+
* Use {@link createWhatsAppClient} to instantiate.
|
|
70
|
+
*/
|
|
71
|
+
export declare class WhatsAppClient implements PlatformClient<WhatsAppClientConfig, string, WhatsAppInbound, WhatsAppOutbound> {
|
|
72
|
+
/** @inheritdoc */
|
|
73
|
+
readonly platform: "whatsapp";
|
|
74
|
+
private readonly graphApi;
|
|
75
|
+
private readonly config;
|
|
76
|
+
private readonly messageHandlers;
|
|
77
|
+
private readonly statusHandlers;
|
|
78
|
+
private readonly reactionHandlers;
|
|
79
|
+
private readonly formatConverterInstance;
|
|
80
|
+
private readonly mediaCache?;
|
|
81
|
+
constructor(config: WhatsAppClientConfig);
|
|
82
|
+
/** WhatsApp-specific format converter. */
|
|
83
|
+
get formatConverter(): FormatConverter;
|
|
84
|
+
/**
|
|
85
|
+
* Register a handler for inbound messages.
|
|
86
|
+
*
|
|
87
|
+
* Multiple handlers can be registered; they are called in order for
|
|
88
|
+
* each incoming message.
|
|
89
|
+
*
|
|
90
|
+
* @param handler - Callback invoked with the normalised message and raw payload.
|
|
91
|
+
*/
|
|
92
|
+
onMessage(handler: MessageHandler<WhatsAppInbound>): void;
|
|
93
|
+
/**
|
|
94
|
+
* Register a handler for delivery/read status updates.
|
|
95
|
+
*
|
|
96
|
+
* @param handler - Callback invoked with the normalised status update.
|
|
97
|
+
*/
|
|
98
|
+
onStatus(handler: StatusHandler): void;
|
|
99
|
+
/**
|
|
100
|
+
* Register a handler for reaction events.
|
|
101
|
+
*
|
|
102
|
+
* @param handler - Callback invoked with the normalised reaction data.
|
|
103
|
+
*/
|
|
104
|
+
onReaction(handler: ReactionHandler): void;
|
|
105
|
+
/**
|
|
106
|
+
* Handle an incoming webhook request from Meta.
|
|
107
|
+
*
|
|
108
|
+
* - **GET** requests are treated as subscription verification challenges.
|
|
109
|
+
* - **POST** requests are validated via HMAC-SHA256 signature, normalised,
|
|
110
|
+
* and dispatched to registered handlers.
|
|
111
|
+
*
|
|
112
|
+
* @param request - The incoming HTTP request.
|
|
113
|
+
* @returns An HTTP response (200 OK, 401 Unauthorized, or 403 Forbidden).
|
|
114
|
+
*/
|
|
115
|
+
handleWebhook(request: Request): Promise<Response>;
|
|
116
|
+
/**
|
|
117
|
+
* Handle webhook verification (GET) from Meta.
|
|
118
|
+
*
|
|
119
|
+
* @param request - The GET request with `hub.mode`, `hub.verify_token`, and `hub.challenge`.
|
|
120
|
+
* @returns 200 with the challenge string, or 403 Forbidden.
|
|
121
|
+
*/
|
|
122
|
+
private handleVerification;
|
|
123
|
+
/**
|
|
124
|
+
* Send a text message.
|
|
125
|
+
*
|
|
126
|
+
* Long messages are automatically split at natural boundaries
|
|
127
|
+
* (paragraphs, lines, words) to stay within WhatsApp's 4096-character limit.
|
|
128
|
+
*
|
|
129
|
+
* @param to - Recipient phone number in E.164 format.
|
|
130
|
+
* @param text - The text content to send.
|
|
131
|
+
* @returns The result of the last chunk sent.
|
|
132
|
+
*/
|
|
133
|
+
sendText(to: string, text: string): Promise<SendResult>;
|
|
134
|
+
/**
|
|
135
|
+
* Send a media message (image, video, audio, document, or sticker).
|
|
136
|
+
*
|
|
137
|
+
* Accepts URLs (string), Buffers (uploaded automatically), or ReadableStreams.
|
|
138
|
+
*
|
|
139
|
+
* @param to - Recipient phone number in E.164 format.
|
|
140
|
+
* @param media - The media payload to send.
|
|
141
|
+
* @returns The send result.
|
|
142
|
+
*/
|
|
143
|
+
sendMedia(to: string, media: MediaPayload): Promise<SendResult>;
|
|
144
|
+
/**
|
|
145
|
+
* Send an interactive message (buttons or list).
|
|
146
|
+
*
|
|
147
|
+
* Converts the platform-agnostic {@link InteractiveMessage} into WhatsApp's
|
|
148
|
+
* interactive message format.
|
|
149
|
+
*
|
|
150
|
+
* @param to - Recipient phone number in E.164 format.
|
|
151
|
+
* @param msg - The interactive message definition.
|
|
152
|
+
* @returns The send result.
|
|
153
|
+
* @throws {@link MessagingError} if the interactive type is unsupported.
|
|
154
|
+
*/
|
|
155
|
+
sendInteractive(to: string, msg: InteractiveMessage): Promise<SendResult>;
|
|
156
|
+
/**
|
|
157
|
+
* Send a raw platform-specific payload.
|
|
158
|
+
*
|
|
159
|
+
* This is an escape hatch for features not covered by the normalised
|
|
160
|
+
* interface. The payload is merged with the standard messaging envelope.
|
|
161
|
+
*
|
|
162
|
+
* @param to - Recipient phone number in E.164 format.
|
|
163
|
+
* @param payload - Raw WhatsApp API payload fields.
|
|
164
|
+
* @returns The send result.
|
|
165
|
+
*/
|
|
166
|
+
sendRaw(to: string, payload: WhatsAppOutbound): Promise<SendResult>;
|
|
167
|
+
/**
|
|
168
|
+
* Mark a message as read on WhatsApp.
|
|
169
|
+
*
|
|
170
|
+
* Sends the blue double-tick indicator to the sender.
|
|
171
|
+
*
|
|
172
|
+
* @param messageId - The WhatsApp message ID to mark as read.
|
|
173
|
+
*/
|
|
174
|
+
markAsRead(messageId: string): Promise<void>;
|
|
175
|
+
/**
|
|
176
|
+
* Send a typing indicator.
|
|
177
|
+
*
|
|
178
|
+
* WhatsApp Cloud API does not currently support typing indicators,
|
|
179
|
+
* so this method is a no-op that satisfies the {@link PlatformClient} interface.
|
|
180
|
+
*
|
|
181
|
+
* @param _to - Recipient phone number (unused).
|
|
182
|
+
*/
|
|
183
|
+
sendTypingIndicator(_to: string): Promise<void>;
|
|
184
|
+
/**
|
|
185
|
+
* Send a pre-approved template message.
|
|
186
|
+
*
|
|
187
|
+
* Templates are the only message type allowed outside the 24-hour
|
|
188
|
+
* customer service window. They must be approved by Meta before use.
|
|
189
|
+
*
|
|
190
|
+
* @param to - Recipient phone number in E.164 format.
|
|
191
|
+
* @param template - The template message payload.
|
|
192
|
+
* @returns The send result.
|
|
193
|
+
*/
|
|
194
|
+
sendTemplate(to: string, template: TemplateMessage): Promise<SendResult>;
|
|
195
|
+
/**
|
|
196
|
+
* Send a text message with automatic template fallback.
|
|
197
|
+
*
|
|
198
|
+
* Attempts to send a free-form text message first. If the 24-hour
|
|
199
|
+
* customer service window has closed (indicated by a {@link WindowClosedError}),
|
|
200
|
+
* automatically falls back to the specified template message.
|
|
201
|
+
*
|
|
202
|
+
* @param to - Recipient phone number in E.164 format.
|
|
203
|
+
* @param opts - Text content and fallback template configuration.
|
|
204
|
+
* @returns The send result (from either the text or template delivery).
|
|
205
|
+
*/
|
|
206
|
+
sendTextOrTemplate(to: string, opts: TextOrTemplateOptions): Promise<SendResult>;
|
|
207
|
+
/**
|
|
208
|
+
* Send a list interactive message.
|
|
209
|
+
*
|
|
210
|
+
* Lists display an expandable set of sections with selectable rows,
|
|
211
|
+
* useful for menus, catalogs, or multi-option selections.
|
|
212
|
+
*
|
|
213
|
+
* @param to - Recipient phone number in E.164 format.
|
|
214
|
+
* @param list - The list message configuration.
|
|
215
|
+
* @returns The send result.
|
|
216
|
+
*/
|
|
217
|
+
sendListMessage(to: string, list: ListMessage): Promise<SendResult>;
|
|
218
|
+
/**
|
|
219
|
+
* Send a button interactive message.
|
|
220
|
+
*
|
|
221
|
+
* Supports up to 3 quick-reply buttons. Button titles are truncated
|
|
222
|
+
* to 20 characters per WhatsApp's requirements.
|
|
223
|
+
*
|
|
224
|
+
* @param to - Recipient phone number in E.164 format.
|
|
225
|
+
* @param msg - The button message configuration.
|
|
226
|
+
* @returns The send result.
|
|
227
|
+
*/
|
|
228
|
+
sendInteractiveButtons(to: string, msg: ButtonMessage): Promise<SendResult>;
|
|
229
|
+
/**
|
|
230
|
+
* Send a call-to-action URL button message.
|
|
231
|
+
*
|
|
232
|
+
* Renders a button that opens the specified URL in the user's browser
|
|
233
|
+
* when tapped.
|
|
234
|
+
*
|
|
235
|
+
* @param to - Recipient phone number in E.164 format.
|
|
236
|
+
* @param cta - The CTA button configuration.
|
|
237
|
+
* @returns The send result.
|
|
238
|
+
*/
|
|
239
|
+
sendCTAButton(to: string, cta: CTAButtonMessage): Promise<SendResult>;
|
|
240
|
+
/**
|
|
241
|
+
* Send a WhatsApp Flow as an interactive message.
|
|
242
|
+
*
|
|
243
|
+
* WhatsApp Flows are multi-screen forms that run natively inside WhatsApp,
|
|
244
|
+
* enabling structured data collection without leaving the chat.
|
|
245
|
+
*
|
|
246
|
+
* @param to - Recipient phone number in E.164 format.
|
|
247
|
+
* @param flow - The flow interactive input configuration.
|
|
248
|
+
* @returns The send result.
|
|
249
|
+
*/
|
|
250
|
+
sendInteractiveFlow(to: string, flow: FlowInteractiveInput): Promise<SendResult>;
|
|
251
|
+
/**
|
|
252
|
+
* Send a reaction emoji on an existing message.
|
|
253
|
+
*
|
|
254
|
+
* To remove a reaction, pass an empty string as the emoji.
|
|
255
|
+
*
|
|
256
|
+
* @param to - Recipient phone number in E.164 format.
|
|
257
|
+
* @param messageId - The message to react to.
|
|
258
|
+
* @param emoji - The emoji to react with (e.g. `"\ud83d\udc4d"`).
|
|
259
|
+
* @returns The send result.
|
|
260
|
+
*/
|
|
261
|
+
sendReaction(to: string, messageId: string, emoji: string): Promise<SendResult>;
|
|
262
|
+
/**
|
|
263
|
+
* Send a location pin message.
|
|
264
|
+
*
|
|
265
|
+
* Renders a map preview with the specified coordinates, name, and address.
|
|
266
|
+
*
|
|
267
|
+
* @param to - Recipient phone number in E.164 format.
|
|
268
|
+
* @param location - The location payload with coordinates and optional metadata.
|
|
269
|
+
* @returns The send result.
|
|
270
|
+
*/
|
|
271
|
+
sendLocation(to: string, location: LocationPayload): Promise<SendResult>;
|
|
272
|
+
/**
|
|
273
|
+
* Send one or more contact cards.
|
|
274
|
+
*
|
|
275
|
+
* @param to - Recipient phone number in E.164 format.
|
|
276
|
+
* @param contacts - Array of contact payloads.
|
|
277
|
+
* @returns The send result.
|
|
278
|
+
*/
|
|
279
|
+
sendContacts(to: string, contacts: ContactPayload[]): Promise<SendResult>;
|
|
280
|
+
/**
|
|
281
|
+
* Template management operations.
|
|
282
|
+
*
|
|
283
|
+
* Provides methods to list, create, and delete message templates
|
|
284
|
+
* via the WhatsApp Business Management API.
|
|
285
|
+
*/
|
|
286
|
+
readonly templates: {
|
|
287
|
+
/**
|
|
288
|
+
* List all message templates for a WhatsApp Business Account.
|
|
289
|
+
*
|
|
290
|
+
* @param wabaId - The WhatsApp Business Account ID.
|
|
291
|
+
* @returns Array of template information objects.
|
|
292
|
+
*/
|
|
293
|
+
list: (wabaId: string) => Promise<TemplateInfo[]>;
|
|
294
|
+
/**
|
|
295
|
+
* Create a new message template.
|
|
296
|
+
*
|
|
297
|
+
* The template must be approved by Meta before it can be used for sending.
|
|
298
|
+
*
|
|
299
|
+
* @param wabaId - The WhatsApp Business Account ID.
|
|
300
|
+
* @param template - The template definition.
|
|
301
|
+
* @returns The created template information.
|
|
302
|
+
*/
|
|
303
|
+
create: (wabaId: string, template: TemplateDefinition) => Promise<TemplateInfo>;
|
|
304
|
+
/**
|
|
305
|
+
* Delete a message template by name.
|
|
306
|
+
*
|
|
307
|
+
* Deletes all language variants of the template. Uses a POST with
|
|
308
|
+
* a `_method=DELETE` override since the Graph API client does not
|
|
309
|
+
* expose a dedicated DELETE method.
|
|
310
|
+
*
|
|
311
|
+
* @param wabaId - The WhatsApp Business Account ID.
|
|
312
|
+
* @param name - The template name to delete.
|
|
313
|
+
*/
|
|
314
|
+
delete: (wabaId: string, name: string) => Promise<void>;
|
|
315
|
+
};
|
|
316
|
+
/**
|
|
317
|
+
* Phone number management operations.
|
|
318
|
+
*
|
|
319
|
+
* Provides methods for phone number registration, verification,
|
|
320
|
+
* and business profile management.
|
|
321
|
+
*/
|
|
322
|
+
readonly phoneNumbers: {
|
|
323
|
+
/**
|
|
324
|
+
* Request a verification code for a phone number.
|
|
325
|
+
*
|
|
326
|
+
* @param phoneNumberId - The phone number ID to verify.
|
|
327
|
+
* @param method - Delivery method (`"SMS"` or `"VOICE"`).
|
|
328
|
+
* @param language - Language code for the verification message.
|
|
329
|
+
*/
|
|
330
|
+
requestCode: (phoneNumberId: string, method: "SMS" | "VOICE", language: string) => Promise<void>;
|
|
331
|
+
/**
|
|
332
|
+
* Verify a phone number with the received code.
|
|
333
|
+
*
|
|
334
|
+
* @param phoneNumberId - The phone number ID to verify.
|
|
335
|
+
* @param code - The verification code received via SMS or voice.
|
|
336
|
+
*/
|
|
337
|
+
verifyCode: (phoneNumberId: string, code: string) => Promise<void>;
|
|
338
|
+
/**
|
|
339
|
+
* Register a phone number for WhatsApp Business.
|
|
340
|
+
*
|
|
341
|
+
* @param phoneNumberId - The phone number ID to register.
|
|
342
|
+
* @param pin - A 6-digit PIN for two-step verification.
|
|
343
|
+
*/
|
|
344
|
+
register: (phoneNumberId: string, pin: string) => Promise<void>;
|
|
345
|
+
/**
|
|
346
|
+
* Get the WhatsApp Business profile for a phone number.
|
|
347
|
+
*
|
|
348
|
+
* @param phoneNumberId - The phone number ID.
|
|
349
|
+
* @returns The business profile data.
|
|
350
|
+
*/
|
|
351
|
+
getBusinessProfile: (phoneNumberId: string) => Promise<BusinessProfile>;
|
|
352
|
+
/**
|
|
353
|
+
* Update the WhatsApp Business profile for a phone number.
|
|
354
|
+
*
|
|
355
|
+
* @param phoneNumberId - The phone number ID.
|
|
356
|
+
* @param profile - The profile fields to update.
|
|
357
|
+
*/
|
|
358
|
+
updateBusinessProfile: (phoneNumberId: string, profile: Partial<BusinessProfile>) => Promise<void>;
|
|
359
|
+
};
|
|
360
|
+
/**
|
|
361
|
+
* WhatsApp Flows management operations.
|
|
362
|
+
*
|
|
363
|
+
* Provides methods to create, update, publish, deprecate, and inspect
|
|
364
|
+
* WhatsApp Flows.
|
|
365
|
+
*/
|
|
366
|
+
readonly flows: {
|
|
367
|
+
/**
|
|
368
|
+
* Create a new WhatsApp Flow.
|
|
369
|
+
*
|
|
370
|
+
* @param wabaId - The WhatsApp Business Account ID.
|
|
371
|
+
* @param flow - The flow definition.
|
|
372
|
+
* @returns The created flow information.
|
|
373
|
+
*/
|
|
374
|
+
create: (wabaId: string, flow: FlowDefinition) => Promise<FlowInfo>;
|
|
375
|
+
/**
|
|
376
|
+
* Update an existing WhatsApp Flow.
|
|
377
|
+
*
|
|
378
|
+
* @param flowId - The flow ID to update.
|
|
379
|
+
* @param flow - The fields to update.
|
|
380
|
+
* @returns The updated flow information.
|
|
381
|
+
*/
|
|
382
|
+
update: (flowId: string, flow: Partial<FlowDefinition>) => Promise<FlowInfo>;
|
|
383
|
+
/**
|
|
384
|
+
* Publish a draft WhatsApp Flow, making it available for use in messages.
|
|
385
|
+
*
|
|
386
|
+
* @param flowId - The flow ID to publish.
|
|
387
|
+
*/
|
|
388
|
+
publish: (flowId: string) => Promise<void>;
|
|
389
|
+
/**
|
|
390
|
+
* Deprecate a WhatsApp Flow (soft delete).
|
|
391
|
+
*
|
|
392
|
+
* Deprecated flows can no longer be sent but existing instances continue working.
|
|
393
|
+
*
|
|
394
|
+
* @param flowId - The flow ID to deprecate.
|
|
395
|
+
*/
|
|
396
|
+
delete: (flowId: string) => Promise<void>;
|
|
397
|
+
/**
|
|
398
|
+
* Get the assets (JSON definition) for a WhatsApp Flow.
|
|
399
|
+
*
|
|
400
|
+
* @param flowId - The flow ID.
|
|
401
|
+
* @returns The flow assets including download URLs.
|
|
402
|
+
*/
|
|
403
|
+
getAssets: (flowId: string) => Promise<FlowAssets>;
|
|
404
|
+
};
|
|
405
|
+
/**
|
|
406
|
+
* Upload media to WhatsApp for later use in messages.
|
|
407
|
+
*
|
|
408
|
+
* @param file - The file content as a Buffer or ReadableStream.
|
|
409
|
+
* @param options - Upload options including MIME type and optional filename.
|
|
410
|
+
* @returns A handle containing the platform-assigned media ID.
|
|
411
|
+
*/
|
|
412
|
+
uploadMedia(file: Buffer | ReadableStream, options: MediaUploadOptions): Promise<MediaHandle>;
|
|
413
|
+
/**
|
|
414
|
+
* Download media from WhatsApp by its ID.
|
|
415
|
+
*
|
|
416
|
+
* Performs a two-step process: first retrieves the temporary download URL
|
|
417
|
+
* via the media info endpoint, then downloads the binary content.
|
|
418
|
+
*
|
|
419
|
+
* @param mediaId - The WhatsApp media ID.
|
|
420
|
+
* @returns The downloaded media content, MIME type, and optional filename.
|
|
421
|
+
*/
|
|
422
|
+
downloadMedia(mediaId: string): Promise<MediaDownload>;
|
|
423
|
+
/**
|
|
424
|
+
* Returns a Hono sub-application that handles webhook routes.
|
|
425
|
+
*
|
|
426
|
+
* Mounts GET (verification) and POST (event delivery) handlers at the
|
|
427
|
+
* root path. Use this to integrate the webhook into an existing Hono app.
|
|
428
|
+
*
|
|
429
|
+
* Requires `hono` to be installed as a peer dependency. The import is
|
|
430
|
+
* performed dynamically to avoid a hard compile-time dependency.
|
|
431
|
+
*
|
|
432
|
+
* @returns A Hono application with webhook routes.
|
|
433
|
+
*
|
|
434
|
+
* @example
|
|
435
|
+
* ```ts
|
|
436
|
+
* import { Hono } from 'hono';
|
|
437
|
+
*
|
|
438
|
+
* const app = new Hono();
|
|
439
|
+
* app.route('/webhooks/whatsapp', client.webhookRouter());
|
|
440
|
+
* ```
|
|
441
|
+
*/
|
|
442
|
+
webhookRouter(): any;
|
|
443
|
+
/**
|
|
444
|
+
* Convert a normalised webhook message to a platform-agnostic {@link InboundMessage}.
|
|
445
|
+
*/
|
|
446
|
+
private toInboundMessage;
|
|
447
|
+
/**
|
|
448
|
+
* Convert a normalised webhook status to a platform-agnostic {@link StatusUpdate}.
|
|
449
|
+
*/
|
|
450
|
+
private toStatusUpdate;
|
|
451
|
+
/**
|
|
452
|
+
* Convert a normalised webhook reaction to a platform-agnostic {@link ReactionData}.
|
|
453
|
+
*/
|
|
454
|
+
private toReactionData;
|
|
455
|
+
/**
|
|
456
|
+
* Convert a {@link WhatsAppSendResponse} to a platform-agnostic {@link SendResult}.
|
|
457
|
+
*/
|
|
458
|
+
private toSendResult;
|
|
459
|
+
/**
|
|
460
|
+
* Map a WhatsApp message type string to the normalised {@link InboundMessage} type union.
|
|
461
|
+
*/
|
|
462
|
+
private mapMessageType;
|
|
463
|
+
/**
|
|
464
|
+
* Extract a text fallback from non-text message types (captions, button text, etc.).
|
|
465
|
+
*/
|
|
466
|
+
private extractTextFallback;
|
|
467
|
+
/**
|
|
468
|
+
* Extract a {@link MediaReference} from a normalised message if it contains media.
|
|
469
|
+
*/
|
|
470
|
+
private extractMedia;
|
|
471
|
+
/**
|
|
472
|
+
* Send a single text message (without splitting).
|
|
473
|
+
*/
|
|
474
|
+
private sendSingleText;
|
|
475
|
+
/**
|
|
476
|
+
* Resolve a MIME type to a WhatsApp media type string.
|
|
477
|
+
*/
|
|
478
|
+
private resolveMediaType;
|
|
479
|
+
}
|
|
480
|
+
export {};
|
|
481
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/whatsapp/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,KAAK,EACV,cAAc,EAGd,UAAU,EACV,YAAY,EACZ,WAAW,EACX,aAAa,EACb,kBAAkB,EAElB,kBAAkB,EAElB,cAAc,EACd,aAAa,EACb,eAAe,EACf,eAAe,EAEhB,MAAM,2BAA2B,CAAC;AASnC,OAAO,KAAK,EACV,iBAAiB,EAGlB,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EACV,oBAAoB,EAGpB,eAAe,EACf,YAAY,EACZ,kBAAkB,EAClB,qBAAqB,EACrB,WAAW,EACX,aAAa,EACb,gBAAgB,EAChB,oBAAoB,EACpB,eAAe,EACf,cAAc,EAEd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