@peopl-health/nexus 3.9.0 → 3.9.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.
@@ -3,6 +3,7 @@ class MessageProvider {
3
3
  this.config = config;
4
4
  this.isConnected = false;
5
5
  this.messageStorage = null;
6
+ this.adapter = null;
6
7
  }
7
8
 
8
9
  /**
@@ -21,6 +22,13 @@ class MessageProvider {
21
22
  throw new Error('connect() must be implemented by provider');
22
23
  }
23
24
 
25
+ async normalize(rawMessage) {
26
+ if (!this.adapter) {
27
+ throw new Error('[MessageProvider] Adapter not initialized');
28
+ }
29
+ return this.adapter.normalize(rawMessage);
30
+ }
31
+
24
32
  /**
25
33
  * Send a message
26
34
  * @param {Object} messageData - Message data
@@ -16,6 +16,7 @@ const { ensureWhatsAppFormat } = require('../helpers/twilioHelper');
16
16
  const { uploadMediaToS3, getFileExtension } = require('../helpers/mediaHelper');
17
17
 
18
18
  const { MessageProvider } = require('../adapters/MessageProvider');
19
+ const { TwilioMessageAdapter } = require('./messageAdapters/TwilioMessageAdapter');
19
20
 
20
21
  class TwilioProvider extends MessageProvider {
21
22
  constructor(config) {
@@ -25,6 +26,7 @@ class TwilioProvider extends MessageProvider {
25
26
  this.authToken = config.authToken;
26
27
  this.whatsappNumber = config.whatsappNumber;
27
28
  this.statusCallbackUrl = config.statusCallbackUrl || null;
29
+ this.adapter = new TwilioMessageAdapter();
28
30
  }
29
31
 
30
32
  async initialize() {
@@ -8,7 +8,9 @@ class TwilioMessageAdapter extends MessageAdapter {
8
8
  async normalize(rawMessage) {
9
9
  const from = rawMessage.From || '';
10
10
  const interactive = this._extractInteractive(rawMessage);
11
- const body = rawMessage.Body || this._extractInteractionText(interactive) || null;
11
+ const media = await this._resolveMedia(rawMessage);
12
+ const hasMedia = parseInt(rawMessage.NumMedia || '0', 10) > 0;
13
+ const body = rawMessage.Body || this._extractInteractionText(interactive) || (hasMedia ? `[Media:${media?.mediaType || 'attachment'}]` : '');
12
14
 
13
15
  return {
14
16
  messageId: rawMessage.MessageSid || null,
@@ -20,7 +22,7 @@ class TwilioMessageAdapter extends MessageAdapter {
20
22
  pushName: rawMessage.ProfileName || null,
21
23
  timestamp: Date.now(),
22
24
  body,
23
- media: await this._resolveMedia(rawMessage),
25
+ media,
24
26
  interactive,
25
27
  quotedMessageId: rawMessage.OriginalRepliedMessageSid || null,
26
28
  raw: rawMessage
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "3.9.0",
3
+ "version": "3.9.2",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",