@prototypevip/baileys 0.1.4 → 0.1.6
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/HELPERS.md +149 -0
- package/lib/Socket/communities.js +2 -0
- package/lib/Socket/messages-send.js +13 -5
- package/lib/Utils/index.js +2 -0
- package/lib/Utils/interactive-message-handler.js +6 -4
- package/lib/Utils/message-builder.js +40 -24
- package/lib/Utils/messages-media.js +6 -3
- package/lib/Utils/messages.js +31 -12
- package/lib/Utils/newsletter-status.js +40 -2
- package/lib/Utils/prototype-helpers.js +732 -0
- package/lib/Utils/view-once.js +160 -0
- package/package.json +12 -3
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* View-Once موحَّد (0.1.6)
|
|
3
|
+
*
|
|
4
|
+
* نقطة واحدة بتلفّ أي محتوى رسالة (نص / صورة / فيديو / صوت / ملف / أزرار / قوائم /
|
|
5
|
+
* كاروسيل / منتج / لوكيشن / جهة اتصال / Rich ...) جوه viewOnceMessage.
|
|
6
|
+
* الدوال دي مفيهاش أي dependency خارجي عشان تتستعمل من messages.js و
|
|
7
|
+
* messages-send.js و message-builder.js و prototype-helpers.js من غير circular imports.
|
|
8
|
+
*
|
|
9
|
+
* طرق التفعيل (كلها بتدخل على نفس الدالة):
|
|
10
|
+
* sock.sendMessage(jid, { ...content, viewOnce: true })
|
|
11
|
+
* sock.sendMessage(jid, content, { viewOnce: true })
|
|
12
|
+
* sock.sendButtons / sendList / sendCarousel / sendAlbum / ... (jid, content, { viewOnce: true })
|
|
13
|
+
* new Carousel(sock).setViewOnce() / new Button(sock).setViewOnce()
|
|
14
|
+
*
|
|
15
|
+
* قيم الـ flag:
|
|
16
|
+
* true | "v1" → viewOnceMessage (الافتراضي — نفس السلوك القديم)
|
|
17
|
+
* "v2" | 2 → viewOnceMessageV2
|
|
18
|
+
* "force" | "v2-force" → نفس اللي فوق، بس بيلف حتى الأنواع اللي مش مدعومة رسمياً (استيكر / استطلاع / ألبوم)
|
|
19
|
+
* { version: 1|2, force: boolean }
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
export const VIEW_ONCE_KEYS = ["viewOnceMessage", "viewOnceMessageV2", "viewOnceMessageV2Extension"];
|
|
23
|
+
|
|
24
|
+
/** رسائل تحكّم/بروتوكول: مينفعش تتلف في viewOnce أبداً (حتى مع force) */
|
|
25
|
+
const NEVER_WRAP = new Set([
|
|
26
|
+
"protocolMessage",
|
|
27
|
+
"reactionMessage",
|
|
28
|
+
"encReactionMessage",
|
|
29
|
+
"pollUpdateMessage",
|
|
30
|
+
"encEventResponseMessage",
|
|
31
|
+
"keepInChatMessage",
|
|
32
|
+
"pinInChatMessage",
|
|
33
|
+
"buttonsResponseMessage",
|
|
34
|
+
"listResponseMessage",
|
|
35
|
+
"interactiveResponseMessage",
|
|
36
|
+
"templateButtonReplyMessage",
|
|
37
|
+
"senderKeyDistributionMessage",
|
|
38
|
+
"editedMessage",
|
|
39
|
+
"ephemeralMessage",
|
|
40
|
+
"groupStatusMessage",
|
|
41
|
+
"groupStatusMessageV2",
|
|
42
|
+
"associatedChildMessage",
|
|
43
|
+
"documentWithCaptionMessage",
|
|
44
|
+
]);
|
|
45
|
+
|
|
46
|
+
/** أنواع واتساب نفسه مبيعرضهاش كـ view-once → بتتخطى إلا مع force */
|
|
47
|
+
const UNSUPPORTED_UNLESS_FORCED = new Set([
|
|
48
|
+
"albumMessage",
|
|
49
|
+
"stickerMessage",
|
|
50
|
+
"stickerPackMessage",
|
|
51
|
+
"pollCreationMessage",
|
|
52
|
+
"pollCreationMessageV2",
|
|
53
|
+
"pollCreationMessageV3",
|
|
54
|
+
"pollCreationMessageV5",
|
|
55
|
+
"pollCreationMessageV6",
|
|
56
|
+
"requestPhoneNumberMessage",
|
|
57
|
+
]);
|
|
58
|
+
|
|
59
|
+
/** أنواع تفاعلية: واتساب بيطلب messageContextInfo جوه الـ viewOnce عشان تتعرض */
|
|
60
|
+
const INTERACTIVE_TYPES = new Set([
|
|
61
|
+
"interactiveMessage",
|
|
62
|
+
"buttonsMessage",
|
|
63
|
+
"listMessage",
|
|
64
|
+
"templateMessage",
|
|
65
|
+
"productMessage",
|
|
66
|
+
"eventMessage",
|
|
67
|
+
"richResponseMessage",
|
|
68
|
+
]);
|
|
69
|
+
|
|
70
|
+
/** ميديا بيحطلها واتساب نفسه viewOnce=true جوه الرسالة كمان (مش الغلاف بس) */
|
|
71
|
+
const MEDIA_TYPES = new Set(["imageMessage", "videoMessage", "audioMessage"]);
|
|
72
|
+
|
|
73
|
+
/** نفس منطق getContentType (متكرر هنا عشان مفيش import دائري) */
|
|
74
|
+
export function getInnerContentType(content) {
|
|
75
|
+
if (!content || typeof content !== "object") return undefined;
|
|
76
|
+
return Object.keys(content).find(
|
|
77
|
+
(k) => (k === "conversation" || k.includes("Message")) && k !== "senderKeyDistributionMessage" && content[k] != null
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** يحوّل أي صيغة flag لـ { key, force } أو null لو مفيش viewOnce */
|
|
82
|
+
export function parseViewOnce(flag) {
|
|
83
|
+
if (!flag) return null;
|
|
84
|
+
if (flag === true || flag === "v1" || flag === 1) return { key: "viewOnceMessage", force: false };
|
|
85
|
+
if (flag === "v2" || flag === 2) return { key: "viewOnceMessageV2", force: false };
|
|
86
|
+
if (flag === "force") return { key: "viewOnceMessage", force: true };
|
|
87
|
+
if (flag === "v2-force") return { key: "viewOnceMessageV2", force: true };
|
|
88
|
+
if (typeof flag === "object") {
|
|
89
|
+
return {
|
|
90
|
+
key: Number(flag.version) === 2 || flag.version === "v2" ? "viewOnceMessageV2" : "viewOnceMessage",
|
|
91
|
+
force: !!flag.force,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
return { key: "viewOnceMessage", force: false }; // أي قيمة truthy تانية
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export const isViewOnceContent = (content) => !!content && VIEW_ONCE_KEYS.some((k) => content[k]);
|
|
98
|
+
|
|
99
|
+
/** يرجّع المحتوى الداخلي لو ملفوف في viewOnce، وإلا نفس المحتوى */
|
|
100
|
+
export function unwrapViewOnce(content) {
|
|
101
|
+
if (!content) return content;
|
|
102
|
+
for (const k of VIEW_ONCE_KEYS) {
|
|
103
|
+
if (content[k]?.message) return content[k].message;
|
|
104
|
+
}
|
|
105
|
+
return content;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* يلف محتوى الرسالة (شكل proto: { xxxMessage: {...} }) في viewOnce.
|
|
110
|
+
* - idempotent: لو الرسالة ملفوفة أصلاً بيرجّعها زي ما هي.
|
|
111
|
+
* - بيتخطى رسائل التحكم (react / delete / edit / poll vote ...) دايماً.
|
|
112
|
+
* - بيتخطى الاستيكر/الاستطلاع/الألبوم إلا مع "force".
|
|
113
|
+
* - بيضيف messageContextInfo الداخلي للأنواع التفاعلية (أزرار/قوائم/كاروسيل...).
|
|
114
|
+
*/
|
|
115
|
+
export function wrapViewOnce(content, flag = true) {
|
|
116
|
+
const opt = parseViewOnce(flag);
|
|
117
|
+
if (!opt || !content || typeof content !== "object") return content;
|
|
118
|
+
if (isViewOnceContent(content)) return content;
|
|
119
|
+
|
|
120
|
+
const type = getInnerContentType(content);
|
|
121
|
+
if (!type) return content;
|
|
122
|
+
if (NEVER_WRAP.has(type)) return content;
|
|
123
|
+
if (UNSUPPORTED_UNLESS_FORCED.has(type) && !opt.force) return content;
|
|
124
|
+
|
|
125
|
+
const inner = { ...content };
|
|
126
|
+
if (MEDIA_TYPES.has(type) && inner[type] && typeof inner[type] === "object") {
|
|
127
|
+
inner[type].viewOnce = true;
|
|
128
|
+
}
|
|
129
|
+
if (INTERACTIVE_TYPES.has(type) && !inner.messageContextInfo) {
|
|
130
|
+
inner.messageContextInfo = { deviceListMetadata: {}, deviceListMetadataVersion: 2 };
|
|
131
|
+
}
|
|
132
|
+
return { [opt.key]: { message: inner } };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** هل النوع ده بيتلف فعلاً مع الـ flag ده؟ (للتشخيص / الاختبارات) */
|
|
136
|
+
export function canWrapViewOnce(content, flag = true) {
|
|
137
|
+
const opt = parseViewOnce(flag);
|
|
138
|
+
if (!opt) return false;
|
|
139
|
+
const type = getInnerContentType(unwrapViewOnce(content));
|
|
140
|
+
if (!type || NEVER_WRAP.has(type)) return false;
|
|
141
|
+
return opt.force || !UNSUPPORTED_UNLESS_FORCED.has(type);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** يجيب نوع المحتوى الحقيقي + المحتوى نفسه حتى لو ملفوف في viewOnce */
|
|
145
|
+
export function getViewOnceTarget(content) {
|
|
146
|
+
const inner = unwrapViewOnce(content);
|
|
147
|
+
const type = getInnerContentType(inner) ?? Object.keys(inner || {})[0];
|
|
148
|
+
return { inner, type, node: type ? inner?.[type] : undefined };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export default {
|
|
152
|
+
VIEW_ONCE_KEYS,
|
|
153
|
+
parseViewOnce,
|
|
154
|
+
wrapViewOnce,
|
|
155
|
+
unwrapViewOnce,
|
|
156
|
+
isViewOnceContent,
|
|
157
|
+
canWrapViewOnce,
|
|
158
|
+
getInnerContentType,
|
|
159
|
+
getViewOnceTarget,
|
|
160
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prototypevip/baileys",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Baileys fork (@prototypevip/baileys) — clean + Channel/Group/Personal Status
|
|
3
|
+
"version": "0.1.6",
|
|
4
|
+
"description": "Baileys fork (@prototypevip/baileys) — clean + Channel/Group/Personal Status + Interactive Buttons/Lists/Album/Carousel + Rich code responses + Call Invites + Universal View-Once (0.1.6)",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
@@ -20,15 +20,24 @@
|
|
|
20
20
|
"files": [
|
|
21
21
|
"lib/**/*",
|
|
22
22
|
"WAProto/**/*",
|
|
23
|
-
"engine-requirements.js"
|
|
23
|
+
"engine-requirements.js",
|
|
24
|
+
"HELPERS.md"
|
|
24
25
|
],
|
|
25
26
|
"keywords": [
|
|
27
|
+
"album",
|
|
26
28
|
"automation",
|
|
27
29
|
"baileys",
|
|
28
30
|
"baileys-fork",
|
|
29
31
|
"baileys-mod",
|
|
32
|
+
"buttons",
|
|
33
|
+
"call-invite",
|
|
34
|
+
"interactive-messages",
|
|
30
35
|
"js-whatsapp",
|
|
31
36
|
"multi-device",
|
|
37
|
+
"native-flow",
|
|
38
|
+
"rich-response",
|
|
39
|
+
"view-once",
|
|
40
|
+
"viewonce",
|
|
32
41
|
"whatsapp",
|
|
33
42
|
"whatsapp-api",
|
|
34
43
|
"whatsapp-bot",
|