@daolmedo/openclaw-twilio-whatsapp 1.1.9 → 1.1.11
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 +35 -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
|
|
@@ -175,6 +194,7 @@ var twilioWhatsappPlugin = {
|
|
|
175
194
|
};
|
|
176
195
|
|
|
177
196
|
// src/http-routes.ts
|
|
197
|
+
import { appendFileSync } from "node:fs";
|
|
178
198
|
import { dispatchInboundDirectDmWithRuntime } from "openclaw/plugin-sdk/direct-dm";
|
|
179
199
|
import { saveMediaBuffer } from "openclaw/plugin-sdk/media-runtime";
|
|
180
200
|
import { transcribeFirstAudio } from "openclaw/plugin-sdk/media-runtime";
|
|
@@ -358,12 +378,19 @@ function registerTwilioWhatsappHttpRoutes(api) {
|
|
|
358
378
|
if (hasAudio) {
|
|
359
379
|
console.log("[twilio-whatsapp] Audio detected, attempting transcription. Media:", resolvedMedia.map((m) => `${m.path} (${m.contentType})`));
|
|
360
380
|
try {
|
|
381
|
+
const cfg = stored.cfg;
|
|
382
|
+
const agentId = cfg.bindings?.find(
|
|
383
|
+
(b) => b.match?.channel === "twilio-whatsapp" && b.match?.accountId === stored.accountId
|
|
384
|
+
)?.agentId;
|
|
385
|
+
const agentDir = cfg.agents?.list?.find((a) => a.id === agentId)?.agentDir;
|
|
386
|
+
appendFileSync("/tmp/twilio-debug.log", JSON.stringify({ bindings: cfg.bindings, accountId: stored.accountId, agentId, agentDir }) + "\n");
|
|
361
387
|
const transcript = await transcribeFirstAudio({
|
|
362
388
|
ctx: {
|
|
363
389
|
MediaPaths: resolvedMedia.map((m) => m.path),
|
|
364
390
|
MediaTypes: resolvedMedia.map((m) => m.contentType)
|
|
365
391
|
},
|
|
366
|
-
cfg: stored.cfg
|
|
392
|
+
cfg: stored.cfg,
|
|
393
|
+
agentDir
|
|
367
394
|
});
|
|
368
395
|
console.log("[twilio-whatsapp] Transcription result:", transcript);
|
|
369
396
|
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.11",
|
|
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
|
+
}
|