@badzz88/baileys 8.4.6 → 8.4.9
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/LICENSE +21 -0
- package/README.md +1055 -337
- package/WAProto/WAProto.proto +850 -32
- package/WAProto/index.d.ts +4913 -25
- package/WAProto/index.js +14074 -98
- package/package.json +96 -131
- package/src/Defaults/index.js +201 -0
- package/src/Defaults/phonenumber-mcc.json +223 -0
- package/src/Signal/Group/ciphertext-message.js +15 -0
- package/src/Signal/Group/group-session-builder.js +92 -0
- package/src/Signal/Group/group_cipher.js +89 -0
- package/src/Signal/Group/index.js +136 -0
- package/src/Signal/Group/keyhelper.js +73 -0
- package/src/Signal/Group/sender-chain-key.js +32 -0
- package/src/Signal/Group/sender-key-distribution-message.js +66 -0
- package/src/Signal/Group/sender-key-message.js +69 -0
- package/src/Signal/Group/sender-key-name.js +50 -0
- package/src/Signal/Group/sender-key-record.js +44 -0
- package/src/Signal/Group/sender-key-state.js +97 -0
- package/src/Signal/Group/sender-message-key.js +30 -0
- package/src/Signal/libsignal.js +470 -0
- package/src/Signal/lid-mapping.js +262 -0
- package/src/Socket/Client/index.js +30 -0
- package/src/Socket/Client/types.js +13 -0
- package/src/Socket/Client/websocket.js +62 -0
- package/src/Socket/aigroups.js +240 -0
- package/src/Socket/business.js +422 -0
- package/src/Socket/chats.js +2374 -0
- package/src/Socket/communities.js +580 -0
- package/src/Socket/graphql.js +915 -0
- package/src/Socket/groups.js +812 -0
- package/src/Socket/index.js +37 -0
- package/src/Socket/interactive-handler.js +579 -0
- package/src/Socket/interop.js +566 -0
- package/src/Socket/managed-account.js +214 -0
- package/src/Socket/messages-recv.js +3012 -0
- package/src/Socket/messages-send.js +2163 -0
- package/{lib → src}/Socket/mex.js +11 -5
- package/src/Socket/newsletter.js +1057 -0
- package/src/Socket/privacy.js +452 -0
- package/src/Socket/registration.js +434 -0
- package/src/Socket/socket.js +1079 -0
- package/src/Socket/text-router.js +67 -0
- package/src/Socket/username.js +234 -0
- package/src/Store/index.js +36 -0
- package/src/Store/make-cache-manager-store.js +90 -0
- package/src/Store/make-in-memory-store.js +506 -0
- package/src/Store/make-ordered-dictionary.js +81 -0
- package/src/Store/object-repository.js +29 -0
- package/src/Types/Auth.js +38 -0
- package/src/Types/Bussines.js +2 -0
- package/src/Types/Call.js +2 -0
- package/src/Types/Chat.js +4 -0
- package/src/Types/Contact.js +2 -0
- package/src/Types/Events.js +2 -0
- package/src/Types/GroupMetadata.js +2 -0
- package/src/Types/Label.js +27 -0
- package/src/Types/LabelAssociation.js +9 -0
- package/src/Types/Message.js +95 -0
- package/src/Types/Newsletter.js +152 -0
- package/src/Types/Product.js +2 -0
- package/src/Types/Signal.js +2 -0
- package/src/Types/Socket.js +2 -0
- package/src/Types/State.js +70 -0
- package/src/Types/USync.js +2 -0
- package/src/Types/index.js +54 -0
- package/src/Utils/auth-utils.js +306 -0
- package/src/Utils/browser-utils.js +114 -0
- package/src/Utils/business.js +247 -0
- package/src/Utils/chat-utils.js +1272 -0
- package/src/Utils/consumer-application.js +107 -0
- package/src/Utils/crypto.js +125 -0
- package/src/Utils/decode-wa-message.js +808 -0
- package/src/Utils/event-buffer.js +586 -0
- package/src/Utils/generics.js +640 -0
- package/src/Utils/group-history.js +60 -0
- package/src/Utils/history.js +244 -0
- package/src/Utils/identity-change-handler.js +52 -0
- package/src/Utils/index.js +53 -0
- package/src/Utils/jid-display-normalization.js +218 -0
- package/src/Utils/link-preview.js +143 -0
- package/src/Utils/logger.js +9 -0
- package/src/Utils/lt-hash.js +10 -0
- package/src/Utils/make-mutex.js +36 -0
- package/src/Utils/message-composer.js +479 -0
- package/src/Utils/message-inspect.js +400 -0
- package/src/Utils/message-retry-manager.js +231 -0
- package/src/Utils/messages-media.js +943 -0
- package/src/Utils/messages.js +2490 -0
- package/src/Utils/meta-ai-msmsg.js +133 -0
- package/src/Utils/noise-handler.js +194 -0
- package/src/Utils/offline-node-processor.js +42 -0
- package/src/Utils/pre-key-manager.js +107 -0
- package/src/Utils/process-message.js +1047 -0
- package/src/Utils/reporting-utils.js +262 -0
- package/src/Utils/signal.js +192 -0
- package/src/Utils/stanza-ack.js +74 -0
- package/src/Utils/sync-action-utils.js +54 -0
- package/src/Utils/tc-token-utils.js +161 -0
- package/src/Utils/use-multi-file-auth-state.js +121 -0
- package/src/Utils/validate-connection.js +248 -0
- package/src/Utils/voip-rekey.js +22 -0
- package/src/WABinary/constants.js +1304 -0
- package/src/WABinary/decode.js +377 -0
- package/src/WABinary/encode.js +58 -0
- package/src/WABinary/generic-utils.js +148 -0
- package/src/WABinary/index.js +33 -0
- package/src/WABinary/jid-utils.js +374 -0
- package/src/WABinary/types.js +2 -0
- package/src/WAM/BinaryInfo.js +13 -0
- package/src/WAM/constants.js +39486 -0
- package/src/WAM/encode.js +142 -0
- package/src/WAM/index.js +31 -0
- package/src/WAUSync/Protocols/USyncBotProfileProtocol.js +55 -0
- package/src/WAUSync/Protocols/USyncBusinessProtocol.js +100 -0
- package/src/WAUSync/Protocols/USyncContactProtocol.js +60 -0
- package/src/WAUSync/Protocols/USyncDeviceProtocol.js +65 -0
- package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
- package/src/WAUSync/Protocols/USyncFeatureProtocol.js +74 -0
- package/src/WAUSync/Protocols/USyncLIDProtocol.js +31 -0
- package/src/WAUSync/Protocols/USyncPictureProtocol.js +32 -0
- package/src/WAUSync/Protocols/USyncSidelistProtocol.js +29 -0
- package/src/WAUSync/Protocols/USyncStatusProtocol.js +44 -0
- package/src/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
- package/src/WAUSync/Protocols/USyncUsernameProtocol.js +28 -0
- package/src/WAUSync/Protocols/index.js +40 -0
- package/src/WAUSync/USyncBackoff.js +31 -0
- package/src/WAUSync/USyncQuery.js +204 -0
- package/src/WAUSync/USyncUser.js +58 -0
- package/src/WAUSync/index.js +32 -0
- package/src/antiban.js +4726 -0
- package/{lib → src}/index.js +48 -16
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/index.js +0 -137
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Signal/Group/Protocols.js +0 -269
- package/lib/Signal/Group/ciphertext-message.js +0 -12
- package/lib/Signal/Group/group-session-builder.js +0 -30
- package/lib/Signal/Group/group_cipher.js +0 -82
- package/lib/Signal/Group/index.js +0 -12
- package/lib/Signal/Group/keyhelper.js +0 -18
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Signal/Group/sender-chain-key.js +0 -26
- package/lib/Signal/Group/sender-key-distribution-message.js +0 -63
- package/lib/Signal/Group/sender-key-message.js +0 -66
- package/lib/Signal/Group/sender-key-name.js +0 -48
- package/lib/Signal/Group/sender-key-record.js +0 -41
- package/lib/Signal/Group/sender-key-state.js +0 -84
- package/lib/Signal/Group/sender-message-key.js +0 -26
- package/lib/Signal/libsignal.js +0 -432
- package/lib/Signal/lid-mapping.js +0 -277
- package/lib/Socket/Client/abstract-socket-client.js +0 -13
- package/lib/Socket/Client/index.js +0 -3
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/types.js +0 -11
- package/lib/Socket/Client/web-socket-client.js +0 -62
- package/lib/Socket/Client/websocket.js +0 -54
- package/lib/Socket/business.js +0 -379
- package/lib/Socket/chats.js +0 -1193
- package/lib/Socket/communities.js +0 -431
- package/lib/Socket/community.js +0 -392
- package/lib/Socket/dugong.js +0 -637
- package/lib/Socket/groups.js +0 -374
- package/lib/Socket/index.js +0 -12
- package/lib/Socket/luxu.js +0 -387
- package/lib/Socket/messages-recv.js +0 -1916
- package/lib/Socket/messages-send.js +0 -1459
- package/lib/Socket/newsletter.js +0 -253
- package/lib/Socket/registration.js +0 -167
- package/lib/Socket/socket.js +0 -950
- package/lib/Socket/username.js +0 -146
- package/lib/Socket/usync.js +0 -69
- package/lib/Store/index.js +0 -10
- package/lib/Store/keyed-db.js +0 -108
- package/lib/Store/make-cache-manager-store.js +0 -85
- package/lib/Store/make-in-memory-store.js +0 -198
- package/lib/Store/make-ordered-dictionary.js +0 -75
- package/lib/Store/object-repository.js +0 -32
- package/lib/Types/Auth.js +0 -2
- package/lib/Types/Bussines.js +0 -2
- package/lib/Types/Call.js +0 -2
- package/lib/Types/Chat.js +0 -8
- package/lib/Types/Contact.js +0 -2
- package/lib/Types/Events.js +0 -2
- package/lib/Types/GroupMetadata.js +0 -2
- package/lib/Types/Label.js +0 -25
- package/lib/Types/LabelAssociation.js +0 -7
- package/lib/Types/Message.js +0 -11
- package/lib/Types/Mex.js +0 -37
- package/lib/Types/Newsletter.js +0 -38
- package/lib/Types/Product.js +0 -2
- package/lib/Types/Signal.js +0 -2
- package/lib/Types/Socket.js +0 -3
- package/lib/Types/State.js +0 -56
- package/lib/Types/USync.js +0 -2
- package/lib/Types/index.js +0 -26
- package/lib/Utils/auth-utils.js +0 -302
- package/lib/Utils/baileys-event-stream.js +0 -63
- package/lib/Utils/browser-utils.js +0 -48
- package/lib/Utils/business.js +0 -231
- package/lib/Utils/chat-utils.js +0 -873
- package/lib/Utils/companion-reg-client-utils.js +0 -35
- package/lib/Utils/crypto.js +0 -118
- package/lib/Utils/decode-wa-message.js +0 -350
- package/lib/Utils/event-buffer.js +0 -622
- package/lib/Utils/generics.js +0 -399
- package/lib/Utils/history.js +0 -134
- package/lib/Utils/identity-change-handler.js +0 -50
- package/lib/Utils/index.js +0 -23
- package/lib/Utils/link-preview.js +0 -85
- package/lib/Utils/logger.js +0 -3
- package/lib/Utils/lt-hash.js +0 -8
- package/lib/Utils/make-mutex.js +0 -33
- package/lib/Utils/message-composer.js +0 -273
- package/lib/Utils/message-retry-manager.js +0 -265
- package/lib/Utils/messages-media.js +0 -788
- package/lib/Utils/messages.js +0 -1260
- package/lib/Utils/noise-handler.js +0 -201
- package/lib/Utils/offline-node-processor.js +0 -40
- package/lib/Utils/pre-key-manager.js +0 -106
- package/lib/Utils/process-message.js +0 -630
- package/lib/Utils/reporting-utils.js +0 -258
- package/lib/Utils/signal.js +0 -202
- package/lib/Utils/stanza-ack.js +0 -38
- package/lib/Utils/sync-action-utils.js +0 -49
- package/lib/Utils/tc-token-utils.js +0 -163
- package/lib/Utils/use-multi-file-auth-state.js +0 -121
- package/lib/Utils/validate-connection.js +0 -204
- package/lib/WABinary/constants.js +0 -1301
- package/lib/WABinary/decode.js +0 -262
- package/lib/WABinary/encode.js +0 -220
- package/lib/WABinary/generic-utils.js +0 -204
- package/lib/WABinary/index.js +0 -6
- package/lib/WABinary/jid-utils.js +0 -98
- package/lib/WABinary/types.js +0 -2
- package/lib/WAM/BinaryInfo.js +0 -10
- package/lib/WAM/constants.js +0 -22853
- package/lib/WAM/encode.js +0 -150
- package/lib/WAM/index.js +0 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -52
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -54
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -27
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -38
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +0 -25
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -51
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -29
- package/lib/WAUSync/Protocols/index.js +0 -6
- package/lib/WAUSync/USyncQuery.js +0 -98
- package/lib/WAUSync/USyncUser.js +0 -31
- package/lib/WAUSync/index.js +0 -4
package/lib/Socket/newsletter.js
DELETED
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
import { XWAPaths } from '../Types/index.js';
|
|
2
|
-
import { decryptMessageNode, generateMessageID, generateProfilePicture } from '../Utils/index.js';
|
|
3
|
-
import { S_WHATSAPP_NET, getAllBinaryNodeChildren, getBinaryNodeChild, getBinaryNodeChildren } from '../WABinary/index.js';
|
|
4
|
-
import { makeGroupsSocket } from './groups.js';
|
|
5
|
-
|
|
6
|
-
const QueryIds = {
|
|
7
|
-
JOB_MUTATION: "7150902998257522",
|
|
8
|
-
METADATA: "6620195908089573",
|
|
9
|
-
UNFOLLOW: "7238632346214362",
|
|
10
|
-
FOLLOW: "7871414976211147",
|
|
11
|
-
UNMUTE: "7337137176362961",
|
|
12
|
-
MUTE: "25151904754424642",
|
|
13
|
-
CREATE: "6996806640408138",
|
|
14
|
-
ADMIN_COUNT: "7130823597031706",
|
|
15
|
-
CHANGE_OWNER: "7341777602580933",
|
|
16
|
-
DELETE: "8316537688363079",
|
|
17
|
-
DEMOTE: "6551828931592903"
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const makeNewsletterSocket = (config) => {
|
|
21
|
-
const sock = makeGroupsSocket(config);
|
|
22
|
-
const { authState, signalRepository, query, generateMessageTag } = sock;
|
|
23
|
-
const encoder = new TextEncoder();
|
|
24
|
-
|
|
25
|
-
const newsletterQuery = async (jid, type, content) => (
|
|
26
|
-
query({
|
|
27
|
-
tag: 'iq',
|
|
28
|
-
attrs: {
|
|
29
|
-
id: generateMessageTag(),
|
|
30
|
-
type,
|
|
31
|
-
xmlns: 'newsletter',
|
|
32
|
-
to: jid,
|
|
33
|
-
},
|
|
34
|
-
content
|
|
35
|
-
})
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
const newsletterWMexQuery = async (jid, query_id, content) => (
|
|
39
|
-
query({
|
|
40
|
-
tag: 'iq',
|
|
41
|
-
attrs: {
|
|
42
|
-
id: generateMessageTag(),
|
|
43
|
-
type: 'get',
|
|
44
|
-
xmlns: 'w:mex',
|
|
45
|
-
to: S_WHATSAPP_NET,
|
|
46
|
-
},
|
|
47
|
-
content: [
|
|
48
|
-
{
|
|
49
|
-
tag: 'query',
|
|
50
|
-
attrs: { query_id },
|
|
51
|
-
content: encoder.encode(JSON.stringify({
|
|
52
|
-
variables: {
|
|
53
|
-
'newsletter_id': jid,
|
|
54
|
-
...content
|
|
55
|
-
}
|
|
56
|
-
}))
|
|
57
|
-
}
|
|
58
|
-
]
|
|
59
|
-
})
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
//delete auto join channel
|
|
63
|
-
|
|
64
|
-
const parseFetchedUpdates = async (node, type) => {
|
|
65
|
-
let child;
|
|
66
|
-
if (type === 'messages')
|
|
67
|
-
child = getBinaryNodeChild(node, 'messages');
|
|
68
|
-
else {
|
|
69
|
-
const parent = getBinaryNodeChild(node, 'message_updates');
|
|
70
|
-
child = getBinaryNodeChild(parent, 'messages');
|
|
71
|
-
}
|
|
72
|
-
return await Promise.all(getAllBinaryNodeChildren(child).map(async (messageNode) => {
|
|
73
|
-
messageNode.attrs.from = child?.attrs.jid;
|
|
74
|
-
const views = parseInt(getBinaryNodeChild(messageNode, 'views_count')?.attrs?.count || '0');
|
|
75
|
-
const reactionNode = getBinaryNodeChild(messageNode, 'reactions');
|
|
76
|
-
const reactions = getBinaryNodeChildren(reactionNode, 'reaction')
|
|
77
|
-
.map(({ attrs }) => ({ count: +attrs.count, code: attrs.code }));
|
|
78
|
-
const data = {
|
|
79
|
-
'server_id': messageNode.attrs.server_id,
|
|
80
|
-
views,
|
|
81
|
-
reactions
|
|
82
|
-
};
|
|
83
|
-
if (type === 'messages') {
|
|
84
|
-
const { fullMessage: message, decrypt } = await decryptMessageNode(messageNode, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, config.logger);
|
|
85
|
-
await decrypt();
|
|
86
|
-
data.message = message;
|
|
87
|
-
}
|
|
88
|
-
return data;
|
|
89
|
-
}));
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
return {
|
|
93
|
-
...sock,
|
|
94
|
-
subscribeNewsletterUpdates: async (jid) => {
|
|
95
|
-
const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }]);
|
|
96
|
-
return getBinaryNodeChild(result, 'live_updates')?.attrs;
|
|
97
|
-
},
|
|
98
|
-
newsletterReactionMode: async (jid, mode) => {
|
|
99
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
100
|
-
updates: { settings: { reaction_codes: { value: mode } } }
|
|
101
|
-
});
|
|
102
|
-
},
|
|
103
|
-
newsletterUpdateDescription: async (jid, description) => {
|
|
104
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
105
|
-
updates: { description: description || '', settings: null }
|
|
106
|
-
});
|
|
107
|
-
},
|
|
108
|
-
newsletterUpdateName: async (jid, name) => {
|
|
109
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
110
|
-
updates: { name, settings: null }
|
|
111
|
-
});
|
|
112
|
-
},
|
|
113
|
-
newsletterUpdatePicture: async (jid, content) => {
|
|
114
|
-
const { img } = await generateProfilePicture(content);
|
|
115
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
116
|
-
updates: { picture: img.toString('base64'), settings: null }
|
|
117
|
-
});
|
|
118
|
-
},
|
|
119
|
-
newsletterRemovePicture: async (jid) => {
|
|
120
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
121
|
-
updates: { picture: '', settings: null }
|
|
122
|
-
});
|
|
123
|
-
},
|
|
124
|
-
newsletterUnfollow: async (jid) => {
|
|
125
|
-
await newsletterWMexQuery(jid, QueryIds.UNFOLLOW);
|
|
126
|
-
},
|
|
127
|
-
newsletterFollow: async (jid) => {
|
|
128
|
-
await newsletterWMexQuery(jid, QueryIds.FOLLOW);
|
|
129
|
-
},
|
|
130
|
-
newsletterUnmute: async (jid) => {
|
|
131
|
-
await newsletterWMexQuery(jid, QueryIds.UNMUTE);
|
|
132
|
-
},
|
|
133
|
-
newsletterMute: async (jid) => {
|
|
134
|
-
await newsletterWMexQuery(jid, QueryIds.MUTE);
|
|
135
|
-
},
|
|
136
|
-
newsletterCreate: async (name, description, picture) => {
|
|
137
|
-
await query({
|
|
138
|
-
tag: 'iq',
|
|
139
|
-
attrs: {
|
|
140
|
-
to: S_WHATSAPP_NET,
|
|
141
|
-
xmlns: 'tos',
|
|
142
|
-
id: generateMessageTag(),
|
|
143
|
-
type: 'set'
|
|
144
|
-
},
|
|
145
|
-
content: [
|
|
146
|
-
{
|
|
147
|
-
tag: 'notice',
|
|
148
|
-
attrs: {
|
|
149
|
-
id: '20601218',
|
|
150
|
-
stage: '5'
|
|
151
|
-
},
|
|
152
|
-
content: []
|
|
153
|
-
}
|
|
154
|
-
]
|
|
155
|
-
});
|
|
156
|
-
const result = await newsletterWMexQuery(undefined, QueryIds.CREATE, {
|
|
157
|
-
input: {
|
|
158
|
-
name,
|
|
159
|
-
description: description ?? null,
|
|
160
|
-
picture: picture ? (await generateProfilePicture(picture)).img.toString('base64') : null,
|
|
161
|
-
settings: null
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
return extractNewsletterMetadata(result, true);
|
|
165
|
-
},
|
|
166
|
-
newsletterMetadata: async (type, key, role) => {
|
|
167
|
-
const result = await newsletterWMexQuery(undefined, QueryIds.METADATA, {
|
|
168
|
-
input: {
|
|
169
|
-
key,
|
|
170
|
-
type: type.toUpperCase(),
|
|
171
|
-
view_role: role || 'GUEST'
|
|
172
|
-
},
|
|
173
|
-
fetch_viewer_metadata: true,
|
|
174
|
-
fetch_full_image: true,
|
|
175
|
-
fetch_creation_time: true
|
|
176
|
-
});
|
|
177
|
-
return extractNewsletterMetadata(result);
|
|
178
|
-
},
|
|
179
|
-
newsletterAdminCount: async (jid) => {
|
|
180
|
-
const result = await newsletterWMexQuery(jid, QueryIds.ADMIN_COUNT);
|
|
181
|
-
const buff = getBinaryNodeChild(result, 'result')?.content?.toString();
|
|
182
|
-
return JSON.parse(buff).data[XWAPaths.ADMIN_COUNT].admin_count;
|
|
183
|
-
},
|
|
184
|
-
/**user is Lid, not Jid */
|
|
185
|
-
newsletterChangeOwner: async (jid, user) => {
|
|
186
|
-
await newsletterWMexQuery(jid, QueryIds.CHANGE_OWNER, {
|
|
187
|
-
user_id: user
|
|
188
|
-
});
|
|
189
|
-
},
|
|
190
|
-
/**user is Lid, not Jid */
|
|
191
|
-
newsletterDemote: async (jid, user) => {
|
|
192
|
-
await newsletterWMexQuery(jid, QueryIds.DEMOTE, {
|
|
193
|
-
user_id: user
|
|
194
|
-
});
|
|
195
|
-
},
|
|
196
|
-
newsletterDelete: async (jid) => {
|
|
197
|
-
await newsletterWMexQuery(jid, QueryIds.DELETE);
|
|
198
|
-
},
|
|
199
|
-
/**if code wasn't passed, the reaction will be removed (if is reacted) */
|
|
200
|
-
newsletterReactMessage: async (jid, server_id, code) => {
|
|
201
|
-
await query({
|
|
202
|
-
tag: 'message',
|
|
203
|
-
attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', server_id, id: generateMessageID() },
|
|
204
|
-
content: [{
|
|
205
|
-
tag: 'reaction',
|
|
206
|
-
attrs: code ? { code } : {}
|
|
207
|
-
}]
|
|
208
|
-
});
|
|
209
|
-
},
|
|
210
|
-
newsletterFetchMessages: async (type, key, count, after) => {
|
|
211
|
-
const afterStr = after?.toString();
|
|
212
|
-
const result = await newsletterQuery(S_WHATSAPP_NET, 'get', [
|
|
213
|
-
{
|
|
214
|
-
tag: 'messages',
|
|
215
|
-
attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after: afterStr || '100' }
|
|
216
|
-
}
|
|
217
|
-
]);
|
|
218
|
-
return await parseFetchedUpdates(result, 'messages');
|
|
219
|
-
},
|
|
220
|
-
newsletterFetchUpdates: async (jid, count, after, since) => {
|
|
221
|
-
const result = await newsletterQuery(jid, 'get', [
|
|
222
|
-
{
|
|
223
|
-
tag: 'message_updates',
|
|
224
|
-
attrs: { count: count.toString(), after: after?.toString() || '100', since: since?.toString() || '0' }
|
|
225
|
-
}
|
|
226
|
-
]);
|
|
227
|
-
return await parseFetchedUpdates(result, 'updates');
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
export const extractNewsletterMetadata = (node, isCreate) => {
|
|
233
|
-
const result = getBinaryNodeChild(node, 'result')?.content?.toString();
|
|
234
|
-
const metadataPath = JSON.parse(result).data[isCreate ? XWAPaths.CREATE : XWAPaths.NEWSLETTER];
|
|
235
|
-
const metadata = {
|
|
236
|
-
id: metadataPath.id,
|
|
237
|
-
state: metadataPath.state.type,
|
|
238
|
-
creation_time: +metadataPath.thread_metadata.creation_time,
|
|
239
|
-
name: metadataPath.thread_metadata.name.text,
|
|
240
|
-
nameTime: +metadataPath.thread_metadata.name.update_time,
|
|
241
|
-
description: metadataPath.thread_metadata.description.text,
|
|
242
|
-
descriptionTime: +metadataPath.thread_metadata.description.update_time,
|
|
243
|
-
invite: metadataPath.thread_metadata.invite,
|
|
244
|
-
handle: metadataPath.thread_metadata.handle,
|
|
245
|
-
picture: metadataPath.thread_metadata.picture?.direct_path || null,
|
|
246
|
-
preview: metadataPath.thread_metadata.preview?.direct_path || null,
|
|
247
|
-
reaction_codes: metadataPath.thread_metadata.settings.reaction_codes.value,
|
|
248
|
-
subscribers: +metadataPath.thread_metadata.subscribers_count,
|
|
249
|
-
verification: metadataPath.thread_metadata.verification,
|
|
250
|
-
viewer_metadata: metadataPath.viewer_metadata
|
|
251
|
-
};
|
|
252
|
-
return metadata;
|
|
253
|
-
};
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.mobileRegisterFetch = exports.mobileRegisterEncrypt = exports.mobileRegister = exports.mobileRegisterExists = exports.mobileRegisterCode = exports.registrationParams = exports.makeRegistrationSocket = void 0;
|
|
7
|
-
/* eslint-disable camelcase */
|
|
8
|
-
const axios_1 = __importDefault(require("axios"));
|
|
9
|
-
const Defaults_1 = require("../Defaults");
|
|
10
|
-
const crypto_1 = require("../Utils/crypto");
|
|
11
|
-
const WABinary_1 = require("../WABinary");
|
|
12
|
-
const business_1 = require("./business");
|
|
13
|
-
const community_1 = require("./community");
|
|
14
|
-
function urlencode(str) {
|
|
15
|
-
return str.replace(/-/g, '%2d').replace(/_/g, '%5f').replace(/~/g, '%7e');
|
|
16
|
-
}
|
|
17
|
-
const validRegistrationOptions = (config) => (config === null || config === void 0 ? void 0 : config.phoneNumberCountryCode) &&
|
|
18
|
-
config.phoneNumberNationalNumber &&
|
|
19
|
-
config.phoneNumberMobileCountryCode;
|
|
20
|
-
const makeRegistrationSocket = (config) => {
|
|
21
|
-
const sock = (0, community_1.makeCommunitiesSocket)(config);
|
|
22
|
-
const register = async (code) => {
|
|
23
|
-
if (!validRegistrationOptions(config.auth.creds.registration)) {
|
|
24
|
-
throw new Error('please specify the registration options');
|
|
25
|
-
}
|
|
26
|
-
const result = await mobileRegister({ ...sock.authState.creds, ...sock.authState.creds.registration, code }, config.options);
|
|
27
|
-
sock.authState.creds.me = {
|
|
28
|
-
id: (0, WABinary_1.jidEncode)(result.login, 's.whatsapp.net'),
|
|
29
|
-
name: '~'
|
|
30
|
-
};
|
|
31
|
-
sock.authState.creds.registered = true;
|
|
32
|
-
sock.ev.emit('creds.update', sock.authState.creds);
|
|
33
|
-
return result;
|
|
34
|
-
};
|
|
35
|
-
const requestRegistrationCode = async (registrationOptions) => {
|
|
36
|
-
registrationOptions = registrationOptions || config.auth.creds.registration;
|
|
37
|
-
if (!validRegistrationOptions(registrationOptions)) {
|
|
38
|
-
throw new Error('Invalid registration options');
|
|
39
|
-
}
|
|
40
|
-
sock.authState.creds.registration = registrationOptions;
|
|
41
|
-
sock.ev.emit('creds.update', sock.authState.creds);
|
|
42
|
-
return mobileRegisterCode({ ...config.auth.creds, ...registrationOptions }, config.options);
|
|
43
|
-
};
|
|
44
|
-
return {
|
|
45
|
-
...sock,
|
|
46
|
-
register,
|
|
47
|
-
requestRegistrationCode,
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
exports.makeRegistrationSocket = makeRegistrationSocket;
|
|
51
|
-
function convertBufferToUrlHex(buffer) {
|
|
52
|
-
var id = '';
|
|
53
|
-
buffer.forEach((x) => {
|
|
54
|
-
// encode random identity_id buffer as percentage url encoding
|
|
55
|
-
id += `%${x.toString(16).padStart(2, '0').toLowerCase()}`;
|
|
56
|
-
});
|
|
57
|
-
return id;
|
|
58
|
-
}
|
|
59
|
-
function registrationParams(params) {
|
|
60
|
-
const e_regid = Buffer.alloc(4);
|
|
61
|
-
e_regid.writeInt32BE(params.registrationId);
|
|
62
|
-
const e_skey_id = Buffer.alloc(3);
|
|
63
|
-
e_skey_id.writeInt16BE(params.signedPreKey.keyId);
|
|
64
|
-
params.phoneNumberCountryCode = params.phoneNumberCountryCode.replace('+', '').trim();
|
|
65
|
-
params.phoneNumberNationalNumber = params.phoneNumberNationalNumber.replace(/[/-\s)(]/g, '').trim();
|
|
66
|
-
return {
|
|
67
|
-
cc: params.phoneNumberCountryCode,
|
|
68
|
-
in: params.phoneNumberNationalNumber,
|
|
69
|
-
Rc: '0',
|
|
70
|
-
lg: 'en',
|
|
71
|
-
lc: 'GB',
|
|
72
|
-
mistyped: '6',
|
|
73
|
-
authkey: Buffer.from(params.noiseKey.public).toString('base64url'),
|
|
74
|
-
e_regid: e_regid.toString('base64url'),
|
|
75
|
-
e_keytype: 'BQ',
|
|
76
|
-
e_ident: Buffer.from(params.signedIdentityKey.public).toString('base64url'),
|
|
77
|
-
// e_skey_id: e_skey_id.toString('base64url'),
|
|
78
|
-
e_skey_id: 'AAAA',
|
|
79
|
-
e_skey_val: Buffer.from(params.signedPreKey.keyPair.public).toString('base64url'),
|
|
80
|
-
e_skey_sig: Buffer.from(params.signedPreKey.signature).toString('base64url'),
|
|
81
|
-
fdid: params.phoneId,
|
|
82
|
-
network_ratio_type: '1',
|
|
83
|
-
expid: params.deviceId,
|
|
84
|
-
simnum: '1',
|
|
85
|
-
hasinrc: '1',
|
|
86
|
-
pid: Math.floor(Math.random() * 1000).toString(),
|
|
87
|
-
id: convertBufferToUrlHex(params.identityId),
|
|
88
|
-
backup_token: convertBufferToUrlHex(params.backupToken),
|
|
89
|
-
token: (0, crypto_1.md5)(Buffer.concat([Defaults_1.MOBILE_TOKEN, Buffer.from(params.phoneNumberNationalNumber)])).toString('hex'),
|
|
90
|
-
fraud_checkpoint_code: params.captcha,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
exports.registrationParams = registrationParams;
|
|
94
|
-
/**
|
|
95
|
-
* Requests a registration code for the given phone number.
|
|
96
|
-
*/
|
|
97
|
-
function mobileRegisterCode(params, fetchOptions) {
|
|
98
|
-
return mobileRegisterFetch('/code', {
|
|
99
|
-
params: {
|
|
100
|
-
...registrationParams(params),
|
|
101
|
-
mcc: `${params.phoneNumberMobileCountryCode}`.padStart(3, '0'),
|
|
102
|
-
mnc: `${params.phoneNumberMobileNetworkCode || '001'}`.padStart(3, '0'),
|
|
103
|
-
sim_mcc: '000',
|
|
104
|
-
sim_mnc: '000',
|
|
105
|
-
method: (params === null || params === void 0 ? void 0 : params.method) || 'sms',
|
|
106
|
-
reason: '',
|
|
107
|
-
hasav: '1'
|
|
108
|
-
},
|
|
109
|
-
...fetchOptions,
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
exports.mobileRegisterCode = mobileRegisterCode;
|
|
113
|
-
function mobileRegisterExists(params, fetchOptions) {
|
|
114
|
-
return mobileRegisterFetch('/exist', {
|
|
115
|
-
params: registrationParams(params),
|
|
116
|
-
...fetchOptions
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
exports.mobileRegisterExists = mobileRegisterExists;
|
|
120
|
-
/**
|
|
121
|
-
* Registers the phone number on whatsapp with the received OTP code.
|
|
122
|
-
*/
|
|
123
|
-
async function mobileRegister(params, fetchOptions) {
|
|
124
|
-
//const result = await mobileRegisterFetch(`/reg_onboard_abprop?cc=${params.phoneNumberCountryCode}&in=${params.phoneNumberNationalNumber}&rc=0`)
|
|
125
|
-
return mobileRegisterFetch('/register', {
|
|
126
|
-
params: { ...registrationParams(params), code: params.code.replace('-', '') },
|
|
127
|
-
...fetchOptions,
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
exports.mobileRegister = mobileRegister;
|
|
131
|
-
/**
|
|
132
|
-
* Encrypts the given string as AEAD aes-256-gcm with the public whatsapp key and a random keypair.
|
|
133
|
-
*/
|
|
134
|
-
function mobileRegisterEncrypt(data) {
|
|
135
|
-
const keypair = crypto_1.Curve.generateKeyPair();
|
|
136
|
-
const key = crypto_1.Curve.sharedKey(keypair.private, Defaults_1.REGISTRATION_PUBLIC_KEY);
|
|
137
|
-
const buffer = (0, crypto_1.aesEncryptGCM)(Buffer.from(data), new Uint8Array(key), Buffer.alloc(12), Buffer.alloc(0));
|
|
138
|
-
return Buffer.concat([Buffer.from(keypair.public), buffer]).toString('base64url');
|
|
139
|
-
}
|
|
140
|
-
exports.mobileRegisterEncrypt = mobileRegisterEncrypt;
|
|
141
|
-
async function mobileRegisterFetch(path, opts = {}) {
|
|
142
|
-
let url = `${Defaults_1.MOBILE_REGISTRATION_ENDPOINT}${path}`;
|
|
143
|
-
if (opts.params) {
|
|
144
|
-
const parameter = [];
|
|
145
|
-
for (const param in opts.params) {
|
|
146
|
-
if (opts.params[param] !== null && opts.params[param] !== undefined) {
|
|
147
|
-
parameter.push(param + '=' + urlencode(opts.params[param]));
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
url += `?${parameter.join('&')}`;
|
|
151
|
-
delete opts.params;
|
|
152
|
-
}
|
|
153
|
-
if (!opts.headers) {
|
|
154
|
-
opts.headers = {};
|
|
155
|
-
}
|
|
156
|
-
opts.headers['User-Agent'] = Defaults_1.MOBILE_USERAGENT;
|
|
157
|
-
const response = await (0, axios_1.default)(url, opts);
|
|
158
|
-
var json = response.data;
|
|
159
|
-
if (response.status > 300 || json.reason) {
|
|
160
|
-
throw json;
|
|
161
|
-
}
|
|
162
|
-
if (json.status && !['ok', 'sent'].includes(json.status)) {
|
|
163
|
-
throw json;
|
|
164
|
-
}
|
|
165
|
-
return json;
|
|
166
|
-
}
|
|
167
|
-
exports.mobileRegisterFetch = mobileRegisterFetch;
|