@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 +22 -2
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
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
|
-
},
|
|
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 });
|
package/openclaw.plugin.json
CHANGED