@badzz88/baileys 8.3.0 → 8.4.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/README.md +27 -27
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +6902 -0
- package/WAProto/fix-import.js +29 -0
- package/WAProto/fix-imports.js +85 -0
- package/WAProto/index.d.ts +79257 -0
- package/WAProto/index.js +204305 -131020
- package/engine-requirements.js +3 -4
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +119 -136
- package/lib/Signal/Group/ciphertext-message.js +2 -5
- package/lib/Signal/Group/group-session-builder.js +7 -41
- package/lib/Signal/Group/group_cipher.js +37 -51
- package/lib/Signal/Group/index.js +12 -57
- package/lib/Signal/Group/keyhelper.js +7 -44
- package/lib/Signal/Group/sender-chain-key.js +7 -15
- package/lib/Signal/Group/sender-key-distribution-message.js +8 -11
- package/lib/Signal/Group/sender-key-message.js +9 -12
- package/lib/Signal/Group/sender-key-name.js +2 -5
- package/lib/Signal/Group/sender-key-record.js +9 -21
- package/lib/Signal/Group/sender-key-state.js +27 -42
- package/lib/Signal/Group/sender-message-key.js +4 -7
- package/lib/Signal/libsignal.js +347 -90
- package/lib/Signal/lid-mapping.js +277 -0
- package/lib/Socket/Client/index.js +3 -19
- package/lib/Socket/Client/types.js +11 -0
- package/lib/Socket/Client/websocket.js +54 -0
- package/lib/Socket/business.js +162 -43
- package/lib/Socket/chats.js +627 -404
- package/lib/Socket/communities.js +431 -0
- package/lib/Socket/community.js +392 -0
- package/lib/Socket/dugong.js +161 -8
- package/lib/Socket/groups.js +154 -160
- package/lib/Socket/index.js +11 -10
- package/lib/Socket/luxu.js +387 -0
- package/lib/Socket/messages-recv.js +1421 -615
- package/lib/Socket/messages-send.js +1150 -624
- package/lib/Socket/mex.js +42 -0
- package/lib/Socket/newsletter.js +139 -314
- package/lib/Socket/registration.js +2 -1
- package/lib/Socket/socket.js +544 -242
- package/lib/Store/index.js +10 -10
- package/lib/Store/keyed-db.js +108 -0
- package/lib/Store/make-cache-manager-store.js +43 -41
- package/lib/Store/make-in-memory-store.js +112 -341
- package/lib/Store/make-ordered-dictionary.js +14 -20
- package/lib/Store/object-repository.js +11 -6
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.js +8 -4
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.js +3 -5
- package/lib/Types/LabelAssociation.js +3 -5
- package/lib/Types/Message.js +11 -9
- package/lib/Types/Mex.js +37 -0
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.js +3 -2
- package/lib/Types/State.js +56 -2
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.js +15 -31
- package/lib/Utils/auth-utils.js +239 -143
- package/lib/Utils/browser-utils.js +48 -0
- package/lib/Utils/business.js +66 -69
- package/lib/Utils/chat-utils.js +396 -253
- package/lib/Utils/companion-reg-client-utils.js +35 -0
- package/lib/Utils/crypto.js +57 -90
- package/lib/Utils/decode-wa-message.js +236 -84
- package/lib/Utils/event-buffer.js +185 -77
- package/lib/Utils/generics.js +188 -283
- package/lib/Utils/history.js +93 -55
- package/lib/Utils/identity-change-handler.js +50 -0
- package/lib/Utils/index.js +23 -33
- package/lib/Utils/link-preview.js +16 -24
- package/lib/Utils/logger.js +3 -7
- package/lib/Utils/lt-hash.js +3 -46
- package/lib/Utils/make-mutex.js +24 -34
- package/lib/Utils/message-composer.js +273 -0
- package/lib/Utils/message-retry-manager.js +265 -0
- package/lib/Utils/messages-media.js +451 -482
- package/lib/Utils/messages.js +796 -359
- package/lib/Utils/noise-handler.js +145 -99
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/pre-key-manager.js +106 -0
- package/lib/Utils/process-message.js +459 -150
- package/lib/Utils/reporting-utils.js +258 -0
- package/lib/Utils/signal.js +120 -72
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/sync-action-utils.js +49 -0
- package/lib/Utils/tc-token-utils.js +163 -0
- package/lib/Utils/use-multi-file-auth-state.js +29 -27
- package/lib/Utils/validate-connection.js +73 -99
- package/lib/WABinary/constants.js +1281 -20
- package/lib/WABinary/decode.js +52 -42
- package/lib/WABinary/encode.js +110 -155
- package/lib/WABinary/generic-utils.js +55 -49
- package/lib/WABinary/index.js +6 -21
- package/lib/WABinary/jid-utils.js +76 -40
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +2 -5
- package/lib/WAM/constants.js +19071 -11568
- package/lib/WAM/encode.js +17 -22
- package/lib/WAM/index.js +4 -19
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +33 -13
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +11 -14
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +9 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +9 -13
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +20 -22
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +13 -8
- package/lib/WAUSync/Protocols/index.js +6 -20
- package/lib/WAUSync/USyncQuery.js +44 -35
- package/lib/WAUSync/USyncUser.js +10 -5
- package/lib/WAUSync/index.js +4 -19
- package/lib/index.js +39 -53
- package/package.json +134 -101
- package/lib/Defaults/index.d.ts +0 -53
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
- package/lib/Signal/Group/group-session-builder.d.ts +0 -14
- package/lib/Signal/Group/group_cipher.d.ts +0 -17
- package/lib/Signal/Group/index.d.ts +0 -11
- package/lib/Signal/Group/keyhelper.d.ts +0 -10
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/sender-chain-key.d.ts +0 -13
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -16
- package/lib/Signal/Group/sender-key-message.d.ts +0 -18
- package/lib/Signal/Group/sender-key-name.d.ts +0 -17
- package/lib/Signal/Group/sender-key-record.d.ts +0 -30
- package/lib/Signal/Group/sender-key-state.d.ts +0 -38
- package/lib/Signal/Group/sender-message-key.d.ts +0 -11
- package/lib/Signal/libsignal.d.ts +0 -3
- package/lib/Socket/Client/abstract-socket-client.d.ts +0 -17
- package/lib/Socket/Client/index.d.ts +0 -3
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
- package/lib/Socket/Client/web-socket-client.d.ts +0 -12
- package/lib/Socket/business.d.ts +0 -171
- package/lib/Socket/chats.d.ts +0 -267
- package/lib/Socket/dugong.d.ts +0 -254
- package/lib/Socket/groups.d.ts +0 -115
- package/lib/Socket/index.d.ts +0 -173
- package/lib/Socket/messages-recv.d.ts +0 -161
- package/lib/Socket/messages-send.d.ts +0 -149
- package/lib/Socket/newsletter.d.ts +0 -134
- package/lib/Socket/registration.d.ts +0 -267
- package/lib/Socket/socket.d.ts +0 -43
- package/lib/Socket/usync.d.ts +0 -36
- package/lib/Store/index.d.ts +0 -3
- package/lib/Store/make-cache-manager-store.d.ts +0 -13
- package/lib/Store/make-in-memory-store.d.ts +0 -118
- package/lib/Store/make-ordered-dictionary.d.ts +0 -13
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Types/Auth.d.ts +0 -110
- package/lib/Types/Call.d.ts +0 -13
- package/lib/Types/Chat.d.ts +0 -102
- package/lib/Types/Contact.d.ts +0 -19
- package/lib/Types/Events.d.ts +0 -157
- package/lib/Types/GroupMetadata.d.ts +0 -55
- package/lib/Types/Label.d.ts +0 -35
- package/lib/Types/LabelAssociation.d.ts +0 -29
- package/lib/Types/Message.d.ts +0 -273
- package/lib/Types/Newsletter.d.ts +0 -103
- package/lib/Types/Product.d.ts +0 -78
- package/lib/Types/Signal.d.ts +0 -57
- package/lib/Types/Socket.d.ts +0 -111
- package/lib/Types/State.d.ts +0 -27
- package/lib/Types/USync.d.ts +0 -25
- package/lib/Types/index.d.ts +0 -57
- package/lib/Utils/auth-utils.d.ts +0 -18
- package/lib/Utils/baileys-event-stream.d.ts +0 -16
- package/lib/Utils/business.d.ts +0 -22
- package/lib/Utils/chat-utils.d.ts +0 -71
- package/lib/Utils/crypto.d.ts +0 -41
- package/lib/Utils/decode-wa-message.d.ts +0 -19
- package/lib/Utils/event-buffer.d.ts +0 -35
- package/lib/Utils/generics.d.ts +0 -92
- package/lib/Utils/history.d.ts +0 -15
- package/lib/Utils/index.d.ts +0 -17
- package/lib/Utils/link-preview.d.ts +0 -21
- package/lib/Utils/logger.d.ts +0 -4
- package/lib/Utils/lt-hash.d.ts +0 -12
- package/lib/Utils/make-mutex.d.ts +0 -7
- package/lib/Utils/messages-media.d.ts +0 -116
- package/lib/Utils/messages.d.ts +0 -77
- package/lib/Utils/noise-handler.d.ts +0 -21
- package/lib/Utils/process-message.d.ts +0 -41
- package/lib/Utils/signal.d.ts +0 -32
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
- package/lib/Utils/validate-connection.d.ts +0 -11
- package/lib/WABinary/constants.d.ts +0 -30
- package/lib/WABinary/decode.d.ts +0 -7
- package/lib/WABinary/encode.d.ts +0 -3
- package/lib/WABinary/generic-utils.d.ts +0 -17
- package/lib/WABinary/index.d.ts +0 -5
- package/lib/WABinary/jid-utils.d.ts +0 -31
- package/lib/WABinary/types.d.ts +0 -18
- package/lib/WAM/BinaryInfo.d.ts +0 -17
- package/lib/WAM/constants.d.ts +0 -38
- package/lib/WAM/encode.d.ts +0 -3
- package/lib/WAM/index.d.ts +0 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -25
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -8
- package/lib/WAUSync/Protocols/index.d.ts +0 -4
- package/lib/WAUSync/USyncQuery.d.ts +0 -28
- package/lib/WAUSync/USyncUser.d.ts +0 -12
- package/lib/WAUSync/index.d.ts +0 -3
- package/lib/index.d.ts +0 -12
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeCommunitiesSocket = exports.extractCommunityMetadata = void 0;
|
|
4
|
+
const { proto } = require("../../WAProto");
|
|
5
|
+
const { WAMessageStubType, WAMessageAddressingMode } = require("../Types");
|
|
6
|
+
const { generateMessageID, unixTimestampSeconds } = require("../Utils");
|
|
7
|
+
const {
|
|
8
|
+
getBinaryNodeChild,
|
|
9
|
+
getBinaryNodeChildren,
|
|
10
|
+
getBinaryNodeChildString,
|
|
11
|
+
jidEncode,
|
|
12
|
+
jidNormalizedUser,
|
|
13
|
+
} = require("../WABinary");
|
|
14
|
+
const { makeBusinessSocket } = require("./business");
|
|
15
|
+
const makeCommunitiesSocket = (config) => {
|
|
16
|
+
const conn = makeBusinessSocket(config);
|
|
17
|
+
const { authState, ev, query, groupMetadata, upsertMessage, cleanDirtyBits } = conn;
|
|
18
|
+
const communityQuery = async (jid, type, content) => query({
|
|
19
|
+
tag: 'iq',
|
|
20
|
+
attrs: { type, xmlns: 'w:g2', to: jid },
|
|
21
|
+
content
|
|
22
|
+
});
|
|
23
|
+
const communityMetadata = async (jid) => {
|
|
24
|
+
const result = await communityQuery(jid, 'get', [
|
|
25
|
+
{ tag: 'query', attrs: { request: 'interactive' } }
|
|
26
|
+
]);
|
|
27
|
+
return extractCommunityMetadata(result);
|
|
28
|
+
};
|
|
29
|
+
const communityFetchAllParticipating = async () => {
|
|
30
|
+
const result = await query({
|
|
31
|
+
tag: 'iq',
|
|
32
|
+
attrs: { to: '@g.us', xmlns: 'w:g2', type: 'get' },
|
|
33
|
+
content: [
|
|
34
|
+
{
|
|
35
|
+
tag: 'participating',
|
|
36
|
+
attrs: {},
|
|
37
|
+
content: [
|
|
38
|
+
{ tag: 'participants', attrs: {} },
|
|
39
|
+
{ tag: 'description', attrs: {} }
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
});
|
|
44
|
+
const data = {};
|
|
45
|
+
const communitiesChild = getBinaryNodeChild(result, 'communities');
|
|
46
|
+
if (communitiesChild) {
|
|
47
|
+
const communities = getBinaryNodeChildren(communitiesChild, 'community');
|
|
48
|
+
for (const communityNode of communities) {
|
|
49
|
+
const meta = extractCommunityMetadata({
|
|
50
|
+
tag: 'result',
|
|
51
|
+
attrs: {},
|
|
52
|
+
content: [communityNode]
|
|
53
|
+
});
|
|
54
|
+
data[meta.id] = meta;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
conn.ev.emit('groups.update', Object.values(data));
|
|
58
|
+
return data;
|
|
59
|
+
};
|
|
60
|
+
async function parseGroupResult(node) {
|
|
61
|
+
var _a;
|
|
62
|
+
(_a = conn.logger) === null || _a === void 0 ? void 0 : _a.info({ node }, 'parseGroupResult');
|
|
63
|
+
const groupNode = getBinaryNodeChild(node, 'group');
|
|
64
|
+
if (groupNode) {
|
|
65
|
+
try {
|
|
66
|
+
const metadata = await groupMetadata(`${groupNode.attrs.id}@g.us`);
|
|
67
|
+
return metadata || null;
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
var _b;
|
|
71
|
+
(_b = conn.logger) === null || _b === void 0 ? void 0 : _b.warn({ error }, 'Error parsing group metadata');
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
conn.ws.on('CB:ib,,dirty', async (node) => {
|
|
78
|
+
const { attrs } = getBinaryNodeChild(node, 'dirty');
|
|
79
|
+
if (attrs.type !== 'communities') {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
await communityFetchAllParticipating();
|
|
83
|
+
await cleanDirtyBits('groups');
|
|
84
|
+
});
|
|
85
|
+
return {
|
|
86
|
+
...conn,
|
|
87
|
+
communityQuery,
|
|
88
|
+
communityMetadata,
|
|
89
|
+
communityCreate: async (subject, body) => {
|
|
90
|
+
const descriptionId = generateMessageID().substring(0, 12);
|
|
91
|
+
const result = await communityQuery('@g.us', 'set', [
|
|
92
|
+
{
|
|
93
|
+
tag: 'create',
|
|
94
|
+
attrs: { subject },
|
|
95
|
+
content: [
|
|
96
|
+
{
|
|
97
|
+
tag: 'description',
|
|
98
|
+
attrs: { id: descriptionId },
|
|
99
|
+
content: [
|
|
100
|
+
{ tag: 'body', attrs: {}, content: Buffer.from(body || '', 'utf-8') }
|
|
101
|
+
]
|
|
102
|
+
},
|
|
103
|
+
{ tag: 'parent', attrs: { default_membership_approval_mode: 'request_required' } },
|
|
104
|
+
{ tag: 'allow_non_admin_sub_group_creation', attrs: {} },
|
|
105
|
+
{ tag: 'create_general_chat', attrs: {} }
|
|
106
|
+
]
|
|
107
|
+
}
|
|
108
|
+
]);
|
|
109
|
+
return await parseGroupResult(result);
|
|
110
|
+
},
|
|
111
|
+
communityCreateGroup: async (subject, participants, parentCommunityJid) => {
|
|
112
|
+
const key = generateMessageID();
|
|
113
|
+
const result = await communityQuery('@g.us', 'set', [
|
|
114
|
+
{
|
|
115
|
+
tag: 'create',
|
|
116
|
+
attrs: { subject, key },
|
|
117
|
+
content: [
|
|
118
|
+
...participants.map((jid) => ({ tag: 'participant', attrs: { jid } })),
|
|
119
|
+
{ tag: 'linked_parent', attrs: { jid: parentCommunityJid } }
|
|
120
|
+
]
|
|
121
|
+
}
|
|
122
|
+
]);
|
|
123
|
+
return await parseGroupResult(result);
|
|
124
|
+
},
|
|
125
|
+
communityLeave: async (id) => {
|
|
126
|
+
await communityQuery('@g.us', 'set', [
|
|
127
|
+
{ tag: 'leave', attrs: {}, content: [{ tag: 'community', attrs: { id } }] }
|
|
128
|
+
]);
|
|
129
|
+
},
|
|
130
|
+
communityUpdateSubject: async (jid, subject) => {
|
|
131
|
+
await communityQuery(jid, 'set', [
|
|
132
|
+
{ tag: 'subject', attrs: {}, content: Buffer.from(subject, 'utf-8') }
|
|
133
|
+
]);
|
|
134
|
+
},
|
|
135
|
+
communityLinkGroup: async (groupJid, parentCommunityJid) => {
|
|
136
|
+
await communityQuery(parentCommunityJid, 'set', [
|
|
137
|
+
{
|
|
138
|
+
tag: 'links',
|
|
139
|
+
attrs: {},
|
|
140
|
+
content: [
|
|
141
|
+
{
|
|
142
|
+
tag: 'link',
|
|
143
|
+
attrs: { link_type: 'sub_group' },
|
|
144
|
+
content: [{ tag: 'group', attrs: { jid: groupJid } }]
|
|
145
|
+
}
|
|
146
|
+
]
|
|
147
|
+
}
|
|
148
|
+
]);
|
|
149
|
+
},
|
|
150
|
+
communityUnlinkGroup: async (groupJid, parentCommunityJid) => {
|
|
151
|
+
await communityQuery(parentCommunityJid, 'set', [
|
|
152
|
+
{
|
|
153
|
+
tag: 'unlink',
|
|
154
|
+
attrs: { unlink_type: 'sub_group' },
|
|
155
|
+
content: [{ tag: 'group', attrs: { jid: groupJid } }]
|
|
156
|
+
}
|
|
157
|
+
]);
|
|
158
|
+
},
|
|
159
|
+
communityFetchLinkedGroups: async (jid) => {
|
|
160
|
+
let communityJid = jid;
|
|
161
|
+
let isCommunity = false;
|
|
162
|
+
const metadata = await groupMetadata(jid);
|
|
163
|
+
if (metadata.linkedParent) {
|
|
164
|
+
communityJid = metadata.linkedParent;
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
isCommunity = true;
|
|
168
|
+
}
|
|
169
|
+
const result = await communityQuery(communityJid, 'get', [
|
|
170
|
+
{ tag: 'sub_groups', attrs: {} }
|
|
171
|
+
]);
|
|
172
|
+
const linkedGroupsData = [];
|
|
173
|
+
const subGroupsNode = getBinaryNodeChild(result, 'sub_groups');
|
|
174
|
+
if (subGroupsNode) {
|
|
175
|
+
const groupNodes = getBinaryNodeChildren(subGroupsNode, 'group');
|
|
176
|
+
for (const groupNode of groupNodes) {
|
|
177
|
+
linkedGroupsData.push({
|
|
178
|
+
id: groupNode.attrs.id ? jidEncode(groupNode.attrs.id, 'g.us') : undefined,
|
|
179
|
+
subject: groupNode.attrs.subject || '',
|
|
180
|
+
creation: groupNode.attrs.creation ? Number(groupNode.attrs.creation) : undefined,
|
|
181
|
+
owner: groupNode.attrs.creator ? jidNormalizedUser(groupNode.attrs.creator) : undefined,
|
|
182
|
+
size: groupNode.attrs.size ? Number(groupNode.attrs.size) : undefined
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return { communityJid, isCommunity, linkedGroups: linkedGroupsData };
|
|
187
|
+
},
|
|
188
|
+
communityRequestParticipantsList: async (jid) => {
|
|
189
|
+
const result = await communityQuery(jid, 'get', [
|
|
190
|
+
{ tag: 'membership_approval_requests', attrs: {} }
|
|
191
|
+
]);
|
|
192
|
+
const node = getBinaryNodeChild(result, 'membership_approval_requests');
|
|
193
|
+
const participants = getBinaryNodeChildren(node, 'membership_approval_request');
|
|
194
|
+
return participants.map((v) => v.attrs);
|
|
195
|
+
},
|
|
196
|
+
communityRequestParticipantsUpdate: async (jid, participants, action) => {
|
|
197
|
+
const result = await communityQuery(jid, 'set', [
|
|
198
|
+
{
|
|
199
|
+
tag: 'membership_requests_action',
|
|
200
|
+
attrs: {},
|
|
201
|
+
content: [
|
|
202
|
+
{
|
|
203
|
+
tag: action,
|
|
204
|
+
attrs: {},
|
|
205
|
+
content: participants.map((jid) => ({ tag: 'participant', attrs: { jid } }))
|
|
206
|
+
}
|
|
207
|
+
]
|
|
208
|
+
}
|
|
209
|
+
]);
|
|
210
|
+
const node = getBinaryNodeChild(result, 'membership_requests_action');
|
|
211
|
+
const nodeAction = getBinaryNodeChild(node, action);
|
|
212
|
+
const participantsAffected = getBinaryNodeChildren(nodeAction, 'participant');
|
|
213
|
+
return participantsAffected.map((p) => ({ status: p.attrs.error || '200', jid: p.attrs.jid }));
|
|
214
|
+
},
|
|
215
|
+
communityParticipantsUpdate: async (jid, participants, action) => {
|
|
216
|
+
const result = await communityQuery(jid, 'set', [
|
|
217
|
+
{
|
|
218
|
+
tag: action,
|
|
219
|
+
attrs: action === 'remove' ? { linked_groups: 'true' } : {},
|
|
220
|
+
content: participants.map((jid) => ({ tag: 'participant', attrs: { jid } }))
|
|
221
|
+
}
|
|
222
|
+
]);
|
|
223
|
+
const node = getBinaryNodeChild(result, action);
|
|
224
|
+
const participantsAffected = getBinaryNodeChildren(node, 'participant');
|
|
225
|
+
return participantsAffected.map((p) => ({ status: p.attrs.error || '200', jid: p.attrs.jid, content: p }));
|
|
226
|
+
},
|
|
227
|
+
communityUpdateDescription: async (jid, description) => {
|
|
228
|
+
var _a;
|
|
229
|
+
const metadata = await communityMetadata(jid);
|
|
230
|
+
const prev = (_a = metadata.descId) !== null && _a !== void 0 ? _a : null;
|
|
231
|
+
await communityQuery(jid, 'set', [
|
|
232
|
+
{
|
|
233
|
+
tag: 'description',
|
|
234
|
+
attrs: {
|
|
235
|
+
...(description ? { id: generateMessageID() } : { delete: 'true' }),
|
|
236
|
+
...(prev ? { prev } : {})
|
|
237
|
+
},
|
|
238
|
+
content: description
|
|
239
|
+
? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }]
|
|
240
|
+
: undefined
|
|
241
|
+
}
|
|
242
|
+
]);
|
|
243
|
+
},
|
|
244
|
+
communityInviteCode: async (jid) => {
|
|
245
|
+
var _a;
|
|
246
|
+
const result = await communityQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
|
|
247
|
+
const inviteNode = getBinaryNodeChild(result, 'invite');
|
|
248
|
+
return (_a = inviteNode === null || inviteNode === void 0 ? void 0 : inviteNode.attrs) === null || _a === void 0 ? void 0 : _a.code;
|
|
249
|
+
},
|
|
250
|
+
communityRevokeInvite: async (jid) => {
|
|
251
|
+
var _a;
|
|
252
|
+
const result = await communityQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
|
|
253
|
+
const inviteNode = getBinaryNodeChild(result, 'invite');
|
|
254
|
+
return (_a = inviteNode === null || inviteNode === void 0 ? void 0 : inviteNode.attrs) === null || _a === void 0 ? void 0 : _a.code;
|
|
255
|
+
},
|
|
256
|
+
communityAcceptInvite: async (code) => {
|
|
257
|
+
var _a;
|
|
258
|
+
const results = await communityQuery('@g.us', 'set', [
|
|
259
|
+
{ tag: 'invite', attrs: { code } }
|
|
260
|
+
]);
|
|
261
|
+
const result = getBinaryNodeChild(results, 'community');
|
|
262
|
+
return (_a = result === null || result === void 0 ? void 0 : result.attrs) === null || _a === void 0 ? void 0 : _a.jid;
|
|
263
|
+
},
|
|
264
|
+
communityRevokeInviteV4: async (communityJid, invitedJid) => {
|
|
265
|
+
const result = await communityQuery(communityJid, 'set', [
|
|
266
|
+
{
|
|
267
|
+
tag: 'revoke',
|
|
268
|
+
attrs: {},
|
|
269
|
+
content: [{ tag: 'participant', attrs: { jid: invitedJid } }]
|
|
270
|
+
}
|
|
271
|
+
]);
|
|
272
|
+
return !!result;
|
|
273
|
+
},
|
|
274
|
+
communityAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
|
|
275
|
+
var _a;
|
|
276
|
+
key = typeof key === 'string' ? { remoteJid: key } : key;
|
|
277
|
+
const results = await communityQuery(inviteMessage.groupJid, 'set', [
|
|
278
|
+
{
|
|
279
|
+
tag: 'accept',
|
|
280
|
+
attrs: {
|
|
281
|
+
code: inviteMessage.inviteCode,
|
|
282
|
+
expiration: inviteMessage.inviteExpiration.toString(),
|
|
283
|
+
admin: key.remoteJid
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
]);
|
|
287
|
+
if (key.id) {
|
|
288
|
+
inviteMessage = proto.Message.GroupInviteMessage.fromObject(inviteMessage);
|
|
289
|
+
inviteMessage.inviteExpiration = 0;
|
|
290
|
+
inviteMessage.inviteCode = '';
|
|
291
|
+
ev.emit('messages.update', [
|
|
292
|
+
{ key, update: { message: { groupInviteMessage: inviteMessage } } }
|
|
293
|
+
]);
|
|
294
|
+
}
|
|
295
|
+
await upsertMessage({
|
|
296
|
+
key: {
|
|
297
|
+
remoteJid: inviteMessage.groupJid,
|
|
298
|
+
id: generateMessageID((_a = conn.user) === null || _a === void 0 ? void 0 : _a.id),
|
|
299
|
+
fromMe: false,
|
|
300
|
+
participant: key.remoteJid
|
|
301
|
+
},
|
|
302
|
+
messageStubType: WAMessageStubType.GROUP_PARTICIPANT_ADD,
|
|
303
|
+
messageStubParameters: [JSON.stringify(authState.creds.me)],
|
|
304
|
+
participant: key.remoteJid,
|
|
305
|
+
messageTimestamp: unixTimestampSeconds()
|
|
306
|
+
}, 'notify');
|
|
307
|
+
return results.attrs.from;
|
|
308
|
+
}),
|
|
309
|
+
communityGetInviteInfo: async (code) => {
|
|
310
|
+
const results = await communityQuery('@g.us', 'get', [
|
|
311
|
+
{ tag: 'invite', attrs: { code } }
|
|
312
|
+
]);
|
|
313
|
+
return extractCommunityMetadata(results);
|
|
314
|
+
},
|
|
315
|
+
communityToggleEphemeral: async (jid, ephemeralExpiration) => {
|
|
316
|
+
const content = ephemeralExpiration
|
|
317
|
+
? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
|
|
318
|
+
: { tag: 'not_ephemeral', attrs: {} };
|
|
319
|
+
await communityQuery(jid, 'set', [content]);
|
|
320
|
+
},
|
|
321
|
+
communitySettingUpdate: async (jid, setting) => {
|
|
322
|
+
await communityQuery(jid, 'set', [{ tag: setting, attrs: {} }]);
|
|
323
|
+
},
|
|
324
|
+
communityMemberAddMode: async (jid, mode) => {
|
|
325
|
+
await communityQuery(jid, 'set', [
|
|
326
|
+
{ tag: 'member_add_mode', attrs: {}, content: mode }
|
|
327
|
+
]);
|
|
328
|
+
},
|
|
329
|
+
communityJoinApprovalMode: async (jid, mode) => {
|
|
330
|
+
await communityQuery(jid, 'set', [
|
|
331
|
+
{
|
|
332
|
+
tag: 'membership_approval_mode',
|
|
333
|
+
attrs: {},
|
|
334
|
+
content: [{ tag: 'community_join', attrs: { state: mode } }]
|
|
335
|
+
}
|
|
336
|
+
]);
|
|
337
|
+
},
|
|
338
|
+
communityFetchAllParticipating
|
|
339
|
+
};
|
|
340
|
+
};
|
|
341
|
+
exports.makeCommunitiesSocket = makeCommunitiesSocket;
|
|
342
|
+
const extractCommunityMetadata = (result) => {
|
|
343
|
+
var _a, _b, _c, _d, _e;
|
|
344
|
+
const community = getBinaryNodeChild(result, 'group');
|
|
345
|
+
const descChild = getBinaryNodeChild(community, 'description');
|
|
346
|
+
let desc;
|
|
347
|
+
let descId;
|
|
348
|
+
if (descChild) {
|
|
349
|
+
desc = getBinaryNodeChildString(descChild, 'body');
|
|
350
|
+
descId = descChild.attrs.id;
|
|
351
|
+
}
|
|
352
|
+
const mode = community.attrs.addressing_mode;
|
|
353
|
+
const communityId = community.attrs.id.includes('@')
|
|
354
|
+
? community.attrs.id
|
|
355
|
+
: jidEncode(community.attrs.id, 'g.us');
|
|
356
|
+
const eph = (_a = getBinaryNodeChild(community, 'ephemeral')) === null || _a === void 0 ? void 0 : _a.attrs.expiration;
|
|
357
|
+
const memberAddMode = getBinaryNodeChildString(community, 'member_add_mode') === 'all_member_add';
|
|
358
|
+
const metadata = {
|
|
359
|
+
id: communityId,
|
|
360
|
+
subject: community.attrs.subject,
|
|
361
|
+
subjectOwner: community.attrs.s_o,
|
|
362
|
+
subjectOwnerAlt: ((_b = community.attrs) === null || _b === void 0 ? void 0 : _b.s_o_pn) ? community.attrs.s_o_pn : community.attrs.s_o,
|
|
363
|
+
subjectTime: Number(community.attrs.s_t || 0),
|
|
364
|
+
size: Number((_c = community.attrs) === null || _c === void 0 ? void 0 : _c.size
|
|
365
|
+
? community.attrs.size
|
|
366
|
+
: getBinaryNodeChildren(community, 'participant').length),
|
|
367
|
+
creation: Number(community.attrs.creation || 0),
|
|
368
|
+
owner: community.attrs.creator ? jidNormalizedUser(community.attrs.creator) : undefined,
|
|
369
|
+
ownerAlt: community.attrs.creator
|
|
370
|
+
? jidNormalizedUser(((_d = community.attrs) === null || _d === void 0 ? void 0 : _d.creator_pn) ? community.attrs.creator_pn : community.attrs.creator)
|
|
371
|
+
: undefined,
|
|
372
|
+
ownerCountry: community.attrs.creator_country_code,
|
|
373
|
+
desc,
|
|
374
|
+
descId,
|
|
375
|
+
linkedParent: ((_e = getBinaryNodeChild(community, 'linked_parent')) === null || _e === void 0 ? void 0 : _e.attrs.jid) || undefined,
|
|
376
|
+
restrict: !!getBinaryNodeChild(community, 'locked'),
|
|
377
|
+
announce: !!getBinaryNodeChild(community, 'announcement'),
|
|
378
|
+
isCommunity: !!getBinaryNodeChild(community, 'parent'),
|
|
379
|
+
isCommunityAnnounce: !!getBinaryNodeChild(community, 'default_sub_group'),
|
|
380
|
+
joinApprovalMode: !!getBinaryNodeChild(community, 'membership_approval_mode'),
|
|
381
|
+
memberAddMode,
|
|
382
|
+
participants: getBinaryNodeChildren(community, 'participant').map(({ attrs }) => ({
|
|
383
|
+
id: mode === WAMessageAddressingMode.LID ? community.attrs.phone_number : attrs.jid,
|
|
384
|
+
lid: mode === WAMessageAddressingMode.LID ? community.attrs.jid : attrs.lid,
|
|
385
|
+
admin: attrs.type || null
|
|
386
|
+
})),
|
|
387
|
+
ephemeralDuration: eph ? Number(eph) : undefined,
|
|
388
|
+
addressingMode: mode
|
|
389
|
+
};
|
|
390
|
+
return metadata;
|
|
391
|
+
};
|
|
392
|
+
exports.extractCommunityMetadata = extractCommunityMetadata;
|
package/lib/Socket/dugong.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
// "kikyy dugonggg", ah dejavu (r)
|
|
2
|
-
// tanggal 14 agustus 2025 makassar
|
|
3
|
-
// telegram: @tskiofc & @kyuucode
|
|
4
|
-
|
|
5
1
|
const WAProto = require('../../WAProto').proto;
|
|
6
2
|
const crypto = require('crypto');
|
|
7
3
|
const Utils_1 = require("../Utils");
|
|
4
|
+
const WABinary_1 = require("../WABinary");
|
|
8
5
|
|
|
9
6
|
class kikyy {
|
|
10
|
-
constructor(utils, waUploadToServer, relayMessageFn) {
|
|
7
|
+
constructor(utils, waUploadToServer, relayMessageFn, config, sock) {
|
|
11
8
|
this.utils = utils;
|
|
12
|
-
this.relayMessage = relayMessageFn
|
|
9
|
+
this.relayMessage = relayMessageFn;
|
|
13
10
|
this.waUploadToServer = waUploadToServer;
|
|
11
|
+
this.config = config;
|
|
12
|
+
this.sock = sock;
|
|
14
13
|
|
|
15
14
|
this.bail = {
|
|
16
15
|
generateWAMessageContent: this.utils.generateWAMessageContent || Utils_1.generateWAMessageContent,
|
|
@@ -389,7 +388,7 @@ class kikyy {
|
|
|
389
388
|
remoteJid: "status@broadcast",
|
|
390
389
|
forwardedNewsletterMessageInfo: {
|
|
391
390
|
newsletterName: "shenvn.",
|
|
392
|
-
newsletterJid: "
|
|
391
|
+
newsletterJid: "120363430179804706@newsletter",
|
|
393
392
|
serverMessageId: 1
|
|
394
393
|
}
|
|
395
394
|
},
|
|
@@ -479,6 +478,160 @@ class kikyy {
|
|
|
479
478
|
messageId: this.bail.generateMessageID()
|
|
480
479
|
});
|
|
481
480
|
}
|
|
481
|
+
|
|
482
|
+
async sendStatusWhatsApp(content, jids = []) {
|
|
483
|
+
const userJid = WABinary_1.jidNormalizedUser(this.sock.authState.creds.me.id);
|
|
484
|
+
let allUsers = new Set();
|
|
485
|
+
allUsers.add(userJid);
|
|
486
|
+
|
|
487
|
+
for (const id of jids) {
|
|
488
|
+
const isGroup = WABinary_1.isJidGroup(id);
|
|
489
|
+
const isPrivate = WABinary_1.isJidUser(id);
|
|
490
|
+
|
|
491
|
+
if (isGroup) {
|
|
492
|
+
try {
|
|
493
|
+
const metadata = await this.sock.groupMetadata(id);
|
|
494
|
+
const participants = metadata.participants.map(p => WABinary_1.jidNormalizedUser(p.id));
|
|
495
|
+
participants.forEach(jid => allUsers.add(jid));
|
|
496
|
+
} catch (error) {
|
|
497
|
+
this.config.logger.error(`Error getting metadata for group ${id}: ${error}`);
|
|
498
|
+
}
|
|
499
|
+
} else if (isPrivate) {
|
|
500
|
+
allUsers.add(WABinary_1.jidNormalizedUser(id));
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
const uniqueUsers = Array.from(allUsers);
|
|
505
|
+
const getRandomHexColor = () => "#" + Math.floor(Math.random() * 16777215).toString(16).padStart(6, "0");
|
|
506
|
+
|
|
507
|
+
const isMedia = content.image || content.video || content.audio;
|
|
508
|
+
const isAudio = !!content.audio;
|
|
509
|
+
|
|
510
|
+
const messageContent = { ...content };
|
|
511
|
+
|
|
512
|
+
if (isMedia && !isAudio) {
|
|
513
|
+
if (messageContent.text) {
|
|
514
|
+
messageContent.caption = messageContent.text;
|
|
515
|
+
delete messageContent.text;
|
|
516
|
+
}
|
|
517
|
+
delete messageContent.ptt;
|
|
518
|
+
delete messageContent.font;
|
|
519
|
+
delete messageContent.backgroundColor;
|
|
520
|
+
delete messageContent.textColor;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
if (isAudio) {
|
|
524
|
+
delete messageContent.text;
|
|
525
|
+
delete messageContent.caption;
|
|
526
|
+
delete messageContent.font;
|
|
527
|
+
delete messageContent.textColor;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
const font = !isMedia ? (content.font || Math.floor(Math.random() * 9)) : undefined;
|
|
531
|
+
const textColor = !isMedia ? (content.textColor || getRandomHexColor()) : undefined;
|
|
532
|
+
const backgroundColor = (!isMedia || isAudio) ? (content.backgroundColor || getRandomHexColor()) : undefined;
|
|
533
|
+
const ptt = isAudio ? (typeof content.ptt === 'boolean' ? content.ptt : true) : undefined;
|
|
534
|
+
|
|
535
|
+
let msg;
|
|
536
|
+
let mediaHandle;
|
|
537
|
+
|
|
538
|
+
try {
|
|
539
|
+
const link_preview_1 = require("../Utils/link-preview");
|
|
540
|
+
|
|
541
|
+
msg = await Utils_1.generateWAMessage(WABinary_1.STORIES_JID, messageContent, {
|
|
542
|
+
logger: this.config.logger,
|
|
543
|
+
userJid,
|
|
544
|
+
getUrlInfo: text => link_preview_1.getUrlInfo(text, {
|
|
545
|
+
thumbnailWidth: this.config.linkPreviewImageThumbnailWidth,
|
|
546
|
+
fetchOpts: { timeout: 3000, ...this.config.options || {} },
|
|
547
|
+
logger: this.config.logger,
|
|
548
|
+
uploadImage: this.config.generateHighQualityLinkPreview ? this.waUploadToServer : undefined
|
|
549
|
+
}),
|
|
550
|
+
upload: async (encFilePath, opts) => {
|
|
551
|
+
const up = await this.waUploadToServer(encFilePath, { ...opts });
|
|
552
|
+
mediaHandle = up.handle;
|
|
553
|
+
return up;
|
|
554
|
+
},
|
|
555
|
+
mediaCache: this.config.mediaCache,
|
|
556
|
+
options: this.config.options,
|
|
557
|
+
font,
|
|
558
|
+
textColor,
|
|
559
|
+
backgroundColor,
|
|
560
|
+
ptt
|
|
561
|
+
});
|
|
562
|
+
} catch (error) {
|
|
563
|
+
this.config.logger.error(`Error generating message: ${error}`);
|
|
564
|
+
throw error;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
await this.relayMessage(WABinary_1.STORIES_JID, msg.message, {
|
|
568
|
+
messageId: msg.key.id,
|
|
569
|
+
statusJidList: uniqueUsers,
|
|
570
|
+
additionalNodes: [
|
|
571
|
+
{
|
|
572
|
+
tag: 'meta',
|
|
573
|
+
attrs: {},
|
|
574
|
+
content: [
|
|
575
|
+
{
|
|
576
|
+
tag: 'mentioned_users',
|
|
577
|
+
attrs: {},
|
|
578
|
+
content: jids.map(jid => ({
|
|
579
|
+
tag: 'to',
|
|
580
|
+
attrs: { jid: WABinary_1.jidNormalizedUser(jid) }
|
|
581
|
+
}))
|
|
582
|
+
}
|
|
583
|
+
]
|
|
584
|
+
}
|
|
585
|
+
]
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
for (const id of jids) {
|
|
589
|
+
try {
|
|
590
|
+
const normalizedId = WABinary_1.jidNormalizedUser(id);
|
|
591
|
+
const isPrivate = WABinary_1.isJidUser(normalizedId);
|
|
592
|
+
const type = isPrivate ? 'statusMentionMessage' : 'groupStatusMentionMessage';
|
|
593
|
+
|
|
594
|
+
const protocolMessage = {
|
|
595
|
+
[type]: {
|
|
596
|
+
message: {
|
|
597
|
+
protocolMessage: {
|
|
598
|
+
key: msg.key,
|
|
599
|
+
type: 25
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
},
|
|
603
|
+
messageContextInfo: {
|
|
604
|
+
messageSecret: crypto.randomBytes(32)
|
|
605
|
+
}
|
|
606
|
+
};
|
|
607
|
+
|
|
608
|
+
const statusMsg = await Utils_1.generateWAMessageFromContent(
|
|
609
|
+
normalizedId,
|
|
610
|
+
protocolMessage,
|
|
611
|
+
{}
|
|
612
|
+
);
|
|
613
|
+
|
|
614
|
+
await this.relayMessage(
|
|
615
|
+
normalizedId,
|
|
616
|
+
statusMsg.message,
|
|
617
|
+
{
|
|
618
|
+
additionalNodes: [{
|
|
619
|
+
tag: 'meta',
|
|
620
|
+
attrs: isPrivate ?
|
|
621
|
+
{ is_status_mention: 'true' } :
|
|
622
|
+
{ is_group_status_mention: 'true' }
|
|
623
|
+
}]
|
|
624
|
+
}
|
|
625
|
+
);
|
|
626
|
+
|
|
627
|
+
await Utils_1.delay(2000);
|
|
628
|
+
} catch (error) {
|
|
629
|
+
this.config.logger.error(`Error sending to ${id}: ${error}`);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
return msg;
|
|
634
|
+
}
|
|
482
635
|
}
|
|
483
636
|
|
|
484
|
-
module.exports = kikyy;
|
|
637
|
+
module.exports = kikyy;
|