meta-cloud-api 0.2.44 → 1.0.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.
Files changed (186) hide show
  1. package/README.md +180 -64
  2. package/dist/{BusinessProfileApi-DE7Nnuy_.d.ts → BusinessProfileApi-WXscSgo-.d.ts} +4 -3
  3. package/dist/{EncryptionApi-PHxeI2G_.d.ts → EncryptionApi-D7pt-OXT.d.ts} +3 -2
  4. package/dist/FlowApi-UAvzhJfV.d.ts +136 -0
  5. package/dist/{MediaApi-B2vtjiCm.d.ts → MediaApi-BrEKpqi_.d.ts} +3 -2
  6. package/dist/{MessageApi-ptFlWg3O.d.ts → MessageApi-Circorzz.d.ts} +4 -3
  7. package/dist/{PhoneNumberApi-DMb_G3uw.d.ts → PhoneNumberApi-DKlu9PHl.d.ts} +4 -3
  8. package/dist/{QrCodeApi-D3rVKuxV.d.ts → QrCodeApi-7vDwIBHR.d.ts} +3 -2
  9. package/dist/{RegistrationApi-DZBJWAZS.d.ts → RegistrationApi-qO_qoti9.d.ts} +4 -3
  10. package/dist/{TemplateApi-BFeM9qJS.d.ts → TemplateApi-xGgIZt89.d.ts} +5 -4
  11. package/dist/{TwoStepVerificationApi-6jV5pDxS.d.ts → TwoStepVerificationApi-DfNPIz-C.d.ts} +3 -2
  12. package/dist/{WabaApi-B8Gv2UNE.d.ts → WabaApi-DqQi_68m.d.ts} +3 -2
  13. package/dist/{WebhookHandler-Bxxi6SdT.d.ts → WebhookProcessor-ByAe7Kf_.d.ts} +22 -32
  14. package/dist/WhatsApp-BIBtT-y9.d.ts +82 -0
  15. package/dist/api/encryption/index.d.ts +10 -0
  16. package/dist/api/encryption/index.js +2 -0
  17. package/dist/api/flow/index.d.ts +10 -0
  18. package/dist/api/flow/index.js +2 -0
  19. package/dist/api/index.d.ts +16 -0
  20. package/dist/api/index.js +2 -0
  21. package/dist/api/media/index.d.ts +10 -0
  22. package/dist/api/media/index.js +2 -0
  23. package/dist/{features → api}/messages/index.d.ts +6 -5
  24. package/dist/api/messages/index.js +2 -0
  25. package/dist/{features → api}/phone/index.d.ts +6 -5
  26. package/dist/api/phone/index.js +2 -0
  27. package/dist/{features → api}/profile/index.d.ts +6 -5
  28. package/dist/api/profile/index.js +2 -0
  29. package/dist/api/qrCode/index.d.ts +10 -0
  30. package/dist/api/qrCode/index.js +2 -0
  31. package/dist/api/registration/index.d.ts +10 -0
  32. package/dist/api/registration/index.js +2 -0
  33. package/dist/{features → api}/template/index.d.ts +6 -5
  34. package/dist/api/template/index.js +2 -0
  35. package/dist/api/twoStepVerification/index.d.ts +10 -0
  36. package/dist/api/twoStepVerification/index.js +2 -0
  37. package/dist/api/waba/index.d.ts +10 -0
  38. package/dist/api/waba/index.js +2 -0
  39. package/dist/api/waba/index.js.map +1 -0
  40. package/dist/base-CdGDdVEl.d.ts +18 -0
  41. package/dist/{chunk-2NJVBJUN.js → chunk-7QBIZCJ4.js} +2 -2
  42. package/dist/chunk-7QBIZCJ4.js.map +1 -0
  43. package/dist/chunk-AMHQGG6Z.js +2 -0
  44. package/dist/{chunk-4C666HHU.js.map → chunk-AMHQGG6Z.js.map} +1 -1
  45. package/dist/chunk-B7DCL6I7.js +10 -0
  46. package/dist/chunk-B7DCL6I7.js.map +1 -0
  47. package/dist/{chunk-7GL74SXM.js → chunk-CRZ7EUYR.js} +2 -2
  48. package/dist/chunk-CRZ7EUYR.js.map +1 -0
  49. package/dist/chunk-FKXSL2JK.js +3 -0
  50. package/dist/chunk-FKXSL2JK.js.map +1 -0
  51. package/dist/chunk-FSKBLPGE.js +2 -0
  52. package/dist/chunk-FSKBLPGE.js.map +1 -0
  53. package/dist/chunk-HJGN3PO4.js +3 -0
  54. package/dist/chunk-HJGN3PO4.js.map +1 -0
  55. package/dist/{chunk-7NQLQPLH.js → chunk-IYSR44P6.js} +2 -2
  56. package/dist/chunk-IYSR44P6.js.map +1 -0
  57. package/dist/chunk-JC6YMVID.js +2 -0
  58. package/dist/chunk-JC6YMVID.js.map +1 -0
  59. package/dist/{chunk-GT3XQN7Y.js → chunk-JPAV644F.js} +2 -2
  60. package/dist/chunk-JPAV644F.js.map +1 -0
  61. package/dist/{chunk-XPPDOFBN.js → chunk-JXCLRKQ7.js} +2 -2
  62. package/dist/chunk-JXCLRKQ7.js.map +1 -0
  63. package/dist/chunk-KMAH6636.js +2 -0
  64. package/dist/chunk-KMAH6636.js.map +1 -0
  65. package/dist/{chunk-5JGM556C.js → chunk-L4ESAO2S.js} +2 -2
  66. package/dist/chunk-L4ESAO2S.js.map +1 -0
  67. package/dist/chunk-LV3TULSI.js +2 -0
  68. package/dist/chunk-LV3TULSI.js.map +1 -0
  69. package/dist/{chunk-BZ5QDXNR.js → chunk-MJEG3K4V.js} +2 -2
  70. package/dist/chunk-MJEG3K4V.js.map +1 -0
  71. package/dist/chunk-NLF2JGYY.js +2 -0
  72. package/dist/chunk-NLF2JGYY.js.map +1 -0
  73. package/dist/chunk-OA2SW4AF.js +2 -0
  74. package/dist/chunk-OA2SW4AF.js.map +1 -0
  75. package/dist/chunk-PHPQ5HP3.js +2 -0
  76. package/dist/chunk-PHPQ5HP3.js.map +1 -0
  77. package/dist/chunk-RIL6QABY.js +2 -0
  78. package/dist/chunk-RIL6QABY.js.map +1 -0
  79. package/dist/chunk-RWCVPWRC.js +2 -0
  80. package/dist/chunk-RWCVPWRC.js.map +1 -0
  81. package/dist/chunk-SNNRWNGZ.js +2 -0
  82. package/dist/chunk-SNNRWNGZ.js.map +1 -0
  83. package/dist/chunk-UCBYECNQ.js +2 -0
  84. package/dist/chunk-UCBYECNQ.js.map +1 -0
  85. package/dist/chunk-VHAODWCN.js +2 -0
  86. package/dist/chunk-VHAODWCN.js.map +1 -0
  87. package/dist/chunk-WGGN32O2.js +2 -0
  88. package/dist/chunk-WGGN32O2.js.map +1 -0
  89. package/dist/{FlowApi-CASVC-Al.d.ts → common-DDXsNyLF.d.ts} +2 -133
  90. package/dist/core/webhook/frameworks/express.d.ts +48 -0
  91. package/dist/core/webhook/frameworks/express.js +2 -0
  92. package/dist/core/webhook/frameworks/express.js.map +1 -0
  93. package/dist/core/webhook/frameworks/nextjs.d.ts +44 -0
  94. package/dist/core/webhook/frameworks/nextjs.js +2 -0
  95. package/dist/core/webhook/frameworks/nextjs.js.map +1 -0
  96. package/dist/core/webhook/index.d.ts +21 -16
  97. package/dist/core/webhook/index.js +1 -1
  98. package/dist/core/whatsapp/index.d.ts +39 -15
  99. package/dist/core/whatsapp/index.js +1 -1
  100. package/dist/{enums-DvwSJq9w.d.ts → enums-BZd9T2ul.d.ts} +1 -1
  101. package/dist/httpsClient-v4gmltzS.d.ts +19 -0
  102. package/dist/index.d.ts +21 -82
  103. package/dist/index.js +1 -1
  104. package/dist/logger-BdE0Vyim.d.ts +9 -0
  105. package/dist/{base-BhCbbsxB.d.ts → request-vYMaEfk5.d.ts} +2 -16
  106. package/dist/{shared/types → types}/config.d.ts +1 -1
  107. package/dist/types/enums.d.ts +1 -0
  108. package/dist/{shared/types → types}/enums.js +1 -1
  109. package/dist/types/index.d.ts +6 -0
  110. package/dist/types/index.js +2 -0
  111. package/dist/types/index.js.map +1 -0
  112. package/dist/utils/index.d.ts +98 -0
  113. package/dist/utils/index.js +2 -0
  114. package/dist/utils/index.js.map +1 -0
  115. package/package.json +91 -34
  116. package/dist/chunk-2NJVBJUN.js.map +0 -1
  117. package/dist/chunk-3MO3BTBC.js +0 -2
  118. package/dist/chunk-3MO3BTBC.js.map +0 -1
  119. package/dist/chunk-4C666HHU.js +0 -2
  120. package/dist/chunk-4O3T25CT.js +0 -2
  121. package/dist/chunk-4O3T25CT.js.map +0 -1
  122. package/dist/chunk-5JGM556C.js.map +0 -1
  123. package/dist/chunk-5O5GLWIE.js +0 -3
  124. package/dist/chunk-5O5GLWIE.js.map +0 -1
  125. package/dist/chunk-7GL74SXM.js.map +0 -1
  126. package/dist/chunk-7NQLQPLH.js.map +0 -1
  127. package/dist/chunk-BZ5QDXNR.js.map +0 -1
  128. package/dist/chunk-CNGQISKS.js +0 -2
  129. package/dist/chunk-CNGQISKS.js.map +0 -1
  130. package/dist/chunk-GIQLIMOD.js +0 -2
  131. package/dist/chunk-GIQLIMOD.js.map +0 -1
  132. package/dist/chunk-GT3XQN7Y.js.map +0 -1
  133. package/dist/chunk-I222VSWK.js +0 -2
  134. package/dist/chunk-I222VSWK.js.map +0 -1
  135. package/dist/chunk-JGX3AVD7.js +0 -3
  136. package/dist/chunk-JGX3AVD7.js.map +0 -1
  137. package/dist/chunk-KFPOVYEJ.js +0 -2
  138. package/dist/chunk-KFPOVYEJ.js.map +0 -1
  139. package/dist/chunk-LGLRGXCE.js +0 -2
  140. package/dist/chunk-LGLRGXCE.js.map +0 -1
  141. package/dist/chunk-O2OTHNWM.js +0 -2
  142. package/dist/chunk-O2OTHNWM.js.map +0 -1
  143. package/dist/chunk-R36L2XYO.js +0 -2
  144. package/dist/chunk-R36L2XYO.js.map +0 -1
  145. package/dist/chunk-UQPD6GIF.js +0 -2
  146. package/dist/chunk-UQPD6GIF.js.map +0 -1
  147. package/dist/chunk-VW3LGHTJ.js +0 -2
  148. package/dist/chunk-VW3LGHTJ.js.map +0 -1
  149. package/dist/chunk-XPPDOFBN.js.map +0 -1
  150. package/dist/features/encryption/index.d.ts +0 -9
  151. package/dist/features/encryption/index.js +0 -2
  152. package/dist/features/flow/index.d.ts +0 -9
  153. package/dist/features/flow/index.js +0 -2
  154. package/dist/features/media/index.d.ts +0 -9
  155. package/dist/features/media/index.js +0 -2
  156. package/dist/features/messages/index.js +0 -2
  157. package/dist/features/phone/index.js +0 -2
  158. package/dist/features/profile/index.js +0 -2
  159. package/dist/features/qrCode/index.d.ts +0 -9
  160. package/dist/features/qrCode/index.js +0 -2
  161. package/dist/features/registration/index.d.ts +0 -9
  162. package/dist/features/registration/index.js +0 -2
  163. package/dist/features/template/index.js +0 -2
  164. package/dist/features/twoStepVerification/index.d.ts +0 -9
  165. package/dist/features/twoStepVerification/index.js +0 -2
  166. package/dist/features/waba/index.d.ts +0 -9
  167. package/dist/features/waba/index.js +0 -2
  168. package/dist/index-DiCI1vEz.d.ts +0 -100
  169. package/dist/shared/types/enums.d.ts +0 -1
  170. package/dist/shared/utils/isMetaError.d.ts +0 -21
  171. package/dist/shared/utils/isMetaError.js +0 -2
  172. package/dist/shared/utils/isMetaError.js.map +0 -1
  173. /package/dist/{features → api}/encryption/index.js.map +0 -0
  174. /package/dist/{features → api}/flow/index.js.map +0 -0
  175. /package/dist/{features/media → api}/index.js.map +0 -0
  176. /package/dist/{features/messages → api/media}/index.js.map +0 -0
  177. /package/dist/{features/phone → api/messages}/index.js.map +0 -0
  178. /package/dist/{features/profile → api/phone}/index.js.map +0 -0
  179. /package/dist/{features/qrCode → api/profile}/index.js.map +0 -0
  180. /package/dist/{features/registration → api/qrCode}/index.js.map +0 -0
  181. /package/dist/{features/template → api/registration}/index.js.map +0 -0
  182. /package/dist/{features/twoStepVerification → api/template}/index.js.map +0 -0
  183. /package/dist/{features/waba → api/twoStepVerification}/index.js.map +0 -0
  184. /package/dist/{shared/types → types}/config.js +0 -0
  185. /package/dist/{shared/types → types}/config.js.map +0 -0
  186. /package/dist/{shared/types → types}/enums.js.map +0 -0
