@prototypevip/baileys 0.0.3 → 0.0.5
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/chats.js
CHANGED
|
@@ -199,6 +199,15 @@ export const makeChatsSocket = (config) => {
|
|
|
199
199
|
}
|
|
200
200
|
};
|
|
201
201
|
|
|
202
|
+
const getUsername = async (jid) => {
|
|
203
|
+
const usyncQuery = new USyncQuery()
|
|
204
|
+
.withUsernameProtocol()
|
|
205
|
+
.withContext("background");
|
|
206
|
+
usyncQuery.withUser(new USyncUser().withId(jid));
|
|
207
|
+
const result = await sock.executeUSyncQuery(usyncQuery);
|
|
208
|
+
return result?.list?.[0]?.username || null;
|
|
209
|
+
};
|
|
210
|
+
|
|
202
211
|
const findUserId = async (pnLid) => {
|
|
203
212
|
const cachedId = USER_ID_CACHE.get(pnLid);
|
|
204
213
|
if (cachedId) {
|
|
@@ -212,6 +221,7 @@ export const makeChatsSocket = (config) => {
|
|
|
212
221
|
)?.[0]?.lid;
|
|
213
222
|
if (!userId.lid) {
|
|
214
223
|
userId.lid = "id-not-found";
|
|
224
|
+
USER_ID_CACHE.set(pnLid, userId);
|
|
215
225
|
return userId;
|
|
216
226
|
}
|
|
217
227
|
} else if (isLidUser(pnLid)) {
|
|
@@ -220,7 +230,18 @@ export const makeChatsSocket = (config) => {
|
|
|
220
230
|
await signalRepository.lidMapping.getPNsForLIDs([pnLid])
|
|
221
231
|
)?.[0]?.pn;
|
|
222
232
|
if (!userId.phoneNumber) {
|
|
233
|
+
// ملحوظه: ده بيحصل عادي دلوقتي مع أي حساب حاطط "username" جديد بتاع
|
|
234
|
+
// واتساب، لأن رقمه بيبقى مش قابل للاكتشاف. من غير الكاش ده، كل رساله
|
|
235
|
+
// جايه من الحساب ده كانت بتعمل استعلام شبكه كامل تاني من الأول، وده
|
|
236
|
+
// اللي كان بيسبب التأخير/التعليق الملحوظ مع أي حد شايل يوزرنيم.
|
|
237
|
+
// كمان بنحاول نجيب اليوزرنيم نفسه عشان يتعرض بدل الرقم/الليد الخام.
|
|
223
238
|
userId.phoneNumber = "id-not-found";
|
|
239
|
+
try {
|
|
240
|
+
userId.username = await getUsername(pnLid);
|
|
241
|
+
} catch {
|
|
242
|
+
userId.username = null;
|
|
243
|
+
}
|
|
244
|
+
USER_ID_CACHE.set(pnLid, userId);
|
|
224
245
|
return userId;
|
|
225
246
|
}
|
|
226
247
|
} else {
|
|
@@ -1091,6 +1112,7 @@ export const makeChatsSocket = (config) => {
|
|
|
1091
1112
|
fetchStatus: fetchStatus,
|
|
1092
1113
|
fetchDisappearingDuration: fetchDisappearingDuration,
|
|
1093
1114
|
findUserId: findUserId,
|
|
1115
|
+
getUsername: getUsername,
|
|
1094
1116
|
updateProfilePicture: updateProfilePicture,
|
|
1095
1117
|
removeProfilePicture: removeProfilePicture,
|
|
1096
1118
|
updateProfileStatus: updateProfileStatus,
|
|
@@ -285,7 +285,12 @@ export const makePrototypeStore = (config = {}) => {
|
|
|
285
285
|
}
|
|
286
286
|
}
|
|
287
287
|
} catch (err) {
|
|
288
|
-
|
|
288
|
+
const code = err?.code || err?.message || "";
|
|
289
|
+
if (String(code).includes("READONLY") || String(code).includes("SQLITE_READONLY")) {
|
|
290
|
+
console.error("PrototypeStore Transaction Step Error (readonly DB - check file path/permissions/volume):", err.message || err);
|
|
291
|
+
} else {
|
|
292
|
+
console.error("PrototypeStore Transaction Step Error:", err);
|
|
293
|
+
}
|
|
289
294
|
}
|
|
290
295
|
}
|
|
291
296
|
})();
|
|
@@ -380,6 +385,22 @@ export const makePrototypeStore = (config = {}) => {
|
|
|
380
385
|
|
|
381
386
|
const presencesCache = {};
|
|
382
387
|
|
|
388
|
+
|
|
389
|
+
const safeAssignChat = (existing, incoming) => {
|
|
390
|
+
if (!existing || !incoming) return existing;
|
|
391
|
+
const savedMessages = existing.messages;
|
|
392
|
+
Object.assign(existing, incoming, { isChats: true });
|
|
393
|
+
// Never let chat events wipe the ordered messages store
|
|
394
|
+
if (
|
|
395
|
+
!existing.messages ||
|
|
396
|
+
typeof existing.messages.upsert !== "function"
|
|
397
|
+
) {
|
|
398
|
+
existing.messages = savedMessages || makeMessagesStore();
|
|
399
|
+
}
|
|
400
|
+
if (!existing.id) existing.id = incoming.id || existing.id;
|
|
401
|
+
return existing;
|
|
402
|
+
};
|
|
403
|
+
|
|
383
404
|
const makeMessagesStore = () =>
|
|
384
405
|
new Proxy(
|
|
385
406
|
makeOrderedDictionary((m) => {
|
|
@@ -421,6 +442,12 @@ export const makePrototypeStore = (config = {}) => {
|
|
|
421
442
|
return jid.endsWith("@g.us");
|
|
422
443
|
},
|
|
423
444
|
};
|
|
445
|
+
} else if (
|
|
446
|
+
!target[jid].messages ||
|
|
447
|
+
typeof target[jid].messages.upsert !== "function"
|
|
448
|
+
) {
|
|
449
|
+
// Recover if messages was overwritten by Object.assign / chat updates
|
|
450
|
+
target[jid].messages = makeMessagesStore();
|
|
424
451
|
}
|
|
425
452
|
return target[jid];
|
|
426
453
|
},
|
|
@@ -606,7 +633,7 @@ export const makePrototypeStore = (config = {}) => {
|
|
|
606
633
|
if (!id || id === "status@broadcast") continue;
|
|
607
634
|
|
|
608
635
|
const existingChat = store.chats[id];
|
|
609
|
-
|
|
636
|
+
safeAssignChat(existingChat, chat);
|
|
610
637
|
|
|
611
638
|
if (id.endsWith("@g.us")) {
|
|
612
639
|
const current = groupsCache[id] || {};
|
|
@@ -731,16 +758,26 @@ export const makePrototypeStore = (config = {}) => {
|
|
|
731
758
|
store.signalRepository?.lidMapping,
|
|
732
759
|
);
|
|
733
760
|
const existingChat = store.chats[id];
|
|
734
|
-
|
|
761
|
+
safeAssignChat(existingChat, chat);
|
|
735
762
|
}
|
|
736
763
|
},
|
|
737
764
|
);
|
|
738
765
|
|
|
739
766
|
listen("messages.upsert", async ({ messages }) => {
|
|
740
767
|
for (let msg of messages) {
|
|
741
|
-
const
|
|
768
|
+
const rawChatId = msg?.key?.remoteJid;
|
|
769
|
+
if (!rawChatId) continue;
|
|
770
|
+
const chatId = await resolveJIDAsync(
|
|
771
|
+
rawChatId,
|
|
772
|
+
store.signalRepository?.lidMapping,
|
|
773
|
+
);
|
|
742
774
|
if (!chatId) continue;
|
|
743
|
-
store.chats[chatId]
|
|
775
|
+
const chat = store.chats[chatId];
|
|
776
|
+
if (!chat) continue;
|
|
777
|
+
if (!chat.messages || typeof chat.messages.upsert !== "function") {
|
|
778
|
+
chat.messages = makeMessagesStore();
|
|
779
|
+
}
|
|
780
|
+
chat.messages.upsert(cloneM(msg));
|
|
744
781
|
|
|
745
782
|
if (db) {
|
|
746
783
|
const msgKey = getMessageKey(
|
|
@@ -29,11 +29,28 @@
|
|
|
29
29
|
*/
|
|
30
30
|
|
|
31
31
|
import crypto from 'crypto';
|
|
32
|
-
import sharp from 'sharp';
|
|
33
32
|
import ffmpeg from 'fluent-ffmpeg';
|
|
34
33
|
import { PassThrough, Readable } from 'stream';
|
|
35
34
|
import { generateWAMessageFromContent, prepareWAMessageMedia } from './messages.js';
|
|
36
35
|
|
|
36
|
+
// sharp اختيارية (peerDependency) — نحمّلها ديناميكيًا وقت الاستخدام فعليًا
|
|
37
|
+
// بدل static import، عشان لو حد ركّب المكتبة من غير ما يثبتها، المكتبة كلها
|
|
38
|
+
// (makeWASocket وكل حاجة تانية) متتأثرش، وميزة الـ builder بس اللي هترمي
|
|
39
|
+
// error واضح لو حد استخدمها فعلاً من غير sharp.
|
|
40
|
+
let _sharpPromise;
|
|
41
|
+
async function loadSharp() {
|
|
42
|
+
if (!_sharpPromise) {
|
|
43
|
+
_sharpPromise = import('sharp')
|
|
44
|
+
.then((mod) => mod.default || mod)
|
|
45
|
+
.catch(() => {
|
|
46
|
+
throw new Error(
|
|
47
|
+
"Toolkit.resize يحتاج مكتبة 'sharp' وهي مش متثبتة. ثبّتها بـ: npm install sharp"
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return _sharpPromise;
|
|
52
|
+
}
|
|
53
|
+
|
|
37
54
|
const VERSION = '4.6';
|
|
38
55
|
|
|
39
56
|
function extractIE(text, { extract = true, hyperlink = true, citation = true, latex = true } = {}) {
|
|
@@ -235,6 +252,7 @@ export class Toolkit {
|
|
|
235
252
|
}
|
|
236
253
|
|
|
237
254
|
static async resize(buffer, x, y, fit = 'cover') {
|
|
255
|
+
const sharp = await loadSharp();
|
|
238
256
|
return await sharp(buffer)
|
|
239
257
|
.resize(x, y, {
|
|
240
258
|
fit,
|
package/lib/Utils/messages.js
CHANGED
|
@@ -938,6 +938,51 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
938
938
|
options,
|
|
939
939
|
);
|
|
940
940
|
m.stickerPackMessage = stickerPackMessage;
|
|
941
|
+
} else if (
|
|
942
|
+
hasNonNullishProperty(message, "buttons") &&
|
|
943
|
+
Array.isArray(message.buttons) &&
|
|
944
|
+
message.buttons.length > 0
|
|
945
|
+
) {
|
|
946
|
+
// === دعم الصيغة القديمة للأزرار (buttonId/buttonText/type + headerType) ===
|
|
947
|
+
// واتساب وقف عرض buttonsMessage/templateMessage القديمة، فبنحوّلها هنا
|
|
948
|
+
// تلقائيًا لنفس آلية nativeFlow الحديثة (المُثبتة إنها بترسم فعليًا)
|
|
949
|
+
// عشان أي بلجن قديم يفضل شغال من غير ما يتعدل.
|
|
950
|
+
const legacyNativeFlow = message.buttons.map((b) => ({
|
|
951
|
+
id: b.buttonId,
|
|
952
|
+
text:
|
|
953
|
+
(typeof b.buttonText === "string"
|
|
954
|
+
? b.buttonText
|
|
955
|
+
: b.buttonText?.displayText) || "👉🏻 اضغط",
|
|
956
|
+
}));
|
|
957
|
+
const interactiveMessage = {
|
|
958
|
+
nativeFlowMessage: prepareNativeFlowButtons({
|
|
959
|
+
nativeFlow: legacyNativeFlow,
|
|
960
|
+
}),
|
|
961
|
+
};
|
|
962
|
+
if (hasOptionalProperty(message, "caption")) {
|
|
963
|
+
let mediaHeader = {};
|
|
964
|
+
if (
|
|
965
|
+
hasOptionalProperty(message, "image") ||
|
|
966
|
+
hasOptionalProperty(message, "video") ||
|
|
967
|
+
hasOptionalProperty(message, "document")
|
|
968
|
+
) {
|
|
969
|
+
mediaHeader = await prepareWAMessageMedia(message, options);
|
|
970
|
+
}
|
|
971
|
+
const isValidHeader = hasValidInteractiveHeader(mediaHeader);
|
|
972
|
+
interactiveMessage.header = {
|
|
973
|
+
title: message.title || "",
|
|
974
|
+
subtitle: message.subtitle || "",
|
|
975
|
+
hasMediaAttachment: !!isValidHeader,
|
|
976
|
+
...mediaHeader,
|
|
977
|
+
};
|
|
978
|
+
interactiveMessage.body = { text: message.caption };
|
|
979
|
+
} else if (hasOptionalProperty(message, "text")) {
|
|
980
|
+
interactiveMessage.body = { text: message.text };
|
|
981
|
+
}
|
|
982
|
+
if (hasOptionalProperty(message, "footer")) {
|
|
983
|
+
interactiveMessage.footer = { text: message.footer };
|
|
984
|
+
}
|
|
985
|
+
m = { interactiveMessage };
|
|
941
986
|
} else if (hasNonNullishProperty(message, "nativeFlow")) {
|
|
942
987
|
const interactiveMessage = {
|
|
943
988
|
nativeFlowMessage: prepareNativeFlowButtons(message),
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
USyncDeviceProtocol,
|
|
7
7
|
USyncDisappearingModeProtocol,
|
|
8
8
|
USyncStatusProtocol,
|
|
9
|
+
USyncUsernameProtocol,
|
|
9
10
|
} from "./Protocols/index.js";
|
|
10
11
|
import { USyncUser } from "./USyncUser.js";
|
|
11
12
|
export class USyncQuery {
|
|
@@ -130,4 +131,8 @@ export class USyncQuery {
|
|
|
130
131
|
this.protocols.push(new USyncLIDProtocol());
|
|
131
132
|
return this;
|
|
132
133
|
}
|
|
134
|
+
withUsernameProtocol() {
|
|
135
|
+
this.protocols.push(new USyncUsernameProtocol());
|
|
136
|
+
return this;
|
|
137
|
+
}
|
|
133
138
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prototypevip/baileys",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "A simple fork of Baileys for WhatsApp automation",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -74,6 +74,9 @@
|
|
|
74
74
|
},
|
|
75
75
|
"link-preview-js": {
|
|
76
76
|
"optional": true
|
|
77
|
+
},
|
|
78
|
+
"sharp": {
|
|
79
|
+
"optional": true
|
|
77
80
|
}
|
|
78
81
|
}
|
|
79
82
|
}
|