@pontasockets/baileys 0.2.0 → 0.2.2
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/Socket/messages-recv.js +46 -2
- package/lib/Utils/decode-wa-message.js +27 -4
- package/lib/WABinary/jid-utils.js +30 -1
- package/lib/index.js +1 -1
- package/package.json +2 -2
- package/lib/Socket/messages-send.js.bak +0 -1471
|
@@ -1348,8 +1348,26 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
1348
1348
|
})
|
|
1349
1349
|
} else {
|
|
1350
1350
|
let type = undefined
|
|
1351
|
+
// FIX: Jangan fallback ke me.id saat LID tidak bisa di-resolve.
|
|
1352
|
+
// Fallback ke me.id menyebabkan semua pesan LID private chat
|
|
1353
|
+
// punya participant = JID bot sendiri, sehingga owner check lolos
|
|
1354
|
+
// untuk semua user yang menggunakan LID addressing.
|
|
1351
1355
|
if (msg.key.participant && msg.key.participant.endsWith('@lid')) {
|
|
1352
|
-
|
|
1356
|
+
if (node.attrs.participant_pn) {
|
|
1357
|
+
// Gunakan nomor telepon asli jika tersedia
|
|
1358
|
+
msg.key.participant = WABinary_1.jidNormalizedUser(node.attrs.participant_pn);
|
|
1359
|
+
} else {
|
|
1360
|
+
// Coba resolve dari lidMapping, jika gagal pakai remoteJid
|
|
1361
|
+
// (lebih aman daripada me.id yang menyebabkan false owner match)
|
|
1362
|
+
try {
|
|
1363
|
+
const resolvedPn = await signalRepository.lidMapping.getPNForLID(msg.key.participant);
|
|
1364
|
+
msg.key.participant = resolvedPn
|
|
1365
|
+
? WABinary_1.jidNormalizedUser(resolvedPn)
|
|
1366
|
+
: WABinary_1.jidNormalizedUser(msg.key.remoteJid);
|
|
1367
|
+
} catch (_) {
|
|
1368
|
+
msg.key.participant = WABinary_1.jidNormalizedUser(msg.key.remoteJid);
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1353
1371
|
}
|
|
1354
1372
|
if (WABinary_1.isJidGroup(msg.key.remoteJid)) {
|
|
1355
1373
|
const mtype = getTypeMessage(msg.message)
|
|
@@ -1418,7 +1436,33 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
1418
1436
|
}
|
|
1419
1437
|
}
|
|
1420
1438
|
if (!WABinary_1.isJidGroup(msg.key.remoteJid) && WABinary_1.isLidUser(msg.key.remoteJid)) {
|
|
1421
|
-
|
|
1439
|
+
// FIX: private chat - resolve remoteJid dari LID ke JID
|
|
1440
|
+
const resolvedRemote = node.attrs.sender_pn || node.attrs.peer_recipient_pn;
|
|
1441
|
+
if (resolvedRemote) {
|
|
1442
|
+
msg.key.remoteJid = WABinary_1.jidNormalizedUser(resolvedRemote);
|
|
1443
|
+
} else {
|
|
1444
|
+
// Fallback: coba resolve dari lidMapping
|
|
1445
|
+
try {
|
|
1446
|
+
const resolvedPn = await signalRepository.lidMapping.getPNForLID(msg.key.remoteJid);
|
|
1447
|
+
if (resolvedPn) {
|
|
1448
|
+
msg.key.remoteJid = WABinary_1.jidNormalizedUser(resolvedPn);
|
|
1449
|
+
}
|
|
1450
|
+
} catch (_) {}
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
// FIX: private chat - jika author masih LID, resolve ke JID
|
|
1454
|
+
if (!WABinary_1.isJidGroup(msg.key.remoteJid) && author && WABinary_1.isLidUser(author)) {
|
|
1455
|
+
const resolvedAuthor = node.attrs.sender_pn
|
|
1456
|
+
|| node.attrs.participant_pn
|
|
1457
|
+
|| node.attrs.peer_recipient_pn;
|
|
1458
|
+
if (resolvedAuthor) {
|
|
1459
|
+
author = WABinary_1.jidNormalizedUser(resolvedAuthor);
|
|
1460
|
+
} else {
|
|
1461
|
+
try {
|
|
1462
|
+
const resolvedPn = await signalRepository.lidMapping.getPNForLID(author);
|
|
1463
|
+
if (resolvedPn) author = WABinary_1.jidNormalizedUser(resolvedPn);
|
|
1464
|
+
} catch (_) {}
|
|
1465
|
+
}
|
|
1422
1466
|
}
|
|
1423
1467
|
let participant = msg.key.participant
|
|
1424
1468
|
if (category === 'peer') {
|
|
@@ -68,13 +68,26 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
|
68
68
|
if (!isMeLid(from)) {
|
|
69
69
|
throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza })
|
|
70
70
|
}
|
|
71
|
-
|
|
71
|
+
// FIX: recipient mungkin LID juga, gunakan peer_recipient_pn jika ada
|
|
72
|
+
chat_id = stanza.attrs.peer_recipient_pn
|
|
73
|
+
? WABinary_1.jidNormalizedUser(stanza.attrs.peer_recipient_pn)
|
|
74
|
+
: recipient
|
|
72
75
|
}
|
|
73
76
|
else {
|
|
74
|
-
chat_id
|
|
77
|
+
// FIX: chat_id dari LID → resolve ke JID via sender_pn
|
|
78
|
+
chat_id = stanza.attrs.sender_pn
|
|
79
|
+
? WABinary_1.jidNormalizedUser(stanza.attrs.sender_pn)
|
|
80
|
+
: stanza.attrs.peer_recipient_pn
|
|
81
|
+
? WABinary_1.jidNormalizedUser(stanza.attrs.peer_recipient_pn)
|
|
82
|
+
: from
|
|
75
83
|
}
|
|
76
84
|
msg_type = 'chat'
|
|
77
|
-
|
|
85
|
+
// FIX: untuk private LID chat, gunakan sender_pn/participant_pn sebagai author
|
|
86
|
+
// agar key.remoteJid dan author tidak berupa LID mentah
|
|
87
|
+
author = stanza.attrs.sender_pn
|
|
88
|
+
|| stanza.attrs.participant_pn
|
|
89
|
+
|| stanza.attrs.peer_recipient_pn
|
|
90
|
+
|| from
|
|
78
91
|
} else if (WABinary_1.isJidGroup(from)) {
|
|
79
92
|
if (!participant) {
|
|
80
93
|
throw new boom_1.Boom('No participant in group message')
|
|
@@ -102,7 +115,17 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
|
102
115
|
} else {
|
|
103
116
|
throw new boom_1.Boom('Unknown message type', { data: stanza })
|
|
104
117
|
}
|
|
105
|
-
|
|
118
|
+
// FIX: untuk private chat (isJidUser), participant === from (bukan undefined),
|
|
119
|
+
// sehingga fallback ke stanza.attrs.from tidak diperlukan dan bisa menyebabkan
|
|
120
|
+
// fromMe=true saat pesan dari orang lain di kondisi edge case LID.
|
|
121
|
+
// Kita batasi fallback hanya untuk group (di mana participant memang bisa undefined).
|
|
122
|
+
const fromMe = WABinary_1.isJidNewsletter(from)
|
|
123
|
+
? !!stanza.attrs?.is_sender
|
|
124
|
+
: WABinary_1.isLidUser(from)
|
|
125
|
+
? isMeLid(participant != null ? participant : stanza.attrs.from)
|
|
126
|
+
: (WABinary_1.isJidGroup(from) || WABinary_1.isJidBroadcast(from))
|
|
127
|
+
? isMe(participant != null ? participant : stanza.attrs.from)
|
|
128
|
+
: isMe(from)
|
|
106
129
|
const pushname = stanza?.attrs?.notify
|
|
107
130
|
const key = {
|
|
108
131
|
remoteJid: chat_id,
|
|
@@ -101,4 +101,33 @@ module.exports = {
|
|
|
101
101
|
isJidBot,
|
|
102
102
|
transferDevice,
|
|
103
103
|
jidNormalizedUser
|
|
104
|
-
}
|
|
104
|
+
}
|
|
105
|
+
// ============================================================
|
|
106
|
+
// FIX: getSenderJid - helper aman untuk identifikasi pengirim
|
|
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
|
package/lib/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
console.log([
|
|
3
3
|
'',
|
|
4
4
|
' \x1b[36m»\x1b[0m \x1b[1m\x1b[97m@pontasockets/baileys\x1b[0m \x1b[36m«\x1b[0m',
|
|
5
|
-
' \x1b[35m
|
|
5
|
+
' \x1b[35m🔥\x1b[0m \x1b[33mTerimakasih sudah memakai baileys ini >.<\x1b[0m',
|
|
6
6
|
'',
|
|
7
7
|
].join('\n'))
|
|
8
8
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pontasockets/baileys",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Baileys is a lightweight JavaScript library for interacting with the WhatsApp Web API using WebSocket.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"facebook",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"url": "git+ssh://git@github.com/pontasockets/baileys.git"
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
|
-
"author": "
|
|
20
|
+
"author": "Pontasockets",
|
|
21
21
|
"main": "lib/index.js",
|
|
22
22
|
"types": "lib/index.d.ts",
|
|
23
23
|
"files": [
|