@prototypevip/baileys 0.0.3 → 0.0.4
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.
|
@@ -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),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prototypevip/baileys",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
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
|
}
|