@ellxz24/baileys 2.0.30 → 2.0.31
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/lib/WABinary/jid-utils.js +107 -41
- package/lib/WABinary/jid-utils.js.bak +62 -0
- package/package.json +1 -1
|
@@ -1,62 +1,128 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.jidNormalizedUser = exports.isJidNewsLetter = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidBroadcast = exports.isLidUser = exports.isJidUser = exports.areJidsSameUser = exports.jidDecode = exports.jidEncode = exports.
|
|
4
|
-
|
|
5
|
-
exports.OFFICIAL_BIZ_JID =
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
8
|
-
exports.
|
|
3
|
+
exports.transferDevice = exports.jidNormalizedUser = exports.isJidBot = exports.isHostedLidUser = exports.isHostedPnUser = exports.isJidNewsletter = exports.isJidNewsLetter = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidBroadcast = exports.isLidUser = exports.isPnUser = exports.isJidUser = exports.isJidMetaAI = exports.areJidsSameUser = exports.jidDecode = exports.jidEncode = exports.getServerFromDomainType = exports.WAJIDDomains = exports.PSA_WID = exports.SERVER_JID = exports.META_AI_JID = exports.STORIES_JID = exports.S_WHATSAPP_NET = exports.OFFICIAL_BIZ_JID = void 0;
|
|
4
|
+
|
|
5
|
+
exports.OFFICIAL_BIZ_JID = "16505361212@c.us";
|
|
6
|
+
exports.S_WHATSAPP_NET = "@s.whatsapp.net";
|
|
7
|
+
exports.STORIES_JID = "status@broadcast";
|
|
8
|
+
exports.META_AI_JID = "13135550002@c.us";
|
|
9
|
+
exports.SERVER_JID = "server@c.us";
|
|
10
|
+
exports.PSA_WID = "0@c.us";
|
|
11
|
+
|
|
12
|
+
var WAJIDDomains;
|
|
13
|
+
(function (WAJIDDomains) {
|
|
14
|
+
WAJIDDomains[WAJIDDomains["WHATSAPP"] = 0] = "WHATSAPP";
|
|
15
|
+
WAJIDDomains[WAJIDDomains["LID"] = 1] = "LID";
|
|
16
|
+
WAJIDDomains[WAJIDDomains["HOSTED"] = 128] = "HOSTED";
|
|
17
|
+
WAJIDDomains[WAJIDDomains["HOSTED_LID"] = 129] = "HOSTED_LID";
|
|
18
|
+
})(WAJIDDomains || (exports.WAJIDDomains = WAJIDDomains = {}));
|
|
19
|
+
|
|
20
|
+
const getServerFromDomainType = (initialServer, domainType) => {
|
|
21
|
+
switch (domainType) {
|
|
22
|
+
case WAJIDDomains.LID:
|
|
23
|
+
return "lid";
|
|
24
|
+
case WAJIDDomains.HOSTED:
|
|
25
|
+
return "hosted";
|
|
26
|
+
case WAJIDDomains.HOSTED_LID:
|
|
27
|
+
return "hosted.lid";
|
|
28
|
+
case WAJIDDomains.WHATSAPP:
|
|
29
|
+
default:
|
|
30
|
+
return initialServer;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
exports.getServerFromDomainType = getServerFromDomainType;
|
|
34
|
+
|
|
9
35
|
const jidEncode = (user, server, device, agent) => {
|
|
10
|
-
|
|
36
|
+
return `${user || ""}${!!agent ? `_${agent}` : ""}${!!device ? `:${device}` : ""}@${server}`;
|
|
11
37
|
};
|
|
12
38
|
exports.jidEncode = jidEncode;
|
|
39
|
+
|
|
13
40
|
const jidDecode = (jid) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
41
|
+
const sepIdx = typeof jid === "string" ? jid.indexOf("@") : -1;
|
|
42
|
+
if (sepIdx < 0) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
const server = jid.slice(sepIdx + 1);
|
|
46
|
+
const userCombined = jid.slice(0, sepIdx);
|
|
47
|
+
const [userAgent, device] = userCombined.split(":");
|
|
48
|
+
const [user, agent] = userAgent.split("_");
|
|
49
|
+
let domainType = WAJIDDomains.WHATSAPP;
|
|
50
|
+
if (server === "lid") {
|
|
51
|
+
domainType = WAJIDDomains.LID;
|
|
52
|
+
}
|
|
53
|
+
else if (server === "hosted") {
|
|
54
|
+
domainType = WAJIDDomains.HOSTED;
|
|
55
|
+
}
|
|
56
|
+
else if (server === "hosted.lid") {
|
|
57
|
+
domainType = WAJIDDomains.HOSTED_LID;
|
|
58
|
+
}
|
|
59
|
+
else if (agent) {
|
|
60
|
+
domainType = parseInt(agent);
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
server: server,
|
|
64
|
+
user: user,
|
|
65
|
+
domainType,
|
|
66
|
+
device: device ? +device : undefined
|
|
67
|
+
};
|
|
28
68
|
};
|
|
29
69
|
exports.jidDecode = jidDecode;
|
|
30
|
-
|
|
70
|
+
|
|
31
71
|
const areJidsSameUser = (jid1, jid2) => {
|
|
32
72
|
var _a, _b;
|
|
33
73
|
return (((_a = (0, exports.jidDecode)(jid1)) === null || _a === void 0 ? void 0 : _a.user) === ((_b = (0, exports.jidDecode)(jid2)) === null || _b === void 0 ? void 0 : _b.user));
|
|
34
74
|
};
|
|
35
75
|
exports.areJidsSameUser = areJidsSameUser;
|
|
36
|
-
|
|
37
|
-
const
|
|
76
|
+
|
|
77
|
+
const isJidMetaAI = (jid) => jid === null || jid === void 0 ? void 0 : jid.endsWith("@bot");
|
|
78
|
+
exports.isJidMetaAI = isJidMetaAI;
|
|
79
|
+
|
|
80
|
+
const isJidUser = (jid) => jid === null || jid === void 0 ? void 0 : jid.endsWith("@s.whatsapp.net");
|
|
38
81
|
exports.isJidUser = isJidUser;
|
|
39
|
-
|
|
40
|
-
const
|
|
82
|
+
|
|
83
|
+
const isPnUser = (jid) => jid === null || jid === void 0 ? void 0 : jid.endsWith("@s.whatsapp.net");
|
|
84
|
+
exports.isPnUser = isPnUser;
|
|
85
|
+
|
|
86
|
+
const isLidUser = (jid) => jid === null || jid === void 0 ? void 0 : jid.endsWith("@lid");
|
|
41
87
|
exports.isLidUser = isLidUser;
|
|
42
|
-
|
|
43
|
-
const isJidBroadcast = (jid) =>
|
|
88
|
+
|
|
89
|
+
const isJidBroadcast = (jid) => jid === null || jid === void 0 ? void 0 : jid.endsWith("@broadcast");
|
|
44
90
|
exports.isJidBroadcast = isJidBroadcast;
|
|
45
|
-
|
|
46
|
-
const isJidGroup = (jid) =>
|
|
91
|
+
|
|
92
|
+
const isJidGroup = (jid) => jid === null || jid === void 0 ? void 0 : jid.endsWith("@g.us");
|
|
47
93
|
exports.isJidGroup = isJidGroup;
|
|
48
|
-
|
|
49
|
-
const isJidStatusBroadcast = (jid) => jid ===
|
|
94
|
+
|
|
95
|
+
const isJidStatusBroadcast = (jid) => jid === "status@broadcast";
|
|
50
96
|
exports.isJidStatusBroadcast = isJidStatusBroadcast;
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
exports.
|
|
97
|
+
|
|
98
|
+
const isJidNewsletter = (jid) => jid === null || jid === void 0 ? void 0 : jid.endsWith("@newsletter");
|
|
99
|
+
exports.isJidNewsletter = isJidNewsletter;
|
|
100
|
+
exports.isJidNewsLetter = isJidNewsletter;
|
|
101
|
+
|
|
102
|
+
const isHostedPnUser = (jid) => jid === null || jid === void 0 ? void 0 : jid.endsWith("@hosted");
|
|
103
|
+
exports.isHostedPnUser = isHostedPnUser;
|
|
104
|
+
|
|
105
|
+
const isHostedLidUser = (jid) => jid === null || jid === void 0 ? void 0 : jid.endsWith("@hosted.lid");
|
|
106
|
+
exports.isHostedLidUser = isHostedLidUser;
|
|
107
|
+
|
|
108
|
+
const botRegexp = /^1313555\d{4}$|^131655500\d{2}$/;
|
|
109
|
+
const isJidBot = (jid) => jid && botRegexp.test(jid.split("@")[0]) && jid.endsWith("@c.us");
|
|
110
|
+
exports.isJidBot = isJidBot;
|
|
111
|
+
|
|
54
112
|
const jidNormalizedUser = (jid) => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
113
|
+
const result = (0, exports.jidDecode)(jid);
|
|
114
|
+
if (!result) {
|
|
115
|
+
return "";
|
|
116
|
+
}
|
|
117
|
+
const { user, server } = result;
|
|
118
|
+
return (0, exports.jidEncode)(user, server === "c.us" ? "s.whatsapp.net" : server);
|
|
61
119
|
};
|
|
62
120
|
exports.jidNormalizedUser = jidNormalizedUser;
|
|
121
|
+
|
|
122
|
+
const transferDevice = (fromJid, toJid) => {
|
|
123
|
+
const fromDecoded = (0, exports.jidDecode)(fromJid);
|
|
124
|
+
const deviceId = (fromDecoded === null || fromDecoded === void 0 ? void 0 : fromDecoded.device) || 0;
|
|
125
|
+
const { server, user } = (0, exports.jidDecode)(toJid);
|
|
126
|
+
return (0, exports.jidEncode)(user, server, deviceId);
|
|
127
|
+
};
|
|
128
|
+
exports.transferDevice = transferDevice;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.jidNormalizedUser = exports.isJidNewsLetter = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidBroadcast = exports.isLidUser = exports.isJidUser = exports.areJidsSameUser = exports.jidDecode = exports.jidEncode = exports.STORIES_JID = exports.PSA_WID = exports.SERVER_JID = exports.OFFICIAL_BIZ_JID = exports.S_WHATSAPP_NET = void 0;
|
|
4
|
+
exports.S_WHATSAPP_NET = '@s.whatsapp.net';
|
|
5
|
+
exports.OFFICIAL_BIZ_JID = '16505361212@c.us';
|
|
6
|
+
exports.SERVER_JID = 'server@c.us';
|
|
7
|
+
exports.PSA_WID = '0@c.us';
|
|
8
|
+
exports.STORIES_JID = 'status@broadcast';
|
|
9
|
+
const jidEncode = (user, server, device, agent) => {
|
|
10
|
+
return `${user || ''}${!!agent ? `_${agent}` : ''}${!!device ? `:${device}` : ''}@${server}`;
|
|
11
|
+
};
|
|
12
|
+
exports.jidEncode = jidEncode;
|
|
13
|
+
const jidDecode = (jid) => {
|
|
14
|
+
const sepIdx = typeof jid === 'string' ? jid.indexOf('@') : -1;
|
|
15
|
+
if (sepIdx < 0) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
const server = jid.slice(sepIdx + 1);
|
|
19
|
+
const userCombined = jid.slice(0, sepIdx);
|
|
20
|
+
const [userAgent, device] = userCombined.split(':');
|
|
21
|
+
const user = userAgent.split('_')[0];
|
|
22
|
+
return {
|
|
23
|
+
server,
|
|
24
|
+
user,
|
|
25
|
+
domainType: server === 'lid' ? 1 : 0,
|
|
26
|
+
device: device ? +device : undefined
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
exports.jidDecode = jidDecode;
|
|
30
|
+
/** is the jid a user */
|
|
31
|
+
const areJidsSameUser = (jid1, jid2) => {
|
|
32
|
+
var _a, _b;
|
|
33
|
+
return (((_a = (0, exports.jidDecode)(jid1)) === null || _a === void 0 ? void 0 : _a.user) === ((_b = (0, exports.jidDecode)(jid2)) === null || _b === void 0 ? void 0 : _b.user));
|
|
34
|
+
};
|
|
35
|
+
exports.areJidsSameUser = areJidsSameUser;
|
|
36
|
+
/** is the jid a user */
|
|
37
|
+
const isJidUser = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@s.whatsapp.net'));
|
|
38
|
+
exports.isJidUser = isJidUser;
|
|
39
|
+
/** is the jid a group */
|
|
40
|
+
const isLidUser = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@lid'));
|
|
41
|
+
exports.isLidUser = isLidUser;
|
|
42
|
+
/** is the jid a broadcast */
|
|
43
|
+
const isJidBroadcast = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@broadcast'));
|
|
44
|
+
exports.isJidBroadcast = isJidBroadcast;
|
|
45
|
+
/** is the jid a group */
|
|
46
|
+
const isJidGroup = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@g.us'));
|
|
47
|
+
exports.isJidGroup = isJidGroup;
|
|
48
|
+
/** is the jid the status broadcast */
|
|
49
|
+
const isJidStatusBroadcast = (jid) => jid === 'status@broadcast';
|
|
50
|
+
exports.isJidStatusBroadcast = isJidStatusBroadcast;
|
|
51
|
+
/** is the jid the newsletter */
|
|
52
|
+
const isJidNewsLetter = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('newsletter'));
|
|
53
|
+
exports.isJidNewsLetter = isJidNewsLetter;
|
|
54
|
+
const jidNormalizedUser = (jid) => {
|
|
55
|
+
const result = (0, exports.jidDecode)(jid);
|
|
56
|
+
if (!result) {
|
|
57
|
+
return '';
|
|
58
|
+
}
|
|
59
|
+
const { user, server } = result;
|
|
60
|
+
return (0, exports.jidEncode)(user, server === 'c.us' ? 's.whatsapp.net' : server);
|
|
61
|
+
};
|
|
62
|
+
exports.jidNormalizedUser = jidNormalizedUser;
|