@builderbot/provider-baileys 1.3.5-alpha.7 → 1.3.5-alpha.9
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/bailey.d.ts +15 -3
- package/dist/bailey.d.ts.map +1 -1
- package/dist/index.cjs +193 -67
- package/dist/index.mjs +193 -67
- package/dist/utils.d.ts +4 -2
- package/dist/utils.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/bailey.d.ts
CHANGED
|
@@ -48,7 +48,7 @@ declare class BaileysProvider extends ProviderClass<WASocket> {
|
|
|
48
48
|
protected getMessage: (key: {
|
|
49
49
|
remoteJid: string;
|
|
50
50
|
id: string;
|
|
51
|
-
}) => Promise<
|
|
51
|
+
}) => Promise<{}>;
|
|
52
52
|
protected saveCredsGlobal: (() => Promise<void>) | null;
|
|
53
53
|
/**
|
|
54
54
|
* Iniciar todo Bailey
|
|
@@ -200,11 +200,23 @@ declare class BaileysProvider extends ProviderClass<WASocket> {
|
|
|
200
200
|
}) => Promise<string>;
|
|
201
201
|
/**
|
|
202
202
|
* Extracts sender information from MessageKey using Baileys v7.0.0+ Alt fields
|
|
203
|
-
*
|
|
203
|
+
* FOLLOWS OFFICIAL GUIDANCE: Prefers LIDs over PNs as per Baileys documentation
|
|
204
|
+
* Reference: https://baileys.wiki/docs/migration/to-v7.0.0
|
|
204
205
|
* @param key MessageKey with potential remoteJidAlt/participantAlt fields
|
|
205
|
-
* @returns Object with identifier, type, and isLID flag
|
|
206
|
+
* @returns Object with identifier (preferring LID per official guidance), type, and isLID flag
|
|
206
207
|
*/
|
|
207
208
|
private extractSenderWithAltFields;
|
|
209
|
+
/**
|
|
210
|
+
* CRITICAL FIX for Baileys v7.0.0+ LID sync issues
|
|
211
|
+
* Resolves LID to PN for outgoing messages to ensure they appear in WhatsApp app
|
|
212
|
+
*
|
|
213
|
+
* Issue: Messages sent to LIDs from linked devices don't sync to main WhatsApp app
|
|
214
|
+
* Solution: Convert LIDs to PNs when sending messages (keep LIDs for receiving)
|
|
215
|
+
*
|
|
216
|
+
* @param identifier The identifier to resolve (LID or PN)
|
|
217
|
+
* @returns PN format for reliable message sending
|
|
218
|
+
*/
|
|
219
|
+
private resolveLIDToPNForSending;
|
|
208
220
|
private shouldReconnect;
|
|
209
221
|
private delayedReconnect;
|
|
210
222
|
/**
|
package/dist/bailey.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bailey.d.ts","sourceRoot":"","sources":["../src/bailey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAS,MAAM,iBAAiB,CAAA;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAIjF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,IAAI,CAAA;AAI9C,OAAO,SAAS,MAAM,YAAY,CAAA;AAIlC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAG3D,OAAO,EAGH,eAAe,EAEf,SAAS,EACT,QAAQ,EASR,KAAK,EAER,MAAM,iBAAiB,CAAA;AAExB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,QAAQ,CAAA;AAWpD,cAAM,eAAgB,SAAQ,aAAa,CAAC,QAAQ,CAAC;IAC1C,gBAAgB,EAAE,sBAAsB,CAgB9C;IAED,OAAO,CAAC,iBAAiB,CAAI;IAC7B,OAAO,CAAC,oBAAoB,CAAK;IACjC,OAAO,CAAC,cAAc,CAAO;IAE7B,oBAAoB,CAAC,EAAE,SAAS,CAAA;IAChC,gBAAgB,CAAC,EAAE,SAAS,CAAA;IAE5B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,SAAS,CAAuB;IAExC,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,MAAM,CAAY;gBAEd,IAAI,EAAE,OAAO,CAAC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AAC,gBAAgB,CAAmE;IAE3F;;;;;OAKG;IACH,QAAQ,GAAU,KAAK,OAAO,CAAC,SAAS,GAAG,UAAU,CAAC,EAAE,UAAU;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,KAAG,OAAO,CAAC,MAAM,CAAC,CAUnG;IAED;;;;;;OAMG;IACH,OAAO,CAAC,0BAA0B;IAkFlC;;;;;;;;;OASG;YACW,wBAAwB;IAgDtC,OAAO,CAAC,eAAe;YAmBT,gBAAgB;IA+B9B;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;IAsD1B;;;;OAIG;IACH,OAAO,CAAC,aAAa;IAarB;;;OAGG;IACI,kBAAkB,IAAI,GAAG;IAYhC;;;;OAIG;IACU,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAgBtE;;;;OAIG;IACU,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAgB9D;;;;;OAKG;IACU,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAgBrF;AAED,OAAO,EAAE,eAAe,EAAE,CAAA"}
|
package/dist/index.cjs
CHANGED
|
@@ -3826,25 +3826,38 @@ const emptyDirSessions = async (pathBase) => new Promise((resolve, reject) => {
|
|
|
3826
3826
|
/**
|
|
3827
3827
|
* Cleans and extracts the appropriate identifier from MessageKey, supporting LID system.
|
|
3828
3828
|
* Uses remoteJidAlt/participantAlt when available according to Baileys v7.0.0+ specs.
|
|
3829
|
+
* FOLLOWS OFFICIAL GUIDANCE: Prefers LIDs over PNs as per Baileys documentation.
|
|
3830
|
+
* Reference: https://baileys.wiki/docs/migration/to-v7.0.0
|
|
3829
3831
|
* @param key The MessageKey object from Baileys with LID support
|
|
3830
|
-
* @returns The
|
|
3832
|
+
* @returns The identifier (preferring LID over PN per official guidance)
|
|
3831
3833
|
*/
|
|
3832
3834
|
function baileyCleanNumberWithLid(key) {
|
|
3835
|
+
let rawIdentifier = '';
|
|
3836
|
+
let isLID = false;
|
|
3833
3837
|
// For groups: use participantAlt if available, fallback to participant
|
|
3834
3838
|
if (key.participant || key.participantAlt) {
|
|
3835
|
-
|
|
3836
|
-
|
|
3839
|
+
rawIdentifier = key.participantAlt || key.participant || '';
|
|
3840
|
+
isLID = rawIdentifier.includes('@lid');
|
|
3837
3841
|
}
|
|
3838
3842
|
// For DMs: use remoteJidAlt if available, fallback to remoteJid
|
|
3839
|
-
if (key.remoteJid || key.remoteJidAlt) {
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
|
|
3843
|
+
else if (key.remoteJid || key.remoteJidAlt) {
|
|
3844
|
+
rawIdentifier = key.remoteJidAlt || key.remoteJid || '';
|
|
3845
|
+
isLID = rawIdentifier.includes('@lid');
|
|
3846
|
+
}
|
|
3847
|
+
if (!rawIdentifier) {
|
|
3848
|
+
return '';
|
|
3849
|
+
}
|
|
3850
|
+
// OFFICIAL BAILEYS STRATEGY: Prefer LIDs over PNs
|
|
3851
|
+
// "THE GOAL SHOULDN'T BE TO RESTORE THE PN JID ANYMORE, MIGRATE TO LIDs. PNs are WAY LESS RELIABLE."
|
|
3852
|
+
if (isLID) {
|
|
3853
|
+
console.log(`[${new Date().toISOString()}] baileyCleanNumberWithLid: Using LID ${rawIdentifier} (Baileys v7.0.0+ best practice)`);
|
|
3854
|
+
return rawIdentifier;
|
|
3846
3855
|
}
|
|
3847
|
-
|
|
3856
|
+
// If we only have PN, use it but log that we should migrate to LID
|
|
3857
|
+
if (rawIdentifier.includes('@s.whatsapp.net')) {
|
|
3858
|
+
console.log(`[${new Date().toISOString()}] baileyCleanNumberWithLid: Using PN ${rawIdentifier} - should migrate to LID when available`);
|
|
3859
|
+
}
|
|
3860
|
+
return rawIdentifier;
|
|
3848
3861
|
}
|
|
3849
3862
|
/**
|
|
3850
3863
|
* Cleans the WhatsApp number format, supporting both LIDs and PNs.
|
|
@@ -3904,7 +3917,7 @@ const baileyIsValidNumber = (rawIdentifier) => {
|
|
|
3904
3917
|
const isGroup = rawIdentifier.match(regexGroup);
|
|
3905
3918
|
if (isGroup)
|
|
3906
3919
|
return false;
|
|
3907
|
-
// Exclude broadcast lists
|
|
3920
|
+
// Exclude broadcast lists
|
|
3908
3921
|
if (rawIdentifier.includes('@broadcast'))
|
|
3909
3922
|
return false;
|
|
3910
3923
|
// Accept LIDs (Local Identifiers) - preferred format
|
|
@@ -31076,8 +31089,21 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
31076
31089
|
};
|
|
31077
31090
|
this.getMessage = async (key) => {
|
|
31078
31091
|
// only if store is present
|
|
31079
|
-
// In Baileys v7.0.0+
|
|
31080
|
-
|
|
31092
|
+
// In Baileys v7.0.0+ use create(), fallback to empty object for tests
|
|
31093
|
+
try {
|
|
31094
|
+
if (baileys.proto.Message.create) {
|
|
31095
|
+
return baileys.proto.Message.create({});
|
|
31096
|
+
}
|
|
31097
|
+
else {
|
|
31098
|
+
// Fallback for tests and older versions
|
|
31099
|
+
return {};
|
|
31100
|
+
}
|
|
31101
|
+
}
|
|
31102
|
+
catch (error) {
|
|
31103
|
+
// Fallback in case of any error
|
|
31104
|
+
this.logger.log(`[${new Date().toISOString()}] Error in getMessage, using fallback:`, error);
|
|
31105
|
+
return {};
|
|
31106
|
+
}
|
|
31081
31107
|
};
|
|
31082
31108
|
this.saveCredsGlobal = null;
|
|
31083
31109
|
/**
|
|
@@ -31485,7 +31511,7 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
31485
31511
|
this.emit('lid_mapping_updated', {
|
|
31486
31512
|
mappings: lidMappingUpdate,
|
|
31487
31513
|
timestamp: new Date().toISOString(),
|
|
31488
|
-
count: Object.keys(lidMappingUpdate).length
|
|
31514
|
+
count: Object.keys(lidMappingUpdate).length,
|
|
31489
31515
|
});
|
|
31490
31516
|
}
|
|
31491
31517
|
}
|
|
@@ -31510,17 +31536,19 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
31510
31536
|
* @example await sendMessage('+XXXXXXXXXXX', 'https://dominio.com/imagen.jpg' | 'img/imagen.jpg')
|
|
31511
31537
|
*/
|
|
31512
31538
|
this.sendMedia = async (number, imageUrl, text) => {
|
|
31539
|
+
// CRITICAL FIX: Resolve LID to PN for outgoing messages
|
|
31540
|
+
const resolvedNumber = await this.resolveLIDToPNForSending(number);
|
|
31513
31541
|
const fileDownloaded = await bot.utils.generalDownload(imageUrl);
|
|
31514
31542
|
const mimeType = mime.lookup(fileDownloaded);
|
|
31515
31543
|
if (`${mimeType}`.includes('image'))
|
|
31516
|
-
return this.sendImage(
|
|
31544
|
+
return this.sendImage(resolvedNumber, fileDownloaded, text);
|
|
31517
31545
|
if (`${mimeType}`.includes('video'))
|
|
31518
|
-
return this.sendVideo(
|
|
31546
|
+
return this.sendVideo(resolvedNumber, fileDownloaded, text);
|
|
31519
31547
|
if (`${mimeType}`.includes('audio')) {
|
|
31520
31548
|
const fileOpus = await bot.utils.convertAudio(fileDownloaded);
|
|
31521
|
-
return this.sendAudio(
|
|
31549
|
+
return this.sendAudio(resolvedNumber, fileOpus);
|
|
31522
31550
|
}
|
|
31523
|
-
return this.sendFile(
|
|
31551
|
+
return this.sendFile(resolvedNumber, fileDownloaded, text);
|
|
31524
31552
|
};
|
|
31525
31553
|
/**
|
|
31526
31554
|
* Enviar imagen
|
|
@@ -31560,11 +31588,14 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
31560
31588
|
* @example await sendMessage('+XXXXXXXXXXX', 'audio.mp3')
|
|
31561
31589
|
*/
|
|
31562
31590
|
this.sendAudio = async (number, audioUrl) => {
|
|
31591
|
+
// CRITICAL FIX: Resolve LID to PN for outgoing messages
|
|
31592
|
+
const resolvedNumber = await this.resolveLIDToPNForSending(number);
|
|
31563
31593
|
const payload = {
|
|
31564
31594
|
audio: { url: audioUrl },
|
|
31565
31595
|
ptt: true,
|
|
31566
31596
|
};
|
|
31567
|
-
|
|
31597
|
+
this.logger.log(`[${new Date().toISOString()}] Sending audio to: ${resolvedNumber} (original: ${number})`);
|
|
31598
|
+
return this.vendor.sendMessage(resolvedNumber, payload);
|
|
31568
31599
|
};
|
|
31569
31600
|
/**
|
|
31570
31601
|
*
|
|
@@ -31573,8 +31604,11 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
31573
31604
|
* @returns
|
|
31574
31605
|
*/
|
|
31575
31606
|
this.sendText = async (number, message) => {
|
|
31607
|
+
// CRITICAL FIX: Ensure we use PN for outgoing messages to prevent sync issues
|
|
31608
|
+
const resolvedNumber = await this.resolveLIDToPNForSending(number);
|
|
31576
31609
|
const payload = { text: message };
|
|
31577
|
-
|
|
31610
|
+
this.logger.log(`[${new Date().toISOString()}] Sending message to: ${resolvedNumber} (original: ${number})`);
|
|
31611
|
+
return this.vendor.sendMessage(resolvedNumber, payload);
|
|
31578
31612
|
};
|
|
31579
31613
|
/**
|
|
31580
31614
|
*
|
|
@@ -31583,6 +31617,8 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
31583
31617
|
* @example await sendMessage('+XXXXXXXXXXX', './document/file.pdf')
|
|
31584
31618
|
*/
|
|
31585
31619
|
this.sendFile = async (number, filePath, text) => {
|
|
31620
|
+
// CRITICAL FIX: Resolve LID to PN for outgoing messages
|
|
31621
|
+
const resolvedNumber = await this.resolveLIDToPNForSending(number);
|
|
31586
31622
|
const mimeType = mime.lookup(filePath);
|
|
31587
31623
|
const fileName = require$$1$1.basename(filePath);
|
|
31588
31624
|
const payload = {
|
|
@@ -31591,7 +31627,8 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
31591
31627
|
fileName: fileName,
|
|
31592
31628
|
caption: text,
|
|
31593
31629
|
};
|
|
31594
|
-
|
|
31630
|
+
this.logger.log(`[${new Date().toISOString()}] Sending file to: ${resolvedNumber} (original: ${number})`);
|
|
31631
|
+
return this.vendor.sendMessage(resolvedNumber, payload);
|
|
31595
31632
|
};
|
|
31596
31633
|
/**
|
|
31597
31634
|
* @deprecated Buttons are not available in this provider, please use sendButtons instead
|
|
@@ -31654,7 +31691,8 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
31654
31691
|
*/
|
|
31655
31692
|
this.sendMessage = async (numberIn, message, options) => {
|
|
31656
31693
|
options = { ...options, ...options['options'] };
|
|
31657
|
-
|
|
31694
|
+
// CRITICAL FIX: Resolve LID to PN for outgoing messages to ensure WhatsApp sync
|
|
31695
|
+
const number = await this.resolveLIDToPNForSending(baileyCleanNumber(`${numberIn}`));
|
|
31658
31696
|
if (options.buttons?.length)
|
|
31659
31697
|
return this.sendButtons(number, message, options.buttons);
|
|
31660
31698
|
if (options.media)
|
|
@@ -31940,47 +31978,66 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
31940
31978
|
afterHttpServerInit() { }
|
|
31941
31979
|
/**
|
|
31942
31980
|
* Extracts sender information from MessageKey using Baileys v7.0.0+ Alt fields
|
|
31943
|
-
*
|
|
31981
|
+
* FOLLOWS OFFICIAL GUIDANCE: Prefers LIDs over PNs as per Baileys documentation
|
|
31982
|
+
* Reference: https://baileys.wiki/docs/migration/to-v7.0.0
|
|
31944
31983
|
* @param key MessageKey with potential remoteJidAlt/participantAlt fields
|
|
31945
|
-
* @returns Object with identifier, type, and isLID flag
|
|
31984
|
+
* @returns Object with identifier (preferring LID per official guidance), type, and isLID flag
|
|
31946
31985
|
*/
|
|
31947
31986
|
extractSenderWithAltFields(key) {
|
|
31948
31987
|
try {
|
|
31988
|
+
let rawIdentifier = '';
|
|
31989
|
+
let isOriginallyLID = false;
|
|
31949
31990
|
// For groups: prioritize participantAlt over participant
|
|
31950
31991
|
if (key?.participant || key?.participantAlt) {
|
|
31951
|
-
|
|
31952
|
-
|
|
31953
|
-
return {
|
|
31954
|
-
identifier: baileyCleanNumber(groupSender),
|
|
31955
|
-
type: groupSender.includes('@lid') ? 'lid' : groupSender.includes('@s.whatsapp.net') ? 'pn' : 'unknown',
|
|
31956
|
-
isLID: groupSender.includes('@lid')
|
|
31957
|
-
};
|
|
31958
|
-
}
|
|
31992
|
+
rawIdentifier = key.participantAlt || key.participant || '';
|
|
31993
|
+
isOriginallyLID = rawIdentifier.includes('@lid');
|
|
31959
31994
|
}
|
|
31960
|
-
// For DMs: prioritize remoteJidAlt over remoteJid
|
|
31961
|
-
if (key?.remoteJid || key?.remoteJidAlt) {
|
|
31962
|
-
|
|
31963
|
-
|
|
31964
|
-
|
|
31965
|
-
|
|
31966
|
-
|
|
31967
|
-
|
|
31968
|
-
|
|
31969
|
-
|
|
31970
|
-
}
|
|
31971
|
-
|
|
31972
|
-
|
|
31973
|
-
|
|
31974
|
-
|
|
31975
|
-
|
|
31976
|
-
|
|
31995
|
+
// For DMs: prioritize remoteJidAlt over remoteJid
|
|
31996
|
+
else if (key?.remoteJid || key?.remoteJidAlt) {
|
|
31997
|
+
rawIdentifier = key.remoteJidAlt || key.remoteJid || '';
|
|
31998
|
+
isOriginallyLID = rawIdentifier.includes('@lid');
|
|
31999
|
+
}
|
|
32000
|
+
if (!rawIdentifier) {
|
|
32001
|
+
return {
|
|
32002
|
+
identifier: '',
|
|
32003
|
+
type: 'unknown',
|
|
32004
|
+
isLID: false,
|
|
32005
|
+
};
|
|
32006
|
+
}
|
|
32007
|
+
// NORMALIZATION STRATEGY: Follow Baileys v7.0.0+ official guidance - MIGRATE TO LIDs
|
|
32008
|
+
// Reference: https://baileys.wiki/docs/migration/to-v7.0.0
|
|
32009
|
+
// "THE GOAL SHOULDN'T BE TO RESTORE THE PN JID ANYMORE, MIGRATE TO LIDs. PNs are WAY LESS RELIABLE."
|
|
32010
|
+
let normalizedIdentifier = rawIdentifier;
|
|
32011
|
+
let shouldPreferLID = false;
|
|
32012
|
+
// Strategy 1: If we have both LID and PN, prefer LID (official recommendation)
|
|
32013
|
+
if (isOriginallyLID) {
|
|
32014
|
+
// Keep the LID - this is the preferred approach per Baileys docs
|
|
32015
|
+
normalizedIdentifier = rawIdentifier;
|
|
32016
|
+
shouldPreferLID = true;
|
|
32017
|
+
this.logger.log(`[${new Date().toISOString()}] Using LID ${rawIdentifier} as primary identifier (Baileys v7.0.0+ best practice)`);
|
|
32018
|
+
}
|
|
32019
|
+
// Strategy 2: If we only have PN but can get LID from store, try to upgrade to LID
|
|
32020
|
+
else if (!isOriginallyLID && rawIdentifier.includes('@s.whatsapp.net')) {
|
|
32021
|
+
// We have a PN, but should try to find corresponding LID if available
|
|
32022
|
+
const lidStore = this.getLIDMappingStore();
|
|
32023
|
+
if (lidStore) {
|
|
32024
|
+
// Note: We would need to implement async LID lookup here in the future
|
|
32025
|
+
// For now, keep the PN but log the situation
|
|
32026
|
+
this.logger.log(`[${new Date().toISOString()}] PN ${rawIdentifier} detected - should lookup corresponding LID for migration`);
|
|
31977
32027
|
}
|
|
31978
32028
|
}
|
|
31979
|
-
//
|
|
32029
|
+
// Clean the normalized identifier
|
|
32030
|
+
const cleanIdentifier = baileyCleanNumber(normalizedIdentifier);
|
|
32031
|
+
// Determine final type based on normalized identifier
|
|
32032
|
+
const finalType = normalizedIdentifier.includes('@lid')
|
|
32033
|
+
? 'lid'
|
|
32034
|
+
: normalizedIdentifier.includes('@s.whatsapp.net')
|
|
32035
|
+
? 'pn'
|
|
32036
|
+
: 'unknown';
|
|
31980
32037
|
return {
|
|
31981
|
-
identifier:
|
|
31982
|
-
type:
|
|
31983
|
-
isLID:
|
|
32038
|
+
identifier: cleanIdentifier,
|
|
32039
|
+
type: finalType,
|
|
32040
|
+
isLID: isOriginallyLID, // Flag indicates if original was LID, even if we normalized to PN
|
|
31984
32041
|
};
|
|
31985
32042
|
}
|
|
31986
32043
|
catch (error) {
|
|
@@ -31989,10 +32046,65 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
31989
32046
|
return {
|
|
31990
32047
|
identifier: baileyCleanNumberWithLid(key),
|
|
31991
32048
|
type: 'unknown',
|
|
31992
|
-
isLID: false
|
|
32049
|
+
isLID: false,
|
|
31993
32050
|
};
|
|
31994
32051
|
}
|
|
31995
32052
|
}
|
|
32053
|
+
/**
|
|
32054
|
+
* CRITICAL FIX for Baileys v7.0.0+ LID sync issues
|
|
32055
|
+
* Resolves LID to PN for outgoing messages to ensure they appear in WhatsApp app
|
|
32056
|
+
*
|
|
32057
|
+
* Issue: Messages sent to LIDs from linked devices don't sync to main WhatsApp app
|
|
32058
|
+
* Solution: Convert LIDs to PNs when sending messages (keep LIDs for receiving)
|
|
32059
|
+
*
|
|
32060
|
+
* @param identifier The identifier to resolve (LID or PN)
|
|
32061
|
+
* @returns PN format for reliable message sending
|
|
32062
|
+
*/
|
|
32063
|
+
async resolveLIDToPNForSending(identifier) {
|
|
32064
|
+
try {
|
|
32065
|
+
// If it's already a PN, return as-is
|
|
32066
|
+
if (identifier.includes('@s.whatsapp.net')) {
|
|
32067
|
+
return identifier;
|
|
32068
|
+
}
|
|
32069
|
+
// If it's a LID, try to resolve to PN using LID store
|
|
32070
|
+
if (identifier.includes('@lid')) {
|
|
32071
|
+
const lidStore = this.getLIDMappingStore();
|
|
32072
|
+
if (lidStore) {
|
|
32073
|
+
try {
|
|
32074
|
+
const pn = await this.getPNFromLID(identifier);
|
|
32075
|
+
if (pn) {
|
|
32076
|
+
this.logger.log(`[${new Date().toISOString()}] 🔄 Resolved LID ${identifier} to PN ${pn} for sending (sync fix)`);
|
|
32077
|
+
return pn;
|
|
32078
|
+
}
|
|
32079
|
+
else {
|
|
32080
|
+
this.logger.log(`[${new Date().toISOString()}] ⚠️ No PN mapping found for LID ${identifier}, using LID (may not sync)`);
|
|
32081
|
+
}
|
|
32082
|
+
}
|
|
32083
|
+
catch (error) {
|
|
32084
|
+
this.logger.log(`[${new Date().toISOString()}] ❌ Error resolving LID to PN:`, error);
|
|
32085
|
+
}
|
|
32086
|
+
}
|
|
32087
|
+
}
|
|
32088
|
+
// If it's a group, return as-is
|
|
32089
|
+
if (identifier.includes('@g.us')) {
|
|
32090
|
+
return identifier;
|
|
32091
|
+
}
|
|
32092
|
+
// For raw numbers, format as PN
|
|
32093
|
+
const cleaned = identifier.replace(/[^\d]/g, '');
|
|
32094
|
+
if (cleaned.length >= 10) {
|
|
32095
|
+
const pn = `${cleaned}@s.whatsapp.net`;
|
|
32096
|
+
this.logger.log(`[${new Date().toISOString()}] 📞 Formatted raw number ${identifier} as PN ${pn}`);
|
|
32097
|
+
return pn;
|
|
32098
|
+
}
|
|
32099
|
+
// Fallback: return original identifier
|
|
32100
|
+
this.logger.log(`[${new Date().toISOString()}] ⚠️ Using original identifier ${identifier} for sending`);
|
|
32101
|
+
return identifier;
|
|
32102
|
+
}
|
|
32103
|
+
catch (error) {
|
|
32104
|
+
this.logger.log(`[${new Date().toISOString()}] ❌ Error in resolveLIDToPNForSending:`, error);
|
|
32105
|
+
return identifier;
|
|
32106
|
+
}
|
|
32107
|
+
}
|
|
31996
32108
|
shouldReconnect(statusCode) {
|
|
31997
32109
|
// Lista de códigos donde SÍ debemos reconectar
|
|
31998
32110
|
const reconnectableCodes = [
|
|
@@ -32040,21 +32152,35 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
32040
32152
|
*/
|
|
32041
32153
|
validateLIDSupport(state) {
|
|
32042
32154
|
try {
|
|
32043
|
-
|
|
32044
|
-
|
|
32045
|
-
|
|
32046
|
-
|
|
32155
|
+
// OFFICIAL REQUIREMENT per https://baileys.wiki/docs/migration/to-v7.0.0
|
|
32156
|
+
// "This system requires the auth state to support the lid-mapping and device-index keys"
|
|
32157
|
+
let hasLidMappingKey = false;
|
|
32158
|
+
let hasDeviceIndexKey = false;
|
|
32159
|
+
if (state.keys && typeof state.keys === 'object') {
|
|
32160
|
+
const keyNames = Object.keys(state.keys);
|
|
32161
|
+
hasLidMappingKey = keyNames.some((key) => key === 'lid-mapping' || key === 'lidMapping' || key.includes('lid-map'));
|
|
32162
|
+
hasDeviceIndexKey = keyNames.some((key) => key === 'device-index' || key === 'deviceIndex' || key.includes('device-index'));
|
|
32047
32163
|
}
|
|
32048
|
-
|
|
32049
|
-
|
|
32164
|
+
// Critical validation as per official docs
|
|
32165
|
+
if (!hasLidMappingKey) {
|
|
32166
|
+
this.logger.log(`[${new Date().toISOString()}] ⚠️ CRITICAL: Auth state missing 'lid-mapping' key support`);
|
|
32167
|
+
this.logger.log(`[${new Date().toISOString()}] This is REQUIRED for Baileys v7.0.0+ LID system`);
|
|
32050
32168
|
}
|
|
32051
|
-
|
|
32052
|
-
|
|
32053
|
-
|
|
32054
|
-
|
|
32169
|
+
if (!hasDeviceIndexKey) {
|
|
32170
|
+
this.logger.log(`[${new Date().toISOString()}] ⚠️ CRITICAL: Auth state missing 'device-index' key support`);
|
|
32171
|
+
this.logger.log(`[${new Date().toISOString()}] This is REQUIRED for Baileys v7.0.0+ LID system`);
|
|
32172
|
+
}
|
|
32173
|
+
if (hasLidMappingKey && hasDeviceIndexKey) {
|
|
32174
|
+
this.logger.log(`[${new Date().toISOString()}] ✅ Auth state supports LID system requirements (lid-mapping ✓, device-index ✓)`);
|
|
32055
32175
|
}
|
|
32056
|
-
|
|
32057
|
-
this.logger.log(`[${new Date().toISOString()}]
|
|
32176
|
+
else {
|
|
32177
|
+
this.logger.log(`[${new Date().toISOString()}] ❌ Auth state does NOT meet Baileys v7.0.0+ LID requirements`);
|
|
32178
|
+
this.logger.log(`[${new Date().toISOString()}] Please update your authentication state provider`);
|
|
32179
|
+
}
|
|
32180
|
+
// Debug logging
|
|
32181
|
+
if (state.keys) {
|
|
32182
|
+
const availableKeys = Object.keys(state.keys).slice(0, 5); // Show first 5 keys only
|
|
32183
|
+
this.logger.log(`[${new Date().toISOString()}] Available auth keys (sample):`, availableKeys);
|
|
32058
32184
|
}
|
|
32059
32185
|
}
|
|
32060
32186
|
catch (error) {
|
package/dist/index.mjs
CHANGED
|
@@ -3824,25 +3824,38 @@ const emptyDirSessions = async (pathBase) => new Promise((resolve, reject) => {
|
|
|
3824
3824
|
/**
|
|
3825
3825
|
* Cleans and extracts the appropriate identifier from MessageKey, supporting LID system.
|
|
3826
3826
|
* Uses remoteJidAlt/participantAlt when available according to Baileys v7.0.0+ specs.
|
|
3827
|
+
* FOLLOWS OFFICIAL GUIDANCE: Prefers LIDs over PNs as per Baileys documentation.
|
|
3828
|
+
* Reference: https://baileys.wiki/docs/migration/to-v7.0.0
|
|
3827
3829
|
* @param key The MessageKey object from Baileys with LID support
|
|
3828
|
-
* @returns The
|
|
3830
|
+
* @returns The identifier (preferring LID over PN per official guidance)
|
|
3829
3831
|
*/
|
|
3830
3832
|
function baileyCleanNumberWithLid(key) {
|
|
3833
|
+
let rawIdentifier = '';
|
|
3834
|
+
let isLID = false;
|
|
3831
3835
|
// For groups: use participantAlt if available, fallback to participant
|
|
3832
3836
|
if (key.participant || key.participantAlt) {
|
|
3833
|
-
|
|
3834
|
-
|
|
3837
|
+
rawIdentifier = key.participantAlt || key.participant || '';
|
|
3838
|
+
isLID = rawIdentifier.includes('@lid');
|
|
3835
3839
|
}
|
|
3836
3840
|
// For DMs: use remoteJidAlt if available, fallback to remoteJid
|
|
3837
|
-
if (key.remoteJid || key.remoteJidAlt) {
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3841
|
+
else if (key.remoteJid || key.remoteJidAlt) {
|
|
3842
|
+
rawIdentifier = key.remoteJidAlt || key.remoteJid || '';
|
|
3843
|
+
isLID = rawIdentifier.includes('@lid');
|
|
3844
|
+
}
|
|
3845
|
+
if (!rawIdentifier) {
|
|
3846
|
+
return '';
|
|
3847
|
+
}
|
|
3848
|
+
// OFFICIAL BAILEYS STRATEGY: Prefer LIDs over PNs
|
|
3849
|
+
// "THE GOAL SHOULDN'T BE TO RESTORE THE PN JID ANYMORE, MIGRATE TO LIDs. PNs are WAY LESS RELIABLE."
|
|
3850
|
+
if (isLID) {
|
|
3851
|
+
console.log(`[${new Date().toISOString()}] baileyCleanNumberWithLid: Using LID ${rawIdentifier} (Baileys v7.0.0+ best practice)`);
|
|
3852
|
+
return rawIdentifier;
|
|
3844
3853
|
}
|
|
3845
|
-
|
|
3854
|
+
// If we only have PN, use it but log that we should migrate to LID
|
|
3855
|
+
if (rawIdentifier.includes('@s.whatsapp.net')) {
|
|
3856
|
+
console.log(`[${new Date().toISOString()}] baileyCleanNumberWithLid: Using PN ${rawIdentifier} - should migrate to LID when available`);
|
|
3857
|
+
}
|
|
3858
|
+
return rawIdentifier;
|
|
3846
3859
|
}
|
|
3847
3860
|
/**
|
|
3848
3861
|
* Cleans the WhatsApp number format, supporting both LIDs and PNs.
|
|
@@ -3902,7 +3915,7 @@ const baileyIsValidNumber = (rawIdentifier) => {
|
|
|
3902
3915
|
const isGroup = rawIdentifier.match(regexGroup);
|
|
3903
3916
|
if (isGroup)
|
|
3904
3917
|
return false;
|
|
3905
|
-
// Exclude broadcast lists
|
|
3918
|
+
// Exclude broadcast lists
|
|
3906
3919
|
if (rawIdentifier.includes('@broadcast'))
|
|
3907
3920
|
return false;
|
|
3908
3921
|
// Accept LIDs (Local Identifiers) - preferred format
|
|
@@ -31074,8 +31087,21 @@ class BaileysProvider extends ProviderClass {
|
|
|
31074
31087
|
};
|
|
31075
31088
|
this.getMessage = async (key) => {
|
|
31076
31089
|
// only if store is present
|
|
31077
|
-
// In Baileys v7.0.0+
|
|
31078
|
-
|
|
31090
|
+
// In Baileys v7.0.0+ use create(), fallback to empty object for tests
|
|
31091
|
+
try {
|
|
31092
|
+
if (proto$2.Message.create) {
|
|
31093
|
+
return proto$2.Message.create({});
|
|
31094
|
+
}
|
|
31095
|
+
else {
|
|
31096
|
+
// Fallback for tests and older versions
|
|
31097
|
+
return {};
|
|
31098
|
+
}
|
|
31099
|
+
}
|
|
31100
|
+
catch (error) {
|
|
31101
|
+
// Fallback in case of any error
|
|
31102
|
+
this.logger.log(`[${new Date().toISOString()}] Error in getMessage, using fallback:`, error);
|
|
31103
|
+
return {};
|
|
31104
|
+
}
|
|
31079
31105
|
};
|
|
31080
31106
|
this.saveCredsGlobal = null;
|
|
31081
31107
|
/**
|
|
@@ -31483,7 +31509,7 @@ class BaileysProvider extends ProviderClass {
|
|
|
31483
31509
|
this.emit('lid_mapping_updated', {
|
|
31484
31510
|
mappings: lidMappingUpdate,
|
|
31485
31511
|
timestamp: new Date().toISOString(),
|
|
31486
|
-
count: Object.keys(lidMappingUpdate).length
|
|
31512
|
+
count: Object.keys(lidMappingUpdate).length,
|
|
31487
31513
|
});
|
|
31488
31514
|
}
|
|
31489
31515
|
}
|
|
@@ -31508,17 +31534,19 @@ class BaileysProvider extends ProviderClass {
|
|
|
31508
31534
|
* @example await sendMessage('+XXXXXXXXXXX', 'https://dominio.com/imagen.jpg' | 'img/imagen.jpg')
|
|
31509
31535
|
*/
|
|
31510
31536
|
this.sendMedia = async (number, imageUrl, text) => {
|
|
31537
|
+
// CRITICAL FIX: Resolve LID to PN for outgoing messages
|
|
31538
|
+
const resolvedNumber = await this.resolveLIDToPNForSending(number);
|
|
31511
31539
|
const fileDownloaded = await utils$d.generalDownload(imageUrl);
|
|
31512
31540
|
const mimeType = mime.lookup(fileDownloaded);
|
|
31513
31541
|
if (`${mimeType}`.includes('image'))
|
|
31514
|
-
return this.sendImage(
|
|
31542
|
+
return this.sendImage(resolvedNumber, fileDownloaded, text);
|
|
31515
31543
|
if (`${mimeType}`.includes('video'))
|
|
31516
|
-
return this.sendVideo(
|
|
31544
|
+
return this.sendVideo(resolvedNumber, fileDownloaded, text);
|
|
31517
31545
|
if (`${mimeType}`.includes('audio')) {
|
|
31518
31546
|
const fileOpus = await utils$d.convertAudio(fileDownloaded);
|
|
31519
|
-
return this.sendAudio(
|
|
31547
|
+
return this.sendAudio(resolvedNumber, fileOpus);
|
|
31520
31548
|
}
|
|
31521
|
-
return this.sendFile(
|
|
31549
|
+
return this.sendFile(resolvedNumber, fileDownloaded, text);
|
|
31522
31550
|
};
|
|
31523
31551
|
/**
|
|
31524
31552
|
* Enviar imagen
|
|
@@ -31558,11 +31586,14 @@ class BaileysProvider extends ProviderClass {
|
|
|
31558
31586
|
* @example await sendMessage('+XXXXXXXXXXX', 'audio.mp3')
|
|
31559
31587
|
*/
|
|
31560
31588
|
this.sendAudio = async (number, audioUrl) => {
|
|
31589
|
+
// CRITICAL FIX: Resolve LID to PN for outgoing messages
|
|
31590
|
+
const resolvedNumber = await this.resolveLIDToPNForSending(number);
|
|
31561
31591
|
const payload = {
|
|
31562
31592
|
audio: { url: audioUrl },
|
|
31563
31593
|
ptt: true,
|
|
31564
31594
|
};
|
|
31565
|
-
|
|
31595
|
+
this.logger.log(`[${new Date().toISOString()}] Sending audio to: ${resolvedNumber} (original: ${number})`);
|
|
31596
|
+
return this.vendor.sendMessage(resolvedNumber, payload);
|
|
31566
31597
|
};
|
|
31567
31598
|
/**
|
|
31568
31599
|
*
|
|
@@ -31571,8 +31602,11 @@ class BaileysProvider extends ProviderClass {
|
|
|
31571
31602
|
* @returns
|
|
31572
31603
|
*/
|
|
31573
31604
|
this.sendText = async (number, message) => {
|
|
31605
|
+
// CRITICAL FIX: Ensure we use PN for outgoing messages to prevent sync issues
|
|
31606
|
+
const resolvedNumber = await this.resolveLIDToPNForSending(number);
|
|
31574
31607
|
const payload = { text: message };
|
|
31575
|
-
|
|
31608
|
+
this.logger.log(`[${new Date().toISOString()}] Sending message to: ${resolvedNumber} (original: ${number})`);
|
|
31609
|
+
return this.vendor.sendMessage(resolvedNumber, payload);
|
|
31576
31610
|
};
|
|
31577
31611
|
/**
|
|
31578
31612
|
*
|
|
@@ -31581,6 +31615,8 @@ class BaileysProvider extends ProviderClass {
|
|
|
31581
31615
|
* @example await sendMessage('+XXXXXXXXXXX', './document/file.pdf')
|
|
31582
31616
|
*/
|
|
31583
31617
|
this.sendFile = async (number, filePath, text) => {
|
|
31618
|
+
// CRITICAL FIX: Resolve LID to PN for outgoing messages
|
|
31619
|
+
const resolvedNumber = await this.resolveLIDToPNForSending(number);
|
|
31584
31620
|
const mimeType = mime.lookup(filePath);
|
|
31585
31621
|
const fileName = basename(filePath);
|
|
31586
31622
|
const payload = {
|
|
@@ -31589,7 +31625,8 @@ class BaileysProvider extends ProviderClass {
|
|
|
31589
31625
|
fileName: fileName,
|
|
31590
31626
|
caption: text,
|
|
31591
31627
|
};
|
|
31592
|
-
|
|
31628
|
+
this.logger.log(`[${new Date().toISOString()}] Sending file to: ${resolvedNumber} (original: ${number})`);
|
|
31629
|
+
return this.vendor.sendMessage(resolvedNumber, payload);
|
|
31593
31630
|
};
|
|
31594
31631
|
/**
|
|
31595
31632
|
* @deprecated Buttons are not available in this provider, please use sendButtons instead
|
|
@@ -31652,7 +31689,8 @@ class BaileysProvider extends ProviderClass {
|
|
|
31652
31689
|
*/
|
|
31653
31690
|
this.sendMessage = async (numberIn, message, options) => {
|
|
31654
31691
|
options = { ...options, ...options['options'] };
|
|
31655
|
-
|
|
31692
|
+
// CRITICAL FIX: Resolve LID to PN for outgoing messages to ensure WhatsApp sync
|
|
31693
|
+
const number = await this.resolveLIDToPNForSending(baileyCleanNumber(`${numberIn}`));
|
|
31656
31694
|
if (options.buttons?.length)
|
|
31657
31695
|
return this.sendButtons(number, message, options.buttons);
|
|
31658
31696
|
if (options.media)
|
|
@@ -31938,47 +31976,66 @@ class BaileysProvider extends ProviderClass {
|
|
|
31938
31976
|
afterHttpServerInit() { }
|
|
31939
31977
|
/**
|
|
31940
31978
|
* Extracts sender information from MessageKey using Baileys v7.0.0+ Alt fields
|
|
31941
|
-
*
|
|
31979
|
+
* FOLLOWS OFFICIAL GUIDANCE: Prefers LIDs over PNs as per Baileys documentation
|
|
31980
|
+
* Reference: https://baileys.wiki/docs/migration/to-v7.0.0
|
|
31942
31981
|
* @param key MessageKey with potential remoteJidAlt/participantAlt fields
|
|
31943
|
-
* @returns Object with identifier, type, and isLID flag
|
|
31982
|
+
* @returns Object with identifier (preferring LID per official guidance), type, and isLID flag
|
|
31944
31983
|
*/
|
|
31945
31984
|
extractSenderWithAltFields(key) {
|
|
31946
31985
|
try {
|
|
31986
|
+
let rawIdentifier = '';
|
|
31987
|
+
let isOriginallyLID = false;
|
|
31947
31988
|
// For groups: prioritize participantAlt over participant
|
|
31948
31989
|
if (key?.participant || key?.participantAlt) {
|
|
31949
|
-
|
|
31950
|
-
|
|
31951
|
-
return {
|
|
31952
|
-
identifier: baileyCleanNumber(groupSender),
|
|
31953
|
-
type: groupSender.includes('@lid') ? 'lid' : groupSender.includes('@s.whatsapp.net') ? 'pn' : 'unknown',
|
|
31954
|
-
isLID: groupSender.includes('@lid')
|
|
31955
|
-
};
|
|
31956
|
-
}
|
|
31990
|
+
rawIdentifier = key.participantAlt || key.participant || '';
|
|
31991
|
+
isOriginallyLID = rawIdentifier.includes('@lid');
|
|
31957
31992
|
}
|
|
31958
|
-
// For DMs: prioritize remoteJidAlt over remoteJid
|
|
31959
|
-
if (key?.remoteJid || key?.remoteJidAlt) {
|
|
31960
|
-
|
|
31961
|
-
|
|
31962
|
-
|
|
31963
|
-
|
|
31964
|
-
|
|
31965
|
-
|
|
31966
|
-
|
|
31967
|
-
|
|
31968
|
-
}
|
|
31969
|
-
|
|
31970
|
-
|
|
31971
|
-
|
|
31972
|
-
|
|
31973
|
-
|
|
31974
|
-
|
|
31993
|
+
// For DMs: prioritize remoteJidAlt over remoteJid
|
|
31994
|
+
else if (key?.remoteJid || key?.remoteJidAlt) {
|
|
31995
|
+
rawIdentifier = key.remoteJidAlt || key.remoteJid || '';
|
|
31996
|
+
isOriginallyLID = rawIdentifier.includes('@lid');
|
|
31997
|
+
}
|
|
31998
|
+
if (!rawIdentifier) {
|
|
31999
|
+
return {
|
|
32000
|
+
identifier: '',
|
|
32001
|
+
type: 'unknown',
|
|
32002
|
+
isLID: false,
|
|
32003
|
+
};
|
|
32004
|
+
}
|
|
32005
|
+
// NORMALIZATION STRATEGY: Follow Baileys v7.0.0+ official guidance - MIGRATE TO LIDs
|
|
32006
|
+
// Reference: https://baileys.wiki/docs/migration/to-v7.0.0
|
|
32007
|
+
// "THE GOAL SHOULDN'T BE TO RESTORE THE PN JID ANYMORE, MIGRATE TO LIDs. PNs are WAY LESS RELIABLE."
|
|
32008
|
+
let normalizedIdentifier = rawIdentifier;
|
|
32009
|
+
let shouldPreferLID = false;
|
|
32010
|
+
// Strategy 1: If we have both LID and PN, prefer LID (official recommendation)
|
|
32011
|
+
if (isOriginallyLID) {
|
|
32012
|
+
// Keep the LID - this is the preferred approach per Baileys docs
|
|
32013
|
+
normalizedIdentifier = rawIdentifier;
|
|
32014
|
+
shouldPreferLID = true;
|
|
32015
|
+
this.logger.log(`[${new Date().toISOString()}] Using LID ${rawIdentifier} as primary identifier (Baileys v7.0.0+ best practice)`);
|
|
32016
|
+
}
|
|
32017
|
+
// Strategy 2: If we only have PN but can get LID from store, try to upgrade to LID
|
|
32018
|
+
else if (!isOriginallyLID && rawIdentifier.includes('@s.whatsapp.net')) {
|
|
32019
|
+
// We have a PN, but should try to find corresponding LID if available
|
|
32020
|
+
const lidStore = this.getLIDMappingStore();
|
|
32021
|
+
if (lidStore) {
|
|
32022
|
+
// Note: We would need to implement async LID lookup here in the future
|
|
32023
|
+
// For now, keep the PN but log the situation
|
|
32024
|
+
this.logger.log(`[${new Date().toISOString()}] PN ${rawIdentifier} detected - should lookup corresponding LID for migration`);
|
|
31975
32025
|
}
|
|
31976
32026
|
}
|
|
31977
|
-
//
|
|
32027
|
+
// Clean the normalized identifier
|
|
32028
|
+
const cleanIdentifier = baileyCleanNumber(normalizedIdentifier);
|
|
32029
|
+
// Determine final type based on normalized identifier
|
|
32030
|
+
const finalType = normalizedIdentifier.includes('@lid')
|
|
32031
|
+
? 'lid'
|
|
32032
|
+
: normalizedIdentifier.includes('@s.whatsapp.net')
|
|
32033
|
+
? 'pn'
|
|
32034
|
+
: 'unknown';
|
|
31978
32035
|
return {
|
|
31979
|
-
identifier:
|
|
31980
|
-
type:
|
|
31981
|
-
isLID:
|
|
32036
|
+
identifier: cleanIdentifier,
|
|
32037
|
+
type: finalType,
|
|
32038
|
+
isLID: isOriginallyLID, // Flag indicates if original was LID, even if we normalized to PN
|
|
31982
32039
|
};
|
|
31983
32040
|
}
|
|
31984
32041
|
catch (error) {
|
|
@@ -31987,10 +32044,65 @@ class BaileysProvider extends ProviderClass {
|
|
|
31987
32044
|
return {
|
|
31988
32045
|
identifier: baileyCleanNumberWithLid(key),
|
|
31989
32046
|
type: 'unknown',
|
|
31990
|
-
isLID: false
|
|
32047
|
+
isLID: false,
|
|
31991
32048
|
};
|
|
31992
32049
|
}
|
|
31993
32050
|
}
|
|
32051
|
+
/**
|
|
32052
|
+
* CRITICAL FIX for Baileys v7.0.0+ LID sync issues
|
|
32053
|
+
* Resolves LID to PN for outgoing messages to ensure they appear in WhatsApp app
|
|
32054
|
+
*
|
|
32055
|
+
* Issue: Messages sent to LIDs from linked devices don't sync to main WhatsApp app
|
|
32056
|
+
* Solution: Convert LIDs to PNs when sending messages (keep LIDs for receiving)
|
|
32057
|
+
*
|
|
32058
|
+
* @param identifier The identifier to resolve (LID or PN)
|
|
32059
|
+
* @returns PN format for reliable message sending
|
|
32060
|
+
*/
|
|
32061
|
+
async resolveLIDToPNForSending(identifier) {
|
|
32062
|
+
try {
|
|
32063
|
+
// If it's already a PN, return as-is
|
|
32064
|
+
if (identifier.includes('@s.whatsapp.net')) {
|
|
32065
|
+
return identifier;
|
|
32066
|
+
}
|
|
32067
|
+
// If it's a LID, try to resolve to PN using LID store
|
|
32068
|
+
if (identifier.includes('@lid')) {
|
|
32069
|
+
const lidStore = this.getLIDMappingStore();
|
|
32070
|
+
if (lidStore) {
|
|
32071
|
+
try {
|
|
32072
|
+
const pn = await this.getPNFromLID(identifier);
|
|
32073
|
+
if (pn) {
|
|
32074
|
+
this.logger.log(`[${new Date().toISOString()}] 🔄 Resolved LID ${identifier} to PN ${pn} for sending (sync fix)`);
|
|
32075
|
+
return pn;
|
|
32076
|
+
}
|
|
32077
|
+
else {
|
|
32078
|
+
this.logger.log(`[${new Date().toISOString()}] ⚠️ No PN mapping found for LID ${identifier}, using LID (may not sync)`);
|
|
32079
|
+
}
|
|
32080
|
+
}
|
|
32081
|
+
catch (error) {
|
|
32082
|
+
this.logger.log(`[${new Date().toISOString()}] ❌ Error resolving LID to PN:`, error);
|
|
32083
|
+
}
|
|
32084
|
+
}
|
|
32085
|
+
}
|
|
32086
|
+
// If it's a group, return as-is
|
|
32087
|
+
if (identifier.includes('@g.us')) {
|
|
32088
|
+
return identifier;
|
|
32089
|
+
}
|
|
32090
|
+
// For raw numbers, format as PN
|
|
32091
|
+
const cleaned = identifier.replace(/[^\d]/g, '');
|
|
32092
|
+
if (cleaned.length >= 10) {
|
|
32093
|
+
const pn = `${cleaned}@s.whatsapp.net`;
|
|
32094
|
+
this.logger.log(`[${new Date().toISOString()}] 📞 Formatted raw number ${identifier} as PN ${pn}`);
|
|
32095
|
+
return pn;
|
|
32096
|
+
}
|
|
32097
|
+
// Fallback: return original identifier
|
|
32098
|
+
this.logger.log(`[${new Date().toISOString()}] ⚠️ Using original identifier ${identifier} for sending`);
|
|
32099
|
+
return identifier;
|
|
32100
|
+
}
|
|
32101
|
+
catch (error) {
|
|
32102
|
+
this.logger.log(`[${new Date().toISOString()}] ❌ Error in resolveLIDToPNForSending:`, error);
|
|
32103
|
+
return identifier;
|
|
32104
|
+
}
|
|
32105
|
+
}
|
|
31994
32106
|
shouldReconnect(statusCode) {
|
|
31995
32107
|
// Lista de códigos donde SÍ debemos reconectar
|
|
31996
32108
|
const reconnectableCodes = [
|
|
@@ -32038,21 +32150,35 @@ class BaileysProvider extends ProviderClass {
|
|
|
32038
32150
|
*/
|
|
32039
32151
|
validateLIDSupport(state) {
|
|
32040
32152
|
try {
|
|
32041
|
-
|
|
32042
|
-
|
|
32043
|
-
|
|
32044
|
-
|
|
32153
|
+
// OFFICIAL REQUIREMENT per https://baileys.wiki/docs/migration/to-v7.0.0
|
|
32154
|
+
// "This system requires the auth state to support the lid-mapping and device-index keys"
|
|
32155
|
+
let hasLidMappingKey = false;
|
|
32156
|
+
let hasDeviceIndexKey = false;
|
|
32157
|
+
if (state.keys && typeof state.keys === 'object') {
|
|
32158
|
+
const keyNames = Object.keys(state.keys);
|
|
32159
|
+
hasLidMappingKey = keyNames.some((key) => key === 'lid-mapping' || key === 'lidMapping' || key.includes('lid-map'));
|
|
32160
|
+
hasDeviceIndexKey = keyNames.some((key) => key === 'device-index' || key === 'deviceIndex' || key.includes('device-index'));
|
|
32045
32161
|
}
|
|
32046
|
-
|
|
32047
|
-
|
|
32162
|
+
// Critical validation as per official docs
|
|
32163
|
+
if (!hasLidMappingKey) {
|
|
32164
|
+
this.logger.log(`[${new Date().toISOString()}] ⚠️ CRITICAL: Auth state missing 'lid-mapping' key support`);
|
|
32165
|
+
this.logger.log(`[${new Date().toISOString()}] This is REQUIRED for Baileys v7.0.0+ LID system`);
|
|
32048
32166
|
}
|
|
32049
|
-
|
|
32050
|
-
|
|
32051
|
-
|
|
32052
|
-
|
|
32167
|
+
if (!hasDeviceIndexKey) {
|
|
32168
|
+
this.logger.log(`[${new Date().toISOString()}] ⚠️ CRITICAL: Auth state missing 'device-index' key support`);
|
|
32169
|
+
this.logger.log(`[${new Date().toISOString()}] This is REQUIRED for Baileys v7.0.0+ LID system`);
|
|
32170
|
+
}
|
|
32171
|
+
if (hasLidMappingKey && hasDeviceIndexKey) {
|
|
32172
|
+
this.logger.log(`[${new Date().toISOString()}] ✅ Auth state supports LID system requirements (lid-mapping ✓, device-index ✓)`);
|
|
32053
32173
|
}
|
|
32054
|
-
|
|
32055
|
-
this.logger.log(`[${new Date().toISOString()}]
|
|
32174
|
+
else {
|
|
32175
|
+
this.logger.log(`[${new Date().toISOString()}] ❌ Auth state does NOT meet Baileys v7.0.0+ LID requirements`);
|
|
32176
|
+
this.logger.log(`[${new Date().toISOString()}] Please update your authentication state provider`);
|
|
32177
|
+
}
|
|
32178
|
+
// Debug logging
|
|
32179
|
+
if (state.keys) {
|
|
32180
|
+
const availableKeys = Object.keys(state.keys).slice(0, 5); // Show first 5 keys only
|
|
32181
|
+
this.logger.log(`[${new Date().toISOString()}] Available auth keys (sample):`, availableKeys);
|
|
32056
32182
|
}
|
|
32057
32183
|
}
|
|
32058
32184
|
catch (error) {
|
package/dist/utils.d.ts
CHANGED
|
@@ -2,8 +2,10 @@ declare const emptyDirSessions: (pathBase: string) => Promise<unknown>;
|
|
|
2
2
|
/**
|
|
3
3
|
* Cleans and extracts the appropriate identifier from MessageKey, supporting LID system.
|
|
4
4
|
* Uses remoteJidAlt/participantAlt when available according to Baileys v7.0.0+ specs.
|
|
5
|
+
* FOLLOWS OFFICIAL GUIDANCE: Prefers LIDs over PNs as per Baileys documentation.
|
|
6
|
+
* Reference: https://baileys.wiki/docs/migration/to-v7.0.0
|
|
5
7
|
* @param key The MessageKey object from Baileys with LID support
|
|
6
|
-
* @returns The
|
|
8
|
+
* @returns The identifier (preferring LID over PN per official guidance)
|
|
7
9
|
*/
|
|
8
10
|
declare function baileyCleanNumberWithLid(key: {
|
|
9
11
|
senderPn?: string;
|
|
@@ -80,5 +82,5 @@ declare const baileyIsLID: (jid: string) => boolean;
|
|
|
80
82
|
* @returns True if it's a PN, false otherwise
|
|
81
83
|
*/
|
|
82
84
|
declare const baileyIsPN: (jid: string) => boolean;
|
|
83
|
-
export { baileyCleanNumber, baileyGenerateImage, baileyIsValidNumber, emptyDirSessions, baileyCleanNumberWithLid, baileyGetLIDFromPN, baileyGetPNFromLID, baileyGetLIDsFromPNs, baileyStoreLIDPNMapping, baileyStoreLIDPNMappings, baileyIsLID, baileyIsPN };
|
|
85
|
+
export { baileyCleanNumber, baileyGenerateImage, baileyIsValidNumber, emptyDirSessions, baileyCleanNumberWithLid, baileyGetLIDFromPN, baileyGetPNFromLID, baileyGetLIDsFromPNs, baileyStoreLIDPNMapping, baileyStoreLIDPNMappings, baileyIsLID, baileyIsPN, };
|
|
84
86
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sour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uBAAuB,GAAU,UAAU,GAAG,EAAE,KAAK,MAAM,EAAE,aAAa,MAAM,KAAG,OAAO,CAAC,IAAI,CAUpG,CAAA;AAED;;;;;GAKG;AACH,QAAA,MAAM,wBAAwB,GAAU,UAAU,GAAG,EAAE,UAAU,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAG,OAAO,CAAC,IAAI,CAUrG,CAAA;AAED;;;;GAIG;AACH,QAAA,MAAM,WAAW,GAAI,KAAK,MAAM,KAAG,OAElC,CAAA;AAED;;;;GAIG;AACH,QAAA,MAAM,UAAU,GAAI,KAAK,MAAM,KAAG,OAEjC,CAAA;AAED,OAAO,EACH,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,wBAAwB,EACxB,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,EACpB,uBAAuB,EACvB,wBAAwB,EACxB,WAAW,EACX,UAAU,GACb,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@builderbot/provider-baileys",
|
|
3
|
-
"version": "1.3.5-alpha.
|
|
3
|
+
"version": "1.3.5-alpha.9",
|
|
4
4
|
"description": "Now I'm the model of a modern major general / The venerated Virginian veteran whose men are all / Lining up, to put me up on a pedestal / Writin' letters to relatives / Embellishin' my elegance and eloquence / But the elephant is in the room / The truth is in ya face when ya hear the British cannons go / BOOM",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "Leifer Mendez <leifer33@gmail.com>",
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
"node-cache": "^5.1.2",
|
|
78
78
|
"sharp": "0.33.3"
|
|
79
79
|
},
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "60e588660de6b2d3aee6b1b902763fd7f9cf890c"
|
|
81
81
|
}
|