miaw-core 1.2.3 → 1.2.5
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/dist/cli/commands/group.js +1 -1
- package/dist/cli/commands/group.js.map +1 -1
- package/dist/cli/commands/index.js +10 -4
- package/dist/cli/commands/index.js.map +1 -1
- package/dist/cli/utils/session.d.ts +1 -1
- package/dist/cli/utils/session.d.ts.map +1 -1
- package/dist/cli/utils/session.js +4 -2
- package/dist/cli/utils/session.js.map +1 -1
- package/dist/client/MiawClient.d.ts.map +1 -1
- package/dist/client/MiawClient.js +95 -57
- package/dist/client/MiawClient.js.map +1 -1
- package/dist/handlers/MessageHandler.d.ts +6 -0
- package/dist/handlers/MessageHandler.d.ts.map +1 -1
- package/dist/handlers/MessageHandler.js +13 -0
- package/dist/handlers/MessageHandler.js.map +1 -1
- package/docs/CLI_INTEGRATION_TEST_PLAN.md +265 -0
- package/package.json +2 -1
- package/sessions-cli/.cli_history +72 -0
- package/sessions-cli/default/app-state-sync-version-regular.json +1 -1
- package/sessions-cli/default/app-state-sync-version-regular_high.json +1 -1
- package/sessions-cli/default/app-state-sync-version-regular_low.json +1 -1
- package/sessions-cli/default/chats.json +39 -6
- package/sessions-cli/default/contacts.json +88 -0
- package/sessions-cli/default/creds.json +1 -1
- package/sessions-cli/default/lid-mapping-144530112270579_reverse.json +1 -0
- package/sessions-cli/default/lid-mapping-177919053803568_reverse.json +1 -0
- package/sessions-cli/default/lid-mapping-197070984101964_reverse.json +1 -0
- package/sessions-cli/default/lid-mapping-198303270604941_reverse.json +1 -0
- package/sessions-cli/default/lid-mapping-2061584318613_reverse.json +1 -0
- package/sessions-cli/default/lid-mapping-270819297075205_reverse.json +1 -0
- package/sessions-cli/default/lid-mapping-6281227800347.json +1 -0
- package/sessions-cli/default/lid-mapping-6282130035583.json +1 -0
- package/sessions-cli/default/lid-mapping-6285338155153.json +1 -0
- package/sessions-cli/default/lid-mapping-628551000185.json +1 -0
- package/sessions-cli/default/lid-mapping-6285792059652.json +1 -0
- package/sessions-cli/default/lid-mapping-6288991818160.json +1 -0
- package/sessions-cli/default/sender-key-120363039902323086@g.us--270819297075205_1--23.json +1 -0
- package/sessions-cli/default/sender-key-120363039902323086@g.us--42877077966917_1--0.json +1 -0
- package/sessions-cli/default/sender-key-120363039902323086@g.us--42877077966917_1--73.json +1 -0
- package/sessions-cli/default/session-106657023574039_1.0.json +1 -0
- package/sessions-cli/default/session-139964746592398_1.0.json +1 -0
- package/sessions-cli/default/session-142481379311646_1.0.json +1 -0
- package/sessions-cli/default/session-143199091859590_1.0.json +1 -0
- package/sessions-cli/default/session-171911065661513_1.0.json +1 -0
- package/sessions-cli/default/session-192259949609102_1.0.json +1 -0
- package/sessions-cli/default/session-197070984101964_1.0.json +1 -0
- package/sessions-cli/default/session-198303270604941_1.0.json +1 -0
- package/sessions-cli/default/session-199527202033812_1.0.json +1 -0
- package/sessions-cli/default/session-199866387066970_1.0.json +1 -0
- package/sessions-cli/default/session-2061584318613_1.0.json +1 -0
- package/sessions-cli/default/session-21844270784649_1.0.json +1 -0
- package/sessions-cli/default/session-221706329321492_1.0.json +1 -0
- package/sessions-cli/default/session-223733570633772_1.0.json +1 -0
- package/sessions-cli/default/session-248180524482638_1.0.json +1 -0
- package/sessions-cli/default/session-263728574541943_1.0.json +1 -1
- package/sessions-cli/default/session-264230716612829_1.0.json +1 -0
- package/sessions-cli/default/session-270819297075205_1.0.json +1 -0
- package/sessions-cli/default/session-270819297075205_1.23.json +1 -0
- package/sessions-cli/default/session-42877077966917_1.0.json +1 -1
- package/sessions-cli/default/session-42877077966917_1.73.json +1 -0
- package/sessions-cli/default/session-42877077966917_1.74.json +1 -0
- package/sessions-cli/default/session-61800770973904_1.0.json +1 -0
- package/sessions-cli/default/session-70484775448831_1.0.json +1 -0
- package/sessions-cli/default/session-72816909103207_1.0.json +1 -0
- package/sessions-cli/default/session-73057444090080_1.0.json +1 -0
- package/sessions-cli/default/tctoken-197070984101964@lid.json +1 -0
- package/sessions-cli/default/tctoken-198303270604941@lid.json +1 -0
- package/sessions-cli/default/tctoken-2061584318613@lid.json +1 -0
- package/sessions-cli/default/tctoken-6285338155153@s.whatsapp.net.json +1 -0
- package/sessions-cli/default/pre-key-16.json +0 -1
- package/sessions-cli/default/pre-key-18.json +0 -1
- package/sessions-cli/default/pre-key-32.json +0 -1
- package/sessions-cli/default/pre-key-46.json +0 -1
- package/sessions-cli/default/pre-key-59.json +0 -1
- package/sessions-cli/default/pre-key-79.json +0 -1
- package/sessions-cli/default/pre-key-80.json +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import makeWASocket, { DisconnectReason, fetchLatestBaileysVersion, makeCacheableSignalKeyStore, Browsers, downloadMediaMessage, } from "@whiskeysockets/baileys";
|
|
1
|
+
import makeWASocket, { DisconnectReason, fetchLatestBaileysVersion, makeCacheableSignalKeyStore, Browsers, downloadMediaMessage, jidNormalizedUser, } from "@whiskeysockets/baileys";
|
|
2
2
|
import { EventEmitter } from "node:events";
|
|
3
3
|
import { createFilteredLogger } from "../utils/filtered-logger.js";
|
|
4
4
|
import { enableConsoleFilter, disableConsoleFilter, } from "../utils/console-filter.js";
|
|
@@ -375,6 +375,13 @@ export class MiawClient extends EventEmitter {
|
|
|
375
375
|
}
|
|
376
376
|
const normalized = MessageHandler.normalize({ messages: [msg], type: "notify" }, this.logger);
|
|
377
377
|
if (normalized) {
|
|
378
|
+
// Resolve @lid JIDs to @s.whatsapp.net for consistent display
|
|
379
|
+
if (normalized.from) {
|
|
380
|
+
normalized.from = this.resolveLidToJid(normalized.from);
|
|
381
|
+
}
|
|
382
|
+
if (normalized.participant) {
|
|
383
|
+
normalized.participant = this.resolveLidToJid(normalized.participant);
|
|
384
|
+
}
|
|
378
385
|
// Resolve senderPhone from LID if not available (WhatsApp privacy feature)
|
|
379
386
|
if (!normalized.senderPhone) {
|
|
380
387
|
if (normalized.isGroup && normalized.participant) {
|
|
@@ -632,10 +639,7 @@ export class MiawClient extends EventEmitter {
|
|
|
632
639
|
*/
|
|
633
640
|
getPhoneFromJid(jid) {
|
|
634
641
|
const resolved = this.resolveLidToJid(jid);
|
|
635
|
-
|
|
636
|
-
return resolved.replace("@s.whatsapp.net", "");
|
|
637
|
-
}
|
|
638
|
-
return undefined;
|
|
642
|
+
return MessageHandler.formatJidToPhone(resolved);
|
|
639
643
|
}
|
|
640
644
|
/**
|
|
641
645
|
* Manually register a LID to phone number mapping
|
|
@@ -701,16 +705,19 @@ export class MiawClient extends EventEmitter {
|
|
|
701
705
|
}
|
|
702
706
|
if (!jid)
|
|
703
707
|
continue;
|
|
704
|
-
// Extract phone number from JID
|
|
705
|
-
const phone =
|
|
706
|
-
? jid.replace("@s.whatsapp.net", "")
|
|
707
|
-
: undefined;
|
|
708
|
+
// Extract phone number from JID (strips device suffix like :72)
|
|
709
|
+
const phone = MessageHandler.formatJidToPhone(jid);
|
|
708
710
|
// Build contact info
|
|
709
711
|
const contactInfo = {
|
|
710
712
|
jid,
|
|
711
713
|
phone,
|
|
712
714
|
name: contact.name || contact.notify || contact.verifiedName || undefined,
|
|
713
715
|
};
|
|
716
|
+
// Preserve existing name if new entry lacks one
|
|
717
|
+
const existing = this.contactsStore.get(jid);
|
|
718
|
+
if (existing?.name && !contactInfo.name) {
|
|
719
|
+
contactInfo.name = existing.name;
|
|
720
|
+
}
|
|
714
721
|
// Update store with phone JID as primary key
|
|
715
722
|
this.contactsStore.set(jid, contactInfo);
|
|
716
723
|
// Also store by LID for lookup if available
|
|
@@ -751,10 +758,8 @@ export class MiawClient extends EventEmitter {
|
|
|
751
758
|
this.addLidMapping(jid, chat.pnJid, "Chat");
|
|
752
759
|
jid = chat.pnJid;
|
|
753
760
|
}
|
|
754
|
-
// Extract phone number from JID
|
|
755
|
-
const phone =
|
|
756
|
-
? jid.replace("@s.whatsapp.net", "")
|
|
757
|
-
: undefined;
|
|
761
|
+
// Extract phone number from JID (strips device suffix like :72)
|
|
762
|
+
const phone = MessageHandler.formatJidToPhone(jid);
|
|
758
763
|
// Build chat info with proper field mapping for proto.IConversation
|
|
759
764
|
const chatInfo = {
|
|
760
765
|
jid,
|
|
@@ -789,6 +794,13 @@ export class MiawClient extends EventEmitter {
|
|
|
789
794
|
const normalized = MessageHandler.normalize({ messages: [msg], type: "notify" }, this.logger);
|
|
790
795
|
if (!normalized)
|
|
791
796
|
return;
|
|
797
|
+
// Resolve @lid JIDs to @s.whatsapp.net for consistent storage
|
|
798
|
+
if (normalized.from) {
|
|
799
|
+
normalized.from = this.resolveLidToJid(normalized.from);
|
|
800
|
+
}
|
|
801
|
+
if (normalized.participant) {
|
|
802
|
+
normalized.participant = this.resolveLidToJid(normalized.participant);
|
|
803
|
+
}
|
|
792
804
|
const chatJid = normalized.from;
|
|
793
805
|
if (!this.messagesStore.has(chatJid)) {
|
|
794
806
|
this.messagesStore.set(chatJid, []);
|
|
@@ -1244,11 +1256,12 @@ export class MiawClient extends EventEmitter {
|
|
|
1244
1256
|
if (this.connectionState !== "connected") {
|
|
1245
1257
|
throw new Error(`Cannot get contact info. Connection state: ${this.connectionState}`);
|
|
1246
1258
|
}
|
|
1247
|
-
const
|
|
1259
|
+
const rawJid = MessageHandler.formatPhoneToJid(jidOrPhone);
|
|
1260
|
+
const jid = this.resolveLidToJid(rawJid);
|
|
1248
1261
|
// Fetch status
|
|
1249
1262
|
let status;
|
|
1250
1263
|
try {
|
|
1251
|
-
const statusResult = await this.socket.fetchStatus(
|
|
1264
|
+
const statusResult = await this.socket.fetchStatus(rawJid);
|
|
1252
1265
|
// fetchStatus returns an array, get first result
|
|
1253
1266
|
const firstResult = Array.isArray(statusResult)
|
|
1254
1267
|
? statusResult[0]
|
|
@@ -1261,16 +1274,14 @@ export class MiawClient extends EventEmitter {
|
|
|
1261
1274
|
// Check if business account
|
|
1262
1275
|
let isBusiness = false;
|
|
1263
1276
|
try {
|
|
1264
|
-
const businessProfile = await this.socket.getBusinessProfile(
|
|
1277
|
+
const businessProfile = await this.socket.getBusinessProfile(rawJid);
|
|
1265
1278
|
isBusiness = !!businessProfile;
|
|
1266
1279
|
}
|
|
1267
1280
|
catch {
|
|
1268
1281
|
// Not a business account or not available
|
|
1269
1282
|
}
|
|
1270
|
-
// Extract phone from JID
|
|
1271
|
-
const phone =
|
|
1272
|
-
? jid.replace("@s.whatsapp.net", "")
|
|
1273
|
-
: undefined;
|
|
1283
|
+
// Extract phone from resolved JID (strips device suffix like :72)
|
|
1284
|
+
const phone = MessageHandler.formatJidToPhone(jid);
|
|
1274
1285
|
return {
|
|
1275
1286
|
jid,
|
|
1276
1287
|
phone,
|
|
@@ -1349,7 +1360,7 @@ export class MiawClient extends EventEmitter {
|
|
|
1349
1360
|
// Not a business account or not available
|
|
1350
1361
|
}
|
|
1351
1362
|
return {
|
|
1352
|
-
jid,
|
|
1363
|
+
jid: resolvedJid,
|
|
1353
1364
|
phone,
|
|
1354
1365
|
name,
|
|
1355
1366
|
status,
|
|
@@ -1430,24 +1441,34 @@ export class MiawClient extends EventEmitter {
|
|
|
1430
1441
|
*/
|
|
1431
1442
|
async fetchAllContacts() {
|
|
1432
1443
|
try {
|
|
1433
|
-
//
|
|
1434
|
-
const
|
|
1435
|
-
|
|
1444
|
+
// Deduplicate contacts by resolved JID, merging data (prefer entries with names)
|
|
1445
|
+
const uniqueContacts = new Map();
|
|
1446
|
+
for (const contact of this.contactsStore.values()) {
|
|
1447
|
+
// Resolve @lid JIDs using LID cache
|
|
1448
|
+
let resolved = contact;
|
|
1436
1449
|
if (contact.jid.endsWith("@lid") && !contact.phone) {
|
|
1437
|
-
const
|
|
1438
|
-
if (
|
|
1439
|
-
|
|
1450
|
+
const resolvedJid = this.resolveLidToJid(contact.jid);
|
|
1451
|
+
if (resolvedJid !== contact.jid && resolvedJid.endsWith("@s.whatsapp.net")) {
|
|
1452
|
+
resolved = {
|
|
1440
1453
|
...contact,
|
|
1441
|
-
jid:
|
|
1442
|
-
phone:
|
|
1454
|
+
jid: resolvedJid,
|
|
1455
|
+
phone: MessageHandler.formatJidToPhone(resolvedJid),
|
|
1443
1456
|
};
|
|
1444
1457
|
}
|
|
1445
1458
|
}
|
|
1446
|
-
|
|
1447
|
-
|
|
1459
|
+
const key = resolved.jid;
|
|
1460
|
+
const existing = uniqueContacts.get(key);
|
|
1461
|
+
if (!existing) {
|
|
1462
|
+
uniqueContacts.set(key, resolved);
|
|
1463
|
+
}
|
|
1464
|
+
else if (!existing.name && resolved.name) {
|
|
1465
|
+
// Merge: prefer the entry that has a name
|
|
1466
|
+
uniqueContacts.set(key, resolved);
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1448
1469
|
return {
|
|
1449
1470
|
success: true,
|
|
1450
|
-
contacts,
|
|
1471
|
+
contacts: Array.from(uniqueContacts.values()),
|
|
1451
1472
|
};
|
|
1452
1473
|
}
|
|
1453
1474
|
catch (error) {
|
|
@@ -1475,11 +1496,11 @@ export class MiawClient extends EventEmitter {
|
|
|
1475
1496
|
jid: g.id,
|
|
1476
1497
|
name: g.subject,
|
|
1477
1498
|
description: g.desc || undefined,
|
|
1478
|
-
owner: g.owner
|
|
1499
|
+
owner: g.owner ? this.resolveLidToJid(g.owner) : undefined,
|
|
1479
1500
|
createdAt: g.creation,
|
|
1480
1501
|
participantCount: g.participants?.length || 0,
|
|
1481
1502
|
participants: g.participants?.map((p) => ({
|
|
1482
|
-
jid: p.id,
|
|
1503
|
+
jid: this.resolveLidToJid(p.id),
|
|
1483
1504
|
role: p.admin === "superadmin"
|
|
1484
1505
|
? "superadmin"
|
|
1485
1506
|
: p.admin === "admin"
|
|
@@ -1514,14 +1535,14 @@ export class MiawClient extends EventEmitter {
|
|
|
1514
1535
|
if (this.connectionState !== "connected") {
|
|
1515
1536
|
throw new Error(`Cannot get own profile. Connection state: ${this.connectionState}`);
|
|
1516
1537
|
}
|
|
1517
|
-
const
|
|
1518
|
-
if (!
|
|
1538
|
+
const rawJid = this.socket.user?.id;
|
|
1539
|
+
if (!rawJid) {
|
|
1519
1540
|
throw new Error("User ID not available");
|
|
1520
1541
|
}
|
|
1521
|
-
//
|
|
1522
|
-
const
|
|
1523
|
-
|
|
1524
|
-
|
|
1542
|
+
// Normalize JID (strips device suffix like :72)
|
|
1543
|
+
const jid = jidNormalizedUser(rawJid);
|
|
1544
|
+
// Extract phone number from normalized JID
|
|
1545
|
+
const phone = MessageHandler.formatJidToPhone(jid);
|
|
1525
1546
|
// Get display name from socket user
|
|
1526
1547
|
const name = this.socket.user?.name;
|
|
1527
1548
|
// Fetch status
|
|
@@ -1661,7 +1682,7 @@ export class MiawClient extends EventEmitter {
|
|
|
1661
1682
|
// Chat not in store, create minimal info
|
|
1662
1683
|
chats.push({
|
|
1663
1684
|
jid,
|
|
1664
|
-
phone:
|
|
1685
|
+
phone: MessageHandler.formatJidToPhone(jid),
|
|
1665
1686
|
isGroup: jid.endsWith("@g.us"),
|
|
1666
1687
|
});
|
|
1667
1688
|
}
|
|
@@ -1768,7 +1789,14 @@ export class MiawClient extends EventEmitter {
|
|
|
1768
1789
|
// Deduplicate by jid (Map may have same contact under multiple keys)
|
|
1769
1790
|
const uniqueContacts = new Map();
|
|
1770
1791
|
for (const contact of this.contactsStore.values()) {
|
|
1771
|
-
if (
|
|
1792
|
+
if (!contact.jid)
|
|
1793
|
+
continue;
|
|
1794
|
+
const existing = uniqueContacts.get(contact.jid);
|
|
1795
|
+
if (!existing) {
|
|
1796
|
+
uniqueContacts.set(contact.jid, contact);
|
|
1797
|
+
}
|
|
1798
|
+
else if (!existing.name && contact.name) {
|
|
1799
|
+
// Prefer entries with names
|
|
1772
1800
|
uniqueContacts.set(contact.jid, contact);
|
|
1773
1801
|
}
|
|
1774
1802
|
}
|
|
@@ -2104,24 +2132,34 @@ export class MiawClient extends EventEmitter {
|
|
|
2104
2132
|
*/
|
|
2105
2133
|
async fetchAllChats() {
|
|
2106
2134
|
try {
|
|
2107
|
-
//
|
|
2108
|
-
const
|
|
2109
|
-
|
|
2135
|
+
// Deduplicate chats by resolved JID, merging data (prefer entries with names)
|
|
2136
|
+
const uniqueChats = new Map();
|
|
2137
|
+
for (const chat of this.chatsStore.values()) {
|
|
2138
|
+
// Resolve @lid JIDs using LID cache
|
|
2139
|
+
let resolved = chat;
|
|
2110
2140
|
if (chat.jid.endsWith("@lid") && !chat.phone) {
|
|
2111
|
-
const
|
|
2112
|
-
if (
|
|
2113
|
-
|
|
2141
|
+
const resolvedJid = this.resolveLidToJid(chat.jid);
|
|
2142
|
+
if (resolvedJid !== chat.jid && resolvedJid.endsWith("@s.whatsapp.net")) {
|
|
2143
|
+
resolved = {
|
|
2114
2144
|
...chat,
|
|
2115
|
-
jid:
|
|
2116
|
-
phone:
|
|
2145
|
+
jid: resolvedJid,
|
|
2146
|
+
phone: MessageHandler.formatJidToPhone(resolvedJid),
|
|
2117
2147
|
};
|
|
2118
2148
|
}
|
|
2119
2149
|
}
|
|
2120
|
-
|
|
2121
|
-
|
|
2150
|
+
const key = resolved.jid;
|
|
2151
|
+
const existing = uniqueChats.get(key);
|
|
2152
|
+
if (!existing) {
|
|
2153
|
+
uniqueChats.set(key, resolved);
|
|
2154
|
+
}
|
|
2155
|
+
else if (!existing.name && resolved.name) {
|
|
2156
|
+
// Merge: prefer the entry that has a name
|
|
2157
|
+
uniqueChats.set(key, resolved);
|
|
2158
|
+
}
|
|
2159
|
+
}
|
|
2122
2160
|
return {
|
|
2123
2161
|
success: true,
|
|
2124
|
-
chats,
|
|
2162
|
+
chats: Array.from(uniqueChats.values()),
|
|
2125
2163
|
};
|
|
2126
2164
|
}
|
|
2127
2165
|
catch (error) {
|
|
@@ -2154,7 +2192,7 @@ export class MiawClient extends EventEmitter {
|
|
|
2154
2192
|
}
|
|
2155
2193
|
const metadata = await this.socket.groupMetadata(groupJid);
|
|
2156
2194
|
const participants = metadata.participants.map((p) => ({
|
|
2157
|
-
jid: p.id,
|
|
2195
|
+
jid: this.resolveLidToJid(p.id),
|
|
2158
2196
|
role: p.admin === "superadmin"
|
|
2159
2197
|
? "superadmin"
|
|
2160
2198
|
: p.admin === "admin"
|
|
@@ -2165,7 +2203,7 @@ export class MiawClient extends EventEmitter {
|
|
|
2165
2203
|
jid: metadata.id,
|
|
2166
2204
|
name: metadata.subject,
|
|
2167
2205
|
description: metadata.desc || undefined,
|
|
2168
|
-
owner: metadata.owner
|
|
2206
|
+
owner: metadata.owner ? this.resolveLidToJid(metadata.owner) : undefined,
|
|
2169
2207
|
createdAt: metadata.creation,
|
|
2170
2208
|
participantCount: metadata.participants.length,
|
|
2171
2209
|
participants,
|
|
@@ -2559,7 +2597,7 @@ export class MiawClient extends EventEmitter {
|
|
|
2559
2597
|
const formattedParticipants = participants.map((p) => MessageHandler.formatPhoneToJid(p));
|
|
2560
2598
|
const metadata = await this.socket.groupCreate(name, formattedParticipants);
|
|
2561
2599
|
const groupParticipants = metadata.participants.map((p) => ({
|
|
2562
|
-
jid: p.id,
|
|
2600
|
+
jid: this.resolveLidToJid(p.id),
|
|
2563
2601
|
role: p.admin === "superadmin"
|
|
2564
2602
|
? "superadmin"
|
|
2565
2603
|
: p.admin === "admin"
|
|
@@ -2573,7 +2611,7 @@ export class MiawClient extends EventEmitter {
|
|
|
2573
2611
|
jid: metadata.id,
|
|
2574
2612
|
name: metadata.subject,
|
|
2575
2613
|
description: metadata.desc || undefined,
|
|
2576
|
-
owner: metadata.owner
|
|
2614
|
+
owner: metadata.owner ? this.resolveLidToJid(metadata.owner) : undefined,
|
|
2577
2615
|
createdAt: metadata.creation,
|
|
2578
2616
|
participantCount: metadata.participants.length,
|
|
2579
2617
|
participants: groupParticipants,
|