dread-fork 2.0.0-dread.0

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.
Files changed (200) hide show
  1. package/DREAD_PATCHES.md +34 -0
  2. package/README.md +34 -0
  3. package/WAProto/index.js +169661 -0
  4. package/engine-requirements.js +10 -0
  5. package/lib/Defaults/baileys-version.json +3 -0
  6. package/lib/Defaults/index.d.ts +53 -0
  7. package/lib/Defaults/index.js +158 -0
  8. package/lib/Defaults/phonenumber-mcc.json +223 -0
  9. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  10. package/lib/Signal/Group/ciphertext-message.js +15 -0
  11. package/lib/Signal/Group/group-session-builder.d.ts +14 -0
  12. package/lib/Signal/Group/group-session-builder.js +64 -0
  13. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  14. package/lib/Signal/Group/group_cipher.js +96 -0
  15. package/lib/Signal/Group/index.d.ts +11 -0
  16. package/lib/Signal/Group/index.js +57 -0
  17. package/lib/Signal/Group/keyhelper.d.ts +10 -0
  18. package/lib/Signal/Group/keyhelper.js +55 -0
  19. package/lib/Signal/Group/queue-job.d.ts +1 -0
  20. package/lib/Signal/Group/queue-job.js +57 -0
  21. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  22. package/lib/Signal/Group/sender-chain-key.js +34 -0
  23. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  24. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  25. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  26. package/lib/Signal/Group/sender-key-message.js +69 -0
  27. package/lib/Signal/Group/sender-key-name.d.ts +17 -0
  28. package/lib/Signal/Group/sender-key-name.js +51 -0
  29. package/lib/Signal/Group/sender-key-record.d.ts +30 -0
  30. package/lib/Signal/Group/sender-key-record.js +53 -0
  31. package/lib/Signal/Group/sender-key-state.d.ts +38 -0
  32. package/lib/Signal/Group/sender-key-state.js +99 -0
  33. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  34. package/lib/Signal/Group/sender-message-key.js +29 -0
  35. package/lib/Signal/libsignal.d.ts +3 -0
  36. package/lib/Signal/libsignal.js +174 -0
  37. package/lib/Socket/Client/abstract-socket-client.d.ts +17 -0
  38. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  39. package/lib/Socket/Client/index.d.ts +3 -0
  40. package/lib/Socket/Client/index.js +19 -0
  41. package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
  42. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  43. package/lib/Socket/Client/web-socket-client.d.ts +12 -0
  44. package/lib/Socket/Client/web-socket-client.js +62 -0
  45. package/lib/Socket/business.d.ts +171 -0
  46. package/lib/Socket/business.js +260 -0
  47. package/lib/Socket/chats.d.ts +267 -0
  48. package/lib/Socket/chats.js +1019 -0
  49. package/lib/Socket/dugong.d.ts +254 -0
  50. package/lib/Socket/dugong.js +509 -0
  51. package/lib/Socket/groups.d.ts +115 -0
  52. package/lib/Socket/groups.js +317 -0
  53. package/lib/Socket/index.d.ts +174 -0
  54. package/lib/Socket/index.js +12 -0
  55. package/lib/Socket/index.js.bak +26 -0
  56. package/lib/Socket/messages-recv.d.ts +161 -0
  57. package/lib/Socket/messages-recv.js +1113 -0
  58. package/lib/Socket/messages-send.d.ts +149 -0
  59. package/lib/Socket/messages-send.js +762 -0
  60. package/lib/Socket/newsletter.d.ts +134 -0
  61. package/lib/Socket/newsletter.js +347 -0
  62. package/lib/Socket/registration.d.ts +267 -0
  63. package/lib/Socket/registration.js +166 -0
  64. package/lib/Socket/socket.d.ts +43 -0
  65. package/lib/Socket/socket.js +694 -0
  66. package/lib/Socket/usync.d.ts +36 -0
  67. package/lib/Socket/usync.js +70 -0
  68. package/lib/Store/index.d.ts +3 -0
  69. package/lib/Store/index.js +10 -0
  70. package/lib/Store/make-cache-manager-store.d.ts +13 -0
  71. package/lib/Store/make-cache-manager-store.js +83 -0
  72. package/lib/Store/make-in-memory-store.d.ts +118 -0
  73. package/lib/Store/make-in-memory-store.js +427 -0
  74. package/lib/Store/make-ordered-dictionary.d.ts +13 -0
  75. package/lib/Store/make-ordered-dictionary.js +81 -0
  76. package/lib/Store/object-repository.d.ts +10 -0
  77. package/lib/Store/object-repository.js +27 -0
  78. package/lib/Types/Auth.d.ts +110 -0
  79. package/lib/Types/Auth.js +2 -0
  80. package/lib/Types/Call.d.ts +13 -0
  81. package/lib/Types/Call.js +2 -0
  82. package/lib/Types/Chat.d.ts +102 -0
  83. package/lib/Types/Chat.js +4 -0
  84. package/lib/Types/Contact.d.ts +19 -0
  85. package/lib/Types/Contact.js +2 -0
  86. package/lib/Types/Events.d.ts +157 -0
  87. package/lib/Types/Events.js +2 -0
  88. package/lib/Types/GroupMetadata.d.ts +55 -0
  89. package/lib/Types/GroupMetadata.js +2 -0
  90. package/lib/Types/Label.d.ts +35 -0
  91. package/lib/Types/Label.js +27 -0
  92. package/lib/Types/LabelAssociation.d.ts +29 -0
  93. package/lib/Types/LabelAssociation.js +9 -0
  94. package/lib/Types/Message.d.ts +273 -0
  95. package/lib/Types/Message.js +9 -0
  96. package/lib/Types/Newsletter.d.ts +103 -0
  97. package/lib/Types/Newsletter.js +38 -0
  98. package/lib/Types/Product.d.ts +78 -0
  99. package/lib/Types/Product.js +2 -0
  100. package/lib/Types/Signal.d.ts +57 -0
  101. package/lib/Types/Signal.js +2 -0
  102. package/lib/Types/Socket.d.ts +111 -0
  103. package/lib/Types/Socket.js +2 -0
  104. package/lib/Types/State.d.ts +27 -0
  105. package/lib/Types/State.js +2 -0
  106. package/lib/Types/USync.d.ts +25 -0
  107. package/lib/Types/USync.js +2 -0
  108. package/lib/Types/index.d.ts +57 -0
  109. package/lib/Types/index.js +42 -0
  110. package/lib/Utils/auth-utils.d.ts +18 -0
  111. package/lib/Utils/auth-utils.js +206 -0
  112. package/lib/Utils/baileys-event-stream.d.ts +16 -0
  113. package/lib/Utils/baileys-event-stream.js +63 -0
  114. package/lib/Utils/business.d.ts +22 -0
  115. package/lib/Utils/business.js +234 -0
  116. package/lib/Utils/chat-utils.d.ts +71 -0
  117. package/lib/Utils/chat-utils.js +729 -0
  118. package/lib/Utils/crypto.d.ts +41 -0
  119. package/lib/Utils/crypto.js +151 -0
  120. package/lib/Utils/decode-wa-message.d.ts +19 -0
  121. package/lib/Utils/decode-wa-message.js +198 -0
  122. package/lib/Utils/event-buffer.d.ts +35 -0
  123. package/lib/Utils/event-buffer.js +514 -0
  124. package/lib/Utils/generics.d.ts +92 -0
  125. package/lib/Utils/generics.js +423 -0
  126. package/lib/Utils/history.d.ts +15 -0
  127. package/lib/Utils/history.js +96 -0
  128. package/lib/Utils/index.d.ts +17 -0
  129. package/lib/Utils/index.js +33 -0
  130. package/lib/Utils/link-preview.d.ts +21 -0
  131. package/lib/Utils/link-preview.js +93 -0
  132. package/lib/Utils/logger.d.ts +4 -0
  133. package/lib/Utils/logger.js +7 -0
  134. package/lib/Utils/lt-hash.d.ts +12 -0
  135. package/lib/Utils/lt-hash.js +51 -0
  136. package/lib/Utils/make-mutex.d.ts +7 -0
  137. package/lib/Utils/make-mutex.js +43 -0
  138. package/lib/Utils/messages-media.d.ts +116 -0
  139. package/lib/Utils/messages-media.js +819 -0
  140. package/lib/Utils/messages.d.ts +77 -0
  141. package/lib/Utils/messages.js +816 -0
  142. package/lib/Utils/noise-handler.d.ts +21 -0
  143. package/lib/Utils/noise-handler.js +155 -0
  144. package/lib/Utils/process-message.d.ts +41 -0
  145. package/lib/Utils/process-message.js +321 -0
  146. package/lib/Utils/signal.d.ts +32 -0
  147. package/lib/Utils/signal.js +153 -0
  148. package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  149. package/lib/Utils/use-multi-file-auth-state.js +119 -0
  150. package/lib/Utils/validate-connection.d.ts +11 -0
  151. package/lib/Utils/validate-connection.js +229 -0
  152. package/lib/WABinary/constants.d.ts +30 -0
  153. package/lib/WABinary/constants.js +40 -0
  154. package/lib/WABinary/decode.d.ts +7 -0
  155. package/lib/WABinary/decode.js +252 -0
  156. package/lib/WABinary/encode.d.ts +3 -0
  157. package/lib/WABinary/encode.js +260 -0
  158. package/lib/WABinary/generic-utils.d.ts +17 -0
  159. package/lib/WABinary/generic-utils.js +198 -0
  160. package/lib/WABinary/index.d.ts +5 -0
  161. package/lib/WABinary/index.js +21 -0
  162. package/lib/WABinary/jid-utils.d.ts +31 -0
  163. package/lib/WABinary/jid-utils.js +62 -0
  164. package/lib/WABinary/types.d.ts +18 -0
  165. package/lib/WABinary/types.js +2 -0
  166. package/lib/WAM/BinaryInfo.d.ts +17 -0
  167. package/lib/WAM/BinaryInfo.js +13 -0
  168. package/lib/WAM/constants.d.ts +38 -0
  169. package/lib/WAM/constants.js +15350 -0
  170. package/lib/WAM/encode.d.ts +3 -0
  171. package/lib/WAM/encode.js +155 -0
  172. package/lib/WAM/index.d.ts +3 -0
  173. package/lib/WAM/index.js +19 -0
  174. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
  175. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  176. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  177. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  178. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  179. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  180. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  181. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  182. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
  183. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
  184. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
  185. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
  186. package/lib/WAUSync/Protocols/index.d.ts +4 -0
  187. package/lib/WAUSync/Protocols/index.js +20 -0
  188. package/lib/WAUSync/USyncQuery.d.ts +28 -0
  189. package/lib/WAUSync/USyncQuery.js +89 -0
  190. package/lib/WAUSync/USyncUser.d.ts +12 -0
  191. package/lib/WAUSync/USyncUser.js +26 -0
  192. package/lib/WAUSync/index.d.ts +3 -0
  193. package/lib/WAUSync/index.js +19 -0
  194. package/lib/dread-features.d.ts +76 -0
  195. package/lib/dread-features.js +543 -0
  196. package/lib/dread-index.d.ts +6 -0
  197. package/lib/dread-index.js +19 -0
  198. package/lib/index.d.ts +12 -0
  199. package/lib/index.js +38 -0
  200. package/package.json +111 -0