package/README.md CHANGED
@@ -18,10 +18,11 @@
18
18
  ## Features
19
19
 
20
20
  - **Type-Safe Development** - Built with TypeScript to provide code completion and catch errors during development
21
- - **Comprehensive Coverage** - Full support for WhatsApp Business Platform APIs
22
- - **Clean Interface** - Intuitive methods organized by domain for improved code readability
21
+ - **Comprehensive Coverage** - Full support for WhatsApp Business Platform APIs including Messages, Media, Templates, Flows, and more
22
+ - **Modular Architecture** - Clean separation of concerns with dedicated API classes for each domain
23
+ - **Framework-Specific Webhooks** - Built-in support for Express.js and Next.js webhook handling
24
+ - **Advanced Features** - Support for Flows, Encryption, QR Codes, Two-Step Verification, and WABA management
23
25
  - **Error Handling** - Standardized error handling with detailed Meta API error information
24
- - **Webhook Handler** - Built-in support for webhook verification and message handling
25
26
 
26
27
  ## Installation
27
28
 
@@ -58,8 +59,6 @@ console.log(`Message ID: ${response.messages[0].id}`);
58
59
 
59
60
  ### Messaging
60
61
 
61
- Send different types of messages through WhatsApp Business Platform:
62
-
63
62
  #### Text Message
