meta-cloud-api 2.5.0 → 2.7.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 +8 -19
- package/dist/{index.d.ts → index.d.mts} +358 -74
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +21 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types/enums.d.ts +25 -25
- package/dist/types/enums.d.ts.map +1 -1
- package/dist/types/index.d.ts +289 -21
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/utils/index.d.ts +2 -3
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +4 -4
- package/dist/utils/index.js.map +1 -1
- package/package.json +20 -20
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -21
- package/dist/index.js.map +0 -1
- /package/dist/{chunk.js → chunk.mjs} +0 -0
package/README.md
CHANGED
|
@@ -78,49 +78,38 @@ wa.waba // WhatsApp Business Account management
|
|
|
78
78
|
|
|
79
79
|
```typescript
|
|
80
80
|
import express from 'express';
|
|
81
|
-
import {
|
|
81
|
+
import { expressWebhookHandler } from 'meta-cloud-api';
|
|
82
82
|
|
|
83
83
|
const app = express();
|
|
84
84
|
app.use(express.json());
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
// Handler is automatically cached per phoneNumberId — safe against HMR re-evaluation
|
|
87
|
+
const Whatsapp = expressWebhookHandler({
|
|
87
88
|
accessToken: process.env.CLOUD_API_ACCESS_TOKEN,
|
|
88
89
|
phoneNumberId: process.env.WA_PHONE_NUMBER_ID,
|
|
89
90
|
webhookVerificationToken: process.env.WEBHOOK_VERIFICATION_TOKEN,
|
|
90
91
|
});
|
|
91
92
|
|
|
92
93
|
// Handle incoming text messages — echo back to sender
|
|
93
|
-
processor.onText(async (wa, processed) => {
|
|
94
|
+
Whatsapp.processor.onText(async (wa, processed) => {
|
|
94
95
|
const { message } = processed;
|
|
95
96
|
await wa.messages.text({ to: message.from, body: `Echo: ${message.text.body}` });
|
|
96
97
|
});
|
|
97
98
|
|
|
98
99
|
// Handle message status updates
|
|
99
|
-
processor.onStatus((wa, processed) => {
|
|
100
|
+
Whatsapp.processor.onStatus((wa, processed) => {
|
|
100
101
|
const { status } = processed;
|
|
101
102
|
console.log(`Message ${status.id}: ${status.status}`);
|
|
102
103
|
});
|
|
103
104
|
|
|
104
105
|
// Handle template status changes
|
|
105
|
-
processor.onMessageTemplateStatusUpdate((wa, { value }) => {
|
|
106
|
+
Whatsapp.processor.onMessageTemplateStatusUpdate((wa, { value }) => {
|
|
106
107
|
console.log(`Template "${value.message_template_name}" is now ${value.event}`);
|
|
107
108
|
});
|
|
108
109
|
|
|
109
|
-
// Access original webhook request headers/body when forwarding or verifying
|
|
110
|
-
processor.onRaw(async (_wa, _payload, context) => {
|
|
111
|
-
await fetch(process.env.BYPASS_WEBHOOK_URL!, {
|
|
112
|
-
method: 'POST',
|
|
113
|
-
headers: {
|
|
114
|
-
'Content-Type': context.headers.get('content-type') ?? 'application/json',
|
|
115
|
-
'X-Hub-Signature-256': context.headers.get('x-hub-signature-256') ?? '',
|
|
116
|
-
},
|
|
117
|
-
body: context.rawBody,
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
|
|
121
110
|
// Mount on Express
|
|
122
|
-
app.get('/webhook',
|
|
123
|
-
app.post('/webhook',
|
|
111
|
+
app.get('/webhook', Whatsapp.GET);
|
|
112
|
+
app.post('/webhook', Whatsapp.POST);
|
|
124
113
|
```
|
|
125
114
|
|
|
126
115
|
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.
|