@peopl-health/nexus 2.5.1-fix → 2.5.2-fix
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/lib/core/NexusMessaging.js +22 -18
- package/package.json +1 -1
|
@@ -373,23 +373,11 @@ class NexusMessaging {
|
|
|
373
373
|
} else if (messageData.flow) {
|
|
374
374
|
return await this.handleFlow(messageData);
|
|
375
375
|
} else {
|
|
376
|
-
if (chatId && this.provider && typeof this.provider.sendTypingIndicator === 'function') {
|
|
377
|
-
const messageId = messageData.id || messageData.MessageSid || messageData.message_id;
|
|
378
|
-
if (messageId) {
|
|
379
|
-
setTimeout(() => {
|
|
380
|
-
this.provider.sendTypingIndicator(messageId).catch(err =>
|
|
381
|
-
logger.debug('[processIncomingMessage] Typing indicator failed', { error: err.message })
|
|
382
|
-
);
|
|
383
|
-
}, 3000);
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
|
|
387
376
|
// For regular messages and media, use batching if enabled
|
|
388
377
|
logger.info('Batching config:', this.batchingConfig);
|
|
389
378
|
if (this.batchingConfig.enabled && chatId) {
|
|
390
379
|
return await this._handleWithBatching(messageData, chatId);
|
|
391
380
|
} else {
|
|
392
|
-
// Handle media and regular messages without batching
|
|
393
381
|
if (messageData.media) {
|
|
394
382
|
return await this.handleMedia(messageData);
|
|
395
383
|
} else {
|
|
@@ -646,14 +634,24 @@ class NexusMessaging {
|
|
|
646
634
|
* Handle message with batching - waits for additional messages before processing
|
|
647
635
|
*/
|
|
648
636
|
async _handleWithBatching(messageData, chatId) {
|
|
649
|
-
|
|
650
|
-
|
|
637
|
+
const existing = this.pendingResponses.get(chatId);
|
|
638
|
+
if (existing) {
|
|
639
|
+
clearTimeout(existing.timeoutId);
|
|
640
|
+
if (existing.typingInterval) {
|
|
641
|
+
clearInterval(existing.typingInterval);
|
|
642
|
+
}
|
|
651
643
|
logger.info(`Received additional message from ${chatId}, resetting wait timer`);
|
|
652
644
|
}
|
|
653
645
|
|
|
646
|
+
// Start typing indicator refresh for batching period
|
|
647
|
+
const typingInterval = await this._startTypingRefresh(chatId);
|
|
648
|
+
|
|
654
649
|
const waitTime = this.batchingConfig.baseWaitTime;
|
|
655
650
|
const timeoutId = setTimeout(async () => {
|
|
656
651
|
try {
|
|
652
|
+
if (typingInterval) {
|
|
653
|
+
clearInterval(typingInterval);
|
|
654
|
+
}
|
|
657
655
|
this.pendingResponses.delete(chatId);
|
|
658
656
|
await this._handleBatchedMessages(chatId);
|
|
659
657
|
} catch (error) {
|
|
@@ -661,7 +659,7 @@ class NexusMessaging {
|
|
|
661
659
|
}
|
|
662
660
|
}, waitTime);
|
|
663
661
|
|
|
664
|
-
this.pendingResponses.set(chatId, timeoutId);
|
|
662
|
+
this.pendingResponses.set(chatId, { timeoutId, typingInterval });
|
|
665
663
|
logger.info(`Waiting ${Math.round(waitTime/1000)} seconds for more messages from ${chatId}`);
|
|
666
664
|
}
|
|
667
665
|
|
|
@@ -684,7 +682,7 @@ class NexusMessaging {
|
|
|
684
682
|
return setInterval(() =>
|
|
685
683
|
this.provider.sendTypingIndicator(lastMessage.message_id).catch(err =>
|
|
686
684
|
logger.debug('[_startTypingRefresh] Failed', { error: err.message })
|
|
687
|
-
),
|
|
685
|
+
), 5000
|
|
688
686
|
);
|
|
689
687
|
}
|
|
690
688
|
|
|
@@ -730,8 +728,14 @@ class NexusMessaging {
|
|
|
730
728
|
* Clear pending response for a chat (useful for cleanup)
|
|
731
729
|
*/
|
|
732
730
|
clearPendingResponse(chatId) {
|
|
733
|
-
|
|
734
|
-
|
|
731
|
+
const pending = this.pendingResponses.get(chatId);
|
|
732
|
+
if (pending) {
|
|
733
|
+
if (pending.timeoutId) {
|
|
734
|
+
clearTimeout(pending.timeoutId);
|
|
735
|
+
}
|
|
736
|
+
if (pending.typingInterval) {
|
|
737
|
+
clearInterval(pending.typingInterval);
|
|
738
|
+
}
|
|
735
739
|
this.pendingResponses.delete(chatId);
|
|
736
740
|
}
|
|
737
741
|
}
|