64
63
 
65
64
  ```typescript
@@ -146,71 +145,96 @@ const result = await client.messages.interactive({
146
145
  });
147
146
  ```
148
147
 
149
- ## Example Projects
148
+ ### Webhook Integration
150
149
 
151
- We provide ready-to-use example projects demonstrating how to integrate Meta Cloud API in different frameworks:
150
+ #### Express.js Webhook
152
151
 
153
- - [Express.js Example](./examples/express-example) - A simple Express.js server with webhook handling for WhatsApp messages
154
- - [Next.js Example](./examples/nextjs-page-router-example) - Integration with Next.js Pages Router, showing how to handle webhooks in a Next.js API route
152
+ ```typescript
153
+ import express from 'express';
154
+ import { MessageTypesEnum } from 'meta-cloud-api';
155
+ import { webhookHandler } from 'meta-cloud-api/webhook/express';
155
156
 
156
- Each example includes its own README with setup instructions and demonstration of core features.
157
+ const app = express();
157
158
 
158
- ### Webhook Integration
159
+ // Create webhook handler
160
+ const bot = webhookHandler({
161
+ accessToken: process.env.CLOUD_API_ACCESS_TOKEN!,
162
+ phoneNumberId: parseInt(process.env.WA_PHONE_NUMBER_ID!),
163
+ webhookVerificationToken: process.env.WEBHOOK_VERIFICATION_TOKEN!,
164
+ });
165
+
166
+ // Handle text messages
167
+ bot.processor.onMessage(MessageTypesEnum.Text, async (whatsapp, message) => {
168
+ await whatsapp.messages.text({
169
+ to: message.from,
170
+ body: `Echo: ${message.text?.body}`,
171
+ });
172
+ });
173
+
174
+ // Setup webhook endpoints
175
+ app.get('/webhook', bot.webhook);
176
+ app.post('/webhook', express.json(), bot.webhook);
159
177
 
160
- Set up a webhook to receive messages and events from the WhatsApp API:
178
+ app.listen(3000);
179
+ ```
180
+
181
+ #### Next.js Webhook
161
182
 
