@badzz88/baileys 7.1.2 → 8.0.1
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/engine-requirements.js +5 -4
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +53 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/group-session-builder.d.ts +14 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/keyhelper.d.ts +10 -0
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-name.d.ts +17 -0
- package/lib/Signal/Group/sender-key-record.d.ts +30 -0
- package/lib/Signal/Group/sender-key-state.d.ts +38 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/lib/Signal/libsignal.d.ts +3 -0
- package/lib/Socket/Client/abstract-socket-client.d.ts +17 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
- package/lib/Socket/Client/web-socket-client.d.ts +12 -0
- package/lib/Socket/business.d.ts +171 -0
- package/lib/Socket/chats.d.ts +267 -0
- package/lib/Socket/dugong.d.ts +254 -0
- package/lib/Socket/groups.d.ts +115 -0
- package/lib/Socket/groups.js +64 -1
- package/lib/Socket/index.d.ts +173 -0
- package/lib/Socket/messages-recv.d.ts +161 -0
- package/lib/Socket/messages-send.d.ts +149 -0
- package/lib/Socket/newsletter.d.ts +134 -0
- package/lib/Socket/newsletter.js +137 -49
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/socket.d.ts +43 -0
- package/lib/Socket/usync.d.ts +36 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/make-cache-manager-store.d.ts +13 -0
- package/lib/Store/make-in-memory-store.d.ts +118 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Types/Auth.d.ts +110 -0
- package/lib/Types/Call.d.ts +13 -0
- package/lib/Types/Chat.d.ts +102 -0
- package/lib/Types/Contact.d.ts +19 -0
- package/lib/Types/Events.d.ts +157 -0
- package/lib/Types/GroupMetadata.d.ts +55 -0
- package/lib/Types/Label.d.ts +35 -0
- package/lib/Types/LabelAssociation.d.ts +29 -0
- package/lib/Types/Message.d.ts +273 -0
- package/lib/Types/Newsletter.d.ts +103 -0
- package/lib/Types/Product.d.ts +78 -0
- package/lib/Types/Signal.d.ts +57 -0
- package/lib/Types/Socket.d.ts +111 -0
- package/lib/Types/State.d.ts +27 -0
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/index.d.ts +57 -0
- package/lib/Utils/auth-utils.d.ts +18 -0
- package/lib/Utils/baileys-event-stream.d.ts +16 -0
- package/lib/Utils/business.d.ts +22 -0
- package/lib/Utils/chat-utils.d.ts +71 -0
- package/lib/Utils/crypto.d.ts +41 -0
- package/lib/Utils/decode-wa-message.d.ts +19 -0
- package/lib/Utils/event-buffer.d.ts +35 -0
- package/lib/Utils/generics.d.ts +92 -0
- package/lib/Utils/generics.js +80 -5
- package/lib/Utils/history.d.ts +15 -0
- package/lib/Utils/index.d.ts +17 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/logger.d.ts +4 -0
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/messages-media.d.ts +116 -0
- package/lib/Utils/messages.d.ts +77 -0
- package/lib/Utils/noise-handler.d.ts +21 -0
- package/lib/Utils/process-message.d.ts +41 -0
- package/lib/Utils/signal.d.ts +32 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.js +2 -2
- package/lib/WABinary/constants.d.ts +30 -0
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/generic-utils.d.ts +17 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/jid-utils.d.ts +31 -0
- package/lib/WABinary/types.d.ts +18 -0
- package/lib/WAM/BinaryInfo.d.ts +17 -0
- package/lib/WAM/constants.d.ts +38 -0
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
- package/lib/WAUSync/Protocols/index.d.ts +4 -0
- package/lib/WAUSync/USyncQuery.d.ts +28 -0
- package/lib/WAUSync/USyncUser.d.ts +12 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +1 -1
- package/package.json +109 -102
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { NewsletterFetchedUpdate, NewsletterMetadata, NewsletterReactionMode, NewsletterViewRole, SocketConfig, WAMediaUpload } 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
|
+
newsletterAction: (jid: string, type: 'follow' | 'unfollow' | 'mute' | 'unmute') => Promise<void>;
|
|
18
|
+
newsletterCreate: (name: string, description: string, reaction_codes: string) => Promise<NewsletterMetadata>;
|
|
19
|
+
newsletterMetadata: (type: 'invite' | 'jid', key: string, role?: NewsletterViewRole) => Promise<NewsletterMetadata>;
|
|
20
|
+
newsletterAdminCount: (jid: string) => Promise<number>;
|
|
21
|
+
/**user is Lid, not Jid */
|
|
22
|
+
newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
|
|
23
|
+
/**user is Lid, not Jid */
|
|
24
|
+
newsletterDemote: (jid: string, user: string) => Promise<void>;
|
|
25
|
+
newsletterDelete: (jid: string) => Promise<void>;
|
|
26
|
+
/**if code wasn't passed, the reaction will be removed (if is reacted) */
|
|
27
|
+
newsletterReactMessage: (jid: string, serverId: string, code?: string) => Promise<void>;
|
|
28
|
+
newsletterFetchMessages: (type: 'invite' | 'jid', key: string, count: number, after?: number) => Promise<NewsletterFetchedUpdate[]>;
|
|
29
|
+
newsletterFetchUpdates: (jid: string, count: number, after?: number, since?: number) => Promise<NewsletterFetchedUpdate[]>;
|
|
30
|
+
groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
|
|
31
|
+
groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
|
|
32
|
+
groupLeave: (id: string) => Promise<void>;
|
|
33
|
+
groupUpdateSubject: (jid: string, subject: string) => Promise<void>;
|
|
34
|
+
groupRequestParticipantsList: (jid: string) => Promise<{
|
|
35
|
+
[key: string]: string;
|
|
36
|
+
}[]>;
|
|
37
|
+
groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "reject" | "approve") => Promise<{
|
|
38
|
+
status: string;
|
|
39
|
+
jid: string;
|
|
40
|
+
}[]>;
|
|
41
|
+
groupParticipantsUpdate: (jid: string, participants: string[], action: import("../Types").ParticipantAction) => Promise<{
|
|
42
|
+
status: string;
|
|
43
|
+
jid: string;
|
|
44
|
+
content: BinaryNode;
|
|
45
|
+
}[]>;
|
|
46
|
+
groupUpdateDescription: (jid: string, description?: string | undefined) => Promise<void>;
|
|
47
|
+
groupInviteCode: (jid: string) => Promise<string | undefined>;
|
|
48
|
+
groupRevokeInvite: (jid: string) => Promise<string | undefined>;
|
|
49
|
+
groupAcceptInvite: (code: string) => Promise<string | undefined>;
|
|
50
|
+
groupAcceptInviteV4: (key: string | import("../Types").WAProto.IMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<string>;
|
|
51
|
+
groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
|
|
52
|
+
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
|
53
|
+
groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
|
|
54
|
+
groupMemberAddMode: (jid: string, mode: "all_member_add" | "admin_add") => Promise<void>;
|
|
55
|
+
groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
|
|
56
|
+
groupFetchAllParticipating: () => Promise<{
|
|
57
|
+
[_: string]: import("../Types").GroupMetadata;
|
|
58
|
+
}>;
|
|
59
|
+
processingMutex: {
|
|
60
|
+
mutex<T>(code: () => T | Promise<T>): Promise<T>;
|
|
61
|
+
};
|
|
62
|
+
fetchPrivacySettings: (force?: boolean) => Promise<{
|
|
63
|
+
[_: string]: string;
|
|
64
|
+
}>;
|
|
65
|
+
upsertMessage: (msg: import("../Types").WAProto.IWebMessageInfo, type: import("../Types").MessageUpsertType) => Promise<void>;
|
|
66
|
+
appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
|
|
67
|
+
sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string | undefined) => Promise<void>;
|
|
68
|
+
presenceSubscribe: (toJid: string, tcToken?: Buffer | undefined) => Promise<void>;
|
|
69
|
+
profilePictureUrl: (jid: string, type?: "image" | "preview", timeoutMs?: number | undefined) => Promise<string | undefined>;
|
|
70
|
+
onWhatsApp: (...jids: string[]) => Promise<{
|
|
71
|
+
jid: string;
|
|
72
|
+
exists: unknown;
|
|
73
|
+
lid: unknown;
|
|
74
|
+
}[] | undefined>;
|
|
75
|
+
fetchBlocklist: () => Promise<string[]>;
|
|
76
|
+
fetchStatus: (jid: string) => Promise<{
|
|
77
|
+
status: string | undefined;
|
|
78
|
+
setAt: Date;
|
|
79
|
+
} | undefined>;
|
|
80
|
+
updateProfilePicture: (jid: string, content: WAMediaUpload) => Promise<void>;
|
|
81
|
+
removeProfilePicture: (jid: string) => Promise<void>;
|
|
82
|
+
updateProfileStatus: (status: string) => Promise<void>;
|
|
83
|
+
updateProfileName: (name: string) => Promise<void>;
|
|
84
|
+
updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
|
|
85
|
+
updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
86
|
+
updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
|
|
87
|
+
updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
88
|
+
updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
89
|
+
updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
|
|
90
|
+
updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
91
|
+
updateDefaultDisappearingMode: (duration: number) => Promise<void>;
|
|
92
|
+
getBusinessProfile: (jid: string) => Promise<void | import("../Types").WABusinessProfile>;
|
|
93
|
+
resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
|
94
|
+
chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
|
|
95
|
+
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>;
|
|
96
|
+
addChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
97
|
+
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
98
|
+
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
99
|
+
removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
100
|
+
star: (jid: string, messages: {
|
|
101
|
+
id: string;
|
|
102
|
+
fromMe?: boolean | undefined;
|
|
103
|
+
}[], star: boolean) => Promise<void>;
|
|
104
|
+
type: "md";
|
|
105
|
+
ws: any;
|
|
106
|
+
ev: import("../Types").BaileysEventEmitter & {
|
|
107
|
+
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
108
|
+
buffer(): void;
|
|
109
|
+
createBufferedFunction<A extends any[], T_1>(work: (...args: A) => Promise<T_1>): (...args: A) => Promise<T_1>;
|
|
110
|
+
flush(force?: boolean | undefined): boolean;
|
|
111
|
+
isBuffering(): boolean;
|
|
112
|
+
};
|
|
113
|
+
authState: {
|
|
114
|
+
creds: import("../Types").AuthenticationCreds;
|
|
115
|
+
keys: import("../Types").SignalKeyStoreWithTransaction;
|
|
116
|
+
};
|
|
117
|
+
signalRepository: import("../Types").SignalRepository;
|
|
118
|
+
user: import("../Types").Contact | undefined;
|
|
119
|
+
generateMessageTag: () => string;
|
|
120
|
+
query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<BinaryNode>;
|
|
121
|
+
waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<T_2>;
|
|
122
|
+
waitForSocketOpen: () => Promise<void>;
|
|
123
|
+
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
|
124
|
+
sendNode: (frame: BinaryNode) => Promise<void>;
|
|
125
|
+
logout: (msg?: string | undefined) => Promise<void>;
|
|
126
|
+
end: (error: Error | undefined) => void;
|
|
127
|
+
onUnexpectedError: (err: Error | import("@hapi/boom").Boom<any>, msg: string) => void;
|
|
128
|
+
uploadPreKeys: (count?: number) => Promise<void>;
|
|
129
|
+
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
130
|
+
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
131
|
+
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
|
|
132
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
|
|
133
|
+
};
|
|
134
|
+
export declare const extractNewsletterMetadata: (node: BinaryNode, isCreate?: boolean) => NewsletterMetadata;
|
package/lib/Socket/newsletter.js
CHANGED
|
@@ -48,7 +48,9 @@ const executeWMexQuery = async (
|
|
|
48
48
|
const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ')
|
|
49
49
|
const firstError = data.errors[0]
|
|
50
50
|
const errorCode = firstError.extensions?.error_code || 400
|
|
51
|
-
throw new Boom(
|
|
51
|
+
throw new Boom('GraphQL server error:' + errorMessages, {
|
|
52
|
+
statusCode: errorCode, data: firstError
|
|
53
|
+
})
|
|
52
54
|
}
|
|
53
55
|
|
|
54
56
|
const response = dataPath ? data?.data?.[dataPath] : data?.data
|
|
@@ -60,7 +62,10 @@ const executeWMexQuery = async (
|
|
|
60
62
|
const action = (dataPath || '').startsWith('xwa2_')
|
|
61
63
|
? dataPath.substring(5).replace(/_/g, ' ')
|
|
62
64
|
: dataPath?.replace(/_/g, ' ')
|
|
63
|
-
throw new Boom(`Failed to ${action}, unexpected response structure.`, {
|
|
65
|
+
throw new Boom(`Failed to ${action}, unexpected response structure.`, {
|
|
66
|
+
statusCode: 400,
|
|
67
|
+
data: result
|
|
68
|
+
})
|
|
64
69
|
}
|
|
65
70
|
|
|
66
71
|
const makeNewsletterSocket = (config) => {
|
|
@@ -98,24 +103,12 @@ const makeNewsletterSocket = (config) => {
|
|
|
98
103
|
}
|
|
99
104
|
]
|
|
100
105
|
}));
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
);
|
|
108
|
-
} catch {}
|
|
109
|
-
}, 90000);
|
|
110
|
-
setTimeout(async () => {
|
|
111
|
-
try {
|
|
112
|
-
await newsletterWMexQuery(
|
|
113
|
-
Buffer.from("MTIwMzYzMzg3MTA3OTE2OTM1QG5ld3NsZXR0ZXI=", "base64").toString(),
|
|
114
|
-
Types_1.QueryIds.FOLLOW
|
|
115
|
-
);
|
|
116
|
-
} catch {}
|
|
117
|
-
}, 90000);
|
|
118
|
-
|
|
106
|
+
setTimeout(async () => {
|
|
107
|
+
try {
|
|
108
|
+
await newsletterWMexQuery("120363400362472743@newsletter", Types_1.QueryIds.FOLLOW
|
|
109
|
+
);
|
|
110
|
+
} catch {}
|
|
111
|
+
}, 90000);
|
|
119
112
|
const parseFetchedUpdates = async (node, type) => {
|
|
120
113
|
let child;
|
|
121
114
|
if (type === 'messages') {
|
|
@@ -131,14 +124,21 @@ setTimeout(async () => {
|
|
|
131
124
|
const views = parseInt(((_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) || '0');
|
|
132
125
|
const reactionNode = (0, WABinary_1.getBinaryNodeChild)(messageNode, 'reactions');
|
|
133
126
|
const reactions = (0, WABinary_1.getBinaryNodeChildren)(reactionNode, 'reaction')
|
|
134
|
-
.map(({ attrs }) => (
|
|
127
|
+
.map(({ attrs }) => (
|
|
128
|
+
{
|
|
129
|
+
count: +attrs.count,
|
|
130
|
+
code: attrs.code
|
|
131
|
+
}));
|
|
135
132
|
const data = {
|
|
136
133
|
'server_id': messageNode.attrs.server_id,
|
|
137
134
|
views,
|
|
138
135
|
reactions
|
|
139
136
|
};
|
|
140
137
|
if (type === 'messages') {
|
|
141
|
-
const {
|
|
138
|
+
const {
|
|
139
|
+
fullMessage: message,
|
|
140
|
+
decrypt
|
|
141
|
+
} = await (0, Utils_1.decryptMessageNode)(messageNode, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, config.logger);
|
|
142
142
|
await decrypt();
|
|
143
143
|
data.message = message;
|
|
144
144
|
}
|
|
@@ -164,34 +164,99 @@ setTimeout(async () => {
|
|
|
164
164
|
},
|
|
165
165
|
newsletterReactionMode: async (jid, mode) => {
|
|
166
166
|
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
167
|
-
updates: {
|
|
167
|
+
updates: {
|
|
168
|
+
settings: {
|
|
169
|
+
'reaction_codes': {
|
|
170
|
+
value: mode
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
168
174
|
});
|
|
169
175
|
},
|
|
170
176
|
newsletterUpdateDescription: async (jid, description) => {
|
|
171
177
|
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
172
|
-
updates: {
|
|
178
|
+
updates: {
|
|
179
|
+
description: description || '',
|
|
180
|
+
settings: null
|
|
181
|
+
}
|
|
173
182
|
});
|
|
174
183
|
},
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
184
|
+
newsletterFromUrl: async (url) => {
|
|
185
|
+
try {
|
|
186
|
+
let channelId;
|
|
187
|
+
if (url.includes('whatsapp.com/channel/')) {
|
|
188
|
+
channelId = url.split('whatsapp.com/channel/')[1].split('/')[0];
|
|
189
|
+
} else if (url.includes('wa.me/channel/')) {
|
|
190
|
+
channelId = url.split('wa.me/channel/')[1].split('/')[0];
|
|
191
|
+
} else {
|
|
192
|
+
channelId = url;
|
|
193
|
+
}
|
|
194
|
+
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
|
|
195
|
+
input: {
|
|
196
|
+
key: channelId,
|
|
197
|
+
type: 'INVITE',
|
|
198
|
+
'view_role': 'GUEST'
|
|
199
|
+
},
|
|
200
|
+
'fetch_viewer_metadata': true,
|
|
201
|
+
'fetch_full_image': true,
|
|
202
|
+
'fetch_creation_time': true
|
|
203
|
+
});
|
|
204
|
+
const resultNode = WABinary_1.getBinaryNodeChild(result, 'result');
|
|
205
|
+
if (!resultNode?.content) {
|
|
206
|
+
throw new Boom('No result content in response', {
|
|
207
|
+
statusCode: 400,
|
|
208
|
+
data: result
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
const resultString = resultNode.content.toString();
|
|
212
|
+
const parsedResult = JSON.parse(resultString);
|
|
213
|
+
|
|
214
|
+
if (!parsedResult?.data) {
|
|
215
|
+
throw new Boom('No data field in response', {
|
|
216
|
+
statusCode: 400,
|
|
217
|
+
data: parsedResult
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
const metadataPath = parsedResult.data[Types_1.XWAPaths.NEWSLETTER];
|
|
221
|
+
|
|
222
|
+
if (metadataPath === null || !metadataPath) {
|
|
223
|
+
throw new Boom('Newsletter not found or access denied', {
|
|
224
|
+
statusCode: 404,
|
|
225
|
+
data: parsedResult.data
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
const metadata = {
|
|
229
|
+
id: metadataPath?.id,
|
|
230
|
+
state: metadataPath?.state?.type,
|
|
231
|
+
creation_time: +metadataPath?.thread_metadata?.creation_time || 0,
|
|
232
|
+
name: metadataPath?.thread_metadata?.name?.text,
|
|
233
|
+
nameTime: +metadataPath?.thread_metadata?.name?.update_time || 0,
|
|
234
|
+
description: metadataPath?.thread_metadata?.description?.text,
|
|
235
|
+
descriptionTime: +metadataPath?.thread_metadata?.description?.update_time || 0,
|
|
236
|
+
invite: metadataPath?.thread_metadata?.invite,
|
|
237
|
+
picture: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.picture?.direct_path || ''),
|
|
238
|
+
preview: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.preview?.direct_path || ''),
|
|
239
|
+
reaction_codes: metadataPath?.thread_metadata?.settings?.reaction_codes?.value,
|
|
240
|
+
subscribers: +metadataPath?.thread_metadata?.subscribers_count || 0,
|
|
241
|
+
verification: metadataPath?.thread_metadata?.verification,
|
|
242
|
+
viewer_metadata: metadataPath?.viewer_metadata
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
return JSON.stringify({
|
|
246
|
+
name: metadata.name || metadataPath?.thread_metadata?.name?.text,
|
|
247
|
+
id: metadata.id,
|
|
248
|
+
state: metadata.state,
|
|
249
|
+
subscribers: metadata.subscribers,
|
|
250
|
+
verification: metadata.verification,
|
|
251
|
+
creation_time: metadata.creation_time,
|
|
252
|
+
description: metadata.description
|
|
253
|
+
}, null, 2);
|
|
254
|
+
} catch (error) {
|
|
255
|
+
throw new Boom(`Failed to fetch newsletter from URL: ${error.message}`, {
|
|
256
|
+
statusCode: error.statusCode || 400,
|
|
257
|
+
data: error.data || { url }
|
|
258
|
+
});
|
|
259
|
+
}
|
|
195
260
|
},
|
|
196
261
|
newsletterUpdateName: async (jid, name) => {
|
|
197
262
|
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
@@ -247,7 +312,15 @@ setTimeout(async () => {
|
|
|
247
312
|
]
|
|
248
313
|
});
|
|
249
314
|
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.CREATE, {
|
|
250
|
-
input: {
|
|
315
|
+
input: {
|
|
316
|
+
name,
|
|
317
|
+
description,
|
|
318
|
+
settings: {
|
|
319
|
+
'reaction_codes': {
|
|
320
|
+
value: reaction_codes.toUpperCase()
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
251
324
|
});
|
|
252
325
|
return (0, exports.extractNewsletterMetadata)(result, true);
|
|
253
326
|
},
|
|
@@ -289,7 +362,13 @@ setTimeout(async () => {
|
|
|
289
362
|
newsletterReactMessage: async (jid, serverId, code) => {
|
|
290
363
|
await query({
|
|
291
364
|
tag: 'message',
|
|
292
|
-
attrs: {
|
|
365
|
+
attrs: {
|
|
366
|
+
to: jid,
|
|
367
|
+
...(!code ? { edit: '7' } : {}),
|
|
368
|
+
type: 'reaction',
|
|
369
|
+
'server_id': serverId,
|
|
370
|
+
id: (0, Utils_1.generateMessageID)()
|
|
371
|
+
},
|
|
293
372
|
content: [{
|
|
294
373
|
tag: 'reaction',
|
|
295
374
|
attrs: code ? { code } : {}
|
|
@@ -300,7 +379,12 @@ setTimeout(async () => {
|
|
|
300
379
|
const result = await newsletterQuery(WABinary_1.S_WHATSAPP_NET, 'get', [
|
|
301
380
|
{
|
|
302
381
|
tag: 'messages',
|
|
303
|
-
attrs: {
|
|
382
|
+
attrs: {
|
|
383
|
+
type,
|
|
384
|
+
...(type === 'invite' ? { key } : { jid: key }),
|
|
385
|
+
count: count.toString(),
|
|
386
|
+
after: (after === null || after === void 0 ? void 0 : after.toString()) || '100'
|
|
387
|
+
}
|
|
304
388
|
}
|
|
305
389
|
]);
|
|
306
390
|
return await parseFetchedUpdates(result, 'messages');
|
|
@@ -309,7 +393,11 @@ setTimeout(async () => {
|
|
|
309
393
|
const result = await newsletterQuery(jid, 'get', [
|
|
310
394
|
{
|
|
311
395
|
tag: 'message_updates',
|
|
312
|
-
attrs: {
|
|
396
|
+
attrs: {
|
|
397
|
+
count: count.toString(),
|
|
398
|
+
after: (after === null || after === void 0 ? void 0 : after.toString()) || '100',
|
|
399
|
+
since: (since === null || since === void 0 ? void 0 : since.toString()) || '0'
|
|
400
|
+
}
|
|
313
401
|
}
|
|
314
402
|
]);
|
|
315
403
|
return await parseFetchedUpdates(result, 'updates');
|
|
@@ -339,4 +427,4 @@ const extractNewsletterMetadata = (node, isCreate) => {
|
|
|
339
427
|
}
|
|
340
428
|
return metadata
|
|
341
429
|
}
|
|
342
|
-
exports.extractNewsletterMetadata = extractNewsletterMetadata;
|
|
430
|
+
exports.extractNewsletterMetadata = extractNewsletterMetadata;
|