meta-cloud-api 3.7.1 → 3.9.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 +35 -4
- package/dist/index.d.mts +777 -224
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +7 -5
- package/dist/index.mjs.map +1 -1
- package/dist/node/chunk.mjs +1 -0
- package/dist/node/index.d.mts +10393 -0
- package/dist/node/index.d.mts.map +1 -0
- package/dist/node/index.mjs +23 -0
- package/dist/node/index.mjs.map +1 -0
- package/dist/testing/index.d.ts +377 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +4 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/node/index.js +3 -0
- package/dist/types/index.d.ts +283 -7
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/utils/index.d.ts +264 -4
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +6 -4
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/node/index.d.ts +682 -0
- package/dist/utils/node/index.d.ts.map +1 -0
- package/dist/utils/node/index.js +16 -0
- package/dist/utils/node/index.js.map +1 -0
- package/package.json +31 -6
package/README.md
CHANGED
|
@@ -15,6 +15,17 @@
|
|
|
15
15
|
|
|
16
16
|
## Quick Start
|
|
17
17
|
|
|
18
|
+
**New project?** Scaffold a working WhatsApp app in 30 seconds. No Meta account needed to start:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm create whatsapp-app@latest my-bot
|
|
22
|
+
cd my-bot && npm run dev
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
It opens in mock mode: you play the customer in the browser, your message runs through the SDK as a real webhook payload, and `lib/bot.ts` replies. Add credentials to `.env.local` and the same code talks to real WhatsApp. See [create-whatsapp-app](./packages/create-whatsapp-app).
|
|
26
|
+
|
|
27
|
+
**Existing project?**
|
|
28
|
+
|
|
18
29
|
```bash
|
|
19
30
|
pnpm add meta-cloud-api
|
|
20
31
|
```
|
|
@@ -51,11 +62,13 @@ await wa.messages.image({ to: '1234567890', link: 'https://example.com/image.png
|
|
|
51
62
|
| Account ban risk | None | None | Yes — violates WhatsApp ToS |
|
|
52
63
|
| Maintenance | Active (tracks OpenAPI v23) | **Archived since 2023** | Varies |
|
|
53
64
|
| TypeScript | Strict, full request/response types | Partial | Varies |
|
|
54
|
-
| API coverage |
|
|
55
|
-
| Webhook adapters | Built-in Express.js
|
|
65
|
+
| API coverage | 22 modules (Messages, Flows, Calling, Payments, and more) | Messaging-focused | Personal-account features |
|
|
66
|
+
| Webhook adapters | Built-in Express.js, Next.js, Hono, Fastify (NestJS via Express) | Manual | Custom event system |
|
|
56
67
|
|
|
57
68
|
If you're building on the official Cloud API and don't want to bet on an unmaintained SDK, this is what the archived one would look like if Meta had kept shipping it.
|
|
58
69
|
|
|
70
|
+
**Coming from the `whatsapp` package?** The [migration guide](https://meta-cloud-api.site/getting-started/migrate-from-whatsapp-nodejs-sdk) maps every API of the archived SDK (config, messages, templates, webhooks, errors) to meta-cloud-api, with a checklist.
|
|
71
|
+
|
|
59
72
|
## API Coverage
|
|
60
73
|
|
|
61
74
|
```
|
|
@@ -78,6 +91,9 @@ wa.blockUsers // Block/unblock users
|
|
|
78
91
|
wa.contactBook // Delete a BSUID contact book entry
|
|
79
92
|
wa.threadControl // Conversation Routing: pass, release, take threads
|
|
80
93
|
wa.waba // WhatsApp Business Account management
|
|
94
|
+
wa.business // Business portfolio, pre-verified phone numbers, owned/client WABAs, credit lines
|
|
95
|
+
wa.messageHistory // Message history and history events
|
|
96
|
+
wa.solutions // Multi-Partner Solutions management
|
|
81
97
|
```
|
|
82
98
|
|
|
83
99
|
## Webhooks
|
|
@@ -87,13 +103,17 @@ import express from 'express';
|
|
|
87
103
|
import { expressWebhookHandler } from 'meta-cloud-api';
|
|
88
104
|
|
|
89
105
|
const app = express();
|
|
90
|
-
|
|
106
|
+
// Keep the raw body: signatures are computed over the exact bytes Meta sent
|
|
107
|
+
app.use(express.json({ verify: (req, _res, buf) => { (req as any).rawBody = buf.toString(); } }));
|
|
91
108
|
|
|
92
109
|
// Handler is automatically cached per phoneNumberId — safe against HMR re-evaluation
|
|
93
110
|
const Whatsapp = expressWebhookHandler({
|
|
94
111
|
accessToken: process.env.CLOUD_API_ACCESS_TOKEN,
|
|
95
112
|
phoneNumberId: process.env.WA_PHONE_NUMBER_ID,
|
|
96
113
|
webhookVerificationToken: process.env.WEBHOOK_VERIFICATION_TOKEN,
|
|
114
|
+
// Reject forged POSTs: require a valid X-Hub-Signature-256 from Meta
|
|
115
|
+
appSecret: process.env.APP_SECRET,
|
|
116
|
+
verifyWebhookSignature: true,
|
|
97
117
|
});
|
|
98
118
|
|
|
99
119
|
// Handle incoming text messages — echo back to sender
|
|
@@ -118,11 +138,22 @@ app.get('/webhook', Whatsapp.GET);
|
|
|
118
138
|
app.post('/webhook', Whatsapp.POST);
|
|
119
139
|
```
|
|
120
140
|
|
|
141
|
+
Other frameworks use the same handler object (`GET`, `POST`, `webhook`, `flow`, `processor`, `destroy`):
|
|
142
|
+
|
|
143
|
+
| Framework | Adapter | Guide |
|
|
144
|
+
|---|---|---|
|
|
145
|
+
| Express.js | `expressWebhookHandler` | [Express](https://meta-cloud-api.site/guides/express/) |
|
|
146
|
+
| Next.js App Router | `nextjsAppWebhookHandler` | [Next.js App Router](https://meta-cloud-api.site/guides/nextjs-app/) |
|
|
147
|
+
| Next.js Pages Router | `nextjsPagesWebhookHandler` | [Next.js Pages Router](https://meta-cloud-api.site/guides/nextjs-pages/) |
|
|
148
|
+
| Hono (Node.js, Bun, Deno, Workers, Edge) | `honoWebhookHandler` | [Hono](https://meta-cloud-api.site/guides/hono/) |
|
|
149
|
+
| Fastify | `fastifyWebhookHandler` | [Fastify](https://meta-cloud-api.site/guides/fastify/) |
|
|
150
|
+
| NestJS | `expressWebhookHandler` or `fastifyWebhookHandler` | [NestJS](https://meta-cloud-api.site/guides/nestjs/) |
|
|
151
|
+
|
|
121
152
|
All 30+ webhook field types are supported — messages, statuses, templates, flows, groups, calls, and more. See the [Webhooks documentation](https://meta-cloud-api.site/) for the full list of handlers.
|
|
122
153
|
|
|
123
154
|
## Requirements
|
|
124
155
|
|
|
125
|
-
- **Node.js**
|
|
156
|
+
- **Node.js** 20.12+, **Bun**, **Deno**, **Cloudflare Workers** or **Vercel Edge** — no runtime dependencies, no `node:*` imports ([runtime guide](https://meta-cloud-api.site/guides/runtimes))
|
|
126
157
|
- **TypeScript** 4.5+ (for TypeScript projects)
|
|
127
158
|
|
|
128
159
|
## Resources
|