162
183
  ```typescript
163
- import WhatsApp, {
164
- WebhookHandler,
165
- MessageTypesEnum,
166
- WebhookMessage
167
- } from 'meta-cloud-api';
168
-
169
- // Initialize the handler
170
- const webhookHandler = new WebhookHandler({
171
- accessToken: process.env.CLOUD_API_ACCESS_TOKEN,
172
- phoneNumberId: Number(process.env.WA_PHONE_NUMBER_ID),
173
- businessAcctId: process.env.WA_BUSINESS_ACCOUNT_ID,
174
- webhookVerificationToken: process.env.WEBHOOK_VERIFICATION_TOKEN
184
+ // pages/api/webhook.ts
185
+ import { NextApiRequest, NextApiResponse } from 'next';
186
+ import { MessageTypesEnum } from 'meta-cloud-api';
187
+ import { webhookHandler } from 'meta-cloud-api/webhook/nextjs';
188
+
189
+ const bot = webhookHandler({
190
+ accessToken: process.env.CLOUD_API_ACCESS_TOKEN!,
191
+ phoneNumberId: parseInt(process.env.WA_PHONE_NUMBER_ID!),
192
+ webhookVerificationToken: process.env.WEBHOOK_VERIFICATION_TOKEN!,
175
193
  });
176
194
 
177
- // Handle webhook verification
178
- app.get('/webhook', (req, res) => {
179
- webhookHandler.handleVerificationRequest(req, res);
195
+ // Handle text messages
196
+ bot.processor.onMessage(MessageTypesEnum.Text, async (whatsapp, message) => {
197
+ await whatsapp.messages.text({
198
+ to: message.from,
199
+ body: `Echo: ${message.text?.body}`,
200
+ });
180
201
  });
181
202
 
182
- // Handle incoming messages
183
- app.post('/webhook', (req, res) => {
184
- webhookHandler.handleWebhookRequest(req, res);
185
- });
203
+ export default async function handler(req: NextApiRequest, res: NextApiResponse) {
204
+ return bot.webhook(req, res);
205
+ }
206
+ ```
207
+
208
+ ### Advanced Message Handling
209
+
210
+ ```typescript
211
+ import { MessageTypesEnum } from 'meta-cloud-api';
186
212
 
187
213
  // Pre-process all messages (e.g., mark as read)
188
- webhookHandler.onMessagePreProcess(async (client: WhatsApp, message: WebhookMessage) => {
189
- await client.messages.markAsRead({ messageId: message.id });
214
+ bot.processor.onMessagePreProcess(async (whatsapp, message) => {
215
+ await whatsapp.messages.markAsRead({ messageId: message.id });
190
216
  });
191
217
 
192
- // Handle text messages
193
- webhookHandler.onMessage(MessageTypesEnum.Text, async (client: WhatsApp, message: WebhookMessage) => {
194
- if (message.text?.body) {
195
- await client.messages.text({
196
- body: `You said: "${message.text.body}"`,
197
- to: message.from
198
- });
199
- }
218
+ // Handle different message types
219
+ bot.processor.onMessage(MessageTypesEnum.Text, async (whatsapp, message) => {
220
+ // Handle text messages
200
221
  });
201
222
 
202
- // Handle image messages
203
- webhookHandler.onMessage(MessageTypesEnum.Image, async (client: WhatsApp, message: WebhookMessage) => {
204
- await client.messages.text({
205
- body: "Thanks for the image!",
206
- to: message.from
207
- });
223
+ bot.processor.onMessage(MessageTypesEnum.Image, async (whatsapp, message) => {
224
+ // Handle image messages
225
+ });
226
+
227
+ bot.processor.onMessage(MessageTypesEnum.Document, async (whatsapp, message) => {
228
+ // Handle document messages
208
229
  });
209
- ```
210
230
 
211
- ### Templates
231
+ // Handle message status updates
232
+ bot.processor.onMessageStatus(async (whatsapp, status) => {
233
+ console.log(`Message ${status.id} status: ${status.status}`);
234
+ });
235
+ ```
212
236
 
213
- Manage message templates for your WhatsApp Business account:
237
+ ### Templates Management
214
238
 
215
239
  ```typescript
216
240
  // List all templates
