@peopl-health/nexus 2.5.1-fix → 2.5.2
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 +34 -18
- package/package.json +1 -1
|
@@ -354,6 +354,18 @@ class NexusMessaging {
|
|
|
354
354
|
|
|
355
355
|
const chatId = messageData.from || messageData.From;
|
|
356
356
|
|
|
357
|
+
// Send initial typing indicator with delay
|
|
358
|
+
if (chatId && this.provider && typeof this.provider.sendTypingIndicator === 'function') {
|
|
359
|
+
const messageId = messageData.id || messageData.MessageSid || messageData.message_id;
|
|
360
|
+
if (messageId) {
|
|
361
|
+
setTimeout(() => {
|
|
362
|
+
this.provider.sendTypingIndicator(messageId).catch(err =>
|
|
363
|
+
logger.debug('[processIncomingMessage] Typing indicator failed', { error: err.message })
|
|
364
|
+
);
|
|
365
|
+
}, 3000);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
357
369
|
if (chatId && hasPreprocessingHandler()) {
|
|
358
370
|
const stop = await invokePreprocessingHandler({
|
|
359
371
|
code: chatId,
|
|
@@ -373,23 +385,11 @@ class NexusMessaging {
|
|
|
373
385
|
} else if (messageData.flow) {
|
|
374
386
|
return await this.handleFlow(messageData);
|
|
375
387
|
} 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
388
|
// For regular messages and media, use batching if enabled
|
|
388
389
|
logger.info('Batching config:', this.batchingConfig);
|
|
389
390
|
if (this.batchingConfig.enabled && chatId) {
|
|
390
391
|
return await this._handleWithBatching(messageData, chatId);
|
|
391
392
|
} else {
|
|
392
|
-
// Handle media and regular messages without batching
|
|
393
393
|
if (messageData.media) {
|
|
394
394
|
return await this.handleMedia(messageData);
|
|
395
395
|
} else {
|
|
@@ -646,14 +646,24 @@ class NexusMessaging {
|
|
|
646
646
|
* Handle message with batching - waits for additional messages before processing
|
|
647
647
|
*/
|
|
648
648
|
async _handleWithBatching(messageData, chatId) {
|
|
649
|
-
|
|
650
|
-
|
|
649
|
+
const existing = this.pendingResponses.get(chatId);
|
|
650
|
+
if (existing) {
|
|
651
|
+
clearTimeout(existing.timeoutId);
|
|
652
|
+
if (existing.typingInterval) {
|
|
653
|
+
clearInterval(existing.typingInterval);
|
|
654
|
+
}
|
|
651
655
|
logger.info(`Received additional message from ${chatId}, resetting wait timer`);
|
|
652
656
|
}
|
|
653
657
|
|
|
658
|
+
// Start typing indicator refresh for batching period
|
|
659
|
+
const typingInterval = await this._startTypingRefresh(chatId);
|
|
660
|
+
|
|
654
661
|
const waitTime = this.batchingConfig.baseWaitTime;
|
|
655
662
|
const timeoutId = setTimeout(async () => {
|
|
656
663
|
try {
|
|
664
|
+
if (typingInterval) {
|
|
665
|
+
clearInterval(typingInterval);
|
|
666
|
+
}
|
|
657
667
|
this.pendingResponses.delete(chatId);
|
|
658
668
|
await this._handleBatchedMessages(chatId);
|
|
659
669
|
} catch (error) {
|
|
@@ -661,7 +671,7 @@ class NexusMessaging {
|
|
|
661
671
|
}
|
|
662
672
|
}, waitTime);
|
|
663
673
|
|
|
664
|
-
this.pendingResponses.set(chatId, timeoutId);
|
|
674
|
+
this.pendingResponses.set(chatId, { timeoutId, typingInterval });
|
|
665
675
|
logger.info(`Waiting ${Math.round(waitTime/1000)} seconds for more messages from ${chatId}`);
|
|
666
676
|
}
|
|
667
677
|
|
|
@@ -684,7 +694,7 @@ class NexusMessaging {
|
|
|
684
694
|
return setInterval(() =>
|
|
685
695
|
this.provider.sendTypingIndicator(lastMessage.message_id).catch(err =>
|
|
686
696
|
logger.debug('[_startTypingRefresh] Failed', { error: err.message })
|
|
687
|
-
),
|
|
697
|
+
), 5000
|
|
688
698
|
);
|
|
689
699
|
}
|
|
690
700
|
|
|
@@ -730,8 +740,14 @@ class NexusMessaging {
|
|
|
730
740
|
* Clear pending response for a chat (useful for cleanup)
|
|
731
741
|
*/
|
|
732
742
|
clearPendingResponse(chatId) {
|
|
733
|
-
|
|
734
|
-
|
|
743
|
+
const pending = this.pendingResponses.get(chatId);
|
|
744
|
+
if (pending) {
|
|
745
|
+
if (pending.timeoutId) {
|
|
746
|
+
clearTimeout(pending.timeoutId);
|
|
747
|
+
}
|
|
748
|
+
if (pending.typingInterval) {
|
|
749
|
+
clearInterval(pending.typingInterval);
|
|
750
|
+
}
|
|
735
751
|
this.pendingResponses.delete(chatId);
|
|
736
752
|
}
|
|
737
753
|
}
|