@daolmedo/openclaw-twilio-whatsapp 1.1.9 → 1.1.10
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/dist/index.js +33 -8
- package/package.json +36 -36
package/dist/index.js
CHANGED
|
@@ -40,17 +40,36 @@ function normalizePhoneNumber(phone) {
|
|
|
40
40
|
|
|
41
41
|
// src/send.ts
|
|
42
42
|
import twilio from "twilio";
|
|
43
|
+
var MAX_BODY_LENGTH = 1550;
|
|
44
|
+
function splitMessage(text) {
|
|
45
|
+
if (text.length <= MAX_BODY_LENGTH) return [text];
|
|
46
|
+
const chunks = [];
|
|
47
|
+
let remaining = text;
|
|
48
|
+
while (remaining.length > MAX_BODY_LENGTH) {
|
|
49
|
+
let splitAt = remaining.lastIndexOf(" ", MAX_BODY_LENGTH);
|
|
50
|
+
if (splitAt <= 0) splitAt = MAX_BODY_LENGTH;
|
|
51
|
+
chunks.push(remaining.slice(0, splitAt).trimEnd());
|
|
52
|
+
remaining = remaining.slice(splitAt).trimStart();
|
|
53
|
+
}
|
|
54
|
+
if (remaining.length > 0) chunks.push(remaining);
|
|
55
|
+
return chunks;
|
|
56
|
+
}
|
|
43
57
|
async function sendTwilioWhatsappMessage(opts) {
|
|
44
58
|
const client = twilio(opts.accountSid, opts.authToken);
|
|
45
59
|
const from = opts.from.startsWith("whatsapp:") ? opts.from : `whatsapp:${opts.from}`;
|
|
46
60
|
const to = opts.to.startsWith("whatsapp:") ? opts.to : `whatsapp:${opts.to}`;
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
61
|
+
const chunks = opts.body ? splitMessage(opts.body) : [void 0];
|
|
62
|
+
let lastSid = "";
|
|
63
|
+
for (const chunk of chunks) {
|
|
64
|
+
const msg = await client.messages.create({
|
|
65
|
+
from,
|
|
66
|
+
to,
|
|
67
|
+
...chunk ? { body: chunk } : {},
|
|
68
|
+
...opts.mediaUrl ? { mediaUrl: [opts.mediaUrl] } : {}
|
|
69
|
+
});
|
|
70
|
+
lastSid = msg.sid;
|
|
71
|
+
}
|
|
72
|
+
return lastSid;
|
|
54
73
|
}
|
|
55
74
|
|
|
56
75
|
// src/outbound-adapter.ts
|
|
@@ -358,12 +377,18 @@ function registerTwilioWhatsappHttpRoutes(api) {
|
|
|
358
377
|
if (hasAudio) {
|
|
359
378
|
console.log("[twilio-whatsapp] Audio detected, attempting transcription. Media:", resolvedMedia.map((m) => `${m.path} (${m.contentType})`));
|
|
360
379
|
try {
|
|
380
|
+
const cfg = stored.cfg;
|
|
381
|
+
const agentId = cfg.bindings?.find(
|
|
382
|
+
(b) => b.match?.channel === "twilio-whatsapp" && b.match?.accountId === stored.accountId
|
|
383
|
+
)?.agentId;
|
|
384
|
+
const agentDir = cfg.agents?.list?.find((a) => a.id === agentId)?.agentDir;
|
|
361
385
|
const transcript = await transcribeFirstAudio({
|
|
362
386
|
ctx: {
|
|
363
387
|
MediaPaths: resolvedMedia.map((m) => m.path),
|
|
364
388
|
MediaTypes: resolvedMedia.map((m) => m.contentType)
|
|
365
389
|
},
|
|
366
|
-
cfg: stored.cfg
|
|
390
|
+
cfg: stored.cfg,
|
|
391
|
+
agentDir
|
|
367
392
|
});
|
|
368
393
|
console.log("[twilio-whatsapp] Transcription result:", transcript);
|
|
369
394
|
bodyForAgent = transcript || messageText || "<media:audio>";
|
package/package.json
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@daolmedo/openclaw-twilio-whatsapp",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "Twilio WhatsApp channel plugin for OpenClaw (Cody ISV)",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"exports": {
|
|
7
|
-
".": "./dist/index.js"
|
|
8
|
-
},
|
|
9
|
-
"files": [
|
|
10
|
-
"dist",
|
|
11
|
-
"openclaw.plugin.json"
|
|
12
|
-
],
|
|
13
|
-
"scripts": {
|
|
14
|
-
"build": "esbuild index.ts --bundle --platform=node --format=esm --external:openclaw --external:openclaw/* --external:twilio --outfile=dist/index.js",
|
|
15
|
-
"prepublishOnly": "npm run build"
|
|
16
|
-
},
|
|
17
|
-
"dependencies": {
|
|
18
|
-
"twilio": "^5.4.0"
|
|
19
|
-
},
|
|
20
|
-
"devDependencies": {
|
|
21
|
-
"esbuild": "^0.28.0",
|
|
22
|
-
"typescript": "^5.4.0"
|
|
23
|
-
},
|
|
24
|
-
"openclaw": {
|
|
25
|
-
"extensions": [
|
|
26
|
-
"./dist/index.js"
|
|
27
|
-
],
|
|
28
|
-
"channel": {
|
|
29
|
-
"id": "twilio-whatsapp",
|
|
30
|
-
"label": "Twilio WhatsApp"
|
|
31
|
-
},
|
|
32
|
-
"install": {
|
|
33
|
-
"minHostVersion": ">=2026.3.24"
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@daolmedo/openclaw-twilio-whatsapp",
|
|
3
|
+
"version": "1.1.10",
|
|
4
|
+
"description": "Twilio WhatsApp channel plugin for OpenClaw (Cody ISV)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"openclaw.plugin.json"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "esbuild index.ts --bundle --platform=node --format=esm --external:openclaw --external:openclaw/* --external:twilio --outfile=dist/index.js",
|
|
15
|
+
"prepublishOnly": "npm run build"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"twilio": "^5.4.0"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"esbuild": "^0.28.0",
|
|
22
|
+
"typescript": "^5.4.0"
|
|
23
|
+
},
|
|
24
|
+
"openclaw": {
|
|
25
|
+
"extensions": [
|
|
26
|
+
"./dist/index.js"
|
|
27
|
+
],
|
|
28
|
+
"channel": {
|
|
29
|
+
"id": "twilio-whatsapp",
|
|
30
|
+
"label": "Twilio WhatsApp"
|
|
31
|
+
},
|
|
32
|
+
"install": {
|
|
33
|
+
"minHostVersion": ">=2026.3.24"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|