@daolmedo/openclaw-twilio-whatsapp 1.1.26 → 1.1.27

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 CHANGED
@@ -405,6 +405,22 @@ function resolveMediaBatchFlushMs() {
405
405
  if (Number.isFinite(raw) && raw >= 0) return Math.min(raw, 6e4);
406
406
  return 3e3;
407
407
  }
408
+ function resolveMediaBatchInitialWaitMs() {
409
+ const rawValue = process.env.TWILIO_WHATSAPP_MEDIA_BATCH_INITIAL_WAIT_MS;
410
+ const raw = Number(rawValue);
411
+ if (rawValue !== void 0 && Number.isFinite(raw) && raw >= 0) {
412
+ return Math.min(raw, 6e4);
413
+ }
414
+ if (process.env.TWILIO_WHATSAPP_MEDIA_BATCH_FLUSH_MS !== void 0) {
415
+ return resolveMediaBatchFlushMs();
416
+ }
417
+ return 15e3;
418
+ }
419
+ function resolveMediaBatchMaxWaitMs() {
420
+ const raw = Number(process.env.TWILIO_WHATSAPP_MEDIA_BATCH_MAX_WAIT_MS);
421
+ if (Number.isFinite(raw) && raw >= 0) return Math.min(raw, 6e4);
422
+ return Math.min(resolveMediaBatchInitialWaitMs() + resolveMediaBatchFlushMs(), 6e4);
423
+ }
408
424
  function resolveMediaBatchMaxItems() {
409
425
  const raw = Number(process.env.TWILIO_WHATSAPP_MEDIA_BATCH_MAX_ITEMS);
410
426
  if (Number.isFinite(raw) && raw > 0) return Math.floor(Math.min(raw, 50));
@@ -469,9 +485,13 @@ function stopBatchTimer(batch) {
469
485
  }
470
486
  function armBatchTimer(api, dispatchInbound, key, batch) {
471
487
  stopBatchTimer(batch);
488
+ const batchAgeMs = Math.max(0, Date.now() - batch.firstReceivedAt);
489
+ const desiredWaitMs = batch.items.length === 1 ? resolveMediaBatchInitialWaitMs() : resolveMediaBatchFlushMs();
490
+ const remainingMaxWaitMs = Math.max(0, resolveMediaBatchMaxWaitMs() - batchAgeMs);
491
+ const waitMs = Math.min(desiredWaitMs, remainingMaxWaitMs);
472
492
  batch.timer = setTimeout(() => {
473
493
  void flushPendingMediaBatch(api, dispatchInbound, key, "timer");
474
- }, resolveMediaBatchFlushMs());
494
+ }, waitMs);
475
495
  batch.timer.unref?.();
476
496
  }
477
497
  async function flushPendingMediaBatch(api, dispatchInbound, key, reason) {
@@ -511,7 +531,7 @@ function queueMediaBatch(api, dispatchInbound, key, item) {
511
531
  return new Promise((resolve, reject) => {
512
532
  let batch = pendingMediaByConversation.get(key);
513
533
  if (!batch) {
514
- batch = { items: [] };
534
+ batch = { items: [], firstReceivedAt: item.receivedAt };
515
535
  pendingMediaByConversation.set(key, batch);
516
536
  }
517
537
  batch.items.push({ ...item, resolve, reject });
@@ -2,7 +2,7 @@
2
2
  "id": "twilio-whatsapp",
3
3
  "name": "Twilio WhatsApp",
4
4
  "description": "WhatsApp channel via Twilio Business API (ISV/WABA)",
5
- "version": "1.1.26",
5
+ "version": "1.1.27",
6
6
  "channels": ["twilio-whatsapp"],
7
7
  "channelConfigs": {
8
8
  "twilio-whatsapp": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@daolmedo/openclaw-twilio-whatsapp",
3
- "version": "1.1.26",
3
+ "version": "1.1.27",
4
4
  "description": "Twilio WhatsApp channel plugin for OpenClaw (Cody ISV)",
5
5
  "type": "module",
6
6
  "engines": {