meta-cloud-api 1.0.0 → 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.
- package/LICENSE +21 -0
- package/README.md +405 -0
- package/dist/BusinessProfileApi-WXscSgo-.d.ts +353 -0
- package/dist/EncryptionApi-D7pt-OXT.d.ts +22 -0
- package/dist/FlowApi-UAvzhJfV.d.ts +136 -0
- package/dist/MediaApi-BrEKpqi_.d.ts +90 -0
- package/dist/MessageApi-Circorzz.d.ts +587 -0
- package/dist/PhoneNumberApi-DKlu9PHl.d.ts +142 -0
- package/dist/QrCodeApi-7vDwIBHR.d.ts +98 -0
- package/dist/RegistrationApi-qO_qoti9.d.ts +47 -0
- package/dist/TemplateApi-xGgIZt89.d.ts +161 -0
- package/dist/TwoStepVerificationApi-DfNPIz-C.d.ts +33 -0
- package/dist/WabaApi-DqQi_68m.d.ts +175 -0
- package/dist/WebhookProcessor-ByAe7Kf_.d.ts +707 -0
- package/dist/WhatsApp-BIBtT-y9.d.ts +82 -0
- package/dist/api/encryption/index.d.ts +10 -0
- package/dist/api/encryption/index.js +2 -0
- package/dist/api/encryption/index.js.map +1 -0
- package/dist/api/flow/index.d.ts +10 -0
- package/dist/api/flow/index.js +2 -0
- package/dist/api/flow/index.js.map +1 -0
- package/dist/api/index.d.ts +16 -0
- package/dist/api/index.js +2 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/media/index.d.ts +10 -0
- package/dist/api/media/index.js +2 -0
- package/dist/api/media/index.js.map +1 -0
- package/dist/api/messages/index.d.ts +10 -0
- package/dist/api/messages/index.js +2 -0
- package/dist/api/messages/index.js.map +1 -0
- package/dist/api/phone/index.d.ts +10 -0
- package/dist/api/phone/index.js +2 -0
- package/dist/api/phone/index.js.map +1 -0
- package/dist/api/profile/index.d.ts +10 -0
- package/dist/api/profile/index.js +2 -0
- package/dist/api/profile/index.js.map +1 -0
- package/dist/api/qrCode/index.d.ts +10 -0
- package/dist/api/qrCode/index.js +2 -0
- package/dist/api/qrCode/index.js.map +1 -0
- package/dist/api/registration/index.d.ts +10 -0
- package/dist/api/registration/index.js +2 -0
- package/dist/api/registration/index.js.map +1 -0
- package/dist/api/template/index.d.ts +215 -0
- package/dist/api/template/index.js +2 -0
- package/dist/api/template/index.js.map +1 -0
- package/dist/api/twoStepVerification/index.d.ts +10 -0
- package/dist/api/twoStepVerification/index.js +2 -0
- package/dist/api/twoStepVerification/index.js.map +1 -0
- package/dist/api/waba/index.d.ts +10 -0
- package/dist/api/waba/index.js +2 -0
- package/dist/api/waba/index.js.map +1 -0
- package/dist/base-CdGDdVEl.d.ts +18 -0
- package/dist/chunk-7QBIZCJ4.js +2 -0
- package/dist/chunk-7QBIZCJ4.js.map +1 -0
- package/dist/chunk-AMHQGG6Z.js +2 -0
- package/dist/chunk-AMHQGG6Z.js.map +1 -0
- package/dist/chunk-B7DCL6I7.js +10 -0
- package/dist/chunk-B7DCL6I7.js.map +1 -0
- package/dist/chunk-CRZ7EUYR.js +2 -0
- package/dist/chunk-CRZ7EUYR.js.map +1 -0
- package/dist/chunk-FKXSL2JK.js +3 -0
- package/dist/chunk-FKXSL2JK.js.map +1 -0
- package/dist/chunk-FSKBLPGE.js +2 -0
- package/dist/chunk-FSKBLPGE.js.map +1 -0
- package/dist/chunk-HJGN3PO4.js +3 -0
- package/dist/chunk-HJGN3PO4.js.map +1 -0
- package/dist/chunk-IYSR44P6.js +2 -0
- package/dist/chunk-IYSR44P6.js.map +1 -0
- package/dist/chunk-JC6YMVID.js +2 -0
- package/dist/chunk-JC6YMVID.js.map +1 -0
- package/dist/chunk-JPAV644F.js +2 -0
- package/dist/chunk-JPAV644F.js.map +1 -0
- package/dist/chunk-JXCLRKQ7.js +2 -0
- package/dist/chunk-JXCLRKQ7.js.map +1 -0
- package/dist/chunk-KMAH6636.js +2 -0
- package/dist/chunk-KMAH6636.js.map +1 -0
- package/dist/chunk-L4ESAO2S.js +2 -0
- package/dist/chunk-L4ESAO2S.js.map +1 -0
- package/dist/chunk-LV3TULSI.js +2 -0
- package/dist/chunk-LV3TULSI.js.map +1 -0
- package/dist/chunk-MJEG3K4V.js +2 -0
- package/dist/chunk-MJEG3K4V.js.map +1 -0
- package/dist/chunk-NLF2JGYY.js +2 -0
- package/dist/chunk-NLF2JGYY.js.map +1 -0
- package/dist/chunk-OA2SW4AF.js +2 -0
- package/dist/chunk-OA2SW4AF.js.map +1 -0
- package/dist/chunk-PHPQ5HP3.js +2 -0
- package/dist/chunk-PHPQ5HP3.js.map +1 -0
- package/dist/chunk-RIL6QABY.js +2 -0
- package/dist/chunk-RIL6QABY.js.map +1 -0
- package/dist/chunk-RWCVPWRC.js +2 -0
- package/dist/chunk-RWCVPWRC.js.map +1 -0
- package/dist/chunk-SNNRWNGZ.js +2 -0
- package/dist/chunk-SNNRWNGZ.js.map +1 -0
- package/dist/chunk-UCBYECNQ.js +2 -0
- package/dist/chunk-UCBYECNQ.js.map +1 -0
- package/dist/chunk-VHAODWCN.js +2 -0
- package/dist/chunk-VHAODWCN.js.map +1 -0
- package/dist/chunk-WGGN32O2.js +2 -0
- package/dist/chunk-WGGN32O2.js.map +1 -0
- package/dist/common-DDXsNyLF.d.ts +376 -0
- package/dist/core/webhook/frameworks/express.d.ts +48 -0
- package/dist/core/webhook/frameworks/express.js +2 -0
- package/dist/core/webhook/frameworks/express.js.map +1 -0
- package/dist/core/webhook/frameworks/nextjs.d.ts +44 -0
- package/dist/core/webhook/frameworks/nextjs.js +2 -0
- package/dist/core/webhook/frameworks/nextjs.js.map +1 -0
- package/dist/core/webhook/index.d.ts +26 -0
- package/dist/core/webhook/index.js +2 -0
- package/dist/core/webhook/index.js.map +1 -0
- package/dist/core/whatsapp/index.d.ts +40 -0
- package/dist/core/whatsapp/index.js +2 -0
- package/dist/core/whatsapp/index.js.map +1 -0
- package/dist/enums-BZd9T2ul.d.ts +707 -0
- package/dist/httpsClient-v4gmltzS.d.ts +19 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/logger-BdE0Vyim.d.ts +9 -0
- package/dist/request-vYMaEfk5.d.ts +50 -0
- package/dist/types/config.d.ts +78 -0
- package/dist/types/config.js +2 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/enums.d.ts +1 -0
- package/dist/types/enums.js +2 -0
- package/dist/types/enums.js.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/index.d.ts +98 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +240 -8
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) [2025] [froggy1014]
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
# Meta Cloud API
|
|
2
|
+
|
|
3
|
+
<div style="display: flex; align-items: center;">
|
|
4
|
+
<img src="public/README.svg" alt="Meta Cloud API" style="flex: 1; width: 100px;">
|
|
5
|
+
<div style="flex: 1; padding-left: 20px;">
|
|
6
|
+
<p>Meta Cloud API - A powerful TypeScript wrapper for Meta's Cloud API, providing a clean and type-safe interface for WhatsApp Business Platform integration.</p>
|
|
7
|
+
</div>
|
|
8
|
+
</div>
|
|
9
|
+
|
|
10
|
+
[](https://www.npmjs.com/package/meta-cloud-api)
|
|
11
|
+
[](https://www.npmjs.com/package/meta-cloud-api)
|
|
12
|
+
[](https://github.com/froggy1014/meta-cloud-api/blob/main/LICENSE)
|
|
13
|
+
|
|
14
|
+
## Resources
|
|
15
|
+
|
|
16
|
+
- [Documentation](https://www.meta-cloud-api.xyz/)
|
|
17
|
+
|
|
18
|
+
## Features
|
|
19
|
+
|
|
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 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
|
|
25
|
+
- **Error Handling** - Standardized error handling with detailed Meta API error information
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install meta-cloud-api
|
|
31
|
+
# or
|
|
32
|
+
yarn add meta-cloud-api
|
|
33
|
+
# or
|
|
34
|
+
pnpm add meta-cloud-api
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Quick Start
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import WhatsApp, { MessageTypesEnum } from 'meta-cloud-api';
|
|
41
|
+
|
|
42
|
+
// Initialize the client
|
|
43
|
+
const client = new WhatsApp({
|
|
44
|
+
accessToken: process.env.CLOUD_API_ACCESS_TOKEN,
|
|
45
|
+
phoneNumberId: Number(process.env.WA_PHONE_NUMBER_ID),
|
|
46
|
+
businessAcctId: process.env.WA_BUSINESS_ACCOUNT_ID
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// Send a WhatsApp text message
|
|
50
|
+
const response = await client.messages.text({
|
|
51
|
+
to: '+1234567890',
|
|
52
|
+
body: 'Hello from Meta Cloud API!'
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
console.log(`Message ID: ${response.messages[0].id}`);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Usage Examples
|
|
59
|
+
|
|
60
|
+
### Messaging
|
|
61
|
+
|
|
62
|
+
#### Text Message
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
const result = await client.messages.text({
|
|
66
|
+
to: "15551234567",
|
|
67
|
+
body: "Hello from Meta Cloud API!"
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
#### Template Message
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { ComponentTypesEnum, LanguagesEnum, ParametersTypesEnum } from 'meta-cloud-api';
|
|
75
|
+
|
|
76
|
+
const result = await client.messages.template({
|
|
77
|
+
to: "15551234567",
|
|
78
|
+
body: {
|
|
79
|
+
name: "shipping_confirmation",
|
|
80
|
+
language: {
|
|
81
|
+
code: LanguagesEnum.English_US,
|
|
82
|
+
policy: "deterministic"
|
|
83
|
+
},
|
|
84
|
+
components: [
|
|
85
|
+
{
|
|
86
|
+
type: ComponentTypesEnum.Body,
|
|
87
|
+
parameters: [
|
|
88
|
+
{
|
|
89
|
+
type: ParametersTypesEnum.Text,
|
|
90
|
+
text: "John Doe"
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
type: ParametersTypesEnum.Text,
|
|
94
|
+
text: "12345"
|
|
95
|
+
}
|
|
96
|
+
]
|
|
97
|
+
}
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
#### Media Message
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
const result = await client.messages.image({
|
|
107
|
+
to: "15551234567",
|
|
108
|
+
body: {
|
|
109
|
+
link: "https://example.com/image.jpg"
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
#### Interactive Message
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
import { InteractiveTypesEnum } from 'meta-cloud-api';
|
|
118
|
+
|
|
119
|
+
const result = await client.messages.interactive({
|
|
120
|
+
to: "15551234567",
|
|
121
|
+
body: {
|
|
122
|
+
type: InteractiveTypesEnum.Button,
|
|
123
|
+
body: {
|
|
124
|
+
text: "What would you like to do?"
|
|
125
|
+
},
|
|
126
|
+
action: {
|
|
127
|
+
buttons: [
|
|
128
|
+
{
|
|
129
|
+
type: "reply",
|
|
130
|
+
reply: {
|
|
131
|
+
id: "help_button",
|
|
132
|
+
title: "Get Help"
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
type: "reply",
|
|
137
|
+
reply: {
|
|
138
|
+
id: "info_button",
|
|
139
|
+
title: "Account Info"
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
]
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Webhook Integration
|
|
149
|
+
|
|
150
|
+
#### Express.js Webhook
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
import express from 'express';
|
|
154
|
+
import { MessageTypesEnum } from 'meta-cloud-api';
|
|
155
|
+
import { webhookHandler } from 'meta-cloud-api/webhook/express';
|
|
156
|
+
|
|
157
|
+
const app = express();
|
|
158
|
+
|
|
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);
|
|
177
|
+
|
|
178
|
+
app.listen(3000);
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
#### Next.js Webhook
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
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!,
|
|
193
|
+
});
|
|
194
|
+
|
|
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
|
+
});
|
|
201
|
+
});
|
|
202
|
+
|
|
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';
|
|
212
|
+
|
|
213
|
+
// Pre-process all messages (e.g., mark as read)
|
|
214
|
+
bot.processor.onMessagePreProcess(async (whatsapp, message) => {
|
|
215
|
+
await whatsapp.messages.markAsRead({ messageId: message.id });
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
// Handle different message types
|
|
219
|
+
bot.processor.onMessage(MessageTypesEnum.Text, async (whatsapp, message) => {
|
|
220
|
+
// Handle text messages
|
|
221
|
+
});
|
|
222
|
+
|
|
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
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
// Handle message status updates
|
|
232
|
+
bot.processor.onMessageStatus(async (whatsapp, status) => {
|
|
233
|
+
console.log(`Message ${status.id} status: ${status.status}`);
|
|
234
|
+
});
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### Templates Management
|
|
238
|
+
|
|
239
|
+
```typescript
|
|
240
|
+
// List all templates
|
|
241
|
+
const templates = await client.templates.list({
|
|
242
|
+
businessId: process.env.WA_BUSINESS_ACCOUNT_ID
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
// Create a new template
|
|
246
|
+
const newTemplate = await client.templates.create({
|
|
247
|
+
businessId: process.env.WA_BUSINESS_ACCOUNT_ID,
|
|
248
|
+
name: "welcome_message",
|
|
249
|
+
category: "MARKETING",
|
|
250
|
+
components: [
|
|
251
|
+
{
|
|
252
|
+
type: "HEADER",
|
|
253
|
+
format: "TEXT",
|
|
254
|
+
text: "Welcome!"
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
type: "BODY",
|
|
258
|
+
text: "Hi {{1}}, welcome to our service!"
|
|
259
|
+
}
|
|
260
|
+
],
|
|
261
|
+
language: "en_US"
|
|
262
|
+
});
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### Media Management
|
|
266
|
+
|
|
267
|
+
```typescript
|
|
268
|
+
import fs from 'fs';
|
|
269
|
+
|
|
270
|
+
// Upload media
|
|
271
|
+
const mediaUpload = await client.media.upload({
|
|
272
|
+
file: fs.createReadStream("./path/to/image.jpg"),
|
|
273
|
+
type: "image/jpeg"
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
// Get media URL
|
|
277
|
+
const media = await client.media.get({
|
|
278
|
+
mediaId: mediaUpload.id
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
// Download media
|
|
282
|
+
const mediaBuffer = await client.media.download({
|
|
283
|
+
mediaId: mediaUpload.id
|
|
284
|
+
});
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
### Business Profile Management
|
|
288
|
+
|
|
289
|
+
```typescript
|
|
290
|
+
// Update business profile
|
|
291
|
+
const profile = await client.businessProfile.update({
|
|
292
|
+
about: "We provide the best service!",
|
|
293
|
+
address: "123 Business St, City",
|
|
294
|
+
description: "Premium products and services",
|
|
295
|
+
email: "contact@business.com",
|
|
296
|
+
websites: ["https://www.business.com"]
|
|
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
|
+
}
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
## Requirements
|
|
395
|
+
|
|
396
|
+
- **Node.js** 18 LTS or later
|
|
397
|
+
- **TypeScript** 4.5+ (for TypeScript projects)
|
|
398
|
+
|
|
399
|
+
## Contributing
|
|
400
|
+
|
|
401
|
+
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
402
|
+
|
|
403
|
+
## License
|
|
404
|
+
|
|
405
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|