@laburen/openclaw-plugin-whatsapp-api 0.6.0 → 0.6.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/README.md +13 -0
- package/index.js +21 -1
- package/openclaw.plugin.json +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -120,6 +120,19 @@ Responses: **`403`** if the shared secret does not match, **`400`** if the paylo
|
|
|
120
120
|
|
|
121
121
|
Per-account fields can override phone id, token, retries, etc. under `channels["whatsapp-api"].accounts.<accountId>`.
|
|
122
122
|
|
|
123
|
+
## LLM Usage Forwarding (`llm_output`) (opcional)
|
|
124
|
+
|
|
125
|
+
Este plugin puede reenviar el usage de tokens cuando OpenClaw emite el hook `llm_output`. Cuando está configurado, hace un `POST` a `{LABUREN_WEB_APP_URL}/api/usage` y envía `Authorization: Bearer <laburenApiKey>`.
|
|
126
|
+
|
|
127
|
+
Para activarlo, configura estas keys del entry del plugin (no del channel):
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
openclaw config set plugins.entries.whatsapp-api.LABUREN_WEB_APP_URL "https://tu-laburen.example"
|
|
131
|
+
openclaw config set plugins.entries.whatsapp-api.userPhoneNumber "+1234567890"
|
|
132
|
+
openclaw config set plugins.entries.whatsapp-api.laburenApiKey "tu-api-key"
|
|
133
|
+
openclaw gateway restart
|
|
134
|
+
```
|
|
135
|
+
|
|
123
136
|
## Notes
|
|
124
137
|
|
|
125
138
|
- Outbound mode is **direct-to-Meta** only (no third-party relay in this plugin).
|
package/index.js
CHANGED
|
@@ -1429,6 +1429,7 @@ const log$3 = waLogger("llm-output/forward-usage");
|
|
|
1429
1429
|
/** Plugin extension config keys (see `openclaw.plugin.json`). */
|
|
1430
1430
|
const LABUREN_WEB_APP_CONFIG_KEY = "LABUREN_WEB_APP_URL";
|
|
1431
1431
|
const USER_PHONE_CONFIG_KEY = "userPhoneNumber";
|
|
1432
|
+
const LABUREN_API_KEY_CONFIG_KEY = "laburenApiKey";
|
|
1432
1433
|
const USAGE_PATH = "/api/usage";
|
|
1433
1434
|
const USAGE_FEATURE = "openclaw_run";
|
|
1434
1435
|
const POST_TIMEOUT_MS = 3e3;
|
|
@@ -1460,6 +1461,17 @@ function resolveUserPhoneNumber() {
|
|
|
1460
1461
|
const phone = raw.trim();
|
|
1461
1462
|
return phone.length > 0 ? phone : null;
|
|
1462
1463
|
}
|
|
1464
|
+
function resolveLaburenApiKey() {
|
|
1465
|
+
let raw;
|
|
1466
|
+
try {
|
|
1467
|
+
raw = getPluginApi().pluginConfig?.[LABUREN_API_KEY_CONFIG_KEY];
|
|
1468
|
+
} catch {
|
|
1469
|
+
return null;
|
|
1470
|
+
}
|
|
1471
|
+
if (typeof raw !== "string") return null;
|
|
1472
|
+
const key = raw.trim();
|
|
1473
|
+
return key.length > 0 ? key : null;
|
|
1474
|
+
}
|
|
1463
1475
|
async function handleForwardLlmUsage(event, ctx) {
|
|
1464
1476
|
const usage = event.usage;
|
|
1465
1477
|
if (!usage) return;
|
|
@@ -1467,6 +1479,11 @@ async function handleForwardLlmUsage(event, ctx) {
|
|
|
1467
1479
|
if (!endpoint) return;
|
|
1468
1480
|
const userPhoneNumber = resolveUserPhoneNumber();
|
|
1469
1481
|
if (!userPhoneNumber) return;
|
|
1482
|
+
const laburenApiKey = resolveLaburenApiKey();
|
|
1483
|
+
if (!laburenApiKey) {
|
|
1484
|
+
log$3.warn(`usage-forwarder: missing ${LABUREN_API_KEY_CONFIG_KEY} (required for authenticated /api/usage calls)`);
|
|
1485
|
+
return;
|
|
1486
|
+
}
|
|
1470
1487
|
const input = usage.input ?? 0;
|
|
1471
1488
|
const output = usage.output ?? 0;
|
|
1472
1489
|
const cacheRead = usage.cacheRead ?? 0;
|
|
@@ -1493,7 +1510,10 @@ async function handleForwardLlmUsage(event, ctx) {
|
|
|
1493
1510
|
try {
|
|
1494
1511
|
const res = await fetch(endpoint, {
|
|
1495
1512
|
method: "POST",
|
|
1496
|
-
headers: {
|
|
1513
|
+
headers: {
|
|
1514
|
+
"Content-Type": "application/json",
|
|
1515
|
+
Authorization: `Bearer ${laburenApiKey}`
|
|
1516
|
+
},
|
|
1497
1517
|
body: JSON.stringify(body),
|
|
1498
1518
|
signal: AbortSignal.timeout(POST_TIMEOUT_MS)
|
|
1499
1519
|
});
|
package/openclaw.plugin.json
CHANGED
|
@@ -17,6 +17,10 @@
|
|
|
17
17
|
"type": "string",
|
|
18
18
|
"description": "WhatsApp user phone (E.164 or your normalised form). Sent on each usage POST so the backend can resolve the user."
|
|
19
19
|
},
|
|
20
|
+
"laburenApiKey": {
|
|
21
|
+
"type": "string",
|
|
22
|
+
"description": "Bearer token for the Laburen usage ingest API (sent as `Authorization: Bearer <laburenApiKey>` on POST {base}/api/usage)."
|
|
23
|
+
},
|
|
20
24
|
"defaults": {
|
|
21
25
|
"type": "object",
|
|
22
26
|
"additionalProperties": false,
|