@builderbot/provider-baileys 1.3.15-alpha.9 → 1.4.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/dist/bailey.d.ts +13 -8
- package/dist/bailey.d.ts.map +1 -1
- package/dist/baileyWrapper.d.ts +2 -2
- package/dist/baileyWrapper.d.ts.map +1 -1
- package/dist/index.cjs +54 -31
- package/dist/index.mjs +54 -31
- package/dist/utils.d.ts +4 -4
- package/dist/utils.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/bailey.d.ts
CHANGED
|
@@ -78,20 +78,25 @@ declare class BaileysProvider extends ProviderClass<WASocket> {
|
|
|
78
78
|
* @example await getOrderDetails('order-id', 'order-token')
|
|
79
79
|
*/
|
|
80
80
|
getOrderDetails: (orderId: string, orderToken: string) => Promise<import("baileys").OrderDetails>;
|
|
81
|
+
/**
|
|
82
|
+
* Accede al lidMapping del signalRepository de Baileys.
|
|
83
|
+
*/
|
|
84
|
+
private get lidMapping();
|
|
81
85
|
/**
|
|
82
86
|
* Obtener LID (Local Identifier) para un número de teléfono (PN)
|
|
83
|
-
* @param
|
|
84
|
-
* @returns {Promise<string|null>} - El LID correspondiente o null si no se encuentra
|
|
85
|
-
* @example await getLIDForPN('1234567890@s.whatsapp.net')
|
|
87
|
+
* @param phoneNumber - JID con formato '1234567890@s.whatsapp.net'
|
|
86
88
|
*/
|
|
87
|
-
getLIDForPN: (phoneNumber: string) => Promise<
|
|
89
|
+
getLIDForPN: (phoneNumber: string) => Promise<string | null>;
|
|
88
90
|
/**
|
|
89
91
|
* Obtener número de teléfono (PN) para un LID (Local Identifier)
|
|
90
|
-
* @param
|
|
91
|
-
|
|
92
|
-
|
|
92
|
+
* @param lid - JID con formato '16424005304394@lid'
|
|
93
|
+
*/
|
|
94
|
+
getPNForLID: (lid: string) => Promise<string | null>;
|
|
95
|
+
/**
|
|
96
|
+
* Normaliza un número entrante a un JID válido para envío.
|
|
97
|
+
* Si es un @lid, intenta resolver a @s.whatsapp.net; si falla, envía al LID directamente.
|
|
93
98
|
*/
|
|
94
|
-
|
|
99
|
+
private resolveNumber;
|
|
95
100
|
/**
|
|
96
101
|
* @param {string} number
|
|
97
102
|
* @param {string} message
|
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;AAGjF,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,EACf,SAAS,EACT,QAAQ,
|
|
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;AAGjF,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,EACf,SAAS,EACT,QAAQ,EAUR,KAAK,EAKR,MAAM,iBAAiB,CAAA;AAExB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,QAAQ,CAAA;AAGpD,cAAM,eAAgB,SAAQ,aAAa,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EH,YAAY,GAAU,WAAW,MAAM,EAAE,UAAU,GAAG,EAAE,WAAW,GAAG,EAAE,WAAU,GAAU;;OAa3F;IAED;;;;;;;OAOG;IAEH,WAAW,GACP,WAAW,GAAG,EACd,eAAe;QAAE,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,GAAG,CAAA;KAAE,EAClE,aAAa,MAAM,EACnB,SAAS,MAAM,EACf,WAAU,GAAU;;OAyBvB;IAED;;;;OAIG;IACH,kBAAkB,GAAU,WAAW,GAAG,EAAE,YAAY,GAAG,mBAE1D;IAED;;;;;;OAMG;IAEH,WAAW,GACP,WAAW,GAAG,EACd,KAAK,MAAM,GAAG,MAAM,EACpB,gBAAgB,OAAO,CAAC,eAAe,CAAC,EACxC,WAAU,GAAU,mBAWvB;IAED,OAAO,CAAC,WAAW,CAYlB;IAED,OAAO,CAAC,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,OAAO,CAAC,eAAe;YAmBT,gBAAgB;CAwCjC;AAED,OAAO,EAAE,eAAe,EAAE,CAAA"}
|
package/dist/baileyWrapper.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import makeWASocketOther, { useMultiFileAuthState, DisconnectReason, proto, makeCacheableSignalKeyStore, getAggregateVotesInPollMessage, WASocket, BaileysEventMap, AnyMediaMessageContent, AnyMessageContent, downloadMediaMessage, WAMessage, MessageUpsertType, isJidGroup, isJidBroadcast, PollMessageOptions, WAVersion, WABrowserDescription } from 'baileys';
|
|
2
|
-
export { makeWASocketOther, useMultiFileAuthState, DisconnectReason, proto, makeCacheableSignalKeyStore, getAggregateVotesInPollMessage, WASocket, BaileysEventMap, AnyMediaMessageContent, AnyMessageContent, downloadMediaMessage, WAMessage, MessageUpsertType, isJidGroup, isJidBroadcast, PollMessageOptions, WAVersion, WABrowserDescription, };
|
|
1
|
+
import makeWASocketOther, { useMultiFileAuthState, DisconnectReason, proto, makeCacheableSignalKeyStore, getAggregateVotesInPollMessage, WASocket, BaileysEventMap, AnyMediaMessageContent, AnyMessageContent, downloadMediaMessage, WAMessage, MessageUpsertType, isJidGroup, isJidBroadcast, isLidUser, PollMessageOptions, WAVersion, WABrowserDescription } from 'baileys';
|
|
2
|
+
export { makeWASocketOther, useMultiFileAuthState, DisconnectReason, proto, makeCacheableSignalKeyStore, getAggregateVotesInPollMessage, WASocket, BaileysEventMap, AnyMediaMessageContent, AnyMessageContent, downloadMediaMessage, WAMessage, MessageUpsertType, isJidGroup, isJidBroadcast, isLidUser, PollMessageOptions, WAVersion, WABrowserDescription, };
|
|
3
3
|
//# sourceMappingURL=baileyWrapper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baileyWrapper.d.ts","sourceRoot":"","sources":["../src/baileyWrapper.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,EAAE,EACtB,qBAAqB,EACrB,gBAAgB,EAChB,KAAK,EACL,2BAA2B,EAC3B,8BAA8B,EAC9B,QAAQ,EACR,eAAe,EACf,sBAAsB,EACtB,iBAAiB,EACjB,oBAAoB,EACpB,SAAS,EACT,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,kBAAkB,EAClB,SAAS,EACT,oBAAoB,EACvB,MAAM,SAAS,CAAA;AAEhB,OAAO,EACH,iBAAiB,EACjB,qBAAqB,EACrB,gBAAgB,EAChB,KAAK,EACL,2BAA2B,EAC3B,8BAA8B,EAC9B,QAAQ,EACR,eAAe,EACf,sBAAsB,EACtB,iBAAiB,EACjB,oBAAoB,EACpB,SAAS,EACT,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,kBAAkB,EAClB,SAAS,EACT,oBAAoB,GACvB,CAAA"}
|
|
1
|
+
{"version":3,"file":"baileyWrapper.d.ts","sourceRoot":"","sources":["../src/baileyWrapper.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,EAAE,EACtB,qBAAqB,EACrB,gBAAgB,EAChB,KAAK,EACL,2BAA2B,EAC3B,8BAA8B,EAC9B,QAAQ,EACR,eAAe,EACf,sBAAsB,EACtB,iBAAiB,EACjB,oBAAoB,EACpB,SAAS,EACT,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,SAAS,EACT,kBAAkB,EAClB,SAAS,EACT,oBAAoB,EACvB,MAAM,SAAS,CAAA;AAEhB,OAAO,EACH,iBAAiB,EACjB,qBAAqB,EACrB,gBAAgB,EAChB,KAAK,EACL,2BAA2B,EAC3B,8BAA8B,EAC9B,QAAQ,EACR,eAAe,EACf,sBAAsB,EACtB,iBAAiB,EACjB,oBAAoB,EACpB,SAAS,EACT,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,SAAS,EACT,kBAAkB,EAClB,SAAS,EACT,oBAAoB,GACvB,CAAA"}
|
package/dist/index.cjs
CHANGED
|
@@ -4226,19 +4226,24 @@ const emptyDirSessions = async (pathBase) => new Promise((resolve, reject) => {
|
|
|
4226
4226
|
});
|
|
4227
4227
|
});
|
|
4228
4228
|
/**
|
|
4229
|
-
* Cleans
|
|
4230
|
-
* @
|
|
4231
|
-
* @param
|
|
4232
|
-
* @returns
|
|
4229
|
+
* Cleans and normalizes a WhatsApp JID.
|
|
4230
|
+
* Supports @s.whatsapp.net, @g.us (groups), and @lid (Local Identifiers).
|
|
4231
|
+
* @param number - Raw JID or phone number
|
|
4232
|
+
* @param full - If true, strips the suffix and returns only the number/id part
|
|
4233
4233
|
*/
|
|
4234
4234
|
const baileyCleanNumber = (number, full = false) => {
|
|
4235
|
-
|
|
4236
|
-
|
|
4237
|
-
|
|
4235
|
+
if (!number)
|
|
4236
|
+
return '';
|
|
4237
|
+
// Groups: always return as-is
|
|
4238
|
+
if (number.includes('@g.us'))
|
|
4239
|
+
return number;
|
|
4240
|
+
// LID (Local Identifiers): always preserve the @lid suffix
|
|
4241
|
+
// so sendMessage/resolveNumber can detect and route correctly
|
|
4242
|
+
if (number.includes('@lid'))
|
|
4238
4243
|
return number;
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
return
|
|
4244
|
+
// Standard phone numbers
|
|
4245
|
+
const raw = number.replace('@s.whatsapp.net', '').replace('+', '').replace(/\s/g, '');
|
|
4246
|
+
return full ? raw : `${raw}@s.whatsapp.net`;
|
|
4242
4247
|
};
|
|
4243
4248
|
/**
|
|
4244
4249
|
* Generates an image from a base64 string.
|
|
@@ -34007,10 +34012,9 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
34007
34012
|
this.logger.log(`[${new Date().toISOString()}] Message received from phone, id=${messageCtx.requestId}`, messageCtx);
|
|
34008
34013
|
}
|
|
34009
34014
|
}
|
|
34010
|
-
//
|
|
34011
|
-
const remoteJid = messageCtx?.key
|
|
34012
|
-
const
|
|
34013
|
-
const fromParse = remoteJid?.includes('@lid') ? remoteJidAlt : remoteJid;
|
|
34015
|
+
// Preferir @s.whatsapp.net (remoteJidAlt) sobre @lid cuando esté disponible
|
|
34016
|
+
const { remoteJid, remoteJidAlt } = (messageCtx?.key ?? {});
|
|
34017
|
+
const fromParse = remoteJid?.includes('@lid') ? remoteJidAlt || remoteJid : remoteJid;
|
|
34014
34018
|
let payload = {
|
|
34015
34019
|
...messageCtx,
|
|
34016
34020
|
body: textToBody,
|
|
@@ -34183,17 +34187,11 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
34183
34187
|
};
|
|
34184
34188
|
/**
|
|
34185
34189
|
* Obtener LID (Local Identifier) para un número de teléfono (PN)
|
|
34186
|
-
* @param
|
|
34187
|
-
* @returns {Promise<string|null>} - El LID correspondiente o null si no se encuentra
|
|
34188
|
-
* @example await getLIDForPN('1234567890@s.whatsapp.net')
|
|
34190
|
+
* @param phoneNumber - JID con formato '1234567890@s.whatsapp.net'
|
|
34189
34191
|
*/
|
|
34190
34192
|
this.getLIDForPN = async (phoneNumber) => {
|
|
34191
34193
|
try {
|
|
34192
|
-
|
|
34193
|
-
if (vendor?.signalRepository?.lidMapping?.getLIDForPN) {
|
|
34194
|
-
return await vendor.signalRepository.lidMapping.getLIDForPN(phoneNumber);
|
|
34195
|
-
}
|
|
34196
|
-
return null;
|
|
34194
|
+
return (await this.lidMapping?.getLIDForPN?.(phoneNumber)) ?? null;
|
|
34197
34195
|
}
|
|
34198
34196
|
catch (e) {
|
|
34199
34197
|
this.logger.log(`[${new Date().toISOString()}] Error getting LID for PN:`, e);
|
|
@@ -34202,23 +34200,32 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
34202
34200
|
};
|
|
34203
34201
|
/**
|
|
34204
34202
|
* Obtener número de teléfono (PN) para un LID (Local Identifier)
|
|
34205
|
-
* @param
|
|
34206
|
-
* @returns {Promise<string|null>} - El número de teléfono correspondiente o null si no se encuentra
|
|
34207
|
-
* @example await getPNForLID('lid:xxxxxx')
|
|
34203
|
+
* @param lid - JID con formato '16424005304394@lid'
|
|
34208
34204
|
*/
|
|
34209
34205
|
this.getPNForLID = async (lid) => {
|
|
34210
34206
|
try {
|
|
34211
|
-
|
|
34212
|
-
if (vendor?.signalRepository?.lidMapping?.getPNForLID) {
|
|
34213
|
-
return await vendor.signalRepository.lidMapping.getPNForLID(lid);
|
|
34214
|
-
}
|
|
34215
|
-
return null;
|
|
34207
|
+
return (await this.lidMapping?.getPNForLID?.(lid)) ?? null;
|
|
34216
34208
|
}
|
|
34217
34209
|
catch (e) {
|
|
34218
34210
|
this.logger.log(`[${new Date().toISOString()}] Error getting PN for LID:`, e);
|
|
34219
34211
|
return null;
|
|
34220
34212
|
}
|
|
34221
34213
|
};
|
|
34214
|
+
/**
|
|
34215
|
+
* Normaliza un número entrante a un JID válido para envío.
|
|
34216
|
+
* Si es un @lid, intenta resolver a @s.whatsapp.net; si falla, envía al LID directamente.
|
|
34217
|
+
*/
|
|
34218
|
+
this.resolveNumber = async (numberIn) => {
|
|
34219
|
+
const jid = baileyCleanNumber(`${numberIn}`);
|
|
34220
|
+
if (!jid.includes('@lid'))
|
|
34221
|
+
return jid;
|
|
34222
|
+
const resolved = await this.getPNForLID(jid);
|
|
34223
|
+
if (resolved) {
|
|
34224
|
+
this.logger.log(`[${new Date().toISOString()}] LID resolved: ${jid} -> ${resolved}`);
|
|
34225
|
+
return baileyCleanNumber(resolved);
|
|
34226
|
+
}
|
|
34227
|
+
return jid;
|
|
34228
|
+
};
|
|
34222
34229
|
/**
|
|
34223
34230
|
* @param {string} number
|
|
34224
34231
|
* @param {string} message
|
|
@@ -34348,7 +34355,7 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
34348
34355
|
*/
|
|
34349
34356
|
this.sendMessage = async (numberIn, message, options) => {
|
|
34350
34357
|
options = { ...options, ...options['options'] };
|
|
34351
|
-
const number =
|
|
34358
|
+
const number = await this.resolveNumber(numberIn);
|
|
34352
34359
|
if (options.buttons?.length)
|
|
34353
34360
|
return this.sendButtons(number, message, options.buttons);
|
|
34354
34361
|
if (options.media)
|
|
@@ -34579,6 +34586,12 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
34579
34586
|
.get('/', this.indexHome);
|
|
34580
34587
|
}
|
|
34581
34588
|
afterHttpServerInit() { }
|
|
34589
|
+
/**
|
|
34590
|
+
* Accede al lidMapping del signalRepository de Baileys.
|
|
34591
|
+
*/
|
|
34592
|
+
get lidMapping() {
|
|
34593
|
+
return this.vendor?.signalRepository?.lidMapping ?? null;
|
|
34594
|
+
}
|
|
34582
34595
|
shouldReconnect(statusCode) {
|
|
34583
34596
|
// Lista de códigos donde SÍ debemos reconectar
|
|
34584
34597
|
const reconnectableCodes = [
|
|
@@ -34612,6 +34625,16 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
34612
34625
|
this.logger.log(`[${new Date().toISOString()}] Reconnection attempt ${this.reconnectAttempts}/${this.maxReconnectAttempts} in ${delay}ms`);
|
|
34613
34626
|
setTimeout(async () => {
|
|
34614
34627
|
try {
|
|
34628
|
+
// Cerrar el socket anterior para evitar conflictos de conexión (xml-not-well-formed)
|
|
34629
|
+
if (this.vendor) {
|
|
34630
|
+
try {
|
|
34631
|
+
this.vendor.ws?.close();
|
|
34632
|
+
this.vendor.end(new Error('Reconnecting'));
|
|
34633
|
+
}
|
|
34634
|
+
catch (e) {
|
|
34635
|
+
this.logger.log(`[${new Date().toISOString()}] Error closing previous socket:`, e);
|
|
34636
|
+
}
|
|
34637
|
+
}
|
|
34615
34638
|
this.initVendor().then((v) => this.listenOnEvents(v));
|
|
34616
34639
|
}
|
|
34617
34640
|
catch (error) {
|
package/dist/index.mjs
CHANGED
|
@@ -4224,19 +4224,24 @@ const emptyDirSessions = async (pathBase) => new Promise((resolve, reject) => {
|
|
|
4224
4224
|
});
|
|
4225
4225
|
});
|
|
4226
4226
|
/**
|
|
4227
|
-
* Cleans
|
|
4228
|
-
* @
|
|
4229
|
-
* @param
|
|
4230
|
-
* @returns
|
|
4227
|
+
* Cleans and normalizes a WhatsApp JID.
|
|
4228
|
+
* Supports @s.whatsapp.net, @g.us (groups), and @lid (Local Identifiers).
|
|
4229
|
+
* @param number - Raw JID or phone number
|
|
4230
|
+
* @param full - If true, strips the suffix and returns only the number/id part
|
|
4231
4231
|
*/
|
|
4232
4232
|
const baileyCleanNumber = (number, full = false) => {
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4233
|
+
if (!number)
|
|
4234
|
+
return '';
|
|
4235
|
+
// Groups: always return as-is
|
|
4236
|
+
if (number.includes('@g.us'))
|
|
4237
|
+
return number;
|
|
4238
|
+
// LID (Local Identifiers): always preserve the @lid suffix
|
|
4239
|
+
// so sendMessage/resolveNumber can detect and route correctly
|
|
4240
|
+
if (number.includes('@lid'))
|
|
4236
4241
|
return number;
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
return
|
|
4242
|
+
// Standard phone numbers
|
|
4243
|
+
const raw = number.replace('@s.whatsapp.net', '').replace('+', '').replace(/\s/g, '');
|
|
4244
|
+
return full ? raw : `${raw}@s.whatsapp.net`;
|
|
4240
4245
|
};
|
|
4241
4246
|
/**
|
|
4242
4247
|
* Generates an image from a base64 string.
|
|
@@ -34005,10 +34010,9 @@ class BaileysProvider extends ProviderClass {
|
|
|
34005
34010
|
this.logger.log(`[${new Date().toISOString()}] Message received from phone, id=${messageCtx.requestId}`, messageCtx);
|
|
34006
34011
|
}
|
|
34007
34012
|
}
|
|
34008
|
-
//
|
|
34009
|
-
const remoteJid = messageCtx?.key
|
|
34010
|
-
const
|
|
34011
|
-
const fromParse = remoteJid?.includes('@lid') ? remoteJidAlt : remoteJid;
|
|
34013
|
+
// Preferir @s.whatsapp.net (remoteJidAlt) sobre @lid cuando esté disponible
|
|
34014
|
+
const { remoteJid, remoteJidAlt } = (messageCtx?.key ?? {});
|
|
34015
|
+
const fromParse = remoteJid?.includes('@lid') ? remoteJidAlt || remoteJid : remoteJid;
|
|
34012
34016
|
let payload = {
|
|
34013
34017
|
...messageCtx,
|
|
34014
34018
|
body: textToBody,
|
|
@@ -34181,17 +34185,11 @@ class BaileysProvider extends ProviderClass {
|
|
|
34181
34185
|
};
|
|
34182
34186
|
/**
|
|
34183
34187
|
* Obtener LID (Local Identifier) para un número de teléfono (PN)
|
|
34184
|
-
* @param
|
|
34185
|
-
* @returns {Promise<string|null>} - El LID correspondiente o null si no se encuentra
|
|
34186
|
-
* @example await getLIDForPN('1234567890@s.whatsapp.net')
|
|
34188
|
+
* @param phoneNumber - JID con formato '1234567890@s.whatsapp.net'
|
|
34187
34189
|
*/
|
|
34188
34190
|
this.getLIDForPN = async (phoneNumber) => {
|
|
34189
34191
|
try {
|
|
34190
|
-
|
|
34191
|
-
if (vendor?.signalRepository?.lidMapping?.getLIDForPN) {
|
|
34192
|
-
return await vendor.signalRepository.lidMapping.getLIDForPN(phoneNumber);
|
|
34193
|
-
}
|
|
34194
|
-
return null;
|
|
34192
|
+
return (await this.lidMapping?.getLIDForPN?.(phoneNumber)) ?? null;
|
|
34195
34193
|
}
|
|
34196
34194
|
catch (e) {
|
|
34197
34195
|
this.logger.log(`[${new Date().toISOString()}] Error getting LID for PN:`, e);
|
|
@@ -34200,23 +34198,32 @@ class BaileysProvider extends ProviderClass {
|
|
|
34200
34198
|
};
|
|
34201
34199
|
/**
|
|
34202
34200
|
* Obtener número de teléfono (PN) para un LID (Local Identifier)
|
|
34203
|
-
* @param
|
|
34204
|
-
* @returns {Promise<string|null>} - El número de teléfono correspondiente o null si no se encuentra
|
|
34205
|
-
* @example await getPNForLID('lid:xxxxxx')
|
|
34201
|
+
* @param lid - JID con formato '16424005304394@lid'
|
|
34206
34202
|
*/
|
|
34207
34203
|
this.getPNForLID = async (lid) => {
|
|
34208
34204
|
try {
|
|
34209
|
-
|
|
34210
|
-
if (vendor?.signalRepository?.lidMapping?.getPNForLID) {
|
|
34211
|
-
return await vendor.signalRepository.lidMapping.getPNForLID(lid);
|
|
34212
|
-
}
|
|
34213
|
-
return null;
|
|
34205
|
+
return (await this.lidMapping?.getPNForLID?.(lid)) ?? null;
|
|
34214
34206
|
}
|
|
34215
34207
|
catch (e) {
|
|
34216
34208
|
this.logger.log(`[${new Date().toISOString()}] Error getting PN for LID:`, e);
|
|
34217
34209
|
return null;
|
|
34218
34210
|
}
|
|
34219
34211
|
};
|
|
34212
|
+
/**
|
|
34213
|
+
* Normaliza un número entrante a un JID válido para envío.
|
|
34214
|
+
* Si es un @lid, intenta resolver a @s.whatsapp.net; si falla, envía al LID directamente.
|
|
34215
|
+
*/
|
|
34216
|
+
this.resolveNumber = async (numberIn) => {
|
|
34217
|
+
const jid = baileyCleanNumber(`${numberIn}`);
|
|
34218
|
+
if (!jid.includes('@lid'))
|
|
34219
|
+
return jid;
|
|
34220
|
+
const resolved = await this.getPNForLID(jid);
|
|
34221
|
+
if (resolved) {
|
|
34222
|
+
this.logger.log(`[${new Date().toISOString()}] LID resolved: ${jid} -> ${resolved}`);
|
|
34223
|
+
return baileyCleanNumber(resolved);
|
|
34224
|
+
}
|
|
34225
|
+
return jid;
|
|
34226
|
+
};
|
|
34220
34227
|
/**
|
|
34221
34228
|
* @param {string} number
|
|
34222
34229
|
* @param {string} message
|
|
@@ -34346,7 +34353,7 @@ class BaileysProvider extends ProviderClass {
|
|
|
34346
34353
|
*/
|
|
34347
34354
|
this.sendMessage = async (numberIn, message, options) => {
|
|
34348
34355
|
options = { ...options, ...options['options'] };
|
|
34349
|
-
const number =
|
|
34356
|
+
const number = await this.resolveNumber(numberIn);
|
|
34350
34357
|
if (options.buttons?.length)
|
|
34351
34358
|
return this.sendButtons(number, message, options.buttons);
|
|
34352
34359
|
if (options.media)
|
|
@@ -34577,6 +34584,12 @@ class BaileysProvider extends ProviderClass {
|
|
|
34577
34584
|
.get('/', this.indexHome);
|
|
34578
34585
|
}
|
|
34579
34586
|
afterHttpServerInit() { }
|
|
34587
|
+
/**
|
|
34588
|
+
* Accede al lidMapping del signalRepository de Baileys.
|
|
34589
|
+
*/
|
|
34590
|
+
get lidMapping() {
|
|
34591
|
+
return this.vendor?.signalRepository?.lidMapping ?? null;
|
|
34592
|
+
}
|
|
34580
34593
|
shouldReconnect(statusCode) {
|
|
34581
34594
|
// Lista de códigos donde SÍ debemos reconectar
|
|
34582
34595
|
const reconnectableCodes = [
|
|
@@ -34610,6 +34623,16 @@ class BaileysProvider extends ProviderClass {
|
|
|
34610
34623
|
this.logger.log(`[${new Date().toISOString()}] Reconnection attempt ${this.reconnectAttempts}/${this.maxReconnectAttempts} in ${delay}ms`);
|
|
34611
34624
|
setTimeout(async () => {
|
|
34612
34625
|
try {
|
|
34626
|
+
// Cerrar el socket anterior para evitar conflictos de conexión (xml-not-well-formed)
|
|
34627
|
+
if (this.vendor) {
|
|
34628
|
+
try {
|
|
34629
|
+
this.vendor.ws?.close();
|
|
34630
|
+
this.vendor.end(new Error('Reconnecting'));
|
|
34631
|
+
}
|
|
34632
|
+
catch (e) {
|
|
34633
|
+
this.logger.log(`[${new Date().toISOString()}] Error closing previous socket:`, e);
|
|
34634
|
+
}
|
|
34635
|
+
}
|
|
34613
34636
|
this.initVendor().then((v) => this.listenOnEvents(v));
|
|
34614
34637
|
}
|
|
34615
34638
|
catch (error) {
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
declare const emptyDirSessions: (pathBase: string) => Promise<unknown>;
|
|
2
2
|
/**
|
|
3
|
-
* Cleans
|
|
4
|
-
* @
|
|
5
|
-
* @param
|
|
6
|
-
* @returns
|
|
3
|
+
* Cleans and normalizes a WhatsApp JID.
|
|
4
|
+
* Supports @s.whatsapp.net, @g.us (groups), and @lid (Local Identifiers).
|
|
5
|
+
* @param number - Raw JID or phone number
|
|
6
|
+
* @param full - If true, strips the suffix and returns only the number/id part
|
|
7
7
|
*/
|
|
8
8
|
declare const baileyCleanNumber: (number: string, full?: boolean) => string;
|
|
9
9
|
/**
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAMA,QAAA,MAAM,gBAAgB,GAAU,UAAU,MAAM,qBAM1C,CAAA;AACN;;;;;GAKG;AACH,QAAA,MAAM,iBAAiB,GAAI,QAAQ,MAAM,EAAE,OAAM,OAAe,KAAG,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAMA,QAAA,MAAM,gBAAgB,GAAU,UAAU,MAAM,qBAM1C,CAAA;AACN;;;;;GAKG;AACH,QAAA,MAAM,iBAAiB,GAAI,QAAQ,MAAM,EAAE,OAAM,OAAe,KAAG,MAalE,CAAA;AAED;;;;GAIG;AACH,QAAA,MAAM,mBAAmB,GAAU,QAAQ,MAAM,EAAE,OAAM,MAAiB,KAAG,OAAO,CAAC,IAAI,CAaxF,CAAA;AAED;;;;GAIG;AACH,QAAA,MAAM,mBAAmB,GAAI,WAAW,MAAM,KAAG,OAKhD,CAAA;AAED,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@builderbot/provider-baileys",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
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>",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"homepage": "https://github.com/codigoencasa/bot-whatsapp#readme",
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@builderbot/bot": "^1.
|
|
41
|
+
"@builderbot/bot": "^1.4.0",
|
|
42
42
|
"@hapi/boom": "^10.0.1",
|
|
43
43
|
"@jest/globals": "^30.2.0",
|
|
44
44
|
"@rollup/plugin-commonjs": "^29.0.0",
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
"node-cache": "^5.1.2",
|
|
78
78
|
"sharp": "0.33.3"
|
|
79
79
|
},
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "219d5d17d93a0b98656659f9c31355e8fb07318c"
|
|
81
81
|
}
|