@peopl-health/nexus 6.4.0-dev.19030 → 6.4.1

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.
@@ -85,6 +85,8 @@ const unbatchedRoutes = {
85
85
  command: 'handleCommand',
86
86
  keyword: 'handleKeyword',
87
87
  };
88
+ // A command or keyword that no handler takes («!me duele») is still the patient talking.
89
+ const DECLINABLE_ROUTES = new Set(['command', 'keyword']);
88
90
 
89
91
  function loadDefaultLlmMonitor() {
90
92
  const { LlmMonitorService } = require('../clinical/monitoring/LlmMonitorService');
@@ -676,7 +678,11 @@ class NexusMessaging {
676
678
  }
677
679
 
678
680
  const route = unbatchedRoutes[messageData.type];
679
- if (route) return this[route](messageData);
681
+ if (route) {
682
+ const result = await this[route](messageData);
683
+ if (result !== false || !DECLINABLE_ROUTES.has(messageData.type)) return result;
684
+ messageData = { ...messageData, type: 'message' };
685
+ }
680
686
 
681
687
  if (this.batchingConfig.enabled && chatId) return this._handleWithCheckAfter(chatId);
682
688
  return messageData.type === 'media' ? this.handleMedia(messageData) : this.handleMessage(messageData);
@@ -711,11 +717,13 @@ class NexusMessaging {
711
717
  }
712
718
 
713
719
  async handleCommand(messageData) {
714
- if (this.handlers.onCommand) return await this.handlers.onCommand(messageData, this);
720
+ if (!this.handlers.onCommand) return false;
721
+ return await this.handlers.onCommand(messageData, this);
715
722
  }
716
723
 
717
724
  async handleKeyword(messageData) {
718
- if (this.handlers.onKeyword) return await this.handlers.onKeyword(messageData, this);
725
+ if (!this.handlers.onKeyword) return false;
726
+ return await this.handlers.onKeyword(messageData, this);
719
727
  }
720
728
 
721
729
  async handleFlow(messageData) {
package/lib/index.d.ts CHANGED
@@ -115,8 +115,10 @@ declare module '@peopl-health/nexus' {
115
115
  export type MessageHandler = (messageData: MessageData, nexus: Nexus) => Promise<void>;
116
116
  export type InteractiveHandler = (messageData: MessageData, nexus: Nexus) => Promise<void>;
117
117
  export type MediaHandler = (messageData: MessageData, nexus: Nexus) => Promise<void>;
118
- export type CommandHandler = (messageData: MessageData, nexus: Nexus) => Promise<void>;
119
- export type KeywordHandler = (messageData: MessageData, nexus: Nexus) => Promise<void>;
118
+ /** Resolve `false` to decline: the message then goes on to the assistant as a normal message. */
119
+ export type CommandHandler = (messageData: MessageData, nexus: Nexus) => Promise<void | boolean>;
120
+ /** Resolve `false` to decline: the message then goes on to the assistant as a normal message. */
121
+ export type KeywordHandler = (messageData: MessageData, nexus: Nexus) => Promise<void | boolean>;
120
122
  export type FlowHandler = (messageData: MessageData, nexus: Nexus) => Promise<void>;
121
123
 
122
124
  export interface MessageHandlers {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "6.4.0-dev.19030",
3
+ "version": "6.4.1",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",