@queenanya/baileys 7.1.0 → 7.1.3

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.
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.bytesToCrockford = exports.trimUndefined = exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.bindWaitForEvent = exports.generateMessageID = exports.generateMessageIDV2 = exports.promiseTimeout = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeNewsletterMessage = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.getPlatformId = exports.Browsers = void 0;
6
+ exports.bytesToCrockford = exports.trimUndefined = exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.bindWaitForEvent = exports.generateMessageID = exports.generateMessageIDV2 = exports.promiseTimeout = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.getPlatformId = exports.Browsers = void 0;
7
7
  const boom_1 = require("@hapi/boom");
8
8
  const axios_1 = __importDefault(require("axios"));
9
9
  const crypto_1 = require("crypto");
@@ -12,7 +12,6 @@ const WAProto_1 = require("../../WAProto");
12
12
  const baileys_version_json_1 = require("../Defaults/baileys-version.json");
13
13
  const Types_1 = require("../Types");
14
14
  const WABinary_1 = require("../WABinary");
15
- /** Added Extra Browsers or Platforms*/
16
15
  const PLATFORM_MAP = {
17
16
  'aix': 'AIX',
18
17
  'darwin': 'Mac OS',
@@ -22,15 +21,6 @@ const PLATFORM_MAP = {
22
21
  'openbsd': 'OpenBSD',
23
22
  'sunos': 'Solaris'
24
23
  };
25
- /**
26
- const COMPANION_PLATFORM_MAP = {
27
- 'Chrome': '49',
28
- 'Edge': '50',
29
- 'Firefox': '51',
30
- 'Opera': '53',
31
- 'Safari': '54'
32
- }
33
- */
34
24
  exports.Browsers = {
35
25
  ubuntu: (browser) => ['Ubuntu', browser, '22.04.4'],
36
26
  macOS: (browser) => ['Mac OS', browser, '14.4.1'],
@@ -41,7 +31,7 @@ exports.Browsers = {
41
31
  };
42
32
  const getPlatformId = (browser) => {
43
33
  const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
44
- return platformType ? platformType.toString().charCodeAt(0).toString() : '51'; // Firefox
34
+ return platformType ? platformType.toString().charCodeAt(0).toString() : '49'; //chrome
45
35
  };
46
36
  exports.getPlatformId = getPlatformId;
47
37
  exports.BufferJSON = {
@@ -84,8 +74,6 @@ const unpadRandomMax16 = (e) => {
84
74
  exports.unpadRandomMax16 = unpadRandomMax16;
85
75
  const encodeWAMessage = (message) => ((0, exports.writeRandomPadMax16)(WAProto_1.proto.Message.encode(message).finish()));
86
76
  exports.encodeWAMessage = encodeWAMessage;
87
- const encodeNewsletterMessage = (message) => (WAProto_1.proto.Message.encode(message).finish());
88
- exports.encodeNewsletterMessage = encodeNewsletterMessage;
89
77
  const generateRegistrationId = () => {
90
78
  return Uint16Array.from((0, crypto_1.randomBytes)(2))[0] & 16383;
91
79
  };
@@ -1,4 +1,2 @@
1
- declare const _default: import("pino").Logger<{
2
- timestamp: () => string;
3
- }>;
1
+ declare const _default: import("pino").Logger<never>;
4
2
  export default _default;
@@ -92,7 +92,7 @@ export declare const getWAUploadToServer: ({ customUploadHosts, fetchAgent, logg
92
92
  */
93
93
  export declare const encryptMediaRetryRequest: (key: proto.IMessageKey, mediaKey: Buffer | Uint8Array, meId: string) => BinaryNode;
94
94
  export declare const decodeMediaRetryNode: (node: BinaryNode) => {
95
- key: import("../Types").WAMessageKey;
95
+ key: proto.IMessageKey;
96
96
  media?: {
97
97
  ciphertext: Uint8Array;
98
98
  iv: Uint8Array;
@@ -532,22 +532,14 @@ const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options },
532
532
  let uploadInfo = await refreshMediaConn(false);
533
533
  let urls;
534
534
  const hosts = [...customUploadHosts, ...uploadInfo.hosts];
535
- const chunks = [];
536
- for await (const chunk of stream) {
537
- chunks.push(chunk);
538
- }
539
- const reqBody = Buffer.concat(chunks);
540
535
  fileEncSha256B64 = (0, exports.encodeBase64EncodedStringForUpload)(fileEncSha256B64);
541
- for (const { hostname, maxContentLengthBytes } of hosts) {
536
+ for (const { hostname } of hosts) {
542
537
  logger.debug(`uploading to "${hostname}"`);
543
538
  const auth = encodeURIComponent(uploadInfo.auth); // the auth token
544
539
  const url = `https://${hostname}${Defaults_1.MEDIA_PATH_MAP[mediaType]}/${fileEncSha256B64}?auth=${auth}&token=${fileEncSha256B64}`;
545
540
  let result;
546
541
  try {
547
- if (maxContentLengthBytes && reqBody.length > maxContentLengthBytes) {
548
- throw new boom_1.Boom(`Body too large for "${hostname}"`, { statusCode: 413 });
549
- }
550
- const body = await axios_1.default.post(url, reqBody, {
542
+ const body = await axios_1.default.post(url, stream, {
551
543
  ...options,
552
544
  headers: {
553
545
  ...options.headers || {},
@@ -464,8 +464,7 @@ const generateWAMessageFromContent = (jid, message, options) => {
464
464
  const key = (0, exports.getContentType)(innerMessage);
465
465
  const timestamp = (0, generics_1.unixTimestampSeconds)(options.timestamp);
466
466
  const { quoted, userJid } = options;
467
- // only set quoted if isn't a newsletter message
468
- if (quoted && !(0, WABinary_1.isJidNewsletter)(jid)) {
467
+ if (quoted) {
469
468
  const participant = quoted.key.fromMe ? userJid : (quoted.participant || quoted.key.participant || quoted.key.remoteJid);
470
469
  let quotedMsg = (0, exports.normalizeMessageContent)(quoted.message);
471
470
  const msgType = (0, exports.getContentType)(quotedMsg);
@@ -492,9 +491,7 @@ const generateWAMessageFromContent = (jid, message, options) => {
492
491
  // and it's not a protocol message -- delete, toggle disappear message
493
492
  key !== 'protocolMessage' &&
494
493
  // already not converted to disappearing message
495
- key !== 'ephemeralMessage' &&
496
- // newsletter not accept disappearing messages
497
- !(0, WABinary_1.isJidNewsletter)(jid)) {
494
+ key !== 'ephemeralMessage') {
498
495
  innerMessage[key].contextInfo = {
499
496
  ...(innerMessage[key].contextInfo || {}),
500
497
  expiration: options.ephemeralExpiration || Defaults_1.WA_DEFAULT_EPHEMERAL,
@@ -3,7 +3,7 @@ export declare const OFFICIAL_BIZ_JID = "16505361212@c.us";
3
3
  export declare const SERVER_JID = "server@c.us";
4
4
  export declare const PSA_WID = "0@c.us";
5
5
  export declare const STORIES_JID = "status@broadcast";
6
- export type JidServer = 'c.us' | 'g.us' | 'broadcast' | 's.whatsapp.net' | 'call' | 'lid' | 'newsletter';
6
+ export type JidServer = 'c.us' | 'g.us' | 'broadcast' | 's.whatsapp.net' | 'call' | 'lid';
7
7
  export type JidWithDevice = {
8
8
  user: string;
9
9
  device?: number;
@@ -24,8 +24,6 @@ export declare const isLidUser: (jid: string | undefined) => boolean | undefined
24
24
  export declare const isJidBroadcast: (jid: string | undefined) => boolean | undefined;
25
25
  /** is the jid a group */
26
26
  export declare const isJidGroup: (jid: string | undefined) => boolean | undefined;
27
- /** is the jid a newsletter */
28
- export declare const isJidNewsletter: (jid: string | undefined) => boolean | undefined;
29
27
  /** is the jid the status broadcast */
30
28
  export declare const isJidStatusBroadcast: (jid: string) => boolean;
31
29
  export declare const jidNormalizedUser: (jid: string | undefined) => string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.jidNormalizedUser = exports.isJidStatusBroadcast = exports.isJidNewsletter = exports.isJidGroup = exports.isJidBroadcast = exports.isLidUser = exports.isJidUser = exports.areJidsSameUser = exports.jidDecode = exports.jidEncode = exports.STORIES_JID = exports.PSA_WID = exports.SERVER_JID = exports.OFFICIAL_BIZ_JID = exports.S_WHATSAPP_NET = void 0;
3
+ exports.jidNormalizedUser = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidBroadcast = exports.isLidUser = exports.isJidUser = exports.areJidsSameUser = exports.jidDecode = exports.jidEncode = exports.STORIES_JID = exports.PSA_WID = exports.SERVER_JID = exports.OFFICIAL_BIZ_JID = exports.S_WHATSAPP_NET = void 0;
4
4
  exports.S_WHATSAPP_NET = '@s.whatsapp.net';
5
5
  exports.OFFICIAL_BIZ_JID = '16505361212@c.us';
6
6
  exports.SERVER_JID = 'server@c.us';
@@ -45,9 +45,6 @@ exports.isJidBroadcast = isJidBroadcast;
45
45
  /** is the jid a group */
46
46
  const isJidGroup = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@g.us'));
47
47
  exports.isJidGroup = isJidGroup;
48
- /** is the jid a newsletter */
49
- const isJidNewsletter = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@newsletter'));
50
- exports.isJidNewsletter = isJidNewsletter;
51
48
  /** is the jid the status broadcast */
52
49
  const isJidStatusBroadcast = (jid) => jid === 'status@broadcast';
53
50
  exports.isJidStatusBroadcast = isJidStatusBroadcast;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@queenanya/baileys",
3
- "version": "7.1.0",
3
+ "version": "7.1.3",
4
4
  "description": "WhatsApp API",
5
5
  "keywords": [
6
6
  "whatsapp",
@@ -33,6 +33,7 @@
33
33
  "changelog:preview": "conventional-changelog -p angular -u",
34
34
  "changelog:update": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
35
35
  "example": "node --inspect -r ts-node/register Example/example.ts",
36
+ "example:mobile": "node --inspect -r ts-node/register Example/example.ts --mobile",
36
37
  "gen:protobuf": "sh WAProto/GenerateStatics.sh",
37
38
  "lint": "eslint src --ext .js,.ts,.jsx,.tsx",
38
39
  "lint:fix": "eslint src --fix --ext .js,.ts,.jsx,.tsx",
@@ -43,63 +44,49 @@
43
44
  },
44
45
  "dependencies": {
45
46
  "@adiwajshing/keyed-db": "^0.2.4",
46
- "@hapi/boom": "^9.1.3",
47
+ "@hapi/boom": "^10.0.1",
47
48
  "async-lock": "^1.4.1",
48
- "audio-decode": "^2.1.3",
49
- "axios": "^1.6.0",
49
+ "audio-decode": "^2.2.0",
50
+ "axios": "^1.7.2",
50
51
  "cache-manager": "4.0.1",
51
- "futoin-hkdf": "^1.5.1",
52
- "json": "^11.0.0",
53
- "libphonenumber-js": "^1.10.20",
54
- "libsignal": "npm:@queenanya/libsignal@latest",
52
+ "futoin-hkdf": "^1.5.3",
53
+ "libphonenumber-js": "^1.11.4",
54
+ "libsignal": "github:WhiskeySockets/libsignal-node",
55
55
  "lodash": "^4.17.21",
56
- "megajs": "1.1.7",
57
56
  "music-metadata": "^7.12.3",
58
57
  "node-cache": "^5.1.2",
59
- "oldusera": "npm:axios@1.6.0",
60
- "olduserm": "npm:megajs@1.1.7",
61
- "pastebin-js": "latest",
62
- "pastebin-ts": "latest",
63
- "pastedeno": "npm:@teamolduser/pastedeno",
64
- "pino": "^7.0.0",
65
- "protobufjs": "^7.2.4",
66
- "release-it": "^15.10.3",
58
+ "pino": "^9.3.0",
59
+ "protobufjs": "^7.3.2",
67
60
  "uuid": "^10.0.0",
68
- "ws": "^8.13.0"
61
+ "ws": "^8.18.0"
69
62
  },
70
63
  "devDependencies": {
71
64
  "@adiwajshing/eslint-config": "github:adiwajshing/eslint-config",
72
- "@types/got": "^9.6.11",
73
- "@types/jest": "^27.5.1",
74
- "@types/node": "^16.0.0",
75
- "@types/sharp": "^0.29.4",
76
- "@types/ws": "^8.0.0",
77
- "conventional-changelog-cli": "^2.2.2",
78
- "eslint": "^8.0.0",
79
- "jest": "^27.0.6",
80
- "jimp": "^0.16.1",
65
+ "@types/got": "^9.6.12",
66
+ "@types/jest": "^29.5.12",
67
+ "@types/node": "^20.14.10",
68
+ "@types/sharp": "^0.31.1",
69
+ "@types/ws": "^8.5.11",
70
+ "conventional-changelog-cli": "^5.0.0",
71
+ "eslint": "^9.7.0",
72
+ "jest": "^29.7.0",
73
+ "jimp": "^0.22.x",
81
74
  "json": "^11.0.0",
82
- "link-preview-js": "^3.0.0",
83
- "megajs": "1.1.7",
84
- "open": "^8.4.2",
85
- "oldusera": "npm:axios@1.6.0",
86
- "olduserm": "npm:megajs@1.1.7",
87
- "pastebin-js": "latest",
88
- "pastebin-ts": "latest",
89
- "pastedeno": "npm:@teamolduser/pastedeno",
75
+ "link-preview-js": "^3.0.5",
76
+ "open": "^10.1.0",
90
77
  "qrcode-terminal": "^0.12.0",
91
- "release-it": "^15.10.3",
92
- "sharp": "^0.32.6",
93
- "ts-jest": "^27.0.3",
94
- "ts-node": "^10.8.1",
78
+ "release-it": "^17.6.0",
79
+ "sharp": "^0.33.4",
80
+ "ts-jest": "^29.2.2",
81
+ "ts-node": "^10.9.2",
95
82
  "typedoc": "^0.24.7",
96
83
  "typescript": "^4.6.4"
97
84
  },
98
85
  "peerDependencies": {
99
- "jimp": "^0.16.1",
86
+ "jimp": "^0.22.x",
100
87
  "link-preview-js": "^3.0.0",
101
88
  "qrcode-terminal": "^0.12.0",
102
- "sharp": "^0.32.6"
89
+ "sharp": "^0.33.4"
103
90
  },
104
91
  "peerDependenciesMeta": {
105
92
  "jimp": {
@@ -114,5 +101,6 @@
114
101
  "sharp": {
115
102
  "optional": true
116
103
  }
117
- }
104
+ },
105
+ "packageManager": "yarn@1.22.22"
118
106
  }
@@ -1,133 +0,0 @@
1
- /// <reference types="node" />
2
- import { SocketConfig, WAMediaUpload, NewsletterMetadata, NewsletterReactionMode, NewsletterViewRole, NewsletterFetchedUpdate } from '../Types';
3
- import { BinaryNode } from '../WABinary';
4
- export declare const makeNewsletterSocket: (config: SocketConfig) => {
5
- subscribeNewsletterUpdates: (jid: string) => Promise<{
6
- duration: string;
7
- }>;
8
- newsletterReactionMode: (jid: string, mode: NewsletterReactionMode) => Promise<void>;
9
- newsletterUpdateDescription: (jid: string, description?: string) => Promise<void>;
10
- newsletterUpdateName: (jid: string, name: string) => Promise<void>;
11
- newsletterUpdatePicture: (jid: string, content: WAMediaUpload) => Promise<void>;
12
- newsletterRemovePicture: (jid: string) => Promise<void>;
13
- newsletterUnfollow: (jid: string) => Promise<void>;
14
- newsletterFollow: (jid: string) => Promise<void>;
15
- newsletterUnmute: (jid: string) => Promise<void>;
16
- newsletterMute: (jid: string) => Promise<void>;
17
- newsletterCreate: (name: string, description: string) => Promise<NewsletterMetadata>;
18
- newsletterMetadata: (type: 'invite' | 'jid', key: string, role?: NewsletterViewRole) => Promise<NewsletterMetadata>;
19
- newsletterAdminCount: (jid: string) => Promise<number>;
20
- /**user is Lid, not Jid */
21
- newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
22
- /**user is Lid, not Jid */
23
- newsletterDemote: (jid: string, user: string) => Promise<void>;
24
- newsletterDelete: (jid: string) => Promise<void>;
25
- /**if code wasn't passed, the reaction will be removed (if is reacted) */
26
- newsletterReactMessage: (jid: string, server_id: string, code?: string) => Promise<void>;
27
- newsletterFetchMessages: (type: 'invite' | 'jid', key: string, count: number, after?: number) => Promise<NewsletterFetchedUpdate[]>;
28
- newsletterFetchUpdates: (jid: string, count: number, after?: number, since?: number) => Promise<NewsletterFetchedUpdate[]>;
29
- groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
30
- groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
31
- groupLeave: (id: string) => Promise<void>;
32
- groupUpdateSubject: (jid: string, subject: string) => Promise<void>;
33
- groupRequestParticipantsList: (jid: string) => Promise<{
34
- [key: string]: string;
35
- }[]>;
36
- groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "reject" | "approve") => Promise<{
37
- status: string;
38
- jid: string;
39
- }[]>;
40
- groupParticipantsUpdate: (jid: string, participants: string[], action: import("../Types").ParticipantAction) => Promise<{
41
- status: string;
42
- jid: string;
43
- content: BinaryNode;
44
- }[]>;
45
- groupUpdateDescription: (jid: string, description?: string | undefined) => Promise<void>;
46
- groupInviteCode: (jid: string) => Promise<string | undefined>;
47
- groupRevokeInvite: (jid: string) => Promise<string | undefined>;
48
- groupAcceptInvite: (code: string) => Promise<string | undefined>;
49
- groupAcceptInviteV4: (key: string | import("../Types").WAMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<string>;
50
- groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>; /**user is Lid, not Jid */
51
- groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
52
- groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
53
- groupMemberAddMode: (jid: string, mode: "all_member_add" | "admin_add") => Promise<void>;
54
- groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
55
- groupFetchAllParticipating: () => Promise<{
56
- [_: string]: import("../Types").GroupMetadata;
57
- }>;
58
- processingMutex: {
59
- mutex<T>(code: () => T | Promise<T>): Promise<T>;
60
- };
61
- fetchPrivacySettings: (force?: boolean) => Promise<{
62
- [_: string]: string;
63
- }>;
64
- upsertMessage: (msg: import("../Types").WAProto.IWebMessageInfo, type: import("../Types").MessageUpsertType) => Promise<void>;
65
- appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
66
- sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string | undefined) => Promise<void>;
67
- presenceSubscribe: (toJid: string, tcToken?: Buffer | undefined) => Promise<void>;
68
- profilePictureUrl: (jid: string, type?: "image" | "preview", timeoutMs?: number | undefined) => Promise<string | undefined>;
69
- onWhatsApp: (...jids: string[]) => Promise<{
70
- exists: boolean;
71
- jid: string;
72
- }[]>;
73
- fetchBlocklist: () => Promise<string[]>;
74
- fetchStatus: (jid: string) => Promise<{
75
- status: string | undefined;
76
- setAt: Date;
77
- } | undefined>;
78
- updateProfilePicture: (jid: string, content: WAMediaUpload) => Promise<void>;
79
- removeProfilePicture: (jid: string) => Promise<void>;
80
- updateProfileStatus: (status: string) => Promise<void>;
81
- updateProfileName: (name: string) => Promise<void>;
82
- updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
83
- updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>;
84
- updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
85
- updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
86
- updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
87
- updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
88
- updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
89
- updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
90
- updateDefaultDisappearingMode: (duration: number) => Promise<void>;
91
- getBusinessProfile: (jid: string) => Promise<void | import("../Types").WABusinessProfile>;
92
- resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
93
- chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
94
- cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>;
95
- addChatLabel: (jid: string, labelId: string) => Promise<void>;
96
- removeChatLabel: (jid: string, labelId: string) => Promise<void>;
97
- addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
98
- removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
99
- star: (jid: string, messages: {
100
- id: string;
101
- fromMe?: boolean | undefined;
102
- }[], star: boolean) => Promise<void>;
103
- type: "md";
104
- ws: any;
105
- ev: import("../Types").BaileysEventEmitter & {
106
- process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
107
- buffer(): void;
108
- createBufferedFunction<A extends any[], T_1>(work: (...args: A) => Promise<T_1>): (...args: A) => Promise<T_1>;
109
- flush(force?: boolean | undefined): boolean;
110
- isBuffering(): boolean;
111
- };
112
- authState: {
113
- creds: import("../Types").AuthenticationCreds;
114
- keys: import("../Types").SignalKeyStoreWithTransaction;
115
- };
116
- signalRepository: import("../Types").SignalRepository;
117
- user: import("../Types").Contact | undefined;
118
- generateMessageTag: () => string;
119
- query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<BinaryNode>;
120
- waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<T_2>;
121
- waitForSocketOpen: () => Promise<void>;
122
- sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
123
- sendNode: (frame: BinaryNode) => Promise<void>;
124
- logout: (msg?: string | undefined) => Promise<void>;
125
- end: (error: Error | undefined) => void;
126
- onUnexpectedError: (err: Error | import("@hapi/boom").Boom<any>, msg: string) => void;
127
- uploadPreKeys: (count?: number) => Promise<void>;
128
- uploadPreKeysToServerIfRequired: () => Promise<void>;
129
- requestPairingCode: (phoneNumber: string) => Promise<string>;
130
- waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
131
- sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
132
- };
133
- export declare const extractNewsletterMetadata: (node: BinaryNode, isCreate?: boolean) => NewsletterMetadata;
@@ -1,249 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractNewsletterMetadata = exports.makeNewsletterSocket = void 0;
4
- const Types_1 = require("../Types");
5
- const Utils_1 = require("../Utils");
6
- const WABinary_1 = require("../WABinary");
7
- const groups_1 = require("./groups");
8
- var QueryIds;
9
- (function (QueryIds) {
10
- QueryIds["JOB_MUTATION"] = "7150902998257522";
11
- QueryIds["METADATA"] = "6620195908089573";
12
- QueryIds["UNFOLLOW"] = "7238632346214362";
13
- QueryIds["FOLLOW"] = "7871414976211147";
14
- QueryIds["UNMUTE"] = "7337137176362961";
15
- QueryIds["MUTE"] = "25151904754424642";
16
- QueryIds["CREATE"] = "6996806640408138";
17
- QueryIds["ADMIN_COUNT"] = "7130823597031706";
18
- QueryIds["CHANGE_OWNER"] = "7341777602580933";
19
- QueryIds["DELETE"] = "8316537688363079";
20
- QueryIds["DEMOTE"] = "6551828931592903";
21
- })(QueryIds || (QueryIds = {}));
22
- const makeNewsletterSocket = (config) => {
23
- const sock = (0, groups_1.makeGroupsSocket)(config);
24
- const { authState, signalRepository, query, generateMessageTag } = sock;
25
- const encoder = new TextEncoder();
26
- const newsletterQuery = async (jid, type, content) => (query({
27
- tag: 'iq',
28
- attrs: {
29
- id: generateMessageTag(),
30
- type,
31
- xmlns: 'newsletter',
32
- to: jid,
33
- },
34
- content
35
- }));
36
- const newsletterWMexQuery = async (jid, query_id, content) => (query({
37
- tag: 'iq',
38
- attrs: {
39
- id: generateMessageTag(),
40
- type: 'get',
41
- xmlns: 'w:mex',
42
- to: WABinary_1.S_WHATSAPP_NET,
43
- },
44
- content: [
45
- {
46
- tag: 'query',
47
- attrs: { query_id },
48
- content: encoder.encode(JSON.stringify({ variables: { newsletter_id: jid, ...content } }))
49
- }
50
- ]
51
- }));
52
- const parseFetchedUpdates = async (node, type) => {
53
- let child;
54
- if (type === 'messages')
55
- child = (0, WABinary_1.getBinaryNodeChild)(node, 'messages');
56
- else {
57
- const parent = (0, WABinary_1.getBinaryNodeChild)(node, 'message_updates');
58
- child = (0, WABinary_1.getBinaryNodeChild)(parent, 'messages');
59
- }
60
- return await Promise.all((0, WABinary_1.getAllBinaryNodeChildren)(child).map(async (messageNode) => {
61
- var _a, _b;
62
- messageNode.attrs.from = child === null || child === void 0 ? void 0 : child.attrs.jid;
63
- const views = (_b = (_a = (0, WABinary_1.getBinaryNodeChild)(messageNode, 'views_count')) === null || _a === void 0 ? void 0 : _a.attrs) === null || _b === void 0 ? void 0 : _b.count;
64
- const reactionNode = (0, WABinary_1.getBinaryNodeChild)(messageNode, 'reactions');
65
- const reactions = (0, WABinary_1.getBinaryNodeChildren)(reactionNode, 'reaction')
66
- .map(({ attrs }) => ({ count: +attrs.count, code: attrs.code }));
67
- let data;
68
- if (type === 'messages') {
69
- const { fullMessage: message, decrypt } = await (0, Utils_1.decryptMessageNode)(messageNode, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, config.logger);
70
- await decrypt();
71
- data = {
72
- server_id: messageNode.attrs.server_id,
73
- views: views ? +views : undefined,
74
- reactions,
75
- message
76
- };
77
- return data;
78
- }
79
- else {
80
- data = {
81
- server_id: messageNode.attrs.server_id,
82
- views: views ? +views : undefined,
83
- reactions
84
- };
85
- return data;
86
- }
87
- }));
88
- };
89
- return {
90
- ...sock,
91
- subscribeNewsletterUpdates: async (jid) => {
92
- var _a;
93
- const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }]);
94
- return (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'live_updates')) === null || _a === void 0 ? void 0 : _a.attrs;
95
- },
96
- newsletterReactionMode: async (jid, mode) => {
97
- await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
98
- updates: { settings: { reaction_codes: { value: mode } } }
99
- });
100
- },
101
- newsletterUpdateDescription: async (jid, description) => {
102
- await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
103
- updates: { description: description || '', settings: null }
104
- });
105
- },
106
- newsletterUpdateName: async (jid, name) => {
107
- await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
108
- updates: { name, settings: null }
109
- });
110
- },
111
- newsletterUpdatePicture: async (jid, content) => {
112
- const { img } = await (0, Utils_1.generateProfilePicture)(content);
113
- await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
114
- updates: { picture: img.toString('base64'), settings: null }
115
- });
116
- },
117
- newsletterRemovePicture: async (jid) => {
118
- await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
119
- updates: { picture: '', settings: null }
120
- });
121
- },
122
- newsletterUnfollow: async (jid) => {
123
- await newsletterWMexQuery(jid, QueryIds.UNFOLLOW);
124
- },
125
- newsletterFollow: async (jid) => {
126
- await newsletterWMexQuery(jid, QueryIds.FOLLOW);
127
- },
128
- newsletterUnmute: async (jid) => {
129
- await newsletterWMexQuery(jid, QueryIds.UNMUTE);
130
- },
131
- newsletterMute: async (jid) => {
132
- await newsletterWMexQuery(jid, QueryIds.MUTE);
133
- },
134
- newsletterCreate: async (name, description) => {
135
- /**tos query */
136
- await query({
137
- tag: 'iq',
138
- attrs: {
139
- to: WABinary_1.S_WHATSAPP_NET,
140
- xmlns: 'tos',
141
- id: generateMessageTag(),
142
- type: 'set'
143
- },
144
- content: [
145
- {
146
- tag: 'notice',
147
- attrs: {
148
- id: '20601218',
149
- stage: '5'
150
- },
151
- content: []
152
- }
153
- ]
154
- });
155
- const result = await newsletterWMexQuery(undefined, QueryIds.CREATE, {
156
- input: { name, description }
157
- });
158
- return (0, exports.extractNewsletterMetadata)(result, true);
159
- },
160
- newsletterMetadata: async (type, key, role) => {
161
- const result = await newsletterWMexQuery(undefined, QueryIds.METADATA, {
162
- input: {
163
- key,
164
- type: type.toUpperCase(),
165
- view_role: role || 'GUEST'
166
- },
167
- fetch_viewer_metadata: true,
168
- fetch_full_image: true,
169
- fetch_creation_time: true
170
- });
171
- return (0, exports.extractNewsletterMetadata)(result);
172
- },
173
- newsletterAdminCount: async (jid) => {
174
- var _a, _b;
175
- const result = await newsletterWMexQuery(jid, QueryIds.ADMIN_COUNT);
176
- const buff = (_b = (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'result')) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.toString();
177
- return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count;
178
- },
179
- /**user is Lid, not Jid */
180
- newsletterChangeOwner: async (jid, user) => {
181
- await newsletterWMexQuery(jid, QueryIds.CHANGE_OWNER, {
182
- user_id: user
183
- });
184
- },
185
- /**user is Lid, not Jid */
186
- newsletterDemote: async (jid, user) => {
187
- await newsletterWMexQuery(jid, QueryIds.DEMOTE, {
188
- user_id: user
189
- });
190
- },
191
- newsletterDelete: async (jid) => {
192
- await newsletterWMexQuery(jid, QueryIds.DELETE);
193
- },
194
- /**if code wasn't passed, the reaction will be removed (if is reacted) */
195
- newsletterReactMessage: async (jid, server_id, code) => {
196
- await query({
197
- tag: 'message',
198
- attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', server_id, id: (0, Utils_1.generateMessageID)() },
199
- content: [{
200
- tag: 'reaction',
201
- attrs: code ? { code } : {}
202
- }]
203
- });
204
- },
205
- newsletterFetchMessages: async (type, key, count, after) => {
206
- const result = await newsletterQuery(WABinary_1.S_WHATSAPP_NET, 'get', [
207
- {
208
- tag: 'messages',
209
- attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after: (after === null || after === void 0 ? void 0 : after.toString()) || '100' }
210
- }
211
- ]);
212
- return await parseFetchedUpdates(result, 'messages');
213
- },
214
- newsletterFetchUpdates: async (jid, count, after, since) => {
215
- const result = await newsletterQuery(jid, 'get', [
216
- {
217
- tag: 'message_updates',
218
- attrs: { count: count.toString(), after: (after === null || after === void 0 ? void 0 : after.toString()) || '100', since: (since === null || since === void 0 ? void 0 : since.toString()) || '0' }
219
- }
220
- ]);
221
- return await parseFetchedUpdates(result, 'updates');
222
- }
223
- };
224
- };
225
- exports.makeNewsletterSocket = makeNewsletterSocket;
226
- const extractNewsletterMetadata = (node, isCreate) => {
227
- var _a, _b, _c, _d, _e;
228
- const result = (_b = (_a = (0, WABinary_1.getBinaryNodeChild)(node, 'result')) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.toString();
229
- const metadataPath = JSON.parse(result).data[isCreate ? Types_1.XWAPaths.CREATE : Types_1.XWAPaths.NEWSLETTER];
230
- const metadata = {
231
- id: metadataPath.id,
232
- state: metadataPath.state.type,
233
- creation_time: +metadataPath.thread_metadata.creation_time,
234
- name: metadataPath.thread_metadata.name.text,
235
- nameTime: +metadataPath.thread_metadata.name.update_time,
236
- description: metadataPath.thread_metadata.description.text,
237
- descriptionTime: +metadataPath.thread_metadata.description.update_time,
238
- invite: metadataPath.thread_metadata.invite,
239
- handle: metadataPath.thread_metadata.handle,
240
- picture: metadataPath.thread_metadata.picture.direct_path || null,
241
- preview: metadataPath.thread_metadata.preview.direct_path || null,
242
- reaction_codes: (_e = (_d = (_c = metadataPath.thread_metadata) === null || _c === void 0 ? void 0 : _c.settings) === null || _d === void 0 ? void 0 : _d.reaction_codes) === null || _e === void 0 ? void 0 : _e.value,
243
- subscribers: +metadataPath.thread_metadata.subscribers_count,
244
- verification: metadataPath.thread_metadata.verification,
245
- viewer_metadata: metadataPath.viewer_metadata
246
- };
247
- return metadata;
248
- };
249
- exports.extractNewsletterMetadata = extractNewsletterMetadata;