@genuxofficial/baileys 1.0.0 → 3.0.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.
- package/README.md +5 -1
- package/WAProto/WAProto.proto +1385 -96
- package/WAProto/index.d.ts +19244 -2787
- package/WAProto/index.js +138202 -74217
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +1 -0
- package/lib/Socket/business.d.ts +47 -17
- package/lib/Socket/chats.d.ts +10 -9
- package/lib/Socket/chats.js +36 -16
- package/lib/Socket/groups.d.ts +12 -11
- package/lib/Socket/groups.js +16 -3
- package/lib/Socket/index.d.ts +52 -22
- package/lib/Socket/messages-recv.d.ts +46 -15
- package/lib/Socket/messages-recv.js +158 -23
- package/lib/Socket/messages-send.d.ts +39 -11
- package/lib/Socket/messages-send.js +188 -22
- package/lib/Socket/newsletter.d.ts +137 -0
- package/lib/Socket/newsletter.js +256 -0
- package/lib/Socket/socket.d.ts +4 -4
- package/lib/Socket/socket.js +25 -12
- package/lib/Socket/usync.d.ts +5 -5
- package/lib/Store/index.d.ts +1 -2
- package/lib/Store/index.js +1 -3
- package/lib/Store/make-in-memory-store.js +14 -5
- package/lib/Types/Chat.d.ts +6 -5
- package/lib/Types/Events.d.ts +27 -0
- package/lib/Types/GroupMetadata.d.ts +6 -0
- package/lib/Types/Label.d.ts +0 -11
- package/lib/Types/Message.d.ts +150 -12
- package/lib/Types/Message.js +0 -2
- package/lib/Types/Newsletter.d.ts +79 -0
- package/lib/Types/Newsletter.js +18 -0
- package/lib/Types/Socket.d.ts +8 -3
- package/lib/Types/index.d.ts +1 -0
- package/lib/Types/index.js +1 -0
- package/lib/Utils/auth-utils.d.ts +1 -1
- package/lib/Utils/auth-utils.js +3 -4
- package/lib/Utils/business.js +15 -3
- package/lib/Utils/chat-utils.js +0 -16
- package/lib/Utils/crypto.js +6 -4
- package/lib/Utils/decode-wa-message.d.ts +5 -3
- package/lib/Utils/decode-wa-message.js +158 -31
- package/lib/Utils/event-buffer.js +1 -3
- package/lib/Utils/generics.d.ts +3 -2
- package/lib/Utils/generics.js +16 -36
- package/lib/Utils/history.d.ts +2 -2
- package/lib/Utils/link-preview.d.ts +1 -1
- package/lib/Utils/link-preview.js +1 -24
- package/lib/Utils/make-mutex.js +0 -1
- package/lib/Utils/messages-media.d.ts +14 -5
- package/lib/Utils/messages-media.js +130 -69
- package/lib/Utils/messages.d.ts +1 -1
- package/lib/Utils/messages.js +309 -57
- package/lib/Utils/noise-handler.d.ts +1 -1
- package/lib/Utils/process-message.js +0 -1
- package/lib/Utils/use-multi-file-auth-state.js +44 -13
- package/lib/Utils/validate-connection.js +1 -3
- package/lib/WABinary/decode.js +3 -2
- package/lib/WABinary/encode.js +13 -5
- package/lib/WABinary/generic-utils.d.ts +3 -5
- package/lib/WABinary/generic-utils.js +34 -19
- package/lib/WABinary/jid-utils.d.ts +12 -3
- package/lib/WABinary/jid-utils.js +29 -4
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +21 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +3 -3
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
- package/lib/WAUSync/USyncQuery.d.ts +2 -0
- package/lib/WAUSync/USyncQuery.js +10 -0
- package/lib/WAUSync/USyncUser.d.ts +2 -0
- package/lib/WAUSync/USyncUser.js +4 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +3 -1
- package/package.json +20 -12
- package/WAProto/GenerateStatics.sh +0 -4
- package/lib/Store/make-cache-manager-store.d.ts +0 -14
- package/lib/Store/make-cache-manager-store.js +0 -83
@@ -0,0 +1,137 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
/// <reference types="node" />
|
3
|
+
import { SocketConfig, WAMediaUpload, NewsletterMetadata, NewsletterReactionMode, NewsletterViewRole, NewsletterFetchedUpdate } from '../Types';
|
4
|
+
import { BinaryNode } from '../WABinary';
|
5
|
+
export declare const makeNewsletterSocket: (config: SocketConfig) => {
|
6
|
+
subscribeNewsletterUpdates: (jid: string) => Promise<{
|
7
|
+
duration: string;
|
8
|
+
}>;
|
9
|
+
newsletterReactionMode: (jid: string, mode: NewsletterReactionMode) => Promise<void>;
|
10
|
+
newsletterUpdateDescription: (jid: string, description?: string) => Promise<void>;
|
11
|
+
newsletterUpdateName: (jid: string, name: string) => Promise<void>;
|
12
|
+
newsletterUpdatePicture: (jid: string, content: WAMediaUpload) => Promise<void>;
|
13
|
+
newsletterRemovePicture: (jid: string) => Promise<void>;
|
14
|
+
newsletterUnfollow: (jid: string) => Promise<void>;
|
15
|
+
newsletterFollow: (jid: string) => Promise<void>;
|
16
|
+
newsletterUnmute: (jid: string) => Promise<void>;
|
17
|
+
newsletterMute: (jid: string) => Promise<void>;
|
18
|
+
newsletterCreate: (name: string, description?: string, picture?: WAMediaUpload) => 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, server_id: 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
|
+
groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
|
51
|
+
groupAcceptInviteV4: (key: string | import("../Types").WAMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<any>;
|
52
|
+
groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>; /**user is Lid, not Jid */
|
53
|
+
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
54
|
+
groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
|
55
|
+
groupMemberAddMode: (jid: string, mode: "all_member_add" | "admin_add") => Promise<void>;
|
56
|
+
groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
|
57
|
+
groupFetchAllParticipating: () => Promise<{
|
58
|
+
[_: string]: import("../Types").GroupMetadata;
|
59
|
+
}>;
|
60
|
+
getBotListV2: () => Promise<import("../Types").BotListInfo[]>;
|
61
|
+
processingMutex: {
|
62
|
+
mutex<T>(code: () => T | Promise<T>): Promise<T>;
|
63
|
+
};
|
64
|
+
fetchPrivacySettings: (force?: boolean) => Promise<{
|
65
|
+
[_: string]: string;
|
66
|
+
}>;
|
67
|
+
upsertMessage: (msg: import("../Types").WAProto.IWebMessageInfo, type: import("../Types").MessageUpsertType) => Promise<void>;
|
68
|
+
appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
|
69
|
+
sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string | undefined) => Promise<void>;
|
70
|
+
presenceSubscribe: (toJid: string, tcToken?: Buffer | undefined) => Promise<void>;
|
71
|
+
profilePictureUrl: (jid: string, type?: "image" | "preview", timeoutMs?: number | undefined) => Promise<string | undefined>;
|
72
|
+
onWhatsApp: (...jids: string[]) => Promise<{
|
73
|
+
jid: string;
|
74
|
+
exists: unknown;
|
75
|
+
lid: unknown;
|
76
|
+
}[] | undefined>;
|
77
|
+
fetchBlocklist: () => Promise<string[]>;
|
78
|
+
fetchDisappearingDuration: (...jids: string[]) => Promise<import("../index").USyncQueryResultList[] | undefined>;
|
79
|
+
fetchStatus: (...jids: string[]) => Promise<import("../index").USyncQueryResultList[] | 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
|
+
updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>;
|
86
|
+
updateMessagesPrivacy: (value: import("../Types").WAPrivacyMessagesValue) => Promise<void>;
|
87
|
+
updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
88
|
+
updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
|
89
|
+
updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
90
|
+
updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
91
|
+
updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
|
92
|
+
updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>;
|
93
|
+
updateDefaultDisappearingMode: (duration: number) => Promise<void>;
|
94
|
+
getBusinessProfile: (jid: string) => Promise<void | import("../Types").WABusinessProfile>;
|
95
|
+
resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
96
|
+
chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
|
97
|
+
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>;
|
98
|
+
addChatLabel: (jid: string, labelId: string) => Promise<void>;
|
99
|
+
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
100
|
+
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
101
|
+
removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
102
|
+
star: (jid: string, messages: {
|
103
|
+
id: string;
|
104
|
+
fromMe?: boolean | undefined;
|
105
|
+
}[], star: boolean) => Promise<void>;
|
106
|
+
executeUSyncQuery: (usyncQuery: import("../index").USyncQuery) => Promise<import("../index").USyncQueryResult | undefined>;
|
107
|
+
type: "md";
|
108
|
+
ws: import("./Client/websocket").WebSocketClient;
|
109
|
+
ev: import("../Types").BaileysEventEmitter & {
|
110
|
+
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
111
|
+
buffer(): void;
|
112
|
+
createBufferedFunction<A extends any[], T_1>(work: (...args: A) => Promise<T_1>): (...args: A) => Promise<T_1>;
|
113
|
+
flush(force?: boolean | undefined): boolean;
|
114
|
+
isBuffering(): boolean;
|
115
|
+
};
|
116
|
+
authState: {
|
117
|
+
creds: import("../Types").AuthenticationCreds;
|
118
|
+
keys: import("../Types").SignalKeyStoreWithTransaction;
|
119
|
+
};
|
120
|
+
signalRepository: import("../Types").SignalRepository;
|
121
|
+
user: import("../Types").Contact | undefined;
|
122
|
+
generateMessageTag: () => string;
|
123
|
+
query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<any>;
|
124
|
+
waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
|
125
|
+
waitForSocketOpen: () => Promise<void>;
|
126
|
+
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
127
|
+
sendNode: (frame: BinaryNode) => Promise<void>;
|
128
|
+
logout: (msg?: string | undefined) => Promise<void>;
|
129
|
+
end: (error: Error | undefined) => void;
|
130
|
+
onUnexpectedError: (err: Error | import("@hapi/boom").Boom<any>, msg: string) => void;
|
131
|
+
uploadPreKeys: (count?: number) => Promise<void>;
|
132
|
+
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
133
|
+
requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
|
134
|
+
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number | undefined) => Promise<void>;
|
135
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
|
136
|
+
};
|
137
|
+
export declare const extractNewsletterMetadata: (node: BinaryNode, isCreate?: boolean) => NewsletterMetadata;
|
@@ -0,0 +1,256 @@
|
|
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 { getMessage } = config;
|
24
|
+
const sock = (0, groups_1.makeGroupsSocket)(config);
|
25
|
+
const { authState, signalRepository, query, generateMessageTag } = sock;
|
26
|
+
const encoder = new TextEncoder();
|
27
|
+
const newsletterQuery = async (jid, type, content) => (query({
|
28
|
+
tag: 'iq',
|
29
|
+
attrs: {
|
30
|
+
id: generateMessageTag(),
|
31
|
+
type,
|
32
|
+
xmlns: 'newsletter',
|
33
|
+
to: jid,
|
34
|
+
},
|
35
|
+
content
|
36
|
+
}));
|
37
|
+
const newsletterWMexQuery = async (jid, query_id, content) => (query({
|
38
|
+
tag: 'iq',
|
39
|
+
attrs: {
|
40
|
+
id: generateMessageTag(),
|
41
|
+
type: 'get',
|
42
|
+
xmlns: 'w:mex',
|
43
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
44
|
+
},
|
45
|
+
content: [
|
46
|
+
{
|
47
|
+
tag: 'query',
|
48
|
+
attrs: { query_id },
|
49
|
+
content: encoder.encode(JSON.stringify({ variables: { newsletter_id: jid, ...content } }))
|
50
|
+
}
|
51
|
+
]
|
52
|
+
}));
|
53
|
+
const parseFetchedUpdates = async (node, type) => {
|
54
|
+
let child;
|
55
|
+
if (type === 'messages')
|
56
|
+
child = (0, WABinary_1.getBinaryNodeChild)(node, 'messages');
|
57
|
+
else {
|
58
|
+
const parent = (0, WABinary_1.getBinaryNodeChild)(node, 'message_updates');
|
59
|
+
child = (0, WABinary_1.getBinaryNodeChild)(parent, 'messages');
|
60
|
+
}
|
61
|
+
return await Promise.all((0, WABinary_1.getAllBinaryNodeChildren)(child).map(async (messageNode) => {
|
62
|
+
var _a, _b;
|
63
|
+
messageNode.attrs.from = child === null || child === void 0 ? void 0 : child.attrs.jid;
|
64
|
+
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;
|
65
|
+
const reactionNode = (0, WABinary_1.getBinaryNodeChild)(messageNode, 'reactions');
|
66
|
+
const reactions = (0, WABinary_1.getBinaryNodeChildren)(reactionNode, 'reaction')
|
67
|
+
.map(({ attrs }) => ({ count: +attrs.count, code: attrs.code }));
|
68
|
+
let data;
|
69
|
+
if (type === 'messages') {
|
70
|
+
const { fullMessage: message, decrypt } = await (0, Utils_1.decryptMessageNode)(messageNode, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, config.logger, getMessage);
|
71
|
+
await decrypt();
|
72
|
+
data = {
|
73
|
+
server_id: messageNode.attrs.server_id,
|
74
|
+
views: views ? +views : undefined,
|
75
|
+
reactions,
|
76
|
+
message
|
77
|
+
};
|
78
|
+
return data;
|
79
|
+
}
|
80
|
+
else {
|
81
|
+
data = {
|
82
|
+
server_id: messageNode.attrs.server_id,
|
83
|
+
views: views ? +views : undefined,
|
84
|
+
reactions
|
85
|
+
};
|
86
|
+
return data;
|
87
|
+
}
|
88
|
+
}));
|
89
|
+
};
|
90
|
+
return {
|
91
|
+
...sock,
|
92
|
+
subscribeNewsletterUpdates: async (jid) => {
|
93
|
+
var _a;
|
94
|
+
const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }]);
|
95
|
+
return (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'live_updates')) === null || _a === void 0 ? void 0 : _a.attrs;
|
96
|
+
},
|
97
|
+
newsletterReactionMode: async (jid, mode) => {
|
98
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
99
|
+
updates: { settings: { reaction_codes: { value: mode } } }
|
100
|
+
});
|
101
|
+
},
|
102
|
+
newsletterUpdateDescription: async (jid, description) => {
|
103
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
104
|
+
updates: { description: description || '', settings: null }
|
105
|
+
});
|
106
|
+
},
|
107
|
+
newsletterUpdateName: async (jid, name) => {
|
108
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
109
|
+
updates: { name, settings: null }
|
110
|
+
});
|
111
|
+
},
|
112
|
+
newsletterUpdatePicture: async (jid, content) => {
|
113
|
+
const { img } = await (0, Utils_1.generateProfilePicture)(content);
|
114
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
115
|
+
updates: { picture: img.toString('base64'), settings: null }
|
116
|
+
});
|
117
|
+
},
|
118
|
+
newsletterRemovePicture: async (jid) => {
|
119
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
120
|
+
updates: { picture: '', settings: null }
|
121
|
+
});
|
122
|
+
},
|
123
|
+
newsletterUnfollow: async (jid) => {
|
124
|
+
await newsletterWMexQuery(jid, QueryIds.UNFOLLOW);
|
125
|
+
},
|
126
|
+
newsletterFollow: async (jid) => {
|
127
|
+
await newsletterWMexQuery(jid, QueryIds.FOLLOW);
|
128
|
+
},
|
129
|
+
newsletterUnmute: async (jid) => {
|
130
|
+
await newsletterWMexQuery(jid, QueryIds.UNMUTE);
|
131
|
+
},
|
132
|
+
newsletterMute: async (jid) => {
|
133
|
+
await newsletterWMexQuery(jid, QueryIds.MUTE);
|
134
|
+
},
|
135
|
+
newsletterCreate: async (name, description, picture) => {
|
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: {
|
157
|
+
name,
|
158
|
+
description: description !== null && description !== void 0 ? description : null,
|
159
|
+
picture: picture ? (await (0, Utils_1.generateProfilePicture)(picture)).img.toString('base64') : null,
|
160
|
+
settings: {
|
161
|
+
reaction_codes: { value: 'ALL' }
|
162
|
+
}
|
163
|
+
}
|
164
|
+
});
|
165
|
+
return (0, exports.extractNewsletterMetadata)(result, true);
|
166
|
+
},
|
167
|
+
newsletterMetadata: async (type, key, role) => {
|
168
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.METADATA, {
|
169
|
+
input: {
|
170
|
+
key,
|
171
|
+
type: type.toUpperCase(),
|
172
|
+
view_role: role || 'GUEST'
|
173
|
+
},
|
174
|
+
fetch_viewer_metadata: true,
|
175
|
+
fetch_full_image: true,
|
176
|
+
fetch_creation_time: true
|
177
|
+
});
|
178
|
+
return (0, exports.extractNewsletterMetadata)(result);
|
179
|
+
},
|
180
|
+
newsletterAdminCount: async (jid) => {
|
181
|
+
var _a, _b;
|
182
|
+
const result = await newsletterWMexQuery(jid, QueryIds.ADMIN_COUNT);
|
183
|
+
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();
|
184
|
+
return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count;
|
185
|
+
},
|
186
|
+
/**user is Lid, not Jid */
|
187
|
+
newsletterChangeOwner: async (jid, user) => {
|
188
|
+
await newsletterWMexQuery(jid, QueryIds.CHANGE_OWNER, {
|
189
|
+
user_id: user
|
190
|
+
});
|
191
|
+
},
|
192
|
+
/**user is Lid, not Jid */
|
193
|
+
newsletterDemote: async (jid, user) => {
|
194
|
+
await newsletterWMexQuery(jid, QueryIds.DEMOTE, {
|
195
|
+
user_id: user
|
196
|
+
});
|
197
|
+
},
|
198
|
+
newsletterDelete: async (jid) => {
|
199
|
+
await newsletterWMexQuery(jid, QueryIds.DELETE);
|
200
|
+
},
|
201
|
+
/**if code wasn't passed, the reaction will be removed (if is reacted) */
|
202
|
+
newsletterReactMessage: async (jid, server_id, code) => {
|
203
|
+
await query({
|
204
|
+
tag: 'message',
|
205
|
+
attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', server_id, id: (0, Utils_1.generateMessageID)() },
|
206
|
+
content: [{
|
207
|
+
tag: 'reaction',
|
208
|
+
attrs: code ? { code } : {}
|
209
|
+
}]
|
210
|
+
});
|
211
|
+
},
|
212
|
+
newsletterFetchMessages: async (type, key, count, after) => {
|
213
|
+
const result = await newsletterQuery(WABinary_1.S_WHATSAPP_NET, 'get', [
|
214
|
+
{
|
215
|
+
tag: 'messages',
|
216
|
+
attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after: (after === null || after === void 0 ? void 0 : after.toString()) || '100' }
|
217
|
+
}
|
218
|
+
]);
|
219
|
+
return await parseFetchedUpdates(result, 'messages');
|
220
|
+
},
|
221
|
+
newsletterFetchUpdates: async (jid, count, after, since) => {
|
222
|
+
const result = await newsletterQuery(jid, 'get', [
|
223
|
+
{
|
224
|
+
tag: 'message_updates',
|
225
|
+
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' }
|
226
|
+
}
|
227
|
+
]);
|
228
|
+
return await parseFetchedUpdates(result, 'updates');
|
229
|
+
}
|
230
|
+
};
|
231
|
+
};
|
232
|
+
exports.makeNewsletterSocket = makeNewsletterSocket;
|
233
|
+
const extractNewsletterMetadata = (node, isCreate) => {
|
234
|
+
var _a, _b, _c, _d;
|
235
|
+
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();
|
236
|
+
const metadataPath = JSON.parse(result).data[isCreate ? Types_1.XWAPaths.CREATE : Types_1.XWAPaths.NEWSLETTER];
|
237
|
+
const metadata = {
|
238
|
+
id: metadataPath.id,
|
239
|
+
state: metadataPath.state.type,
|
240
|
+
creation_time: +metadataPath.thread_metadata.creation_time,
|
241
|
+
name: metadataPath.thread_metadata.name.text,
|
242
|
+
nameTime: +metadataPath.thread_metadata.name.update_time,
|
243
|
+
description: metadataPath.thread_metadata.description.text,
|
244
|
+
descriptionTime: +metadataPath.thread_metadata.description.update_time,
|
245
|
+
invite: metadataPath.thread_metadata.invite,
|
246
|
+
handle: metadataPath.thread_metadata.handle,
|
247
|
+
picture: ((_c = metadataPath.thread_metadata.picture) === null || _c === void 0 ? void 0 : _c.direct_path) || null,
|
248
|
+
preview: ((_d = metadataPath.thread_metadata.preview) === null || _d === void 0 ? void 0 : _d.direct_path) || null,
|
249
|
+
reaction_codes: metadataPath.thread_metadata.settings.reaction_codes.value,
|
250
|
+
subscribers: +metadataPath.thread_metadata.subscribers_count,
|
251
|
+
verification: metadataPath.thread_metadata.verification,
|
252
|
+
viewer_metadata: metadataPath.viewer_metadata
|
253
|
+
};
|
254
|
+
return metadata;
|
255
|
+
};
|
256
|
+
exports.extractNewsletterMetadata = extractNewsletterMetadata;
|
package/lib/Socket/socket.d.ts
CHANGED
@@ -27,8 +27,8 @@ export declare const makeSocket: (config: SocketConfig) => {
|
|
27
27
|
signalRepository: import("../Types").SignalRepository;
|
28
28
|
readonly user: import("../Types").Contact | undefined;
|
29
29
|
generateMessageTag: () => string;
|
30
|
-
query: (node: BinaryNode, timeoutMs?: number) => Promise<
|
31
|
-
waitForMessage: <T_1>(msgId: string, timeoutMs?: number | undefined) => Promise<
|
30
|
+
query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
|
31
|
+
waitForMessage: <T_1>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
|
32
32
|
waitForSocketOpen: () => Promise<void>;
|
33
33
|
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
34
34
|
sendNode: (frame: BinaryNode) => Promise<void>;
|
@@ -37,9 +37,9 @@ export declare const makeSocket: (config: SocketConfig) => {
|
|
37
37
|
onUnexpectedError: (err: Error | Boom, msg: string) => void;
|
38
38
|
uploadPreKeys: (count?: number) => Promise<void>;
|
39
39
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
40
|
-
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
40
|
+
requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
|
41
41
|
/** Waits for the connection to WA to reach a state */
|
42
42
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number | undefined) => Promise<void>;
|
43
|
-
sendWAMBuffer: (wamBuffer: Buffer) => Promise<
|
43
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
|
44
44
|
};
|
45
45
|
export type Socket = ReturnType<typeof makeSocket>;
|
package/lib/Socket/socket.js
CHANGED
@@ -114,7 +114,7 @@ const makeSocket = (config) => {
|
|
114
114
|
let onRecv;
|
115
115
|
let onErr;
|
116
116
|
try {
|
117
|
-
|
117
|
+
const result = await (0, Utils_1.promiseTimeout)(timeoutMs, (resolve, reject) => {
|
118
118
|
onRecv = resolve;
|
119
119
|
onErr = err => {
|
120
120
|
reject(err || new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
|
@@ -123,6 +123,7 @@ const makeSocket = (config) => {
|
|
123
123
|
ws.on('close', onErr); // if the socket closes, you'll never receive the message
|
124
124
|
ws.off('error', onErr);
|
125
125
|
});
|
126
|
+
return result;
|
126
127
|
}
|
127
128
|
finally {
|
128
129
|
ws.off(`TAG:${msgId}`, onRecv);
|
@@ -136,9 +137,10 @@ const makeSocket = (config) => {
|
|
136
137
|
node.attrs.id = generateMessageTag();
|
137
138
|
}
|
138
139
|
const msgId = node.attrs.id;
|
139
|
-
const
|
140
|
-
|
141
|
-
|
140
|
+
const [result] = await Promise.all([
|
141
|
+
waitForMessage(msgId, timeoutMs),
|
142
|
+
sendNode(node)
|
143
|
+
]);
|
142
144
|
if ('tag' in result) {
|
143
145
|
(0, WABinary_1.assertNodeErrorFree)(result);
|
144
146
|
}
|
@@ -360,8 +362,13 @@ const makeSocket = (config) => {
|
|
360
362
|
}
|
361
363
|
end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
|
362
364
|
};
|
363
|
-
const requestPairingCode = async (phoneNumber) => {
|
364
|
-
|
365
|
+
const requestPairingCode = async (phoneNumber, pairCode) => {
|
366
|
+
if (pairCode) {
|
367
|
+
authState.creds.pairingCode = pairCode.substring(0, 8).toUpperCase();
|
368
|
+
}
|
369
|
+
else {
|
370
|
+
authState.creds.pairingCode = (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5));
|
371
|
+
}
|
365
372
|
authState.creds.me = {
|
366
373
|
id: (0, WABinary_1.jidEncode)(phoneNumber, 's.whatsapp.net'),
|
367
374
|
name: '~'
|
@@ -506,12 +513,18 @@ const makeSocket = (config) => {
|
|
506
513
|
});
|
507
514
|
// login complete
|
508
515
|
ws.on('CB:success', async (node) => {
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
516
|
+
try {
|
517
|
+
await uploadPreKeysToServerIfRequired();
|
518
|
+
await sendPassiveIq('active');
|
519
|
+
logger.info('opened connection to WA');
|
520
|
+
clearTimeout(qrTimer); // will never happen in all likelyhood -- but just in case WA sends success on first try
|
521
|
+
ev.emit('creds.update', { me: { ...authState.creds.me, lid: node.attrs.lid } });
|
522
|
+
ev.emit('connection.update', { connection: 'open' });
|
523
|
+
}
|
524
|
+
catch (err) {
|
525
|
+
logger.error({ err }, 'error opening connection');
|
526
|
+
end(err);
|
527
|
+
}
|
515
528
|
});
|
516
529
|
ws.on('CB:stream:error', (node) => {
|
517
530
|
logger.error({ node }, 'stream errored out');
|
package/lib/Socket/usync.d.ts
CHANGED
@@ -7,7 +7,7 @@ import { USyncQuery } from '../WAUSync';
|
|
7
7
|
export declare const makeUSyncSocket: (config: SocketConfig) => {
|
8
8
|
executeUSyncQuery: (usyncQuery: USyncQuery) => Promise<import("../WAUSync").USyncQueryResult | undefined>;
|
9
9
|
type: "md";
|
10
|
-
ws: import("./Client").WebSocketClient;
|
10
|
+
ws: import("./Client/websocket").WebSocketClient;
|
11
11
|
ev: import("../Types").BaileysEventEmitter & {
|
12
12
|
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
13
13
|
buffer(): void;
|
@@ -22,8 +22,8 @@ export declare const makeUSyncSocket: (config: SocketConfig) => {
|
|
22
22
|
signalRepository: import("../Types").SignalRepository;
|
23
23
|
user: import("../Types").Contact | undefined;
|
24
24
|
generateMessageTag: () => string;
|
25
|
-
query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<
|
26
|
-
waitForMessage: <T_1>(msgId: string, timeoutMs?: number | undefined) => Promise<
|
25
|
+
query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<any>;
|
26
|
+
waitForMessage: <T_1>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
|
27
27
|
waitForSocketOpen: () => Promise<void>;
|
28
28
|
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
29
29
|
sendNode: (frame: BinaryNode) => Promise<void>;
|
@@ -32,7 +32,7 @@ export declare const makeUSyncSocket: (config: SocketConfig) => {
|
|
32
32
|
onUnexpectedError: (err: Error | Boom<any>, msg: string) => void;
|
33
33
|
uploadPreKeys: (count?: number) => Promise<void>;
|
34
34
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
35
|
-
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
35
|
+
requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
|
36
36
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number | undefined) => Promise<void>;
|
37
|
-
sendWAMBuffer: (wamBuffer: Buffer) => Promise<
|
37
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
|
38
38
|
};
|
package/lib/Store/index.d.ts
CHANGED
package/lib/Store/index.js
CHANGED
@@ -3,8 +3,6 @@ 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.
|
7
|
-
const make_cache_manager_store_1 = __importDefault(require("./make-cache-manager-store"));
|
8
|
-
exports.makeCacheManagerAuthState = make_cache_manager_store_1.default;
|
6
|
+
exports.makeInMemoryStore = void 0;
|
9
7
|
const make_in_memory_store_1 = __importDefault(require("./make-in-memory-store"));
|
10
8
|
exports.makeInMemoryStore = make_in_memory_store_1.default;
|
@@ -56,6 +56,14 @@ exports.default = (config) => {
|
|
56
56
|
labels.upsertById(label.id, label);
|
57
57
|
}
|
58
58
|
};
|
59
|
+
const getValidContacts = () => {
|
60
|
+
for (const contact of Object.keys(contacts)) {
|
61
|
+
if (contact.indexOf('@') < 0) {
|
62
|
+
delete contacts[contact];
|
63
|
+
}
|
64
|
+
}
|
65
|
+
return Object.keys(contacts);
|
66
|
+
};
|
59
67
|
/**
|
60
68
|
* binds to a BaileysEventEmitter.
|
61
69
|
* It listens to all events and constructs a state that you can query accurate data from.
|
@@ -104,10 +112,11 @@ exports.default = (config) => {
|
|
104
112
|
contact = contacts[update.id];
|
105
113
|
}
|
106
114
|
else {
|
107
|
-
const
|
115
|
+
const validContacts = getValidContacts();
|
116
|
+
const contactHashes = validContacts.map((contactId) => {
|
108
117
|
const { user } = (0, WABinary_1.jidDecode)(contactId);
|
109
|
-
return [contactId, (
|
110
|
-
})
|
118
|
+
return [contactId, ((0, Utils_1.md5)(Buffer.from(user + 'WA_ADD_NOTIF', 'utf8'))).toString('base64').slice(0, 3)];
|
119
|
+
});
|
111
120
|
contact = contacts[((_a = contactHashes.find(([, b]) => b === update.id)) === null || _a === void 0 ? void 0 : _a[0]) || '']; // find contact by attrs.hash, when user is not saved as a contact
|
112
121
|
}
|
113
122
|
if (contact) {
|
@@ -117,11 +126,11 @@ exports.default = (config) => {
|
|
117
126
|
else if (update.imgUrl === 'removed') {
|
118
127
|
delete contact.imgUrl;
|
119
128
|
}
|
129
|
+
Object.assign(contacts[contact.id], contact);
|
120
130
|
}
|
121
131
|
else {
|
122
|
-
|
132
|
+
logger.debug({ update }, 'got update for non-existant contact');
|
123
133
|
}
|
124
|
-
Object.assign(contacts[contact.id], contact);
|
125
134
|
}
|
126
135
|
});
|
127
136
|
ev.on('chats.upsert', newChats => {
|
package/lib/Types/Chat.d.ts
CHANGED
@@ -1,17 +1,16 @@
|
|
1
1
|
import type { proto } from '../../WAProto';
|
2
2
|
import type { AccountSettings } from './Auth';
|
3
3
|
import type { BufferedEventData } from './Events';
|
4
|
-
import type { LabelActionBody } from './Label';
|
5
4
|
import type { ChatLabelAssociationActionBody } from './LabelAssociation';
|
6
5
|
import type { MessageLabelAssociationActionBody } from './LabelAssociation';
|
7
6
|
import type { MinimalMessage, WAMessageKey } from './Message';
|
8
7
|
/** privacy settings in WhatsApp Web */
|
9
8
|
export type WAPrivacyValue = 'all' | 'contacts' | 'contact_blacklist' | 'none';
|
9
|
+
export type WAPrivacyCallValue = 'all' | 'known';
|
10
|
+
export type WAPrivacyMessagesValue = 'all' | 'contacts';
|
10
11
|
export type WAPrivacyOnlineValue = 'all' | 'match_last_seen';
|
11
12
|
export type WAPrivacyGroupAddValue = 'all' | 'contacts' | 'contact_blacklist';
|
12
13
|
export type WAReadReceiptsValue = 'all' | 'none';
|
13
|
-
export type WAPrivacyCallValue = 'all' | 'known';
|
14
|
-
export type WAPrivacyMessagesValue = 'all' | 'contacts';
|
15
14
|
/** set of statuses visible to other people; see updatePresence() in WhatsAppWeb.Send */
|
16
15
|
export type WAPresence = 'unavailable' | 'available' | 'composing' | 'recording' | 'paused';
|
17
16
|
export declare const ALL_WA_PATCH_NAMES: readonly ["critical_block", "critical_unblock_low", "regular_high", "regular_low", "regular"];
|
@@ -20,6 +19,10 @@ export interface PresenceData {
|
|
20
19
|
lastKnownPresence: WAPresence;
|
21
20
|
lastSeen?: number;
|
22
21
|
}
|
22
|
+
export type BotListInfo = {
|
23
|
+
jid: string;
|
24
|
+
personaId: string;
|
25
|
+
};
|
23
26
|
export type ChatMutation = {
|
24
27
|
syncAction: proto.ISyncActionData;
|
25
28
|
index: string[];
|
@@ -84,8 +87,6 @@ export type ChatModification = {
|
|
84
87
|
} | {
|
85
88
|
delete: true;
|
86
89
|
lastMessages: LastMessageList;
|
87
|
-
} | {
|
88
|
-
addLabel: LabelActionBody;
|
89
90
|
} | {
|
90
91
|
addChatLabel: ChatLabelAssociationActionBody;
|
91
92
|
} | {
|