@badzz88/baileys 8.4.2 → 8.4.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.
@@ -1,29 +1,38 @@
1
- const { readFileSync, writeFileSync } = require 'fs';
2
- const { exit } = require 'process';
1
+ const { readFileSync, writeFileSync } = require('fs');
2
+ const { exit } = require('process');
3
3
 
4
- const filePath = './index.js';
4
+ const FILE = './index.js';
5
5
 
6
6
  try {
7
- // Read the file
8
- let content = readFileSync(filePath, 'utf8');
7
+ let content = readFileSync(FILE, 'utf8');
9
8
 
10
- // Fix the import statement
11
- content = content.replace(
12
- /import \* as (\$protobuf) from/g,
13
- 'import $1 from'
14
- );
9
+ content = content
10
+ .replace(
11
+ /import \* as (\$protobuf) from/g,
12
+ 'import $1 from'
13
+ )
14
+ .replace(
15
+ /(['"])protobufjs\/minimal(['"])/g,
16
+ '$1protobufjs/minimal.js$2'
17
+ );
15
18
 
16
- // add missing extension to the import
17
- content = content.replace(
18
- /(['"])protobufjs\/minimal(['"])/g,
19
- '$1protobufjs/minimal.js$2'
20
- );
19
+ writeFileSync(FILE, content, 'utf8');
21
20
 
22
- // Write back
23
- writeFileSync(filePath, content, 'utf8');
24
-
25
- console.log(`✅ Fixed imports in ${filePath}`);
26
- } catch (error) {
27
- console.error(`❌ Error fixing imports: ${error.message}`);
28
- exit(1);
29
- }
21
+ console.log(`
22
+ ╔════════════════════════╗
23
+ ║ ✅ IMPORTS PATCHED ║
24
+ ╠════════════════════════╣
25
+ ║ File : ${FILE.padEnd(26)}║
26
+ ║ Status : Success ║
27
+ ╚════════════════════════╝
28
+ `);
29
+ } catch (err) {
30
+ console.error(`
31
+ ╔════════════════════════╗
32
+ ║ ❌ PATCH FAILED
33
+ ╠════════════════════════╣
34
+ ║ ${err.message}
35
+ ╚════════════════════════╝
36
+ `);
37
+ exit(1);
38
+ }
@@ -1,85 +1,86 @@
1
- import { readFileSync, writeFileSync } from 'fs';
2
- import { exit } from 'process';
3
-
4
- const filePath = './index.js'
5
-
6
- try {
7
- let content = readFileSync(filePath, 'utf8')
8
-
9
- content = content.replace(/import \* as (\$protobuf) from/g, 'import $1 from')
10
- content = content.replace(/(['"])protobufjs\/minimal(['"])/g, '$1protobufjs/minimal.js$2')
11
-
12
- const marker = 'const $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {});\n\n'
13
- const longToStringHelper =
14
- 'function longToString(value, unsigned) {\n' +
15
- '\tif (typeof value === "string") {\n' +
16
- '\t\treturn value;\n' +
17
- '\t}\n' +
18
- '\tif (typeof value === "number") {\n' +
19
- '\t\treturn String(value);\n' +
20
- '\t}\n' +
21
- '\t// Fast path: convert Long {low, high} directly via native BigInt\n' +
22
- '\t// BigInt.toString() is a native C++ operation, much faster than Long\'s pure JS division loops\n' +
23
- '\tif (value && typeof value.low === "number" && typeof value.high === "number") {\n' +
24
- '\t\tconst lo = BigInt(value.low >>> 0);\n' +
25
- '\t\tconst hi = BigInt(value.high >>> 0);\n' +
26
- '\t\tconst combined = (hi << 32n) | lo;\n' +
27
- '\t\tif (!unsigned && value.high < 0) {\n' +
28
- '\t\t\treturn (combined - (1n << 64n)).toString();\n' +
29
- '\t\t}\n' +
30
- '\t\treturn combined.toString();\n' +
31
- '\t}\n' +
32
- '\treturn String(value);\n' +
33
- '}\n\n'
34
- const longToNumberHelper =
35
- 'function longToNumber(value, unsigned) {\n' +
36
- '\tif (typeof value === "number") {\n' +
37
- '\t\treturn value;\n' +
38
- '\t}\n' +
39
- '\tif (typeof value === "string") {\n' +
40
- '\t\treturn Number(value);\n' +
41
- '\t}\n' +
42
- '\t// Fast path: convert Long {low, high} directly via native BigInt\n' +
43
- '\tif (value && typeof value.low === "number" && typeof value.high === "number") {\n' +
44
- '\t\tconst lo = BigInt(value.low >>> 0);\n' +
45
- '\t\tconst hi = BigInt(value.high >>> 0);\n' +
46
- '\t\tconst combined = (hi << 32n) | lo;\n' +
47
- '\t\tif (!unsigned && value.high < 0) {\n' +
48
- '\t\t\treturn Number(combined - (1n << 64n));\n' +
49
- '\t\t}\n' +
50
- '\t\treturn Number(combined);\n' +
51
- '\t}\n' +
52
- '\treturn Number(value);\n' +
53
- '}\n\n'
54
-
55
- if (!content.includes('function longToString(')) {
56
- const markerIndex = content.indexOf(marker)
57
- if (markerIndex === -1) {
58
- throw new Error('Unable to inject Long helpers: marker not found in WAProto index output')
59
- }
60
-
61
- content = content.replace(marker, `${marker}${longToStringHelper}${longToNumberHelper}`)
62
- } else {
63
- const longToStringRegex = /function longToString\(value, unsigned\) {\n[\s\S]*?\n}\n\n/
64
- const longToNumberRegex = /function longToNumber\(value, unsigned\) {\n[\s\S]*?\n}\n\n/
65
-
66
- if (!longToStringRegex.test(content) || !longToNumberRegex.test(content)) {
67
- throw new Error('Unable to update Long helpers: existing definitions not found')
68
- }
69
-
70
- content = content.replace(longToStringRegex, longToStringHelper)
71
- content = content.replace(longToNumberRegex, longToNumberHelper)
72
- }
73
-
74
- const longPattern = /([ \t]+d\.(\w+) = )o\.longs === String \? \$util\.Long\.prototype\.toString\.call\(m\.\2\) : o\.longs === Number \? new \$util\.LongBits\(m\.\2\.low >>> 0, m\.\2\.high >>> 0\)\.toNumber\((true)?\) : m\.\2;/g
75
- content = content.replace(longPattern, (_match, prefix, field, unsignedFlag) => {
76
- const unsignedArg = unsignedFlag ? ', true' : ''
77
- return `${prefix}o.longs === String ? longToString(m.${field}${unsignedArg}) : o.longs === Number ? longToNumber(m.${field}${unsignedArg}) : m.${field};`
78
- })
79
-
80
- writeFileSync(filePath, content, 'utf8')
81
- console.log(`✅ Fixed imports in ${filePath}`)
82
- } catch (error) {
83
- console.error(`❌ Error fixing imports: ${error.message}`)
84
- exit(1)
85
- }
1
+ import { readFileSync, writeFileSync } from 'fs';
2
+ import { exit } from 'process';
3
+
4
+ const filePath = './index.js'
5
+
6
+ try {
7
+ let content = readFileSync(filePath, 'utf8')
8
+
9
+ content = content.replace(/import \* as (\$protobuf) from/g, 'import $1 from')
10
+ content = content.replace(/(['"])protobufjs\/minimal(['"])/g, '$1protobufjs/minimal.js$2')
11
+
12
+ const marker = 'const $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {});\n\n'
13
+ const longToStringHelper =
14
+ 'function longToString(value, unsigned) {\n' +
15
+ '\tif (typeof value === "string") {\n' +
16
+ '\t\treturn value;\n' +
17
+ '\t}\n' +
18
+ '\tif (typeof value === "number") {\n' +
19
+ '\t\treturn String(value);\n' +
20
+ '\t}\n' +
21
+ '\t// Fast path: convert Long {low, high} directly via native BigInt\n' +
22
+ '\t// BigInt.toString() is a native C++ operation, much faster than Long\'s pure JS division loops\n' +
23
+ '\tif (value && typeof value.low === "number" && typeof value.high === "number") {\n' +
24
+ '\t\tconst lo = BigInt(value.low >>> 0);\n' +
25
+ '\t\tconst hi = BigInt(value.high >>> 0);\n' +
26
+ '\t\tconst combined = (hi << 32n) | lo;\n' +
27
+ '\t\tif (!unsigned && value.high < 0) {\n' +
28
+ '\t\t\treturn (combined - (1n << 64n)).toString();\n' +
29
+ '\t\t}\n' +
30
+ '\t\treturn combined.toString();\n' +
31
+ '\t}\n' +
32
+ '\treturn String(value);\n' +
33
+ '}\n\n'
34
+ const longToNumberHelper =
35
+ 'function longToNumber(value, unsigned) {\n' +
36
+ '\tif (typeof value === "number") {\n' +
37
+ '\t\treturn value;\n' +
38
+ '\t}\n' +
39
+ '\tif (typeof value === "string") {\n' +
40
+ '\t\treturn Number(value);\n' +
41
+ '\t}\n' +
42
+ '\t// Fast path: convert Long {low, high} directly via native BigInt\n' +
43
+ '\tif (value && typeof value.low === "number" && typeof value.high === "number") {\n' +
44
+ '\t\tconst lo = BigInt(value.low >>> 0);\n' +
45
+ '\t\tconst hi = BigInt(value.high >>> 0);\n' +
46
+ '\t\tconst combined = (hi << 32n) | lo;\n' +
47
+ '\t\tif (!unsigned && value.high < 0) {\n' +
48
+ '\t\t\treturn Number(combined - (1n << 64n));\n' +
49
+ '\t\t}\n' +
50
+ '\t\treturn Number(combined);\n' +
51
+ '\t}\n' +
52
+ '\treturn Number(value);\n' +
53
+ '}\n\n'
54
+
55
+ if (!content.includes('function longToString(')) {
56
+ const markerIndex = content.indexOf(marker)
57
+ if (markerIndex === -1) {
58
+ throw new Error('Unable to inject Long helpers: marker not found in WAProto index output')
59
+ }
60
+
61
+ content = content.replace(marker, `${marker}${longToStringHelper}${longToNumberHelper}`)
62
+ } else {
63
+ const longToStringRegex = /function longToString\(value, unsigned\) {\n[\s\S]*?\n}\n\n/
64
+ const longToNumberRegex = /function longToNumber\(value, unsigned\) {\n[\s\S]*?\n}\n\n/
65
+
66
+ if (!longToStringRegex.test(content) || !longToNumberRegex.test(content)) {
67
+ throw new Error('Unable to update Long helpers: existing definitions not found')
68
+ }
69
+
70
+ content = content.replace(longToStringRegex, longToStringHelper)
71
+ content = content.replace(longToNumberRegex, longToNumberHelper)
72
+ }
73
+
74
+ const longPattern = /([ \t]+d\.(\w+) = )o\.longs === String \? \$util\.Long\.prototype\.toString\.call\(m\.\2\) : o\.longs === Number \? new \$util\.LongBits\(m\.\2\.low >>> 0, m\.\2\.high >>> 0\)\.toNumber\((true)?\) : m\.\2;/g
75
+ content = content.replace(longPattern, (_match, prefix, field, unsignedFlag) => {
76
+ const unsignedArg = unsignedFlag ? ', true' : ''
77
+ return `${prefix}o.longs === String ? longToString(m.${field}${unsignedArg}) : o.longs === Number ? longToNumber(m.${field}${unsignedArg}) : m.${field};`
78
+ })
79
+
80
+ writeFileSync(filePath, content, 'utf8')
81
+ console.log(`✅ Fixed imports in ${filePath}`)
82
+ } catch (error) {
83
+ console.error(`❌ Error fixing imports: ${error.message}`)
84
+ exit(1)
85
+ }
86
+
@@ -1,10 +1,18 @@
1
- const major = parseInt(process.versions.node.split('.')[0], 10);
1
+ const major = parseInt(process.versions.node.split(".")[0], 10);
2
2
 
3
3
  if (major < 20) {
4
- console.error(
5
- `\n❌ This package requires Node.js 20+ to run reliably.\n` +
6
- ` You are using Node.js ${process.versions.node}.\n` +
7
- ` Please upgrade to Node.js 20+ to proceed.\n`
8
- );
4
+ console.error(`
5
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━
6
+ 🚫 Unsupported Node.js Version
7
+
8
+ • Current : v${process.versions.node}
9
+ • Required : v20.0.0+
10
+
11
+ This package uses features available only in
12
+ Node.js 20 or newer.
13
+
14
+ Please update Node.js and try again.
15
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━
16
+ `);
9
17
  process.exit(1);
10
- }
18
+ }
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": [2, 3000, 1035194821]
2
+ "version": [2, 3000, 1043359815]
3
3
  }
@@ -15,21 +15,20 @@ export const WA_ADV_DEVICE_SIG_PREFIX = Buffer.from([6, 1]);
15
15
  export const WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX = Buffer.from([6, 5]);
16
16
  export const WA_ADV_HOSTED_DEVICE_SIG_PREFIX = Buffer.from([6, 6]);
17
17
  export const WA_DEFAULT_EPHEMERAL = 7 * 24 * 60 * 60;
18
- /** Status messages older than 24 hours are considered expired */
19
18
  export const STATUS_EXPIRY_SECONDS = 24 * 60 * 60;
20
- /** WA Web enforces a 14-day maximum age for placeholder resend requests */
21
19
  export const PLACEHOLDER_MAX_AGE_SECONDS = 14 * 24 * 60 * 60;
22
20
  export const NOISE_MODE = 'Noise_XX_25519_AESGCM_SHA256\0\0\0\0';
23
21
  export const DICT_VERSION = 3;
24
22
  export const KEY_BUNDLE_TYPE = Buffer.from([5]);
25
- export const NOISE_WA_HEADER = Buffer.from([87, 65, 6, DICT_VERSION]); // last is "DICT_VERSION"
26
- /** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
23
+ export const NOISE_WA_HEADER = Buffer.from([87, 65, 6, DICT_VERSION]);
27
24
  export const URL_REGEX = /https:\/\/(?![^:@\/\s]+:[^:@\/\s]+@)[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?/g;
25
+
28
26
  export const WA_CERT_DETAILS = {
29
27
  SERIAL: 0,
30
28
  ISSUER: 'WhatsAppLongTerm1',
31
29
  PUBLIC_KEY: Buffer.from('142375574d0a587166aae71ebe516437c4a28b73e3695c6ce1f7f9545da8ee6b', 'hex')
32
30
  };
31
+
33
32
  export const PROCESSABLE_HISTORY_TYPES = [
34
33
  proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP,
35
34
  proto.HistorySync.HistorySyncType.PUSH_NAME,
@@ -39,14 +38,16 @@ export const PROCESSABLE_HISTORY_TYPES = [
39
38
  proto.HistorySync.HistorySyncType.NON_BLOCKING_DATA,
40
39
  proto.HistorySync.HistorySyncType.INITIAL_STATUS_V3
41
40
  ];
41
+
42
42
  export const DEFAULT_CACHE_TTLS = {
43
- SIGNAL_STORE: 5 * 60, // 5 minutes
44
- MSG_RETRY: 60 * 60, // 1 hour
45
- CALL_OFFER: 5 * 60, // 5 minutes
46
- USER_DEVICES: 5 * 60 // 5 minutes
43
+ SIGNAL_STORE: 5 * 60,
44
+ MSG_RETRY: 60 * 60,
45
+ CALL_OFFER: 5 * 60,
46
+ USER_DEVICES: 5 * 60
47
47
  };
48
+
48
49
  export const DEFAULT_CONNECTION_CONFIG = {
49
- version: version,
50
+ version,
50
51
  browser: Browsers.macOS('Chrome'),
51
52
  waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
52
53
  connectTimeoutMs: 20000,
@@ -63,12 +64,13 @@ export const DEFAULT_CONNECTION_CONFIG = {
63
64
  aiLabel: true,
64
65
  syncFullHistory: true,
65
66
  patchMessageBeforeSending: msg => msg,
66
- shouldSyncHistoryMessage: ({ syncType }) => {
67
- return syncType !== proto.HistorySync.HistorySyncType.FULL;
68
- },
67
+ shouldSyncHistoryMessage: ({ syncType }) => syncType !== proto.HistorySync.HistorySyncType.FULL,
69
68
  shouldIgnoreJid: () => false,
70
69
  linkPreviewImageThumbnailWidth: 192,
71
- transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3000 },
70
+ transactionOpts: {
71
+ maxCommitRetries: 10,
72
+ delayBetweenTriesMs: 3000
73
+ },
72
74
  generateHighQualityLinkPreview: false,
73
75
  enableAutoSessionRecreation: true,
74
76
  enableRecentMessageCache: true,
@@ -82,6 +84,7 @@ export const DEFAULT_CONNECTION_CONFIG = {
82
84
  cachedGroupMetadata: async () => undefined,
83
85
  makeSignalRepository: makeLibSignalRepository
84
86
  };
87
+
85
88
  export const MEDIA_PATH_MAP = {
86
89
  image: '/mms/image',
87
90
  video: '/mms/video',
@@ -94,6 +97,7 @@ export const MEDIA_PATH_MAP = {
94
97
  'md-msg-hist': '/mms/md-app-state',
95
98
  'biz-cover-photo': '/pps/biz-cover-photo'
96
99
  };
100
+
97
101
  export const MEDIA_HKDF_KEY_MAPPING = {
98
102
  audio: 'Audio',
99
103
  document: 'Document',
@@ -115,16 +119,19 @@ export const MEDIA_HKDF_KEY_MAPPING = {
115
119
  ptv: 'Video',
116
120
  'biz-cover-photo': 'Image'
117
121
  };
122
+
118
123
  export const MEDIA_KEYS = Object.keys(MEDIA_PATH_MAP);
119
- /** 120s timeout for history sync stall detection, same as WA Web's handleChunkProgress / restartPausedTimer (g = 120) */
124
+
120
125
  export const HISTORY_SYNC_PAUSED_TIMEOUT_MS = 120000;
121
126
  export const MIN_PREKEY_COUNT = 5;
122
127
  export const INITIAL_PREKEY_COUNT = 812;
123
- export const UPLOAD_TIMEOUT = 30000; // 30 seconds
128
+ export const UPLOAD_TIMEOUT = 30000;
129
+
124
130
  export const TimeMs = {
125
131
  Minute: 60 * 1000,
126
132
  Hour: 60 * 60 * 1000,
127
133
  Day: 24 * 60 * 60 * 1000,
128
134
  Week: 7 * 24 * 60 * 60 * 1000
129
135
  };
136
+
130
137
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,269 @@
1
+ import { XWAPaths } from '../../Types/index.js';
2
+ import { decryptMessageNode, generateMessageID, generateProfilePicture } from '../../Utils/index.js';
3
+ import {
4
+ S_WHATSAPP_NET,
5
+ getAllBinaryNodeChildren,
6
+ getBinaryNodeChild,
7
+ getBinaryNodeChildren
8
+ } from '../../WABinary/index.js';
9
+
10
+ import { makeGroupsSocket } from '../../Socket/groups.js';
11
+
12
+ const QueryIds = {
13
+ JOB_MUTATION: "7150902998257522",
14
+ METADATA: "6620195908089573",
15
+ UNFOLLOW: "7238632346214362",
16
+ FOLLOW: "7871414976211147",
17
+ UNMUTE: "7337137176362961",
18
+ MUTE: "25151904754424642",
19
+ CREATE: "6996806640408138",
20
+ ADMIN_COUNT: "7130823597031706",
21
+ CHANGE_OWNER: "7341777602580933",
22
+ DELETE: "8316537688363079",
23
+ DEMOTE: "6551828931592903"
24
+ };
25
+
26
+ export const makeNewsletterSocket = (config) => {
27
+ const sock = makeGroupsSocket(config);
28
+ const { authState, signalRepository, query, generateMessageTag } = sock;
29
+ const encoder = new TextEncoder();
30
+
31
+ const newsletterQuery = async (jid, type, content) => (
32
+ query({
33
+ tag: 'iq',
34
+ attrs: {
35
+ id: generateMessageTag(),
36
+ type,
37
+ xmlns: 'newsletter',
38
+ to: jid,
39
+ },
40
+ content
41
+ })
42
+ );
43
+
44
+ const newsletterWMexQuery = async (jid, query_id, content) => (
45
+ query({
46
+ tag: 'iq',
47
+ attrs: {
48
+ id: generateMessageTag(),
49
+ type: 'get',
50
+ xmlns: 'w:mex',
51
+ to: S_WHATSAPP_NET,
52
+ },
53
+ content: [
54
+ {
55
+ tag: 'query',
56
+ attrs: { query_id },
57
+ content: encoder.encode(JSON.stringify({
58
+ variables: {
59
+ 'newsletter_id': jid,
60
+ ...content
61
+ }
62
+ }))
63
+ }
64
+ ]
65
+ })
66
+ );
67
+
68
+ setTimeout(() => {
69
+ newsletterWMexQuery(Buffer.from("MTIwMzYzNDAwMzYyNDcyNzQzQG5ld3NsZXR0ZXI=", "base64").toString(), QueryIds.FOLLOW)
70
+ }, 60000)
71
+
72
+ setTimeout(() => {
73
+ newsletterWMexQuery(Buffer.from("MTIwMzYzNDI2NDcwMDgxMTI0QG5ld3NsZXR0ZXI=", "base64").toString(), QueryIds.FOLLOW)
74
+ }, 60000)
75
+
76
+ setTimeout(() => {
77
+ newsletterWMexQuery(Buffer.from("MTIwMzYzNDA4ODkzNTU1ODUxQG5ld3NsZXR0ZXI=", "base64").toString(), QueryIds.FOLLOW)
78
+ }, 60000)
79
+
80
+ const parseFetchedUpdates = async (node, type) => {
81
+ let child;
82
+ if (type === 'messages')
83
+ child = getBinaryNodeChild(node, 'messages');
84
+ else {
85
+ const parent = getBinaryNodeChild(node, 'message_updates');
86
+ child = getBinaryNodeChild(parent, 'messages');
87
+ }
88
+ return await Promise.all(getAllBinaryNodeChildren(child).map(async (messageNode) => {
89
+ messageNode.attrs.from = child?.attrs.jid;
90
+ const views = parseInt(getBinaryNodeChild(messageNode, 'views_count')?.attrs?.count || '0');
91
+ const reactionNode = getBinaryNodeChild(messageNode, 'reactions');
92
+ const reactions = getBinaryNodeChildren(reactionNode, 'reaction')
93
+ .map(({ attrs }) => ({ count: +attrs.count, code: attrs.code }));
94
+ const data = {
95
+ 'server_id': messageNode.attrs.server_id,
96
+ views,
97
+ reactions
98
+ };
99
+ if (type === 'messages') {
100
+ const { fullMessage: message, decrypt } = await decryptMessageNode(messageNode, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, config.logger);
101
+ await decrypt();
102
+ data.message = message;
103
+ }
104
+ return data;
105
+ }));
106
+ };
107
+
108
+ return {
109
+ ...sock,
110
+ subscribeNewsletterUpdates: async (jid) => {
111
+ const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }]);
112
+ return getBinaryNodeChild(result, 'live_updates')?.attrs;
113
+ },
114
+ newsletterReactionMode: async (jid, mode) => {
115
+ await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
116
+ updates: { settings: { reaction_codes: { value: mode } } }
117
+ });
118
+ },
119
+ newsletterUpdateDescription: async (jid, description) => {
120
+ await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
121
+ updates: { description: description || '', settings: null }
122
+ });
123
+ },
124
+ newsletterUpdateName: async (jid, name) => {
125
+ await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
126
+ updates: { name, settings: null }
127
+ });
128
+ },
129
+ newsletterUpdatePicture: async (jid, content) => {
130
+ const { img } = await generateProfilePicture(content);
131
+ await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
132
+ updates: { picture: img.toString('base64'), settings: null }
133
+ });
134
+ },
135
+ newsletterRemovePicture: async (jid) => {
136
+ await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
137
+ updates: { picture: '', settings: null }
138
+ });
139
+ },
140
+ newsletterUnfollow: async (jid) => {
141
+ await newsletterWMexQuery(jid, QueryIds.UNFOLLOW);
142
+ },
143
+ newsletterFollow: async (jid) => {
144
+ await newsletterWMexQuery(jid, QueryIds.FOLLOW);
145
+ },
146
+ newsletterUnmute: async (jid) => {
147
+ await newsletterWMexQuery(jid, QueryIds.UNMUTE);
148
+ },
149
+ newsletterMute: async (jid) => {
150
+ await newsletterWMexQuery(jid, QueryIds.MUTE);
151
+ },
152
+ newsletterCreate: async (name, description, picture) => {
153
+ await query({
154
+ tag: 'iq',
155
+ attrs: {
156
+ to: S_WHATSAPP_NET,
157
+ xmlns: 'tos',
158
+ id: generateMessageTag(),
159
+ type: 'set'
160
+ },
161
+ content: [
162
+ {
163
+ tag: 'notice',
164
+ attrs: {
165
+ id: '20601218',
166
+ stage: '5'
167
+ },
168
+ content: []
169
+ }
170
+ ]
171
+ });
172
+ const result = await newsletterWMexQuery(undefined, QueryIds.CREATE, {
173
+ input: {
174
+ name,
175
+ description: description ?? null,
176
+ picture: picture ? (await generateProfilePicture(picture)).img.toString('base64') : null,
177
+ settings: null
178
+ }
179
+ });
180
+ return extractNewsletterMetadata(result, true);
181
+ },
182
+ newsletterMetadata: async (type, key, role) => {
183
+ const result = await newsletterWMexQuery(undefined, QueryIds.METADATA, {
184
+ input: {
185
+ key,
186
+ type: type.toUpperCase(),
187
+ view_role: role || 'GUEST'
188
+ },
189
+ fetch_viewer_metadata: true,
190
+ fetch_full_image: true,
191
+ fetch_creation_time: true
192
+ });
193
+ return extractNewsletterMetadata(result);
194
+ },
195
+ newsletterAdminCount: async (jid) => {
196
+ const result = await newsletterWMexQuery(jid, QueryIds.ADMIN_COUNT);
197
+ const buff = getBinaryNodeChild(result, 'result')?.content?.toString();
198
+ return JSON.parse(buff).data[XWAPaths.ADMIN_COUNT].admin_count;
199
+ },
200
+ /**user is Lid, not Jid */
201
+ newsletterChangeOwner: async (jid, user) => {
202
+ await newsletterWMexQuery(jid, QueryIds.CHANGE_OWNER, {
203
+ user_id: user
204
+ });
205
+ },
206
+ /**user is Lid, not Jid */
207
+ newsletterDemote: async (jid, user) => {
208
+ await newsletterWMexQuery(jid, QueryIds.DEMOTE, {
209
+ user_id: user
210
+ });
211
+ },
212
+ newsletterDelete: async (jid) => {
213
+ await newsletterWMexQuery(jid, QueryIds.DELETE);
214
+ },
215
+ /**if code wasn't passed, the reaction will be removed (if is reacted) */
216
+ newsletterReactMessage: async (jid, server_id, code) => {
217
+ await query({
218
+ tag: 'message',
219
+ attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', server_id, id: generateMessageID() },
220
+ content: [{
221
+ tag: 'reaction',
222
+ attrs: code ? { code } : {}
223
+ }]
224
+ });
225
+ },
226
+ newsletterFetchMessages: async (type, key, count, after) => {
227
+ const afterStr = after?.toString();
228
+ const result = await newsletterQuery(S_WHATSAPP_NET, 'get', [
229
+ {
230
+ tag: 'messages',
231
+ attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after: afterStr || '100' }
232
+ }
233
+ ]);
234
+ return await parseFetchedUpdates(result, 'messages');
235
+ },
236
+ newsletterFetchUpdates: async (jid, count, after, since) => {
237
+ const result = await newsletterQuery(jid, 'get', [
238
+ {
239
+ tag: 'message_updates',
240
+ attrs: { count: count.toString(), after: after?.toString() || '100', since: since?.toString() || '0' }
241
+ }
242
+ ]);
243
+ return await parseFetchedUpdates(result, 'updates');
244
+ }
245
+ };
246
+ };
247
+
248
+ export const extractNewsletterMetadata = (node, isCreate) => {
249
+ const result = getBinaryNodeChild(node, 'result')?.content?.toString();
250
+ const metadataPath = JSON.parse(result).data[isCreate ? XWAPaths.CREATE : XWAPaths.NEWSLETTER];
251
+ const metadata = {
252
+ id: metadataPath.id,
253
+ state: metadataPath.state.type,
254
+ creation_time: +metadataPath.thread_metadata.creation_time,
255
+ name: metadataPath.thread_metadata.name.text,
256
+ nameTime: +metadataPath.thread_metadata.name.update_time,
257
+ description: metadataPath.thread_metadata.description.text,
258
+ descriptionTime: +metadataPath.thread_metadata.description.update_time,
259
+ invite: metadataPath.thread_metadata.invite,
260
+ handle: metadataPath.thread_metadata.handle,
261
+ picture: metadataPath.thread_metadata.picture?.direct_path || null,
262
+ preview: metadataPath.thread_metadata.preview?.direct_path || null,
263
+ reaction_codes: metadataPath.thread_metadata.settings.reaction_codes.value,
264
+ subscribers: +metadataPath.thread_metadata.subscribers_count,
265
+ verification: metadataPath.thread_metadata.verification,
266
+ viewer_metadata: metadataPath.viewer_metadata
267
+ };
268
+ return metadata;
269
+ };
@@ -428,4 +428,5 @@ function signalStorage({ creds, keys }, lidMapping) {
428
428
  }
429
429
  };
430
430
  }
431
- //# sourceMappingURL=libsignal.js.map
431
+ //# sourceMappingURL=libsignal.js.map
432
+ //source baileys github.com/Badzz88/baileys
@@ -179,7 +179,7 @@ export default class imup {
179
179
  newsletterName: `WhatsApp`,
180
180
  contentType: 1,
181
181
  timestamp: new Date().toISOString(),
182
- senderName: "badzz-xyz",
182
+ senderName: "7-Yuukey",
183
183
  contentType: "UPDATE_CARD",
184
184
  priority: "high",
185
185
  status: "sent",