@@ -0,0 +1,12 @@
1
+ export declare class USyncUser {
2
+ id: string;
3
+ lid: string;
4
+ phone: string;
5
+ type: string;
6
+ personaId: string;
7
+ withId(id: string): this;
8
+ withLid(lid: string): this;
9
+ withPhone(phone: string): this;
10
+ withType(type: string): this;
11
+ withPersonaId(personaId: string): this;
12
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.USyncUser = void 0;
4
+ class USyncUser {
5
+ withId(id) {
6
+ this.id = id;
7
+ return this;
8
+ }
9
+ withLid(lid) {
10
+ this.lid = lid;
11
+ return this;
12
+ }
13
+ withPhone(phone) {
14
+ this.phone = phone;
15
+ return this;
16
+ }
17
+ withType(type) {
18
+ this.type = type;
19
+ return this;
20
+ }
21
+ withPersonaId(personaId) {
22
+ this.personaId = personaId;
23
+ return this;
24
+ }
25
+ }
26
+ exports.USyncUser = USyncUser;
@@ -0,0 +1,3 @@
1
+ export * from './Protocols';
2
+ export * from './USyncQuery';
3
+ export * from './USyncUser';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Protocols"), exports);
18
+ __exportStar(require("./USyncQuery"), exports);
19
+ __exportStar(require("./USyncUser"), exports);
@@ -0,0 +1,76 @@
1
+ import { MiscMessageGenerationOptions, proto } from './Types';
2
+
3
+ export type RichMenuButton = string | {
4
+ id?: string;
5
+ label?: string;
6
+ };
7
+
8
+ export type RichMenuCard = {
9
+ title?: string;
10
+ toast?: string;
11
+ buttons?: RichMenuButton[];
12
+ };
13
+
14
+ export type RichMenuContent = {
15
+ header?: {
16
+ disclaimer?: boolean;
17
+ disclaimerText?: string;
18
+ image?: {
19
+ inline?: boolean;
20
+ mime_type?: string;
21
+ url?: string;
22
+ width?: number;
23
+ height?: number;
24
+ };
25
+ title?: string;
26
+ };
27
+ body?: {
28
+ cards?: RichMenuCard[];
29
+ buttons?: RichMenuButton[];
30
+ title?: string;
31
+ toast?: string;
32
+ carousel?: boolean;
33
+ row?: boolean;
34
+ };
35
+ footer?: {
36
+ text?: string;
37
+ url?: string;
38
+ image?: {
39
+ mime_type?: string;
40
+ url?: string;
41
+ width?: number;
42
+ height?: number;
43
+ };
44
+ };
45
+ contextInfo?: proto.IContextInfo;
46
+ };
47
+
48
+ export type DreadSocketHelpers = {
49
+ decodeJid(jid?: string): string | undefined;
50
+ sendjson(target: string, json?: proto.IMessage, config?: Record<string, unknown>): Promise<string>;
51
+ richMenu(target: string, content?: RichMenuContent, config?: Record<string, unknown>): Promise<proto.WebMessageInfo>;
52
+ pollMenu(jid: string, name?: string, pollOptions?: { vote: string; [key: string]: unknown }[], context?: Record<string, unknown>, selectableCount?: number): Promise<proto.WebMessageInfo>;
53
+ makeFakeCommand(m: any, text: string, chatUpdate?: any): Promise<boolean>;
54
+ getLidForJid(jid: string): Promise<string>;
55
+ listKnownLids(jid?: string): Promise<string[]>;
56
+ revealViewOnce(target: string, quotedOrMessage: any, options?: Record<string, unknown>): Promise<string>;
57
+ sendDreadText(jid: string, text: string, options?: MiscMessageGenerationOptions): Promise<proto.WebMessageInfo>;
58
+ runCheckDevice(payload: { msg: any; from: string; reply?: (text: string) => unknown | Promise<unknown> }): Promise<unknown>;
59
+ };
60
+
61
+ export declare function attachDreadFeatures<T extends Record<string, any>>(sock: T): T & DreadSocketHelpers;
62
+ export declare function buildRichMenuMessage(content?: RichMenuContent): proto.IMessage;
63
+ export declare function getDevice(id?: string): 'ios' | 'web' | 'android' | 'desktop' | 'unknown';
64
+ export declare function getLidForJid(sock: any, jid: string): Promise<string>;
65
+ export declare function jidNumber(jid?: string): string;
66
+ export declare function listKnownLids(sock: any, jid?: string): Promise<string[]>;
67
+ export declare function makeFakeCommand(sock: any, m: any, text: string, chatUpdate?: any): Promise<boolean>;
68
+ export declare function normalizeJid(jid?: string): string | undefined;
69
+ export declare function patchConnectionConfig<T extends Record<string, any>>(config?: T): T & { patchMessageBeforeSending: (...args: any[]) => any };
70
+ export declare function patchRichResponseMessage(message: proto.IMessage): proto.IMessage;
71
+ export declare function pollMenu(sock: any, jid: string, name?: string, pollOptions?: { vote: string; [key: string]: unknown }[], context?: Record<string, unknown>, selectableCount?: number): Promise<proto.WebMessageInfo>;
72
+ export declare function revealViewOnce(sock: any, target: string, quotedOrMessage: any, options?: Record<string, unknown>): Promise<string>;
73
+ export declare function richMenu(sock: any, target: string, content?: RichMenuContent, config?: Record<string, unknown>): Promise<proto.WebMessageInfo>;
74
+ export declare function runCheckDevice(payload: { sock: any; msg: any; from: string; reply?: (text: string) => unknown | Promise<unknown> }): Promise<unknown>;
75
+ export declare function sendDreadText(sock: any, jid: string, text: string, options?: MiscMessageGenerationOptions): Promise<proto.WebMessageInfo>;
76
+ export declare function sendjson(sock: any, target: string, json?: proto.IMessage, config?: Record<string, unknown>): Promise<string>;
@@ -0,0 +1,543 @@
1
+ "use strict";
2
+
3
+ let utilsModule;
4
+ let waBinaryModule;
5
+ let waUSyncModule;
6
+
7
+ function utils() {
8
+ if (!utilsModule) utilsModule = require("./Utils");
9
+ return utilsModule;
10
+ }
11
+
12
+ function waBinary() {
13
+ if (!waBinaryModule) waBinaryModule = require("./WABinary");
14
+ return waBinaryModule;
15
+ }
16
+
17
+ function waUSync() {
18
+ if (!waUSyncModule) waUSyncModule = require("./WAUSync");
19
+ return waUSyncModule;
20
+ }
21
+
22
+ function jidNumber(jid) {
23
+ return String(jid || "").split("@")[0].split(":")[0].replace(/[^0-9]/g, "");
24
+ }
25
+
26
+ function normalizeJid(jid) {
27
+ if (!jid) return jid;
28
+ if (/:\d+@/gi.test(jid)) {
29
+ const decoded = waBinary().jidDecode(jid) || {};
30
+ return decoded.user && decoded.server ? `${decoded.user}@${decoded.server}` : jid;
31
+ }
32
+ return jid;
33
+ }
34
+
35
+ function getDevice(id) {
36
+ if (!id || typeof id !== "string") return "unknown";
37
+ if (/^3A.{18}$/.test(id)) return "ios";
38
+ if (/^3E.{20}$/.test(id)) return "web";
39
+ if (/^(.{21}|.{32})$/.test(id)) return "android";
40
+ if (/^(3F|.{18}$)/.test(id)) return "desktop";
41
+ return "unknown";
42
+ }
43
+
44
+ function patchRichResponseMessage(msg) {
45
+ const wrapRich = (message) => {
46
+ const richResponse =
47
+ message?.botForwardedMessage?.message?.richResponseMessage ||
48
+ message?.richResponseMessage;
49
+
50
+ if (!richResponse) return message;
51
+
52
+ richResponse.contextInfo = {
53
+ ...richResponse.contextInfo,
54
+ isForwarded: true,
55
+ forwardOrigin: 4,
56
+ };
57
+
58
+ return message.botForwardedMessage
59
+ ? message
60
+ : { botForwardedMessage: { message } };
61
+ };
62
+
63
+ if (msg?.deviceSentMessage?.message) {
64
+ msg.deviceSentMessage.message = wrapRich(msg.deviceSentMessage.message);
65
+ return msg;
66
+ }
67
+
68
+ return wrapRich(msg);
69
+ }
70
+
71
+ function patchConnectionConfig(config = {}) {
72
+ const originalPatch = config.patchMessageBeforeSending;
73
+ return {
74
+ ...config,
75
+ patchMessageBeforeSending: async (msg, ...args) => {
76
+ const patched = typeof originalPatch === "function"
77
+ ? await originalPatch(msg, ...args)
78
+ : msg;
79
+
80
+ if (Array.isArray(patched)) {
81
+ return patched.map((entry) => ({
82
+ ...entry,
83
+ message: patchRichResponseMessage(entry.message),
84
+ }));
85
+ }
86
+
87
+ return patchRichResponseMessage(patched);
88
+ },
89
+ };
90
+ }
91
+
92
+ function buildRichMenuMessage(content = {}) {
93
+ const header = content?.header;
94
+ const body = content?.body;
95
+ const footer = content?.footer;
96
+ let contextWrapper = {};
97
+ const sections = [];
98
+
99
+ if (header) {
100
+ const {
101
+ disclaimer = false,
102
+ disclaimerText = " ",
103
+ image = { inline: false },
104
+ title = "",
105
+ } = header ?? {};
106
+
107
+ if (disclaimer) {
108
+ contextWrapper = {
109
+ messageContextInfo: {
110
+ botMetadata: {
111
+ messageDisclaimerText: disclaimerText,
112
+ },
113
+ },
114
+ };
115
+ }
116
+
117
+ if (title) {
118
+ sections.push({
119
+ __typename: "GenAIUnifiedResponseSection",
120
+ view_model: {
121
+ __typename: "GenAISingleLayoutViewModel",
122
+ primitive: {
123
+ __typename: "FOATextPrimitive",
124
+ text: `# ${title}`,
125
+ },
126
+ },
127
+ });
128
+ }
129
+
130
+ if (image?.url) {
131
+ if (image?.inline) {
132
+ sections.push({
133
+ __typename: "GenAIUnifiedResponseSection",
134
+ view_model: {
135
+ __typename: "GenAISingleLayoutViewModel",
136
+ primitive: {
137
+ __typename: "GenAIMarkdownTextUXPrimitive",
138
+ text: "{{header}}.{{/header}}",
139
+ inline_entities: [
140
+ {
141
+ __typename: "GenAITextInlineEntity",
142
+ key: "header",
143
+ metadata: {
144
+ __typename: "GenAILatexItem",
145
+ latex_expression: ".",
146
+ font_height: 24,
147
+ padding: 4,
148
+ latex_image: {
149
+ __typename: "GenAIMediaItem",
150
+ mime_type: image.mime_type || "image/png",
151
+ url: image.url,
152
+ url_fallback: image.url,
153
+ width: image.width || 500,
154
+ height: image.height || 500,
155
+ expiration_timestamp_ms: Date.now() + 86400000,
156
+ },
157
+ },
158
+ },
159
+ ],
160
+ },
161
+ },
162
+ });
163
+ } else {
164
+ sections.push({
165
+ __typename: "GenAIUnifiedResponseSection",
166
+ view_model: {
167
+ __typename: "GenAISingleLayoutViewModel",
168
+ primitive: {
169
+ __typename: "GenAIImagePrimitive",
170
+ preview_image: {
171
+ __typename: "GenAIMediaItem",
172
+ mime_type: image.mime_type || "image/png",
173
+ url: image.url,
174
+ },
175
+ full_image: {
176
+ __typename: "GenAIMediaItem",
177
+ mime_type: image.mime_type || "image/png",
178
+ url: image.url,
179
+ },
180
+ },
181
+ },
182
+ });
183
+ }
184
+ }
185
+ }
186
+
187
+ if (body) {
188
+ const {
189
+ cards = null,
190
+ buttons = null,
191
+ title = "",
192
+ toast = "",
193
+ carousel = false,
194
+ row = false,
195
+ } = body ?? {};
196
+
197
+ if (carousel || row) {
198
+ if (cards?.length >= 1) {
199
+ sections.push({
200
+ __typename: "GenAIUnifiedResponseSection",
201
+ view_model: {
202
+ primitives: cards.map((card, cardIndex) => ({
203
+ __typename: "GenAI3PExtWidgetPrimitive",
204
+ header: {
205
+ __typename: "GenAI3PExtWidgetStandardHeader",
206
+ title: card?.title || "",
207
+ },
208
+ body: {
209
+ __typename: "GenAI3PExtCalendarEventList",
210
+ ctas: (card?.buttons || []).map((item, buttonIndex) => {
211
+ const label = typeof item === "object" ? item.label || item.id || "" : item;
212
+ return {
213
+ label,
214
+ state: "PENDING",
215
+ kind: "OTHER",
216
+ tool_call_id: `${cardIndex}${buttonIndex}`,
217
+ toast: {
218
+ label: card?.toast || "",
219
+ __typename: "GenAI3PExtWidgetToast",
220
+ },
221
+ __typename: "GenAI3PExtWidgetCTA",
222
+ };
223
+ }),
224
+ sections: [],
225
+ },
226
+ })),
227
+ __typename: carousel
228
+ ? "GenAIHScrollLayoutViewModel"
229
+ : "GenAIActionRowLayoutViewModel",
230
+ },
231
+ });
232
+ }
233
+ } else if (buttons?.length) {
234
+ sections.push({
235
+ __typename: "GenAIUnifiedResponseSection",
236
+ view_model: {
237
+ primitive: {
238
+ __typename: "GenAI3PExtWidgetPrimitive",
239
+ header: {
240
+ __typename: "GenAI3PExtWidgetStandardHeader",
241
+ title: title || "",
242
+ },
243
+ body: {
244
+ __typename: "GenAI3PExtCalendarEventList",
245
+ ctas: buttons.map((item, buttonIndex) => {
246
+ const label = typeof item === "object" ? item.label || item.id || "" : item;
247
+ return {
248
+ label,
249
+ state: "PENDING",
250
+ kind: "OTHER",
251
+ tool_call_id: `${buttonIndex}`,
252
+ toast: {
253
+ label: toast,
254
+ __typename: "GenAI3PExtWidgetToast",
255
+ },
256
+ __typename: "GenAI3PExtWidgetCTA",
257
+ };
258
+ }),
259
+ sections: [],
260
+ },
261
+ },
262
+ __typename: "GenAISingleLayoutViewModel",
263
+ },
264
+ });
265
+ }
266
+ }
267
+
268
+ if (footer) {
269
+ const { text = "", url = "", image = {} } = footer ?? {};
270
+ const footerPrimitives = [];
271
+ if (image?.url) {
272
+ footerPrimitives.push({
273
+ __typename: "GenAIMarkdownTextUXPrimitive",
274
+ text: "{{header}}.{{/header}}",
275
+ inline_entities: [
276
+ {
277
+ __typename: "GenAITextInlineEntity",
278
+ key: "header",
279
+ metadata: {
280
+ __typename: "GenAILatexItem",
281
+ latex_expression: ".",
282
+ font_height: 24,
283
+ padding: -5,
284
+ latex_image: {
285
+ __typename: "GenAIMediaItem",
286
+ mime_type: image.mime_type || "image/png",
287
+ url: image.url,
288
+ url_fallback: image.url,
289
+ width: image.width || 100,
290
+ height: image.height || 100,
291
+ expiration_timestamp_ms: Date.now() + 86400000,
292
+ },
293
+ },
294
+ },
295
+ ],
296
+ });
297
+ }
298
+
299
+ sections.push({
300
+ view_model: {
301
+ primitives: [
302
+ {
303
+ cta_text: text || "Tg",
304
+ cta_type: "OPEN_URL",
305
+ cta_url: url || "https://t.me/kenzki_01",
306
+ __typename: "GenAIFooterActionPrimitive",
307
+ },
308
+ ...footerPrimitives,
309
+ ],
310
+ __typename: "GenAIActionRowLayoutViewModel",
311
+ },
312
+ });
313
+ }
314
+
315
+ return {
316
+ ...contextWrapper,
317
+ botForwardedMessage: {
318
+ message: {
319
+ richResponseMessage: {
320
+ unifiedResponse: {
321
+ data: Buffer.from(JSON.stringify({ sections })).toString("base64"),
322
+ },
323
+ contextInfo: {
324
+ isForwarded: true,
325
+ forwardOrigin: 4,
326
+ ...(content?.contextInfo ?? {}),
327
+ },
328
+ },
329
+ },
330
+ },
331
+ };
332
+ }
333
+
334
+ async function sendjson(sock, target, json = {}, config = {}) {
335
+ const { generateWAMessageFromContent } = utils();
336
+ const msg = generateWAMessageFromContent(target, json, { userJid: sock.user?.id });
337
+ return sock.relayMessage(target, msg.message, { messageId: msg.key.id, ...config });
338
+ }
339
+
340
+ async function richMenu(sock, target, content = {}, config = {}) {
341
+ const { generateWAMessageFromContent } = utils();
342
+ const msg = generateWAMessageFromContent(target, buildRichMenuMessage(content), {
343
+ userJid: sock.user?.id,
344
+ });
345
+ await sock.relayMessage(target, msg.message, { messageId: msg.key.id, ...config });
346
+ return msg;
347
+ }
348
+
349
+ async function sendDreadText(sock, jid, text, options = {}) {
350
+ const { generateWAMessageFromContent } = utils();
351
+ const mentions = Array.isArray(options.mentions) ? options.mentions : [];
352
+ const generated = generateWAMessageFromContent(
353
+ jid,
354
+ {
355
+ extendedTextMessage: {
356
+ text: String(text ?? ""),
357
+ ...(mentions.length ? { contextInfo: { mentionedJid: mentions } } : {}),
358
+ },
359
+ },
360
+ { userJid: sock.user?.id },
361
+ );
362
+
363
+ await sock.relayMessage(jid, generated.message, { messageId: generated.key.id });
364
+ return generated;
365
+ }
366
+
367
+ async function pollMenu(sock, jid, name = "", pollOptions = [], _context = {}, selectableCount = 1) {
368
+ const { generateWAMessage } = utils();
369
+ const values = pollOptions.map((option) => option.vote);
370
+ const pollMsg = await generateWAMessage(
371
+ jid,
372
+ { poll: { name, values, selectableCount } },
373
+ { userJid: sock.user?.id },
374
+ );
375
+ await sock.relayMessage(jid, pollMsg.message, { messageId: pollMsg.key.id });
376
+ sock.tempPollStore = sock.tempPollStore || [];
377
+ sock.tempPollStore.push({ id: pollMsg.key.id, cmds: pollOptions });
378
+ return pollMsg;
379
+ }
380
+
381
+ async function makeFakeCommand(sock, m, text, chatUpdate) {
382
+ const { generateWAMessageFromContent } = utils();
383
+ let recipient = m.key.remoteJid;
384
+ if (recipient?.includes(":")) {
385
+ recipient = `${recipient.split(":")[0]}@lid`;
386
+ }
387
+
388
+ const messages = await generateWAMessageFromContent(
389
+ recipient,
390
+ { extendedTextMessage: { text: text || "" } },
391
+ { userJid: sock.user?.id },
392
+ );
393
+ messages.key.fromMe = true;
394
+ messages.key.id = "INTERNAL-CMD";
395
+ messages.pushName = m.pushName;
396
+ if (chatUpdate) {
397
+ messages.key.participant =
398
+ chatUpdate[0]?.update?.pollUpdates?.[0]?.pollUpdateMessageKey?.participant || "";
399
+ }
400
+
401
+ return sock.ev.emit("messages.upsert", {
402
+ messages: [messages],
403
+ type: "append",
404
+ });
405
+ }
406
+
407
+ async function getLidForJid(sock, jid) {
408
+ const { USyncQuery, USyncUser } = waUSync();
409
+ const normalized = normalizeJid(jid);
410
+ if (!normalized) return "";
411
+ if (normalized.endsWith("@lid")) return normalized;
412
+ if (typeof sock.executeUSyncQuery !== "function") return "";
413
+
414
+ const query = new USyncQuery()
415
+ .withContext("background")
416
+ .withLIDProtocol()
417
+ .withUser(new USyncUser().withId(normalized));
418
+ const result = await sock.executeUSyncQuery(query);
419
+ const match = result?.list?.find((entry) => entry?.lid || entry?.id === normalized);
420
+ return normalizeJid(match?.lid || "");
421
+ }
422
+
423
+ async function listKnownLids(sock, jid = sock.user?.id) {
424
+ const { USyncQuery, USyncUser } = waUSync();
425
+ const lids = new Set();
426
+ const ownLid = normalizeJid(sock.user?.lid || "");
427
+ const normalized = normalizeJid(jid || "");
428
+
429
+ if (ownLid) lids.add(ownLid);
430
+ if (normalized?.endsWith("@lid")) lids.add(normalized);
431
+
432
+ if (typeof sock.executeUSyncQuery === "function" && normalized) {
433
+ const user = normalized.endsWith("@lid")
434
+ ? new USyncUser().withLid(normalized)
435
+ : new USyncUser().withId(normalized);
436
+ const query = new USyncQuery().withContext("background").withLIDProtocol().withUser(user);
437
+ const result = await sock.executeUSyncQuery(query);
438
+ for (const entry of result?.list || []) {
439
+ if (entry?.lid) lids.add(normalizeJid(entry.lid));
440
+ }
441
+ }
442
+
443
+ return Array.from(lids).filter(Boolean);
444
+ }
445
+
446
+ async function revealViewOnce(sock, target, quotedOrMessage, options = {}) {
447
+ const { getContentType } = utils();
448
+ const message =
449
+ quotedOrMessage?.fakeObj?.message ||
450
+ quotedOrMessage?.message ||
451
+ quotedOrMessage?.extendedTextMessage?.contextInfo?.quotedMessage ||
452
+ quotedOrMessage;
453
+
454
+ if (!message || typeof message !== "object") {
455
+ throw new Error("No quoted view-once message found.");
456
+ }
457
+
458
+ const type = getContentType(message);
459
+ const inner = type ? message[type] : message;
460
+ if (inner?.videoMessage?.viewOnce) inner.videoMessage.viewOnce = false;
461
+ if (inner?.imageMessage?.viewOnce) inner.imageMessage.viewOnce = false;
462
+ if (inner?.audioMessage?.viewOnce) inner.audioMessage.viewOnce = false;
463
+ if (message?.videoMessage?.viewOnce) message.videoMessage.viewOnce = false;
464
+ if (message?.imageMessage?.viewOnce) message.imageMessage.viewOnce = false;
465
+ if (message?.audioMessage?.viewOnce) message.audioMessage.viewOnce = false;
466
+
467
+ return sock.relayMessage(target, message, options);
468
+ }
469
+
470
+ async function runCheckDevice({ sock, msg, from, reply }) {
471
+ const ctx = msg?.message?.extendedTextMessage?.contextInfo || msg?.msg?.contextInfo || null;
472
+ if (!ctx || !ctx.stanzaId || !ctx.participant) {
473
+ if (reply) return reply("Reply to a user's recent message to reveal their device.");
474
+ return;
475
+ }
476
+
477
+ const userJid = ctx.participant;
478
+ const number = String(userJid || "").split("@")[0];
479
+ const candidateIds = [
480
+ ctx.stanzaId,
481
+ msg?.key?.id,
482
+ msg?.quoted?.id,
483
+ msg?.message?.extendedTextMessage?.contextInfo?.stanzaId,
484
+ msg?.msg?.key?.id,
485
+ ].filter(Boolean);
486
+
487
+ let device = "unknown";
488
+ for (const id of candidateIds) {
489
+ const detected = getDevice(id);
490
+ if (detected !== "unknown") {
491
+ device = detected;
492
+ break;
493
+ }
494
+ }
495
+
496
+ const pretty = {
497
+ android: "A N D R O I D",
498
+ ios: "I P H O N E",
499
+ web: "W A - W E B",
500
+ desktop: "D E S K T O P",
501
+ unknown: "U N K N O W N",
502
+ }[device] || device.toUpperCase();
503
+
504
+ return sendDreadText(sock, from, `DEVICE CHECK\n@${number}\nDevice: *${pretty}*`, {
505
+ mentions: [userJid],
506
+ });
507
+ }
508
+
509
+ function attachDreadFeatures(sock) {
510
+ sock.tempPollStore = sock.tempPollStore || [];
511
+ sock.decodeJid = sock.decodeJid || normalizeJid;
512
+ sock.sendjson = (target, json = {}, config = {}) => sendjson(sock, target, json, config);
513
+ sock.richMenu = (target, content = {}, config = {}) => richMenu(sock, target, content, config);
514
+ sock.pollMenu = (jid, name = "", pollOptions = [], context = {}, selectableCount = 1) =>
515
+ pollMenu(sock, jid, name, pollOptions, context, selectableCount);
516
+ sock.makeFakeCommand = (m, text, chatUpdate) => makeFakeCommand(sock, m, text, chatUpdate);
517
+ sock.getLidForJid = (jid) => getLidForJid(sock, jid);
518
+ sock.listKnownLids = (jid) => listKnownLids(sock, jid);
519
+ sock.revealViewOnce = (target, quotedOrMessage, options = {}) =>
520
+ revealViewOnce(sock, target, quotedOrMessage, options);
521
+ sock.sendDreadText = (jid, text, options = {}) => sendDreadText(sock, jid, text, options);
522
+ sock.runCheckDevice = (payload) => runCheckDevice({ sock, ...payload });
523
+ return sock;
524
+ }
525
+
526
+ module.exports = {
527
+ attachDreadFeatures,
528
+ buildRichMenuMessage,
529
+ getDevice,
530
+ getLidForJid,
531
+ jidNumber,
532
+ listKnownLids,
533
+ makeFakeCommand,
534
+ normalizeJid,
535
+ patchConnectionConfig,
536
+ patchRichResponseMessage,
537
+ pollMenu,
538
+ revealViewOnce,
539
+ richMenu,
540
+ runCheckDevice,
541
+ sendDreadText,
542
+ sendjson,
543
+ };
@@ -0,0 +1,6 @@
1
+ import makeWASocket from './Socket';
2
+
3
+ export * from './index';
4
+ export * from './dread-features';
5
+ export { makeWASocket };
6
+ export default makeWASocket;