@daolmedo/openclaw-twilio-whatsapp 1.1.8 → 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.
Files changed (2) hide show
  1. package/dist/index.js +35 -8
  2. 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 msg = await client.messages.create({
48
- from,
49
- to,
50
- ...opts.body ? { body: opts.body } : {},
51
- ...opts.mediaUrl ? { mediaUrl: [opts.mediaUrl] } : {}
52
- });
53
- return msg.sid;
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
@@ -356,14 +375,22 @@ function registerTwilioWhatsappHttpRoutes(api) {
356
375
  let bodyForAgent = messageText || void 0;
357
376
  const hasAudio = resolvedMedia.some((m) => m.contentType.startsWith("audio/"));
358
377
  if (hasAudio) {
378
+ console.log("[twilio-whatsapp] Audio detected, attempting transcription. Media:", resolvedMedia.map((m) => `${m.path} (${m.contentType})`));
359
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;
360
385
  const transcript = await transcribeFirstAudio({
361
386
  ctx: {
362
387
  MediaPaths: resolvedMedia.map((m) => m.path),
363
388
  MediaTypes: resolvedMedia.map((m) => m.contentType)
364
389
  },
365
- cfg: stored.cfg
390
+ cfg: stored.cfg,
391
+ agentDir
366
392
  });
393
+ console.log("[twilio-whatsapp] Transcription result:", transcript);
367
394
  bodyForAgent = transcript || messageText || "<media:audio>";
368
395
  } catch (err) {
369
396
  console.error("[twilio-whatsapp] Audio transcription failed:", err);
package/package.json CHANGED
@@ -1,36 +1,36 @@
1
- {
2
- "name": "@daolmedo/openclaw-twilio-whatsapp",
3
- "version": "1.1.8",
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
+ }