@@ -221,21 +245,17 @@ const templates = await client.templates.list({
221
245
  // Create a new template
222
246
  const newTemplate = await client.templates.create({
223
247
  businessId: process.env.WA_BUSINESS_ACCOUNT_ID,
224
- name: "my_special_template",
248
+ name: "welcome_message",
225
249
  category: "MARKETING",
226
250
  components: [
227
251
  {
228
252
  type: "HEADER",
229
253
  format: "TEXT",
230
- text: "Special Offer"
254
+ text: "Welcome!"
231
255
  },
232
256
  {
233
257
  type: "BODY",
234
- text: "Hi {{1}}, we have a special offer for you: {{2}}% off your next purchase!"
235
- },
236
- {
237
- type: "FOOTER",
238
- text: "Tap the button below to shop now"
258
+ text: "Hi {{1}}, welcome to our service!"
239
259
  }
240
260
  ],
241
261
  language: "en_US"
@@ -244,8 +264,6 @@ const newTemplate = await client.templates.create({
244
264
 
245
265
  ### Media Management
246
266
 
247
- Upload and retrieve media for your messages:
248
-
249
267
  ```typescript
250
268
  import fs from 'fs';
251
269
 
@@ -259,13 +277,17 @@ const mediaUpload = await client.media.upload({
259
277
  const media = await client.media.get({
260
278
  mediaId: mediaUpload.id
261
279
  });
262
- ```
263
280
 
264
- ### Business Profile
281
+ // Download media
282
+ const mediaBuffer = await client.media.download({
283
+ mediaId: mediaUpload.id
284
+ });
285
+ ```
265
286
 
266
- Update your WhatsApp Business profile information:
287
+ ### Business Profile Management
267
288
 
268
289
  ```typescript
290
+ // Update business profile
269
291
  const profile = await client.businessProfile.update({
270
292
  about: "We provide the best service!",
271
293
  address: "123 Business St, City",
@@ -273,12 +295,106 @@ const profile = await client.businessProfile.update({
273
295
  email: "contact@business.com",
274
296
  websites: ["https://www.business.com"]
275
297
  });
298
+
299
+ // Get current profile
300
+ const currentProfile = await client.businessProfile.get();
301
+ ```
302
+
303
+ ### WhatsApp Flows
304
+
305
+ ```typescript
306
+ // Create a flow
307
+ const flow = await client.flows.create({
308
+ name: "Customer Survey",
309
+ categories: ["SURVEY"],
310
+ clone_flow_id: "existing_flow_id" // Optional
311
+ });
312
+
313
+ // Update flow
314
+ const updatedFlow = await client.flows.update({
315
+ flowId: flow.id,
316
+ name: "Updated Survey",
317
+ categories: ["SURVEY", "FEEDBACK"]
318
+ });
319
+ ```
320
+
321
+ ## Example Projects
322
+
323
+ We provide ready-to-use example projects demonstrating integration with different frameworks:
324
+
325
+ ### [Express.js Echo Bot](./examples/express-example)
326
+ A simple echo bot that responds to any text message. Perfect for getting started!
327
+
328
+ ```bash
329
+ cd examples/express-example
330
+ npm install
331
+ cp env.example .env # Configure your credentials
332
+ npm run dev
333
+ ```
334
+
335
+ ### [Next.js Echo Bot](./examples/nextjs-page-router-example)
336
+ Next.js implementation with API routes for webhook handling.
337
+
338
+ ```bash
339
+ cd examples/nextjs-page-router-example
340
+ npm install
341
+ cp env.example .env.local # Configure your credentials
342
+ npm run dev
343
+ ```
344
+
345
+ ## Modular Imports
346
+
347
+ Use specific imports for better tree-shaking:
348
+
349
+ ```typescript
350
+ // Import specific API classes
351
+ import { MessagesApi } from 'meta-cloud-api/messages';
352
+ import { MediaApi } from 'meta-cloud-api/media';
353
+ import { TemplateApi } from 'meta-cloud-api/template';
354
+
355
+ // Import specific webhook handlers
356
+ import { webhookHandler } from 'meta-cloud-api/webhook/express';
357
+ import { webhookHandler } from 'meta-cloud-api/webhook/nextjs';
358
+
359
+ // Import types and enums
360
+ import { MessageTypesEnum, InteractiveTypesEnum } from 'meta-cloud-api/types/enums';
361
+ import type { WhatsAppConfig } from 'meta-cloud-api/types/config';
362
+ ```
363
+
364
+ ## Configuration
365
+
366
+ ```typescript
367
+ interface WhatsAppConfig {
368
+ accessToken: string; // Required: Meta Cloud API access token
369
+ phoneNumberId: number; // Required: WhatsApp phone number ID
370
+ businessAcctId?: string; // Optional: Business account ID
371
+ apiVersion?: string; // Optional: API version (default: v21.0)
372
+ webhookVerificationToken?: string; // Optional: For webhook verification
373
+ requestTimeout?: number; // Optional: Request timeout in ms
374
+ }
375
+ ```
376
+
377
+ ## Error Handling
378
+
379
+ ```typescript
380
+ try {
381
+ const result = await client.messages.text({
382
+ to: "15551234567",
383
+ body: "Hello World"
384
+ });
385
+ } catch (error) {
386
+ if (error.response?.data?.error) {
387
+ console.error('Meta API Error:', error.response.data.error);
388
+ } else {
389
+ console.error('Network Error:', error.message);
390
+ }
391
+ }
276
392
  ```
277
393
 
278
394
  ## Requirements
279
395
 
280
- - TypeScript 4.5+
281
- - Node.js 18 LTS or later
396
+ - **Node.js** 18 LTS or later
397
+ - **TypeScript** 4.5+ (for TypeScript projects)
282
398
 
283
399
  ## Contributing
284
400
 
@@ -1,6 +1,7 @@
1
- import { d as BaseClass, R as ResponseSuccess, B as BaseAPI, a as RequesterClass } from './base-BhCbbsxB.js';
2
- import { WabaConfigType } from './shared/types/config.js';
3
- import { B as BusinessVerticalEnum } from './enums-DvwSJq9w.js';
1
+ import { a as BaseClass, B as BaseAPI } from './base-CdGDdVEl.js';
2
+ import { WabaConfigType } from './types/config.js';
3
+ import { e as ResponseSuccess, R as RequesterClass } from './request-vYMaEfk5.js';
4
+ import { k as BusinessVerticalEnum } from './enums-BZd9T2ul.js';
4
5
 
5
6
  /**
6
7
  * Upload session information for creating upload sessions.
@@ -1,5 +1,6 @@
1
- import { c as ResponseData, R as ResponseSuccess, B as BaseAPI, a as RequesterClass } from './base-BhCbbsxB.js';
2
- import { WabaConfigType } from './shared/types/config.js';
1
+ import { B as BaseAPI } from './base-CdGDdVEl.js';
2
+ import { WabaConfigType } from './types/config.js';
3
+ import { c as ResponseData, e as ResponseSuccess, R as RequesterClass } from './request-vYMaEfk5.js';
3
4
 
4
5
  type EncryptionPublicKeyResponse = ResponseData<{
5
6
  business_public_key: string;
@@ -0,0 +1,136 @@
1
+ import { B as BaseAPI } from './base-CdGDdVEl.js';
2
+ import { WabaConfigType } from './types/config.js';
3
+ import { R as RequesterClass, e as ResponseSuccess } from './request-vYMaEfk5.js';
4
+ import { e as FlowClass, j as FlowsListResponse, d as FlowCategoryEnum, C as CreateFlowResponse, F as Flow, i as FlowPreviewResponse, c as FlowAssetsResponse, U as UpdateFlowResponse, V as ValidateFlowJsonResponse, h as FlowMigrationResponse } from './common-DDXsNyLF.js';
5
+
6
+ /**
7
+ * API for managing WhatsApp Flows.
8
+ *
9
+ * This API allows you to:
10
+ * - List flows
11
+ * - Create flows
12
+ * - Get flow details and previews
13
+ * - Update flow metadata and JSON
14
+ * - Delete flows
15
+ * - Publish and deprecate flows
16
+ * - Migrate flows between WABAs
17
+ * - Validate flow JSON
18
+ */
19
+ declare class FlowApi extends BaseAPI implements FlowClass {
20
+ constructor(config: WabaConfigType, client: RequesterClass);
21
+ /**
22
+ * List Flows
23
+ *
24
+ * @param wabaId - The WABA ID
25
+ * @returns Promise with the list of flows
26
+ */
27
+ listFlows(wabaId: string): Promise<FlowsListResponse>;
28
+ /**
29
+ * Create Flow
30
+ *
31
+ * @param wabaId - The WABA ID
32
+ * @param data - The flow data including name, categories, endpoint_uri, and optional clone_flow_id
33
+ * @returns Promise with the created flow ID and validation errors if any
34
+ */
35
+ createFlow(wabaId: string, data: {
36
+ name: string;
37
+ categories?: FlowCategoryEnum[];
38
+ endpoint_uri?: string;
39
+ clone_flow_id?: string;
40
+ flow_json?: string;
41
+ publish?: boolean;
42
+ }): Promise<CreateFlowResponse>;
43
+ /**
44
+ * Get Flow details
45
+ *
46
+ * @param flowId - The flow ID
47
+ * @param fields - Optional fields to return (e.g., 'name,status,preview.invalidate(false)')
48
+ * @param dateFormat - Optional date format
49
+ * @returns Promise with the flow details or preview response
50
+ */
51
+ getFlow(flowId: string, fields?: string, dateFormat?: string): Promise<Flow | FlowPreviewResponse>;
52
+ /**
53
+ * Get Flow Preview URL
54
+ *
55
+ * @param flowId - The flow ID
56
+ * @param invalidate - Optional. If true, invalidates existing preview and generates a new one. Defaults to false.
57
+ * @returns Promise with the flow preview details
58
+ */
59
+ getFlowPreview(flowId: string, invalidate?: boolean): Promise<FlowPreviewResponse>;
60
+ /**
61
+ * Update Flow Metadata
62
+ *
63
+ * @param flowId - The flow ID
64
+ * @param data - The flow metadata to update (name, categories, endpoint_uri, application_id)
65
+ * @returns Promise with the success status
66
+ */
67
+ updateFlowMetadata(flowId: string, data: {
68
+ name?: string;
69
+ categories?: FlowCategoryEnum[];
70
+ endpoint_uri?: string;
71
+ application_id?: string;
72
+ }): Promise<ResponseSuccess>;
73
+ /**
74
+ * Delete Flow (only works if the Flow is in DRAFT status)
75
+ *
76
+ * @param flowId - The flow ID
77
+ * @returns Promise with the success status
78
+ */
79
+ deleteFlow(flowId: string): Promise<ResponseSuccess>;
80
+ /**
81
+ * List Assets (e.g., get Flow JSON download URL)
82
+ *
83
+ * @param flowId - The flow ID
84
+ * @returns Promise with the list of assets
85
+ */
86
+ listAssets(flowId: string): Promise<FlowAssetsResponse>;
87
+ /**
88
+ * Update Flow JSON by uploading a file, buffer, JSON object, or Blob.
89
+ *
90
+ * @param flowId - The flow ID
91
+ * @param data - Object containing the file data and optional name.
92
+ * @param data.file - The Flow JSON content as a Buffer, JSON object, or Blob.
93
+ * @param data.name - Optional name for the asset, defaults to 'flow.json'.
94
+ * @returns Promise with the success status and validation errors, if any.
95
+ */
96
+ updateFlowJson(flowId: string, data: {
97
+ file: Blob | Buffer | object;
98
+ name?: string;
99
+ }): Promise<UpdateFlowResponse>;
100
+ /**
101
+ * Validate Flow JSON by attempting an update without publishing.
102
+ * This is a convenience method; the API doesn't have a dedicated validation endpoint.
103
+ *
104
+ * @param flowId - The ID of the Flow (must exist, can be in DRAFT status).
105
+ * @param flowJsonData - The Flow JSON content as a file path (string), Buffer, JSON object, or Blob.
106
+ * @returns Promise indicating if the JSON is valid and includes validation errors if any.
107
+ */
108
+ validateFlowJson(flowId: string, flowJsonData: Blob | Buffer | object): Promise<ValidateFlowJsonResponse>;
109
+ /**
110
+ * Publish Flow
111
+ *
112
+ * @param flowId - The flow ID
113
+ * @returns Promise with the success status
114
+ */
115
+ publishFlow(flowId: string): Promise<ResponseSuccess>;
116
+ /**
117
+ * Deprecate Flow
118
+ *
119
+ * @param flowId - The flow ID
120
+ * @returns Promise with the success status
121
+ */
122
+ deprecateFlow(flowId: string): Promise<ResponseSuccess>;
123
+ /**
124
+ * Migrate Flows between WABAs
125
+ *
126
+ * @param destinationWabaId - The destination WABA ID
127
+ * @param data - The migration data including source_waba_id and optional source_flow_names
128
+ * @returns Promise with migration results (successes and failures)
129
+ */
130
+ migrateFlows(destinationWabaId: string, data: {
131
+ source_waba_id: string;
132
+ source_flow_names?: string[];
133
+ }): Promise<FlowMigrationResponse>;
134
+ }
135
+
136
+ export { FlowApi as F };
@@ -1,5 +1,6 @@
1
- import { R as ResponseSuccess, B as BaseAPI, a as RequesterClass } from './base-BhCbbsxB.js';
2
- import { WabaConfigType } from './shared/types/config.js';
1
+ import { B as BaseAPI } from './base-CdGDdVEl.js';
2
+ import { WabaConfigType } from './types/config.js';
3
+ import { e as ResponseSuccess, R as RequesterClass } from './request-vYMaEfk5.js';
3
4
 
4
5
  type MediaResponse = {
5
6
  id: string;
@@ -1,6 +1,7 @@
1
- import { d as BaseClass, G as GeneralRequestBody, B as BaseAPI, a as RequesterClass } from './base-BhCbbsxB.js';
2
- import { WabaConfigType } from './shared/types/config.js';
3
- import { I as InteractiveTypesEnum, c as ComponentTypesEnum, L as LanguagesEnum, P as ParametersTypesEnum, C as CurrencyCodesEnum, S as SubTypeEnum, b as ButtonPositionEnum, M as MessageTypesEnum } from './enums-DvwSJq9w.js';
1
+ import { a as BaseClass, B as BaseAPI } from './base-CdGDdVEl.js';
2
+ import { WabaConfigType } from './types/config.js';
3
+ import { I as InteractiveTypesEnum, C as ComponentTypesEnum, L as LanguagesEnum, P as ParametersTypesEnum, i as CurrencyCodesEnum, S as SubTypeEnum, B as ButtonPositionEnum, M as MessageTypesEnum } from './enums-BZd9T2ul.js';
4
+ import { a as GeneralRequestBody, R as RequesterClass } from './request-vYMaEfk5.js';
4
5
 
5
6
  interface ReactionParams {
6
7
  messageId: string;
@@ -1,5 +1,6 @@
1
- import { P as Paging, R as ResponseSuccess, B as BaseAPI, a as RequesterClass } from './base-BhCbbsxB.js';
2
- import { WabaConfigType } from './shared/types/config.js';
1
+ import { B as BaseAPI } from './base-CdGDdVEl.js';
2
+ import { WabaConfigType } from './types/config.js';
3
+ import { P as Paging, e as ResponseSuccess, R as RequesterClass } from './request-vYMaEfk5.js';
3
4
 
4
5
  type QualityRating = 'GREEN' | 'YELLOW' | 'RED' | 'NA';
5
6
  type AccountMode = 'LIVE' | 'SANDBOX';
@@ -80,7 +81,7 @@ interface PhoneNumberClass {
80
81
  }
81
82
 
82
83
  /**
83
- * API for managing WhatsApp Phone Numbers.
84
+ * API for managing WhatsApp Phone Numb ers.
84
85
  *
85
86
  * This API allows you to:
86
87
  * - Get phone number information by ID
@@ -1,5 +1,6 @@
1
- import { c as ResponseData, R as ResponseSuccess, B as BaseAPI, a as RequesterClass } from './base-BhCbbsxB.js';
2
- import { WabaConfigType } from './shared/types/config.js';
1
+ import { B as BaseAPI } from './base-CdGDdVEl.js';
2
+ import { WabaConfigType } from './types/config.js';
3
+ import { c as ResponseData, e as ResponseSuccess, R as RequesterClass } from './request-vYMaEfk5.js';
3
4
 
4
5
  type QrCodeResponse = {
5
6
  code: string;
@@ -1,6 +1,7 @@
1
- import { R as ResponseSuccess, B as BaseAPI, a as RequesterClass } from './base-BhCbbsxB.js';
2
- import { WabaConfigType } from './shared/types/config.js';
3
- import { D as DataLocalizationRegionEnum } from './enums-DvwSJq9w.js';
1
+ import { B as BaseAPI } from './base-CdGDdVEl.js';
2
+ import { WabaConfigType } from './types/config.js';
3
+ import { j as DataLocalizationRegionEnum } from './enums-BZd9T2ul.js';
4
+ import { e as ResponseSuccess, R as RequesterClass } from './request-vYMaEfk5.js';
4
5
 
5
6
  type RegistrationRequest = {
6
7
  messaging_product: 'whatsapp';
@@ -1,6 +1,7 @@
1
- import { G as GeneralRequestBody, R as ResponseSuccess, b as ResponsePagination, B as BaseAPI, a as RequesterClass } from './base-BhCbbsxB.js';
2
- import { WabaConfigType } from './shared/types/config.js';
3
- import { L as LanguagesEnum, a as CategoryEnum, T as TemplateStatusEnum } from './enums-DvwSJq9w.js';
1
+ import { B as BaseAPI } from './base-CdGDdVEl.js';
2
+ import { WabaConfigType } from './types/config.js';
3
+ import { a as GeneralRequestBody, e as ResponseSuccess, d as ResponsePagination, R as RequesterClass } from './request-vYMaEfk5.js';
4
+ import { L as LanguagesEnum, a as CategoryEnum, T as TemplateStatusEnum } from './enums-BZd9T2ul.js';
4
5
 
5
6
  type TemplateFormat = 'TEXT' | 'IMAGE' | 'VIDEO' | 'DOCUMENT' | 'LOCATION' | 'PRODUCT';
6
7
  type PhoneNumberButton = {
@@ -157,4 +158,4 @@ declare class TemplateApi extends BaseAPI implements TemplateClass {
157
158
  deleteTemplate(params: TemplateDeleteParams): Promise<ResponseSuccess>;
158
159
  }
159
160
 
160
- export { type CatalogButton as C, type FlowButton as F, type MPMButton as M, type OTPButton as O, type PhoneNumberButton as P, type QuickReplyButton as Q, type SPMButton as S, type TemplateFormat as T, type URLButton as U, type TemplateRequestBody as a, TemplateClass as b, type TemplateDeleteParams as c, type TemplateGetParams as d, type TemplateResponse as e, TemplateApi as f, type ComponentTypes as g, type CopyCodeButton as h, type TemplateBody as i, type TemplateButton as j, type TemplateButtons as k, type TemplateCarousel as l, type TemplateFooter as m, type TemplateHeader as n, type TemplateHeaderExample as o, type TemplateLimitedTimeOffer as p, type MediaCarouselCard as q, type ProductCarouselCard as r };
161
+ export { type CatalogButton as C, type FlowButton as F, type MPMButton as M, type OTPButton as O, type PhoneNumberButton as P, type QuickReplyButton as Q, type SPMButton as S, TemplateApi as T, type URLButton as U, TemplateClass as a, type TemplateDeleteParams as b, type TemplateGetParams as c, type TemplateRequestBody as d, type TemplateResponse as e, type TemplateFormat as f, type ComponentTypes as g, type CopyCodeButton as h, type TemplateBody as i, type TemplateButton as j, type TemplateButtons as k, type TemplateCarousel as l, type TemplateFooter as m, type TemplateHeader as n, type TemplateHeaderExample as o, type TemplateLimitedTimeOffer as p, type MediaCarouselCard as q, type ProductCarouselCard as r };
@@ -1,5 +1,6 @@
1
- import { R as ResponseSuccess, B as BaseAPI, a as RequesterClass } from './base-BhCbbsxB.js';
2
- import { WabaConfigType } from './shared/types/config.js';
1
+ import { B as BaseAPI } from './base-CdGDdVEl.js';
2
+ import { WabaConfigType } from './types/config.js';
3
+ import { e as ResponseSuccess, R as RequesterClass } from './request-vYMaEfk5.js';
3
4
 
4
5
  type TwoStepVerificationRequest = {
5
6
  pin: string;
@@ -1,5 +1,6 @@
1
- import { R as ResponseSuccess, B as BaseAPI, a as RequesterClass } from './base-BhCbbsxB.js';
2
- import { WabaConfigType } from './shared/types/config.js';
1
+ import { B as BaseAPI } from './base-CdGDdVEl.js';
2
+ import { WabaConfigType } from './types/config.js';
3
+ import { e as ResponseSuccess, R as RequesterClass } from './request-vYMaEfk5.js';
3
4
 
4
5
  /**
5
6
  * WhatsApp Business Account subscription configuration
@@ -1,7 +1,7 @@
1
- import { g as FlowEndpointRequest, n as FlowTypeEnum } from './FlowApi-CASVC-Al.js';
2
- import { WabaConfigType, WhatsAppConfig } from './shared/types/config.js';
3
- import { M as MessageTypesEnum } from './enums-DvwSJq9w.js';
4
- import { W as WhatsApp } from './index-DiCI1vEz.js';
1
+ import { f as FlowEndpointRequest, l as FlowTypeEnum } from './common-DDXsNyLF.js';
2
+ import { WabaConfigType, WhatsAppConfig } from './types/config.js';
3
+ import { M as MessageTypesEnum } from './enums-BZd9T2ul.js';
4
+ import { W as WhatsApp } from './WhatsApp-BIBtT-y9.js';
5
5
 
6
6
  interface WebhookContact {
7
7
  /**
@@ -672,11 +672,20 @@ declare function processWebhookMessages(request: Request, whatsapp: WhatsApp, ha
672
672
  * Handle flow requests
673
673
  */
674
674
  declare function processFlowRequest(request: Request, config: WabaConfigType, whatsapp: WhatsApp, flowHandlers: Map<FlowTypeEnum, FlowHandler>): Promise<Response>;
675
-
676
675
  /**
677
- * WebhookHandler based on Web Standard API
676
+ * Constructs a full URL from framework-specific request headers and URL
677
+ * @param headers - Request headers containing host and protocol information
678
+ * @param url - Relative URL path
679
+ * @returns Full URL string
678
680
  */
679
- declare class WebhookHandler {
681
+ declare function constructFullUrl(headers: Record<string, string | string[] | undefined>, url?: string): string;
682
+
683
+ interface WebhookResponse {
684
+ status: number;
685
+ body: string;
686
+ headers: Record<string, string>;
687
+ }
688
+ declare class WebhookProcessor {
680
689
  private config;
681
690
  private client;
682
691
  private messageHandlers;
@@ -684,34 +693,15 @@ declare class WebhookHandler {
684
693
  private postProcessHandler;
685
694
  private flowHandlers;
686
695
  constructor(config: WhatsAppConfig);
687
- /**
688
- * Handle webhook requests using Web Standard API
689
- */
690
- handleWebhook(request: Request): Promise<Response>;
691
- /**
692
- * Handle flow requests
693
- */
694
- handleFlow(request: Request): Promise<Response>;
695
- /**
696
- * Verify webhook signature
697
- */
698
- private verifySignature;
699
- /**
700
- * Register a message handler for a specific message type
701
- */
696
+ processVerification(mode: string | null, token: string | null, challenge: string | null): Promise<WebhookResponse>;
697
+ processWebhook(request: Request): Promise<WebhookResponse>;
698
+ processFlow(request: Request): Promise<WebhookResponse>;
702
699
  onMessage(type: MessageTypesEnum, handler: MessageHandler): void;
703
- /**
704
- * Register a pre-process handler that runs before all message handlers
705
- */
706
700
  onMessagePreProcess(handler: MessageHandler): void;
707
- /**
708
- * Register a post-process handler that runs after all message handlers
709
- */
710
701
  onMessagePostProcess(handler: MessageHandler): void;
711
- /**
712
- * Register a flow handler for a specific flow type
713
- */
714
702
  onFlow(type: FlowTypeEnum, handler: FlowHandler): void;
703
+ getClient(): WhatsApp;
704
+ getConfig(): WabaConfigType;
715
705
  }
716
706
 
717
- export { type FlowHandler as F, MessageStatus as M, type WebhookContact as W, type WebhookEvent as a, type WebhookMessage as b, WebhookHandler as c, type MessageHandler as d, processFlowRequest as e, processWebhookMessages as p };
707
+ export { type FlowHandler as F, MessageStatus as M, type WebhookContact as W, type WebhookEvent as a, type WebhookMessage as b, WebhookProcessor as c, type WebhookResponse as d, type MessageHandler as e, processFlowRequest as f, constructFullUrl as g, processWebhookMessages as p };