@moltflow/skills 1.4.0 → 2.0.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.
@@ -0,0 +1,392 @@
1
+ ---
2
+ name: moltflow-admin
3
+ description: "Manage MoltFlow platform authentication, users, billing, API keys, and tenant settings via the admin API."
4
+ source: "MoltFlow Team"
5
+ version: "2.0.0"
6
+ risk: safe
7
+ requiredEnv:
8
+ - MOLTFLOW_API_KEY
9
+ primaryEnv: MOLTFLOW_API_KEY
10
+ disableModelInvocation: true
11
+ ---
12
+
13
+ > **MoltFlow** — WhatsApp Business automation for teams. Connect, monitor, and automate WhatsApp at scale.
14
+ > [Save up to 17% with yearly billing](https://molt.waiflow.app/checkout?plan=free) -- Free tier available, no credit card required.
15
+
16
+ # MoltFlow Admin Skill
17
+
18
+ Manage authentication, users, billing, API keys, usage tracking, and platform administration for MoltFlow.
19
+
20
+ ## When to Use
21
+
22
+ Use this skill when you need to:
23
+ - Authenticate with MoltFlow (login, token refresh, magic link)
24
+ - Manage API keys (create, rotate, revoke)
25
+ - Check subscription status, plan limits, or usage
26
+ - Create a Stripe checkout session or billing portal link
27
+ - Manage users as an admin (list, suspend, activate)
28
+ - View platform stats, tenants, or audit logs (superadmin)
29
+ - Manage plans and pricing (superadmin)
30
+
31
+ Trigger phrases: "login to MoltFlow", "create API key", "check subscription", "billing portal", "admin stats", "list users", "manage plans", "usage report"
32
+
33
+ ## Prerequisites
34
+
35
+ - **MOLTFLOW_API_KEY** — required for most endpoints. Generate from [MoltFlow Dashboard > API Keys](https://molt.waiflow.app/api-keys)
36
+ - Auth endpoints (`/auth/*`) accept email/password — no API key needed for initial login
37
+ - Admin endpoints require superadmin role
38
+
39
+ ## Base URL
40
+
41
+ ```
42
+ https://apiv2.waiflow.app/api/v2
43
+ ```
44
+
45
+ ## Authentication
46
+
47
+ All requests (except login/signup) require one of:
48
+ - `Authorization: Bearer <access_token>` (JWT from login)
49
+ - `X-API-Key: <api_key>` (API key from dashboard)
50
+
51
+ ---
52
+
53
+ ## Auth Endpoints
54
+
55
+ | Method | Endpoint | Description |
56
+ |--------|----------|-------------|
57
+ | POST | `/auth/login` | Login with email/password |
58
+ | POST | `/auth/refresh` | Refresh access token |
59
+ | GET | `/auth/me` | Get current user profile |
60
+ | POST | `/auth/logout` | Invalidate session |
61
+ | POST | `/auth/forgot-password` | Request password reset email |
62
+ | POST | `/auth/reset-password` | Confirm password reset |
63
+ | POST | `/auth/verify-email` | Verify email address |
64
+ | POST | `/auth/magic-link/request` | Request magic link login |
65
+ | POST | `/auth/magic-link/verify` | Verify magic link token |
66
+ | POST | `/auth/setup-password` | Set password for magic-link users |
67
+
68
+ ### Login — Request/Response
69
+
70
+ ```json
71
+ // POST /auth/login
72
+ {
73
+ "email": "user@example.com",
74
+ "password": "your-password"
75
+ }
76
+
77
+ // Response
78
+ {
79
+ "access_token": "eyJhbGciOi...",
80
+ "refresh_token": "eyJhbGciOi...",
81
+ "token_type": "bearer",
82
+ "user": {
83
+ "id": "uuid",
84
+ "email": "user@example.com",
85
+ "full_name": "John Doe",
86
+ "role": "owner",
87
+ "tenant_id": "uuid"
88
+ }
89
+ }
90
+ ```
91
+
92
+ ---
93
+
94
+ ## User Management
95
+
96
+ Self-service user profile endpoints (authenticated user):
97
+
98
+ | Method | Endpoint | Description |
99
+ |--------|----------|-------------|
100
+ | GET | `/users/me` | Get own profile |
101
+ | PATCH | `/users/me` | Update own profile |
102
+ | DELETE | `/users/me` | Delete own account (soft) |
103
+
104
+ Admin user management (superadmin only — via `/admin` prefix):
105
+
106
+ | Method | Endpoint | Description |
107
+ |--------|----------|-------------|
108
+ | GET | `/admin/users` | List all users (pagination, search) |
109
+ | GET | `/admin/users/{id}` | Get user details |
110
+ | PATCH | `/admin/users/{id}` | Update user |
111
+ | POST | `/admin/users/{id}/suspend` | Suspend user |
112
+ | POST | `/admin/users/{id}/activate` | Reactivate user |
113
+ | DELETE | `/admin/users/{id}` | Delete user (soft) |
114
+
115
+ ---
116
+
117
+ ## API Keys
118
+
119
+ | Method | Endpoint | Description |
120
+ |--------|----------|-------------|
121
+ | GET | `/api-keys` | List all API keys |
122
+ | POST | `/api-keys` | Create new key |
123
+ | GET | `/api-keys/{id}` | Get key details |
124
+ | DELETE | `/api-keys/{id}` | Revoke key |
125
+ | POST | `/api-keys/{id}/rotate` | Rotate key (new secret) |
126
+
127
+ ### Create API Key — Request/Response
128
+
129
+ ```json
130
+ // POST /api-keys
131
+ {
132
+ "name": "Production Integration"
133
+ }
134
+
135
+ // Response (raw key shown ONCE — save it immediately)
136
+ {
137
+ "id": "uuid",
138
+ "name": "Production Integration",
139
+ "key_prefix": "mf_abc1",
140
+ "raw_key": "mf_abc1234567890abcdef...",
141
+ "created_at": "2026-01-15T10:00:00Z",
142
+ "is_active": true
143
+ }
144
+ ```
145
+
146
+ **Important:** The `raw_key` is only returned at creation time. It is stored as a SHA-256 hash — it cannot be retrieved later.
147
+
148
+ ---
149
+
150
+ ## Billing & Subscription
151
+
152
+ | Method | Endpoint | Description |
153
+ |--------|----------|-------------|
154
+ | GET | `/billing/subscription` | Current plan, limits, and usage |
155
+ | POST | `/billing/checkout` | Create Stripe checkout session |
156
+ | POST | `/billing/portal` | Get Stripe billing portal URL |
157
+ | POST | `/billing/cancel` | Cancel subscription |
158
+ | GET | `/billing/plans` | List available plans and pricing |
159
+ | POST | `/billing/signup-checkout` | Checkout for new signups |
160
+
161
+ ### Check Subscription — Response
162
+
163
+ ```json
164
+ {
165
+ "plan_id": "pro",
166
+ "display_name": "Pro",
167
+ "status": "active",
168
+ "billing_cycle": "monthly",
169
+ "current_period_end": "2026-02-15T00:00:00Z",
170
+ "limits": {
171
+ "max_sessions": 3,
172
+ "max_messages_per_month": 5000,
173
+ "max_groups": 10,
174
+ "max_labels": 50,
175
+ "ai_replies_per_month": 500
176
+ },
177
+ "usage": {
178
+ "sessions": 2,
179
+ "messages_this_month": 1247,
180
+ "groups": 5,
181
+ "labels": 12,
182
+ "ai_replies_this_month": 89
183
+ }
184
+ }
185
+ ```
186
+
187
+ ### Create Checkout — Request
188
+
189
+ ```json
190
+ // POST /billing/checkout
191
+ {
192
+ "plan_id": "pro",
193
+ "billing_cycle": "monthly"
194
+ }
195
+
196
+ // Response
197
+ {
198
+ "checkout_url": "https://checkout.stripe.com/c/pay/cs_live_...",
199
+ "session_id": "cs_live_..."
200
+ }
201
+ ```
202
+
203
+ ---
204
+
205
+ ## Usage Tracking
206
+
207
+ | Method | Endpoint | Description |
208
+ |--------|----------|-------------|
209
+ | GET | `/usage/current` | Current month usage summary |
210
+ | GET | `/usage/history` | Historical usage by month |
211
+ | GET | `/usage/daily` | Daily breakdown for current month |
212
+
213
+ ---
214
+
215
+ ## Tenant Settings
216
+
217
+ Self-service tenant configuration (owner/admin role required for writes).
218
+
219
+ | Method | Endpoint | Description |
220
+ |--------|----------|-------------|
221
+ | GET | `/tenant/settings` | Get current tenant settings |
222
+ | PATCH | `/tenant/settings` | Update tenant settings (owner/admin only) |
223
+
224
+ ### Get Settings — Response
225
+
226
+ ```json
227
+ {
228
+ "allowed_numbers": ["+5511999999999"],
229
+ "require_approval": false,
230
+ "ai_consent_enabled": true
231
+ }
232
+ ```
233
+
234
+ ### Update Settings — Request Body
235
+
236
+ All fields are optional. Only provided fields are updated.
237
+
238
+ ```json
239
+ {
240
+ "allowed_numbers": ["+5511999999999", "+5511888888888"],
241
+ "require_approval": true,
242
+ "ai_consent_enabled": true
243
+ }
244
+ ```
245
+
246
+ **Notes:**
247
+ - `ai_consent_enabled` records a GDPR consent entry (consent type `ai_processing`, version `1.0`) with the user's IP and user-agent.
248
+ - Any authenticated user can read settings; only `owner` or `admin` roles can update.
249
+
250
+ ---
251
+
252
+ ## GDPR — Contact Erasure
253
+
254
+ Erase all data for a specific phone number within your tenant. This supports GDPR "right to erasure" (Article 17) requests.
255
+
256
+ | Method | Endpoint | Description |
257
+ |--------|----------|-------------|
258
+ | POST | `/gdpr/contact-erasure` | Erase all data for a phone number |
259
+
260
+ ### Request Body
261
+
262
+ ```json
263
+ {
264
+ "phone": "972501234567@c.us",
265
+ "reason": "gdpr_request"
266
+ }
267
+ ```
268
+
269
+ | Field | Type | Required | Description |
270
+ |-------|------|----------|-------------|
271
+ | `phone` | string | Yes | Phone number (with or without `@c.us` suffix) |
272
+ | `reason` | string | No | Reason for erasure (default: `gdpr_request`) |
273
+
274
+ ### Response
275
+
276
+ ```json
277
+ {
278
+ "phone": "972501234567@c.us",
279
+ "messages_deleted": 142,
280
+ "reviews_deleted": 3,
281
+ "chats_anonymized": 1,
282
+ "group_members_anonymized": 2,
283
+ "audit_logged": true,
284
+ "completed_at": "2026-02-12T14:30:00Z"
285
+ }
286
+ ```
287
+
288
+ **What gets erased:**
289
+ - **Messages**: Permanently deleted (handles both plaintext and encrypted rows)
290
+ - **Reviews**: CollectedReview records where sender matches — permanently deleted
291
+ - **Chats**: Contact phone and name set to `REDACTED` (anonymized, not deleted)
292
+ - **Group members**: Phone and name set to `REDACTED` (anonymized)
293
+ - **Audit log**: SHA-256 hash of the phone (first 16 chars) + erasure statistics logged for compliance
294
+
295
+ **Important:** Erasure is scoped to your tenant only. Encrypted fields are decrypted in-memory to match, then the rows are deleted.
296
+
297
+ ---
298
+
299
+ ## Admin Endpoints (Superadmin Only)
300
+
301
+ These endpoints require the `superadmin` role.
302
+
303
+ | Method | Endpoint | Description |
304
+ |--------|----------|-------------|
305
+ | GET | `/admin/stats` | Platform-wide statistics |
306
+ | GET | `/admin/health` | Service health check |
307
+ | GET | `/admin/audit-logs` | Audit log viewer |
308
+ | GET | `/admin/tenants` | List all tenants |
309
+ | GET | `/admin/tenants/{id}` | Get tenant details |
310
+ | PATCH | `/admin/tenants/{id}` | Update tenant |
311
+ | DELETE | `/admin/tenants/{id}` | Delete tenant (soft) |
312
+ | POST | `/admin/tenants/{id}/reset-limits` | Reset usage counters |
313
+ | GET | `/admin/tenants/{id}/effective-limits` | View resolved plan limits |
314
+ | GET | `/admin/plans` | List all plans |
315
+ | POST | `/admin/plans` | Create new plan |
316
+ | PATCH | `/admin/plans/{id}` | Update plan |
317
+ | DELETE | `/admin/plans/{id}` | Delete plan |
318
+ | POST | `/admin/plans/{id}/stripe-sync` | Sync plan to Stripe |
319
+ | POST | `/admin/plans/stripe-sync-all` | Sync all plans to Stripe |
320
+
321
+ ---
322
+
323
+ ## curl Examples
324
+
325
+ ### 1. Login and Get Token
326
+
327
+ ```bash
328
+ curl -X POST https://apiv2.waiflow.app/api/v2/auth/login \
329
+ -H "Content-Type: application/json" \
330
+ -d '{
331
+ "email": "admin@example.com",
332
+ "password": "your-password"
333
+ }'
334
+ ```
335
+
336
+ ### 2. Create an API Key
337
+
338
+ ```bash
339
+ curl -X POST https://apiv2.waiflow.app/api/v2/api-keys \
340
+ -H "Authorization: Bearer eyJhbGciOi..." \
341
+ -H "Content-Type: application/json" \
342
+ -d '{"name": "CI/CD Pipeline"}'
343
+ ```
344
+
345
+ ### 3. Check Subscription and Limits
346
+
347
+ ```bash
348
+ curl https://apiv2.waiflow.app/api/v2/billing/subscription \
349
+ -H "X-API-Key: mf_your_api_key_here"
350
+ ```
351
+
352
+ ### 4. Get Platform Stats (Superadmin)
353
+
354
+ ```bash
355
+ curl https://apiv2.waiflow.app/api/v2/admin/stats \
356
+ -H "Authorization: Bearer eyJhbGciOi..."
357
+ ```
358
+
359
+ ---
360
+
361
+ ## Error Responses
362
+
363
+ | Status | Meaning |
364
+ |--------|---------|
365
+ | 400 | Invalid request body or parameters |
366
+ | 401 | Missing or invalid authentication |
367
+ | 403 | Insufficient permissions (not admin/superadmin) |
368
+ | 404 | Resource not found |
369
+ | 409 | Conflict (duplicate email, plan ID, etc.) |
370
+ | 422 | Validation error |
371
+ | 429 | Rate limit exceeded |
372
+
373
+ ---
374
+
375
+ ## Tips
376
+
377
+ - **API key security**: The raw key is only shown once at creation. Store it in a secrets manager.
378
+ - **Token refresh**: Access tokens expire in 30 minutes. Use the refresh endpoint to get new ones without re-authenticating.
379
+ - **Magic links**: For passwordless login, use `magic-link/request` then `magic-link/verify`.
380
+ - **Plan limits**: Use `GET /billing/subscription` to check remaining quotas before making API calls.
381
+ - **Admin operations**: All admin endpoints require the `superadmin` role. Regular users get 403.
382
+
383
+ ---
384
+
385
+ ## Related Skills
386
+
387
+ - **moltflow** -- Core API: sessions, messaging, groups, labels, webhooks
388
+ - **moltflow-outreach** -- Bulk Send, Scheduled Messages, Custom Groups
389
+ - **moltflow-leads** -- Lead detection, pipeline tracking, bulk operations, CSV/JSON export
390
+ - **moltflow-ai** -- AI-powered auto-replies, voice transcription, RAG knowledge base, style profiles
391
+ - **moltflow-a2a** -- Agent-to-Agent protocol, encrypted messaging, content policy
392
+ - **moltflow-reviews** -- Review collection and testimonial management