@diegoaltoworks/chatter 0.41.0 → 0.43.0

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/README.md CHANGED
@@ -76,6 +76,7 @@ Complete guides for setup, deployment, and integration:
76
76
  - **[Deployment](./docs/deployment.md)** - Google Cloud Run, Fly.io, Railway, VPS
77
77
  - **[Testing](./docs/testing.md)** - Comprehensive testing guide
78
78
  - **[Code Quality](./docs/CODE_QUALITY.md)** - Security assessment and architecture review
79
+ - **[Sprint Review](./docs/sprint-review.md)** - Cross-module & security-invariant audit
79
80
  - **[FAQs](./docs/faqs.md)** - Troubleshooting and common questions
80
81
 
81
82
  ## Demo
@@ -82,6 +82,29 @@ export interface WaMessageContext {
82
82
  export declare function messageContext(message: WAMessage): WaMessageContext;
83
83
  /** Text/caption across every shape that can carry one — plain text, a reply, or a photo/video/document caption. */
84
84
  export declare function extractText(message: WAMessage): string;
85
+ /**
86
+ * Removes the bot's OWN @mention tokens from a message's text.
87
+ *
88
+ * WhatsApp puts a mention in the raw text as the literal token `@<digits>` —
89
+ * the mentioned jid's user part — and only resolves it to a jid separately,
90
+ * on `contextInfo.mentionedJid`. Handed to a model untouched, the bot's own
91
+ * mention reads as a meaningless number, and the answer derails into asking
92
+ * the sender what `@<botDigits>` means instead of doing what the rest of the
93
+ * message asked.
94
+ *
95
+ * Only the bot's own tokens go: another participant's mention is real
96
+ * context ("tell @<someoneElse> I'm late"), and the numeral is all the model
97
+ * gets of them. Matching is on the digits alone, so both the phone-number and
98
+ * the LID form of the bot's own identity are covered.
99
+ *
100
+ * Everything else in the message is left byte-for-byte alone — indentation
101
+ * and blank lines in a pasted snippet included.
102
+ *
103
+ * A mention-only message ("@bot" and nothing else) keeps its original text:
104
+ * emptying it would make the reply gates read it as blank and drop it, so the
105
+ * bot would go silent on being addressed rather than answer.
106
+ */
107
+ export declare function stripOwnMentions(text: string, ownIds: string[]): string;
85
108
  export interface WhatsAppInboundConfig {
86
109
  client: OpenAI;
87
110
  store: VectorStore;
@@ -1 +1 @@
1
- {"version":3,"file":"inbound.d.ts","sourceRoot":"","sources":["../../../src/channels/whatsapp/inbound.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,KAAK,QAAQ,EAAc,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,KAAK,UAAU,EAAkB,MAAM,oBAAoB,CAAC;AAErE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAKL,KAAK,uBAAuB,EAE7B,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAIrD,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE/C;AAED,kGAAkG;AAClG,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,EAAE,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAI/E;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAGpD;AAeD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,cAAc,CAClC,IAAI,EAAE,QAAQ,EACd,OAAO,EAAE,SAAS,EAClB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,CAAC,CA+BjB;AAID,MAAM,WAAW,gBAAgB;IAC/B,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;;;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AC,MAAM,GAAG,SAAS,CAAC,CAAC;IACvD;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,oBAAoB,CAAC;IAC9B,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAqBD,4JAA4J;AAC5J,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,qBAAqB,GAC5B,CAAC,KAAK,EAAE,oBAAoB,KAAK,OAAO,CAAC,IAAI,CAAC,CAgIhD"}
@@ -30,6 +30,6 @@ export { loadBaileys } from "./baileys";
30
30
  export { acquireSessionLease, createWhatsAppChannel, type LeaseGatedConnectDeps, reconnectDelayMs, senderNameFor, shutdownWaSessions, type WaSessionHandle, type WhatsAppChannelConfig, type WhatsAppMessageEvent, } from "./channel";
31
31
  export { decrypt, encrypt } from "./crypto";
32
32
  export { createWhatsAppImageHandler, type DrawRequestDetectorConfig, drawSubject, isDrawRequest, type WhatsAppImageHandler, type WhatsAppImageHandlerDeps, type WhatsAppImageRequestContext, type WhatsAppImageStrings, } from "./images";
33
- export { createWhatsAppInboundHandler, extractText, isGroupJid, jidsMatch, jidToPhoneNumber, messageContext, senderPhoneFor, type WaMessageContext, type WhatsAppInboundConfig, } from "./inbound";
33
+ export { createWhatsAppInboundHandler, extractText, isGroupJid, jidsMatch, jidToPhoneNumber, messageContext, senderPhoneFor, stripOwnMentions, type WaMessageContext, type WhatsAppInboundConfig, } from "./inbound";
34
34
  export { canAcquireLease, createTursoWaLeaseStore, LEASE_HEARTBEAT_MS, LEASE_STALE_MS, LEASE_WAIT_MS, type WaLeaseRow, type WaLeaseStore, } from "./lease";
35
35
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/channels/whatsapp/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,YAAY,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,YAAY,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,KAAK,qBAAqB,EAC1B,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,GAC1B,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EACL,0BAA0B,EAC1B,KAAK,yBAAyB,EAC9B,WAAW,EACX,aAAa,EACb,KAAK,oBAAoB,EACzB,KAAK,wBAAwB,EAC7B,KAAK,2BAA2B,EAChC,KAAK,oBAAoB,GAC1B,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,4BAA4B,EAC5B,WAAW,EACX,UAAU,EACV,SAAS,EACT,gBAAgB,EAChB,cAAc,EACd,cAAc,EACd,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,GAC3B,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,kBAAkB,EAClB,cAAc,EACd,aAAa,EACb,KAAK,UAAU,EACf,KAAK,YAAY,GAClB,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/channels/whatsapp/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,YAAY,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,YAAY,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,KAAK,qBAAqB,EAC1B,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,GAC1B,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EACL,0BAA0B,EAC1B,KAAK,yBAAyB,EAC9B,WAAW,EACX,aAAa,EACb,KAAK,oBAAoB,EACzB,KAAK,wBAAwB,EAC7B,KAAK,2BAA2B,EAChC,KAAK,oBAAoB,GAC1B,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,4BAA4B,EAC5B,WAAW,EACX,UAAU,EACV,SAAS,EACT,gBAAgB,EAChB,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,GAC3B,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,kBAAkB,EAClB,cAAc,EACd,aAAa,EACb,KAAK,UAAU,EACf,KAAK,YAAY,GAClB,MAAM,SAAS,CAAC"}
@@ -53,6 +53,7 @@ __export(index_exports, {
53
53
  senderNameFor: () => senderNameFor,
54
54
  senderPhoneFor: () => senderPhoneFor,
55
55
  shutdownWaSessions: () => shutdownWaSessions,
56
+ stripOwnMentions: () => stripOwnMentions,
56
57
  useTursoAuthState: () => useTursoAuthState
57
58
  });
58
59
  module.exports = __toCommonJS(index_exports);
@@ -717,19 +718,21 @@ function isEffectivelyFromSelf(msg, registry) {
717
718
  function isGroupJid(jid) {
718
719
  return jid.endsWith("@g.us");
719
720
  }
721
+ function bareUser(jid) {
722
+ return jid.split("@")[0]?.split(":")[0] ?? "";
723
+ }
720
724
  function jidsMatch(a, b) {
721
725
  if (!a || !b) return false;
722
- const bare = (jid) => jid.split("@")[0]?.split(":")[0] ?? jid;
723
- return bare(a) === bare(b);
726
+ return bareUser(a) === bareUser(b);
724
727
  }
725
728
  function jidToPhoneNumber(jid) {
726
- const bare = jid.split("@")[0]?.split(":")[0] ?? "";
729
+ const bare = bareUser(jid);
727
730
  return bare.startsWith("+") ? bare : `+${bare}`;
728
731
  }
729
732
  function normalizeJid(jid) {
730
733
  const [user = "", domain] = jid.split("@");
731
- const bareUser = user.split(":")[0] ?? user;
732
- return domain ? `${bareUser}@${domain}` : bareUser;
734
+ const withoutDevice = user.split(":")[0] ?? user;
735
+ return domain ? `${withoutDevice}@${domain}` : withoutDevice;
733
736
  }
734
737
  async function senderPhoneFor(sock, message, chatJid) {
735
738
  const key = message.key;
@@ -758,6 +761,19 @@ function extractText(message) {
758
761
  if (!content) return "";
759
762
  return content.conversation ?? content.extendedTextMessage?.text ?? content.imageMessage?.caption ?? content.videoMessage?.caption ?? content.documentMessage?.caption ?? "";
760
763
  }
764
+ function stripOwnMentions(text, ownIds) {
765
+ const ownUsers = new Set(ownIds.map(bareUser).filter(Boolean));
766
+ if (!text || ownUsers.size === 0) return text;
767
+ let struck = false;
768
+ const stripped = text.replace(/(?<!\S)@(\d+)[^\S\n]*/g, (token, digits) => {
769
+ if (!ownUsers.has(digits)) return token;
770
+ struck = true;
771
+ return "";
772
+ });
773
+ if (!struck) return text;
774
+ const cleaned = stripped.trim();
775
+ return cleaned ? cleaned : text;
776
+ }
761
777
  var DEFAULT_GROUP_RATE_LIMIT = { max: 30, windowMs: 60 * 60 * 1e3 };
762
778
  var DEFAULT_DM_RATE_LIMIT = { max: 20, windowMs: 60 * 60 * 1e3 };
763
779
  async function resolvePersonaLayer(config, ctx) {
@@ -780,11 +796,12 @@ function createWhatsAppInboundHandler(config) {
780
796
  try {
781
797
  const chatId = message.key.remoteJid ?? "";
782
798
  if (!chatId || chatId === "status@broadcast") return;
783
- const text = extractText(message);
799
+ const rawText = extractText(message);
784
800
  const context = messageContext(message);
785
801
  const senderId = message.key.participant ?? chatId;
786
802
  const ownIds = [sock.user?.id, sock.user?.lid].filter((id) => Boolean(id)).map(normalizeJid);
787
803
  config.registry.set(sessionId, ownIds);
804
+ const text = stripOwnMentions(rawText, ownIds);
788
805
  const fromBot = isEffectivelyFromSelf(
789
806
  { fromBot: message.key.fromMe ?? false, senderId: normalizeJid(senderId) },
790
807
  config.registry
@@ -888,5 +905,6 @@ function createWhatsAppInboundHandler(config) {
888
905
  senderNameFor,
889
906
  senderPhoneFor,
890
907
  shutdownWaSessions,
908
+ stripOwnMentions,
891
909
  useTursoAuthState
892
910
  });
@@ -658,19 +658,21 @@ function isEffectivelyFromSelf(msg, registry) {
658
658
  function isGroupJid(jid) {
659
659
  return jid.endsWith("@g.us");
660
660
  }
661
+ function bareUser(jid) {
662
+ return jid.split("@")[0]?.split(":")[0] ?? "";
663
+ }
661
664
  function jidsMatch(a, b) {
662
665
  if (!a || !b) return false;
663
- const bare = (jid) => jid.split("@")[0]?.split(":")[0] ?? jid;
664
- return bare(a) === bare(b);
666
+ return bareUser(a) === bareUser(b);
665
667
  }
666
668
  function jidToPhoneNumber(jid) {
667
- const bare = jid.split("@")[0]?.split(":")[0] ?? "";
669
+ const bare = bareUser(jid);
668
670
  return bare.startsWith("+") ? bare : `+${bare}`;
669
671
  }
670
672
  function normalizeJid(jid) {
671
673
  const [user = "", domain] = jid.split("@");
672
- const bareUser = user.split(":")[0] ?? user;
673
- return domain ? `${bareUser}@${domain}` : bareUser;
674
+ const withoutDevice = user.split(":")[0] ?? user;
675
+ return domain ? `${withoutDevice}@${domain}` : withoutDevice;
674
676
  }
675
677
  async function senderPhoneFor(sock, message, chatJid) {
676
678
  const key = message.key;
@@ -699,6 +701,19 @@ function extractText(message) {
699
701
  if (!content) return "";
700
702
  return content.conversation ?? content.extendedTextMessage?.text ?? content.imageMessage?.caption ?? content.videoMessage?.caption ?? content.documentMessage?.caption ?? "";
701
703
  }
704
+ function stripOwnMentions(text, ownIds) {
705
+ const ownUsers = new Set(ownIds.map(bareUser).filter(Boolean));
706
+ if (!text || ownUsers.size === 0) return text;
707
+ let struck = false;
708
+ const stripped = text.replace(/(?<!\S)@(\d+)[^\S\n]*/g, (token, digits) => {
709
+ if (!ownUsers.has(digits)) return token;
710
+ struck = true;
711
+ return "";
712
+ });
713
+ if (!struck) return text;
714
+ const cleaned = stripped.trim();
715
+ return cleaned ? cleaned : text;
716
+ }
702
717
  var DEFAULT_GROUP_RATE_LIMIT = { max: 30, windowMs: 60 * 60 * 1e3 };
703
718
  var DEFAULT_DM_RATE_LIMIT = { max: 20, windowMs: 60 * 60 * 1e3 };
704
719
  async function resolvePersonaLayer(config, ctx) {
@@ -721,11 +736,12 @@ function createWhatsAppInboundHandler(config) {
721
736
  try {
722
737
  const chatId = message.key.remoteJid ?? "";
723
738
  if (!chatId || chatId === "status@broadcast") return;
724
- const text = extractText(message);
739
+ const rawText = extractText(message);
725
740
  const context = messageContext(message);
726
741
  const senderId = message.key.participant ?? chatId;
727
742
  const ownIds = [sock.user?.id, sock.user?.lid].filter((id) => Boolean(id)).map(normalizeJid);
728
743
  config.registry.set(sessionId, ownIds);
744
+ const text = stripOwnMentions(rawText, ownIds);
729
745
  const fromBot = isEffectivelyFromSelf(
730
746
  { fromBot: message.key.fromMe ?? false, senderId: normalizeJid(senderId) },
731
747
  config.registry
@@ -828,5 +844,6 @@ export {
828
844
  senderNameFor,
829
845
  senderPhoneFor,
830
846
  shutdownWaSessions,
847
+ stripOwnMentions,
831
848
  useTursoAuthState
832
849
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diegoaltoworks/chatter",
3
- "version": "0.41.0",
3
+ "version": "0.43.0",
4
4
  "description": "Embeddable AI chatbot framework with RAG, authentication, and customizable widgets",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",