@pontalabs/baileys 1.0.11 → 1.1.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 +96 -85
- package/lib/Defaults/connection.js +39 -0
- package/lib/Defaults/constants.js +50 -0
- package/lib/Defaults/history.js +13 -0
- package/lib/Defaults/index.js +36 -151
- package/lib/Defaults/media.js +43 -0
- package/lib/Defaults/phonenumber-mcc.json +221 -221
- package/lib/Defaults/prefix.js +12 -0
- package/lib/Defaults/vialeys-version.json +7 -0
- package/lib/Signal/Group/ciphertext-message.js +10 -15
- package/lib/Signal/Group/group-session-builder.js +34 -60
- package/lib/Signal/Group/group_cipher.js +69 -76
- package/lib/Signal/Group/index.js +41 -60
- package/lib/Signal/Group/keyhelper.js +12 -57
- package/lib/Signal/Group/sender-chain-key.js +20 -33
- package/lib/Signal/Group/sender-key-distribution-message.js +43 -48
- package/lib/Signal/Group/sender-key-message.js +58 -53
- package/lib/Signal/Group/sender-key-name.js +21 -31
- package/lib/Signal/Group/sender-key-record.js +21 -34
- package/lib/Signal/Group/sender-key-state.js +59 -106
- package/lib/Signal/Group/sender-message-key.js +16 -21
- package/lib/Signal/libsignal.js +282 -203
- package/lib/Signal/lid-mapping.js +164 -184
- package/lib/Socket/Client/index.js +31 -22
- package/lib/Socket/Client/types.js +9 -15
- package/lib/Socket/Client/websocket.js +42 -37
- package/lib/Socket/business.js +212 -336
- package/lib/Socket/chats.js +696 -940
- package/lib/Socket/community.js +454 -369
- package/lib/Socket/groups.js +278 -280
- package/lib/Socket/index.js +9 -21
- package/lib/Socket/messages-recv.js +1027 -1570
- package/lib/Socket/messages-send.js +1180 -1136
- package/lib/Socket/mex.js +59 -0
- package/lib/Socket/newsletter.js +193 -251
- package/lib/Socket/socket.js +758 -898
- package/lib/Store/index.js +35 -24
- package/lib/Store/make-cache-manager-store.js +53 -66
- package/lib/Store/make-in-memory-store.js +319 -325
- package/lib/Store/make-ordered-dictionary.js +49 -57
- package/lib/Store/object-repository.js +10 -15
- package/lib/Types/Auth.js +2 -3
- package/lib/Types/Bussines.js +2 -3
- package/lib/Types/Call.js +2 -3
- package/lib/Types/Chat.js +10 -9
- package/lib/Types/Contact.js +2 -3
- package/lib/Types/Events.js +2 -3
- package/lib/Types/GroupMetadata.js +2 -3
- package/lib/Types/Label.js +6 -12
- package/lib/Types/LabelAssociation.js +4 -13
- package/lib/Types/Message.js +10 -18
- package/lib/Types/MexUpdates.js +15 -18
- package/lib/Types/Newsletter.js +26 -34
- package/lib/Types/Product.js +2 -3
- package/lib/Types/Signal.js +2 -3
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.js +8 -13
- package/lib/Types/USync.js +2 -3
- package/lib/Types/index.js +49 -40
- package/lib/Utils/auth-utils.js +190 -495
- package/lib/Utils/browser-utils.js +29 -0
- package/lib/Utils/business.js +177 -199
- package/lib/Utils/chat-utils.js +711 -624
- package/lib/Utils/crypto.js +116 -161
- package/lib/Utils/decode-wa-message.js +225 -321
- package/lib/Utils/event-buffer.js +363 -405
- package/lib/Utils/generics.js +318 -472
- package/lib/Utils/history.js +72 -76
- package/lib/Utils/index.js +49 -41
- package/lib/Utils/link-preview.js +59 -103
- package/lib/Utils/logger.js +4 -7
- package/lib/Utils/lt-hash.js +29 -42
- package/lib/Utils/make-mutex.js +26 -42
- package/lib/Utils/message-retry-manager.js +134 -160
- package/lib/Utils/messages-media.js +665 -731
- package/lib/Utils/messages.js +518 -1
- package/lib/Utils/noise-handler.js +127 -125
- package/lib/Utils/pre-key-manager.js +86 -0
- package/lib/Utils/process-message.js +739 -351
- package/lib/Utils/signal.js +146 -129
- package/lib/Utils/use-multi-file-auth-state.js +68 -135
- package/lib/Utils/validate-connection.js +183 -142
- package/lib/Utils/vialeys-event-stream.js +41 -0
- package/lib/WABinary/constants.js +1281 -1289
- package/lib/WABinary/decode.js +145 -200
- package/lib/WABinary/encode.js +149 -202
- package/lib/WABinary/generic-utils.js +79 -97
- package/lib/WABinary/index.js +36 -25
- package/lib/WABinary/jid-utils.js +91 -123
- package/lib/WABinary/types.js +2 -3
- package/lib/WAM/BinaryInfo.js +8 -13
- package/lib/WAM/constants.js +16584 -11464
- package/lib/WAM/encode.js +117 -133
- package/lib/WAM/index.js +34 -23
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +62 -69
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +11 -25
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +32 -44
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +13 -23
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +24 -38
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +17 -31
- package/lib/WAUSync/Protocols/index.js +37 -26
- package/lib/WAUSync/USyncQuery.js +66 -66
- package/lib/WAUSync/USyncUser.js +13 -18
- package/lib/WAUSync/index.js +34 -23
- package/lib/index.js +95 -28
- package/package.json +2 -1
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Socket/usync.d.ts +0 -37
- package/lib/Socket/usync.js +0 -83
- package/lib/Utils/baileys-event-stream.d.ts +0 -18
- package/lib/Utils/baileys-event-stream.js +0 -70
- package/lib/Utils/signal-housekeeping.d.ts +0 -19
- package/lib/Utils/signal-housekeeping.js +0 -73
- package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
- package/lib/Utils/use-mongo-file-auth-state.js +0 -84
- package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
- package/lib/Utils/use-single-file-auth-state.js +0 -80
package/lib/WABinary/index.js
CHANGED
|
@@ -1,25 +1,36 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
__exportStar
|
|
23
|
-
__exportStar
|
|
24
|
-
|
|
25
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
const __createBinding =
|
|
3
|
+
(this && this.__createBinding) ||
|
|
4
|
+
(Object.create
|
|
5
|
+
? function (o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
let desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return m[k];
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc);
|
|
17
|
+
}
|
|
18
|
+
: function (o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
o[k2] = m[k];
|
|
21
|
+
});
|
|
22
|
+
const __exportStar =
|
|
23
|
+
(this && this.__exportStar) ||
|
|
24
|
+
function (m, exports) {
|
|
25
|
+
for (var p in m) {
|
|
26
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) {
|
|
27
|
+
__createBinding(exports, m, p);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
__exportStar(require("./encode"), exports);
|
|
33
|
+
__exportStar(require("./decode"), exports);
|
|
34
|
+
__exportStar(require("./generic-utils"), exports);
|
|
35
|
+
__exportStar(require("./jid-utils"), exports);
|
|
36
|
+
__exportStar(require("./types"), exports);
|
|
@@ -1,133 +1,101 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const S_WHATSAPP_NET = "@s.whatsapp.net";
|
|
4
|
+
const OFFICIAL_BIZ_JID = "16505361212@c.us";
|
|
5
|
+
const SERVER_JID = "server@c.us";
|
|
6
|
+
const PSA_WID = "0@c.us";
|
|
7
|
+
const STORIES_JID = "status@broadcast";
|
|
8
|
+
const META_AI_JID = "13135550002@c.us";
|
|
9
|
+
const WAJIDDomains = { WHATSAPP: 0, LID: 1, HOSTED: 128, HOSTED_LID: 129 };
|
|
10
|
+
const getServerFromDomainType = (initialServer, domainType) => {
|
|
11
|
+
switch (domainType) {
|
|
12
|
+
case WAJIDDomains.LID:
|
|
13
|
+
return "lid";
|
|
14
|
+
case WAJIDDomains.HOSTED:
|
|
15
|
+
return "hosted";
|
|
16
|
+
case WAJIDDomains.HOSTED_LID:
|
|
17
|
+
return "hosted.lid";
|
|
18
|
+
case WAJIDDomains.WHATSAPP:
|
|
19
|
+
default:
|
|
20
|
+
return initialServer;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const jidEncode = (user, server, device, agent) =>
|
|
24
|
+
`${user || ""}${!!agent ? `_${agent}` : ""}${!!device ? `:${device}` : ""}@${server}`;
|
|
21
25
|
const jidDecode = (jid) => {
|
|
22
|
-
const sepIdx = typeof jid ===
|
|
26
|
+
const sepIdx = typeof jid === "string" ? jid.indexOf("@") : -1;
|
|
23
27
|
if (sepIdx < 0) {
|
|
24
|
-
return undefined
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
const server = jid.slice(sepIdx + 1);
|
|
31
|
+
const userCombined = jid.slice(0, sepIdx);
|
|
32
|
+
const [userAgent, device] = userCombined.split(":");
|
|
33
|
+
const [user, agent] = userAgent.split("_");
|
|
34
|
+
let domainType = WAJIDDomains.WHATSAPP;
|
|
35
|
+
if (server === "lid") {
|
|
36
|
+
domainType = WAJIDDomains.LID;
|
|
37
|
+
} else if (server === "hosted") {
|
|
38
|
+
domainType = WAJIDDomains.HOSTED;
|
|
39
|
+
} else if (server === "hosted.lid") {
|
|
40
|
+
domainType = WAJIDDomains.HOSTED_LID;
|
|
41
|
+
} else if (agent) {
|
|
42
|
+
domainType = parseInt(agent);
|
|
25
43
|
}
|
|
26
|
-
const server = jid.slice(sepIdx + 1)
|
|
27
|
-
const userCombined = jid.slice(0, sepIdx)
|
|
28
|
-
const [userAgent, device] = userCombined.split(':')
|
|
29
|
-
const user = userAgent.split('_')[0]
|
|
30
44
|
return {
|
|
31
45
|
server: server,
|
|
32
|
-
user,
|
|
33
|
-
domainType:
|
|
34
|
-
device: device ? +device : undefined
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
/** is the lid a user */
|
|
50
|
-
const isLidUser = (jid) => jid?.endsWith('@lid')
|
|
51
|
-
|
|
52
|
-
/** is the jid a broadcast */
|
|
53
|
-
const isJidBroadcast = (jid) => jid?.endsWith('@broadcast')
|
|
54
|
-
|
|
55
|
-
/** is the jid a group */
|
|
56
|
-
const isJidGroup = (jid) => jid?.endsWith('@g.us')
|
|
57
|
-
|
|
58
|
-
/** is the jid the status broadcast */
|
|
59
|
-
const isJidStatusBroadcast = (jid) => jid === 'status@broadcast'
|
|
60
|
-
|
|
61
|
-
/** is the jid a newsletter */
|
|
62
|
-
const isJidNewsletter = (jid) => jid?.endsWith('@newsletter')
|
|
63
|
-
|
|
64
|
-
/** is the jid a bot */
|
|
65
|
-
const botRegexp = /^1313555\d{4}$|^131655500\d{2}$/
|
|
66
|
-
const isJidBot = (jid) => (jid && botRegexp.test(jid.split('@')[0]) && jid.endsWith('@c.us'))
|
|
67
|
-
|
|
46
|
+
user: user,
|
|
47
|
+
domainType: domainType,
|
|
48
|
+
device: device ? +device : undefined,
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
const areJidsSameUser = (jid1, jid2) => jidDecode(jid1)?.user === jidDecode(jid2)?.user;
|
|
52
|
+
const isJidMetaAI = (jid) => jid?.endsWith("@bot");
|
|
53
|
+
const isPnUser = (jid) => jid?.endsWith("@s.whatsapp.net");
|
|
54
|
+
const isLidUser = (jid) => jid?.endsWith("@lid");
|
|
55
|
+
const isJidBroadcast = (jid) => jid?.endsWith("@broadcast");
|
|
56
|
+
const isJidGroup = (jid) => jid?.endsWith("@g.us");
|
|
57
|
+
const isJidStatusBroadcast = (jid) => jid === "status@broadcast";
|
|
58
|
+
const isJidNewsletter = (jid) => jid?.endsWith("@newsletter");
|
|
59
|
+
const isHostedPnUser = (jid) => jid?.endsWith("@hosted");
|
|
60
|
+
const isHostedLidUser = (jid) => jid?.endsWith("@hosted.lid");
|
|
61
|
+
const botRegexp = /^1313555\d{4}$|^131655500\d{2}$/;
|
|
62
|
+
const isJidBot = (jid) => jid && botRegexp.test(jid.split("@")[0]) && jid.endsWith("@c.us");
|
|
68
63
|
const jidNormalizedUser = (jid) => {
|
|
69
|
-
const result = jidDecode(jid)
|
|
64
|
+
const result = jidDecode(jid);
|
|
70
65
|
if (!result) {
|
|
71
|
-
return
|
|
66
|
+
return "";
|
|
72
67
|
}
|
|
73
|
-
const { user, server } = result
|
|
74
|
-
return jidEncode(user, server ===
|
|
75
|
-
}
|
|
76
|
-
|
|
68
|
+
const { user: user, server: server } = result;
|
|
69
|
+
return jidEncode(user, server === "c.us" ? "s.whatsapp.net" : server);
|
|
70
|
+
};
|
|
77
71
|
const transferDevice = (fromJid, toJid) => {
|
|
78
|
-
const fromDecoded = jidDecode(fromJid)
|
|
79
|
-
const deviceId = fromDecoded?.device || 0
|
|
80
|
-
const { server, user } = jidDecode(toJid)
|
|
81
|
-
return jidEncode(user, server, deviceId)
|
|
82
|
-
}
|
|
83
|
-
|
|
72
|
+
const fromDecoded = jidDecode(fromJid);
|
|
73
|
+
const deviceId = fromDecoded?.device || 0;
|
|
74
|
+
const { server: server, user: user } = jidDecode(toJid);
|
|
75
|
+
return jidEncode(user, server, deviceId);
|
|
76
|
+
};
|
|
84
77
|
module.exports = {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
* Mendapatkan JID pengirim sebenarnya dari sebuah pesan.
|
|
110
|
-
* Aman digunakan untuk private chat maupun group.
|
|
111
|
-
*
|
|
112
|
-
* Cara pakai di bot:
|
|
113
|
-
* const { getSenderJid, areJidsSameUser } = require('@whiskeysockets/baileys')
|
|
114
|
-
* const sender = getSenderJid(msg)
|
|
115
|
-
* if (areJidsSameUser(sender, ownerNumber)) { ... }
|
|
116
|
-
*
|
|
117
|
-
* @param {object} msg - objek WebMessageInfo dari event messages.upsert
|
|
118
|
-
* @returns {string} JID pengirim yang sudah dinormalisasi
|
|
119
|
-
*/
|
|
120
|
-
const getSenderJid = (msg) => {
|
|
121
|
-
const key = msg?.key
|
|
122
|
-
if (!key) return ''
|
|
123
|
-
// Pesan dari bot sendiri: remoteJid adalah lawan bicara
|
|
124
|
-
if (key.fromMe) return jidNormalizedUser(key.remoteJid)
|
|
125
|
-
// Group / broadcast: gunakan participant
|
|
126
|
-
if (isJidGroup(key.remoteJid) || isJidBroadcast(key.remoteJid)) {
|
|
127
|
-
return jidNormalizedUser(key.participant || key.remoteJid)
|
|
128
|
-
}
|
|
129
|
-
// Private chat: pengirim adalah remoteJid itu sendiri
|
|
130
|
-
return jidNormalizedUser(key.remoteJid)
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
exports.getSenderJid = getSenderJid
|
|
78
|
+
S_WHATSAPP_NET: S_WHATSAPP_NET,
|
|
79
|
+
OFFICIAL_BIZ_JID: OFFICIAL_BIZ_JID,
|
|
80
|
+
SERVER_JID: SERVER_JID,
|
|
81
|
+
PSA_WID: PSA_WID,
|
|
82
|
+
STORIES_JID: STORIES_JID,
|
|
83
|
+
META_AI_JID: META_AI_JID,
|
|
84
|
+
WAJIDDomains: WAJIDDomains,
|
|
85
|
+
jidEncode: jidEncode,
|
|
86
|
+
jidDecode: jidDecode,
|
|
87
|
+
areJidsSameUser: areJidsSameUser,
|
|
88
|
+
isJidMetaAI: isJidMetaAI,
|
|
89
|
+
isPnUser: isPnUser,
|
|
90
|
+
isLidUser: isLidUser,
|
|
91
|
+
isJidBroadcast: isJidBroadcast,
|
|
92
|
+
isJidGroup: isJidGroup,
|
|
93
|
+
isJidStatusBroadcast: isJidStatusBroadcast,
|
|
94
|
+
isJidNewsletter: isJidNewsletter,
|
|
95
|
+
isHostedPnUser: isHostedPnUser,
|
|
96
|
+
isHostedLidUser: isHostedLidUser,
|
|
97
|
+
isJidBot: isJidBot,
|
|
98
|
+
transferDevice: transferDevice,
|
|
99
|
+
jidNormalizedUser: jidNormalizedUser,
|
|
100
|
+
getServerFromDomainType: getServerFromDomainType,
|
|
101
|
+
};
|
package/lib/WABinary/types.js
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true })
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/lib/WAM/BinaryInfo.js
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
3
|
class BinaryInfo {
|
|
6
4
|
constructor(options = {}) {
|
|
7
|
-
this.protocolVersion = 5
|
|
8
|
-
this.sequence = 0
|
|
9
|
-
this.events = []
|
|
10
|
-
this.buffer = []
|
|
11
|
-
Object.assign(this, options)
|
|
5
|
+
this.protocolVersion = 5;
|
|
6
|
+
this.sequence = 0;
|
|
7
|
+
this.events = [];
|
|
8
|
+
this.buffer = [];
|
|
9
|
+
Object.assign(this, options);
|
|
12
10
|
}
|
|
13
11
|
}
|
|
14
|
-
|
|
15
|
-
module.exports = {
|
|
16
|
-
BinaryInfo
|
|
17
|
-
}
|
|
12
|
+
module.exports = { BinaryInfo: BinaryInfo };
|